List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
From source file:Api.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww. ja v a 2s . c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("Content-Type: text/javascript"); PrintWriter out = response.getWriter(); // Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("Config.xml"); try { //Se parcea el archivo xml para crear el documento //que se va a tratar. Document documento = (Document) builder.build(xmlFile); // Se obtiene la raiz del documento. En este caso 'cruisecontrol' Element rootNode = documento.getRootElement(); // // Obtengo el tag "info" como nodo raiz para poder trabajar // // los tags de ste. // Element rootNode_Level2 = rootNode.getChild("info"); // // Obtengo los nodos "property" del tag info y los almaceno en // // una lista. // List<Element> lista = rootNode_Level2.getChildren("property"); // // //Imprimo por consola la lista. // for (int i = 0; i < lista.size(); i++) { // System.out.println(((Element) lista.get(i)).getAttributeValue("value")); // } // out.println("<!DOCTYPE html>"); Map<String, Object> actions = new LinkedHashMap<String, Object>(); for (Element action : rootNode.getChildren()) { ArrayList<Map> methods = new ArrayList<Map>(); for (Element method : action.getChildren()) { Map<String, Object> md = new LinkedHashMap<String, Object>(); if (method.getAttribute("len") != null) { md.put("name", method.getName()); md.put("len", method.getAttributeValue("len")); } else { md.put("name", method.getName()); md.put("params", method.getAttributeValue("params")); } if (method.getAttribute("formHandler") != null && method.getAttribute("formHandler") != null) { md.put("formHandler", true); } methods.add(md); } actions.put(action.getName(), methods); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } finally { out.close(); } }
From source file:AIR.ResourceBundler.Xml.FileSet.java
License:Open Source License
public void parse(Element resourcesEl) throws ResourcesException { Attribute fileSetAttrib = null; // parse main attributes fileSetAttrib = resourcesEl.getAttribute("name"); _name = (fileSetAttrib != null) ? fileSetAttrib.getValue() : null; fileSetAttrib = resourcesEl.getAttribute("output"); setOutput((fileSetAttrib != null) ? fileSetAttrib.getValue() : null); // parse setting attributes fileSetAttrib = resourcesEl.getAttribute("compress"); if (fileSetAttrib != null) _compress = (fileSetAttrib.getValue() == "true"); fileSetAttrib = resourcesEl.getAttribute("removeLines"); if (fileSetAttrib != null) _removeEmptyLines = (fileSetAttrib.getValue() == "true"); fileSetAttrib = resourcesEl.getAttribute("removeComments"); if (fileSetAttrib != null) _removeComments = (fileSetAttrib.getValue() == "true"); fileSetAttrib = resourcesEl.getAttribute("removeSpaces"); if (fileSetAttrib != null) removeSpaces = (fileSetAttrib.getValue() == "true"); for (Element childEl : resourcesEl.getChildren()) { String childName = childEl.getName(); if ("input".equalsIgnoreCase(childName)) { parseFileInput(childEl);/*w w w . j a v a 2 s .c o m*/ } else if ("reference".equalsIgnoreCase(childName)) { parseReference(childEl); } else if ("exclude".equalsIgnoreCase(childName)) { parseExclude(childEl); } else if ("replace".equalsIgnoreCase(childName)) { parseReplace(childEl); } } }
From source file:AIR.ResourceBundler.Xml.FileSet.java
License:Open Source License
private void parseReference(Element dependencyEl) throws ResourcesException { // lookup dependency Attribute setAttrib = dependencyEl.getAttribute("set"); String setName = (setAttrib != null) ? setAttrib.getValue() : null; // Replacing tts by tts2 if ("tts".equals(setName)) setName = "tts2"; // add files/*from w w w.j a v a 2 s. c om*/ FileSet fileSet = _parentResources.getFileSet(setName); if (fileSet != null) { _entries.add(fileSet); } }
From source file:AIR.ResourceBundler.Xml.FileSet.java
License:Open Source License
private void parseExclude(Element excludeEl) { Attribute setAttrib = excludeEl.getAttribute("set"); String setName = (setAttrib != null) ? setAttrib.getValue() : null; // add files/*from w w w .j a v a 2s .c om*/ FileSet fileSet = _parentResources.getFileSet(setName); if (fileSet != null) { _excludedSets.add(fileSet); } }
From source file:AIR.ResourceBundler.Xml.FileSet.java
License:Open Source License
private void parseReplace(Element replaceEl) { // get source fileset Attribute setAttrib = replaceEl.getAttribute("set"); String fileSetName = (setAttrib != null) ? setAttrib.getValue() : null; FileSet fileSet = _parentResources.getFileSet(fileSetName); // get desintation fileset Attribute newAttrib = replaceEl.getAttribute("new"); String newFileSetName = (newAttrib != null) ? newAttrib.getValue() : null; FileSet newFileSet = _parentResources.getFileSet(newFileSetName); _replaceSets.put(fileSet, newFileSet); }
From source file:AIR.ResourceBundler.Xml.FileSetInput.java
License:Open Source License
public void parse(Element fileEl) { // get file path setPath(_fileSet.resolveFile(fileEl.getValue())); Attribute attrib = null;/*from w w w.ja v a 2s.c om*/ attrib = fileEl.getAttribute("prepend"); _prepend = (attrib != null) ? attrib.getValue() : null; attrib = fileEl.getAttribute("append"); _append = (attrib != null) ? attrib.getValue() : null; }
From source file:AIR.ResourceBundler.Xml.Resources.java
License:Open Source License
private void parseRemove(Element excludeEl) { Attribute setAttrib = excludeEl.getAttribute("set"); String setName = (setAttrib != null) ? setAttrib.getValue() : null; // remove fileset globally if (!StringUtils.isEmpty(setName)) { _fileSets.remove(setName);//w w w . j a va2s . c o m } }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.FormulaConverter.java
License:Open Source License
/** * Replaces all formulas with the html representation of the mapped formula objects * * @param doc JDOM Document where to replace the formulas * @param formulaMap Map of the indexed Formula Objects * @return JDOM Document with replaced formulas *//*from w w w.ja v a 2 s .c o m*/ public Document replaceFormulas(Document doc, Map<Integer, Formula> formulaMap) { List<Element> foundFormulas = xpath.evaluate(doc); if (foundFormulas.size() > 0) { Map<String, Element> formulaMarkupMap = new HashMap<>(); // Initialize markup map for (Element element : foundFormulas) { formulaMarkupMap.put(element.getAttribute("id").getValue(), element); } // Replace all found formulas Iterator<Integer> formulaIterator = formulaMap.keySet().iterator(); while (formulaIterator.hasNext()) { Integer id = formulaIterator.next(); Element formulaMarkupRoot = formulaMarkupMap.get(FORMULA_ID_PREFIX + id); Formula formula = formulaMap.get(id); formulaMarkupRoot.removeAttribute("class"); formulaMarkupRoot.removeContent(); formulaMarkupRoot.setName("div"); Element div = (Element) formulaMarkupRoot.getParent(); div.setName("div"); div.setAttribute("class", "formula"); // Potentially there's text inside the paragraph... List<Text> texts = div.getContent(Filters.textOnly()); if (texts.isEmpty() == false) { String textString = ""; for (Text text : texts) { textString += text.getText(); } Element textSpan = new Element("span"); textSpan.setAttribute("class", "text"); textSpan.setText(textString); div.addContent(textSpan); List<Content> content = div.getContent(); content.removeAll(texts); } if (generateDebugMarkup) { div.setAttribute("style", "border: 1px solid black;"); // Header Element h4 = new Element("h4"); h4.setText("DEBUG - Formula #" + formula.getId()); div.addContent(h4); // Render LaTeX source Element latexPre = new Element("pre"); latexPre.setAttribute("class", "debug-latex"); latexPre.setText(formula.getLatexCode()); div.addContent(latexPre); // Render MathML markup Element mathmlPre = new Element("pre"); mathmlPre.setAttribute("class", "debug-mathml"); mathmlPre.setText(formula.getMathMl()); div.addContent(mathmlPre); // Render HTML Markup Element htmlPre = new Element("pre"); htmlPre.setAttribute("class", "debug-html"); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.setFormat(Format.getRawFormat()); htmlPre.setText(xmlOutputter.outputString(formula.getHtml())); div.addContent(htmlPre); } // Set formula into formulaMarkupRoot.addContent(formula.getHtml()); } } return doc; }
From source file:at.newmedialab.lmf.search.services.cores.SolrCoreServiceImpl.java
License:Apache License
/** * Create/update the solrconfig.xml file for the given core according to the core configuration. * * @param engine the solr core configuration *//*ww w.jav a 2 s . c om*/ private void createSolrConfigXml(SolrCoreConfiguration engine) throws MarmottaException { File configTemplate = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "solrconfig-template.xml"); File configFile = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "solrconfig.xml"); try { SAXBuilder parser = new SAXBuilder(XMLReaders.NONVALIDATING); Document solrConfig = parser.build(configTemplate); FileOutputStream out = new FileOutputStream(configFile); // Configure suggestion service: add fields to suggestion handler Program<Value> program = engine.getProgram(); for (Element handler : solrConfig.getRootElement().getChildren("requestHandler")) { if (handler.getAttribute("class").getValue().equals(SuggestionRequestHandler.class.getName())) { for (Element lst : handler.getChildren("lst")) { if (lst.getAttribute("name").getValue().equals("defaults")) { //set suggestion fields for (FieldMapping<?, Value> fieldMapping : program.getFields()) { String fieldName = fieldMapping.getFieldName(); final Map<String, String> fieldConfig = fieldMapping.getFieldConfig(); if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_SUGGESTION_FIELD_OPTION)) { String suggestionType = fieldConfig.get(SOLR_SUGGESTION_FIELD_OPTION); if (suggestionType.equals("facet")) { Element field_elem = new Element("str"); field_elem.setAttribute("name", SuggestionRequestParams.SUGGESTION_FIELD); field_elem.setText(fieldName); lst.addContent(field_elem); } else { log.error("suggestionType " + suggestionType + " not supported"); } } } } } } } XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat().setIndent(" ")); xo.output(solrConfig, out); out.close(); } catch (JDOMException e) { throw new MarmottaException("parse error while parsing SOLR schema template file " + configTemplate, e); } catch (IOException e) { throw new MarmottaException("I/O error while parsing SOLR schema template file " + configTemplate, e); } }
From source file:ataraxis.passwordmanager.AccountSorter.java
License:Open Source License
/** * Compare first object with second./*w ww . jav a2 s . c o m*/ * The result my be: * <ul> * <li>-1 if first is group, second is not a group</li> * <li>1 if first is not a group but second is</li> * <li>any number of the String.compareTo()-Method if first and * second are from the same type</li> * </ul> * * @param first the first object * @param second the second object * @return the result of the comparison */ public int compare(Element first, Element second) { LOGGER.debug("compare(Object, Object) - start"); int result = 0; Element elm0 = (Element) first; Element elm1 = (Element) second; String elm0Type = elm0.getName(); String elm1Type = elm1.getName(); LOGGER.debug("element 0 is: " + elm0Type); LOGGER.debug("element 1 is: " + elm1Type); if (elm0Type.equals("group") && !elm1Type.equals("group")) { result = -1; } else if (!elm0Type.equals("group") && elm1Type.equals("group")) { result = 1; } else { result = (elm0.getAttribute("id").toString().toLowerCase()) .compareTo(elm1.getAttribute("id").toString().toLowerCase()); } LOGGER.debug("result is: " + result); LOGGER.debug("compare(Object, Object) - end"); return result; }