List of usage examples for org.jdom2 Element getName
public String getName()
From source file:Api.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w.jav a2s . c o m*/ * * @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:JDOMAdapterNode.java
License:Apache License
public String getName(int searchIndex) { Element child = (Element) node.getChildren().get(searchIndex); return child.getName(); }
From source file:AIR.Common.xml.XmlElement.java
License:Open Source License
public List<Element> getElementsByTagName(String name) { List<Element> list = new ArrayList<Element>(); if (!(_element instanceof Element)) return list; Iterator<Element> it = ((Element) _element).getDescendants(Filters.element()); while (it.hasNext()) { Element e = it.next(); if (e.getName().equals(name)) { list.add(e);/*from ww w . j av a2s. c om*/ } } return list; }
From source file:AIR.Common.xml.XmlReader.java
License:Open Source License
public String getName() throws XmlReaderException { Element e = getNodeAsElement(); if (e != null) return e.getName(); return null;//from w w w . jav a 2s. c o m }
From source file:AIR.Common.xml.XmlReader.java
License:Open Source License
private boolean readToDescendant(String item) throws XmlReaderException, IOException { MutablePair<Content, Integer> alwaysTop = null; if (_stack.size() > 0) { alwaysTop = _stack.peek();//from w w w .j ava2s. com } while (_stack.size() != 0) { MutablePair<Content, Integer> topElement = _stack.peek(); if (topElement.getLeft().getCType() == CType.Element) { Element topElementNode = (Element) topElement.getLeft(); if (StringUtils.equals(item, topElementNode.getName())) return true; int nextChild = topElement.getRight() + 1; if (topElementNode.getChildren().size() > nextChild) { topElement.setRight(nextChild); Element nextTraversalNode = topElementNode.getChildren().get(nextChild); _stack.push(new MutablePair<Content, Integer>(nextTraversalNode, -1)); } else { // we do not want to pop the original top node (alwaysTop) as we are // only doing descendant. if (!alwaysTop.equals(topElement)) _stack.pop(); else break; } } } return false; }
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);//from w ww .ja 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.Resources.java
License:Open Source License
public void parse() throws JDOMException, IOException, ResourcesException { SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(_configFile); Document document = (Document) builder.build(xmlFile); Element rootElement = document.getRootElement(); String attr = rootElement.getAttributeValue("name"); name = (attr != null) ? attr : null; for (Element childEl : rootElement.getChildren()) { String childName = childEl.getName(); if ("import".equalsIgnoreCase(childName)) { parseImport(childEl);/* w ww . j ava 2 s . c om*/ } else if ("fileSet".equalsIgnoreCase(childName)) { parseFileSet(childEl); } else if ("remove".equalsIgnoreCase(childName)) { parseRemove(childEl); } } }
From source file:amara.applications.ingame.entitysystem.templates.CustomSerializer_Ingame.java
public static void registerClasses() { BitstreamClassManager.getInstance().register(ArrayList.class, //physics/HitboxComponent Circle.class, Rectangle.class, RegularCyclic.class, Shape.class, ConvexShape.class, SimpleConvexPolygon.class, PointShape.class, Transform2D.class, Vector2D.class, PolygonShape.class, BoundRectangle.class, Polygon.class, SetPolygon.class, HolePolygon.class, SimplePolygon.class, //units/DamageHistoryComponent DamageHistoryComponent.DamageHistoryEntry.class); ComponentsRegistrator.registerComponents(); try {//from w w w . java 2s .c o m ComponentSerializer.registerFieldSerializer( new Field[] { Vector2f.class.getDeclaredField("x"), Vector2f.class.getDeclaredField("y") }, new FieldSerializer_Float(20, 8)); ComponentSerializer.registerFieldSerializer(new Field[] { Vector2D.class.getDeclaredField("x"), Vector2D.class.getDeclaredField("y"), Transform2D.class.getDeclaredField("scalecos"), Transform2D.class.getDeclaredField("scalesin"), Transform2D.class.getDeclaredField("x"), Transform2D.class.getDeclaredField("y"), Circle.class.getDeclaredField("localRadius"), }, new FieldSerializer_DoubleAsFloat(20, 8)); } catch (NoSuchFieldException ex) { ex.printStackTrace(); } XMLTemplateManager xmlTemplateManager = XMLTemplateManager.getInstance(); //effects/physics xmlTemplateManager .registerComponent(new XMLComponentConstructor<AddCollisionGroupsComponent>("addCollisionGroups") { @Override public AddCollisionGroupsComponent construct(EntityWorld entityWorld, Element element) { long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf")); long targets = getCollisionGroupBitMask(element.getAttributeValue("targets")); return new AddCollisionGroupsComponent(targetOf, targets); } }); xmlTemplateManager.registerComponent( new XMLComponentConstructor<RemoveCollisionGroupsComponent>("removeCollisionGroups") { @Override public RemoveCollisionGroupsComponent construct(EntityWorld entityWorld, Element element) { long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf")); long targets = getCollisionGroupBitMask(element.getAttributeValue("targets")); return new RemoveCollisionGroupsComponent(targetOf, targets); } }); //physics xmlTemplateManager.registerComponent(new XMLComponentConstructor<HitboxComponent>("hitbox") { @Override public HitboxComponent construct(EntityWorld entityWorld, Element element) { Shape shape = null; Element childElement = (Element) element.getChildren().get(0); String shapeType = childElement.getName(); double x = 0; String xText = childElement.getAttributeValue("x"); if (xText != null) { x = Double.parseDouble(xText); } double y = 0; String yText = childElement.getAttributeValue("y"); if (yText != null) { y = Double.parseDouble(yText); } if (shapeType.equals("regularCyclic")) { int edges = Integer.parseInt(childElement.getAttributeValue("edges")); double radius = Double.parseDouble(childElement.getAttributeValue("radius")); shape = new RegularCyclic(edges, radius); } else if (shapeType.equals("circle")) { double radius = Double.parseDouble(childElement.getAttributeValue("radius")); shape = new Circle(x, y, radius); } else if (shapeType.equals("rectangle")) { double width = Double.parseDouble(childElement.getAttributeValue("width")); double height = Double.parseDouble(childElement.getAttributeValue("height")); shape = new Rectangle(x, y, width, height); } else if (shapeType.equals("point")) { Vector2D localPoint = new Vector2D(); String[] positionCoordinates = element.getText().split(","); if (positionCoordinates.length > 1) { double localPointX = Double .parseDouble(xmlTemplateManager.parseValue(entityWorld, positionCoordinates[0])); double localPointY = Double .parseDouble(xmlTemplateManager.parseValue(entityWorld, positionCoordinates[1])); localPoint = new Vector2D(localPointX, localPointY); } shape = new PointShape(localPoint); } if (shape == null) { throw new UnsupportedOperationException("Unsupported shape type '" + shapeType + "'."); } return new HitboxComponent(shape); } }); //spawns xmlTemplateManager.registerComponent(new XMLComponentConstructor<SpawnTemplateComponent>("spawnTemplate") { @Override public SpawnTemplateComponent construct(EntityWorld entityWorld, Element element) { String[] templates = element.getText().split("\\|"); for (int i = 0; i < templates.length; i++) { templates[i] = xmlTemplateManager.parseTemplate(entityWorld, templates[i]); } return new SpawnTemplateComponent(templates); } }); //spells xmlTemplateManager.registerComponent(new XMLComponentConstructor<CastTypeComponent>("castType") { @Override public CastTypeComponent construct(EntityWorld entityWorld, Element element) { return new CastTypeComponent(CastTypeComponent.CastType.valueOf(element.getText().toUpperCase())); } }); //units xmlTemplateManager .registerComponent(new XMLComponentConstructor<CollisionGroupComponent>("collisionGroup") { @Override public CollisionGroupComponent construct(EntityWorld entityWorld, Element element) { long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf")); long targets = getCollisionGroupBitMask(element.getAttributeValue("targets")); return new CollisionGroupComponent(targetOf, targets); } }); xmlTemplateManager .registerComponent(new XMLComponentConstructor<HealthBarStyleComponent>("healthBarStyle") { @Override public HealthBarStyleComponent construct(EntityWorld entityWorld, Element element) { return new HealthBarStyleComponent( HealthBarStyleComponent.HealthBarStyle.valueOf(element.getText().toUpperCase())); } }); }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.DOMFormulaConverter.java
License:Open Source License
@Override public Formula parse(int id, String latexFormula) { Formula formula = super.parseToMathML(id, latexFormula); // Generate output Element div = new Element("div"); Element html = new Element("div"); html.setAttribute("class", "math"); if (formula.isInvalid() == false) { SAXBuilder builder = new SAXBuilder(); try {/*from www . j a v a 2 s .c o m*/ Document mathml = builder.build(new StringReader(formula.getMathMl())); Element root = mathml.getRootElement(); if (root.getChildren().isEmpty()) { return null; } Iterator<Element> it = root.getChildren().iterator(); while (it.hasNext()) { Element cur = it.next(); FormulaElement formulaElement = renderElement(cur); if (formulaElement != null) { Element resultHtml = formulaElement.render(null, null); if (resultHtml != null) { html.addContent(resultHtml); } else { logger.debug("HTML is NULL: " + cur.getName()); } } } } catch (JDOMException e) { logger.error("Error parsing generated MathML:"); logger.error(formula.getMathMl()); logger.error(e.getMessage(), e); } catch (IOException e) { logger.error("Error reading generated MathML:"); logger.error(formula.getMathMl()); logger.error(e.getMessage(), e); } } else { html.addContent(renderInvalidFormulaSource(formula)); } div.addContent(html); formula.setHtml(div); return formula; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.DOMFormulaConverter.java
License:Open Source License
/** * Recursive function to render all FormulaElements * Converts MathML to HTML/*from w w w .j a v a2 s . com*/ * * @param cur the current processed MathML JDOM2 Element (a node or leaf inside MathML's DOM tree) * @return an object which implements the FormulaElement interface, so it can be rendered to HTML */ private FormulaElement renderElement(Element cur) { String name = cur.getName(); String mathvariant = null; FormulaElement output; // Based on the MathML tag a corresponding class will be chosen and output will be rendered switch (name.toLowerCase()) { // Superscripts case "msup": Msup msup = new Msup(); msup.setBase(renderElement(cur.getChildren().get(0))); msup.setSuperscript(renderElement(cur.getChildren().get(1))); output = msup; break; // Subscripts case "msub": Msub msub = new Msub(); msub.setBase(renderElement(cur.getChildren().get(0))); msub.setSubscript(renderElement(cur.getChildren().get(1))); output = msub; break; // Subscript-superscript Pairs case "msubsup": Msubsup msubsup = new Msubsup(); msubsup.setBase(renderElement(cur.getChildren().get(0))); msubsup.setSubscript(renderElement(cur.getChildren().get(1))); msubsup.setSuperscript(renderElement(cur.getChildren().get(2))); output = msubsup; break; // Rows case "mrow": Mrow mrow = new Mrow(); Iterator<Element> iterator = cur.getChildren().iterator(); while (iterator.hasNext()) { Element element = iterator.next(); FormulaElement rowElement = renderElement(element); mrow.addElement(rowElement); } output = mrow; break; // operators case "mo": Mo mo; String operator = cur.getText(); // find operator in dictionary mo = MathmlCharacterDictionary.findOperator(operator, cur.getAttributeValue("form", "infix")); if (mo == null) { mo = new Mo(); mo.setValue(operator); // Parse attributes mo.setAccent(Boolean.parseBoolean(cur.getAttributeValue("accent", "false"))); mo.setSeparator(Boolean.parseBoolean(cur.getAttributeValue("separator", "false"))); mo.setFence(Boolean.parseBoolean(cur.getAttributeValue("fence", "false"))); mo.setMovablelimits(Boolean.parseBoolean(cur.getAttributeValue("movablelimits", "false"))); mo.setLargeop(Boolean.parseBoolean(cur.getAttributeValue("largeop", "false"))); mo.setStretchy(Boolean.parseBoolean(cur.getAttributeValue("stretchy", "false"))); mo.setLspace(Unit.parse(cur.getAttributeValue("lspace", "thickmathspace"))); mo.setRspace(Unit.parse(cur.getAttributeValue("rspace", "thickmathspace"))); mo.setMinsize(Unit.parse(cur.getAttributeValue("minsize"))); mo.setMaxsize(Unit.parse(cur.getAttributeValue("maxsize"))); } output = mo; break; // numbers case "mn": Mn mn = new Mn(); mn.setValue(cur.getText()); output = mn; break; // identifiers case "mi": Mi mi = new Mi(); mi.setValue(cur.getText()); mathvariant = cur.getAttributeValue("mathvariant"); if (mathvariant != null && mathvariant.isEmpty() == false) { mi.setMathvariant(mathvariant); mathvariant = null; } output = mi; break; // fractions case "mfrac": Mfrac mfrac = new Mfrac(); mfrac.setNumerator(renderElement(cur.getChildren().get(0))); mfrac.setDenominator(renderElement(cur.getChildren().get(1))); String linethickness = cur.getAttributeValue("linethickness"); if (linethickness != null) { mfrac.setLinethickness(linethickness); } output = mfrac; break; // Expression Inside Pair of Fences case "mfenced": Mfenced mfenced = new Mfenced(); mfenced.setOpened(cur.getAttributeValue("open")); mfenced.setClosed(cur.getAttributeValue("close")); mfenced.setSeparators(cur.getAttributeValue("separators")); List<Element> children = cur.getChildren(); if (children.isEmpty() == false) { List<FormulaElement> renderedChildren = new ArrayList<>(); for (Element child : children) { FormulaElement renderedChild = renderElement(child); renderedChildren.add(renderedChild); } mfenced.setContent(renderedChildren); } output = mfenced; break; // Space case "mspace": Mspace mspace = new Mspace(); // Parse attributes String widthAttribute = cur.getAttributeValue("width"); if (widthAttribute != null) { mspace.setWidth(Unit.parse(widthAttribute)); } String heightAttribute = cur.getAttributeValue("height"); if (heightAttribute != null) { mspace.setHeight(Unit.parse(heightAttribute)); } // linebreaks will be ignored for now output = mspace; break; // Square root case "msqrt": Mroot msqrt = new Mroot(); msqrt.setBase(renderElement(cur.getChildren().get(0))); // no index output = msqrt; break; // Root case "mroot": Mroot mroot = new Mroot(); mroot.setBase(renderElement(cur.getChildren().get(0))); mroot.setDegree(renderElement(cur.getChildren().get(1))); output = mroot; break; // String literal case "ms": Ms ms = new Ms(); ms.setValue(cur.getText()); output = ms; break; // Text case "mtext": Mtext mtext = new Mtext(); mtext.setValue(cur.getText()); output = mtext; break; // Style change case "mstyle": Mstyle mstyle = new Mstyle(); mathvariant = cur.getAttributeValue("mathvariant"); if (mathvariant != null && mathvariant.isEmpty() == false) { mstyle.setStyle(mathvariant); mathvariant = null; } Iterator<Element> mstyleIterator = cur.getChildren().iterator(); while (mstyleIterator.hasNext()) { mstyle.addBaseElement(renderElement(mstyleIterator.next())); } output = mstyle; break; // Overscript case "mover": Mover mover = new Mover(); mover.setBase(renderElement(cur.getChildren().get(0))); mover.setOverscript(renderElement(cur.getChildren().get(1))); output = mover; break; // Underscript case "munder": Munder munder = new Munder(); munder.setBase(renderElement(cur.getChildren().get(0))); munder.setUnderscript(renderElement(cur.getChildren().get(1))); output = munder; break; // Matrices & tables case "mtable": Mtable mtable = new Mtable(); Iterator<Element> mRowIterator = cur.getChildren().iterator(); while (mRowIterator.hasNext()) { Mtr mtr = (Mtr) renderElement(mRowIterator.next()); mtable.getRows().add(mtr); } output = mtable; break; // Table rows case "mtr": Mtr mtr = new Mtr(); Iterator<Element> mCellIterator = cur.getChildren().iterator(); while (mCellIterator.hasNext()) { Mtd mtd = (Mtd) renderElement(mCellIterator.next()); mtr.getTds().add(mtd); } output = mtr; break; // Table cells case "mtd": Mtd mtd = new Mtd(); Mrow tdContent = new Mrow(); Iterator<Element> mContentIterator = cur.getChildren().iterator(); while (mContentIterator.hasNext()) { tdContent.addElement(renderElement(mContentIterator.next())); } mtd.setContent(tdContent); output = mtd; break; default: logger.info("MathML conversion of element <" + cur.getName() + "> NOT YET IMPLEMENTED"); output = null; break; } return output; }