List of usage examples for org.dom4j Element elements
List<Element> elements();
From source file:com.jswiff.xml.TagXMLReader.java
License:Open Source License
private static Tag readDefineFontInfo2(Element tagElement) { int fontId = RecordXMLReader.getIntAttribute("fontid", tagElement); String fontName = getStringAttribute("fontname", tagElement); List charElements = tagElement.elements(); int arrayLength = charElements.size(); char[] codeTable = new char[arrayLength]; for (int i = 0; i < arrayLength; i++) { Element charElement = (Element) charElements.get(i); codeTable[i] = charElement.getText().charAt(0); }//from w w w.ja va 2s.c om DefineFontInfo2 defineFontInfo2 = new DefineFontInfo2(fontId, fontName, codeTable, readLangCode(tagElement)); if (RecordXMLReader.getBooleanAttribute("bold", tagElement)) { defineFontInfo2.setBold(true); } if (RecordXMLReader.getBooleanAttribute("italic", tagElement)) { defineFontInfo2.setItalic(true); } if (RecordXMLReader.getBooleanAttribute("smalltext", tagElement)) { defineFontInfo2.setSmallText(true); } return defineFontInfo2; }
From source file:com.jswiff.xml.TagXMLReader.java
License:Open Source License
private static Tag readDefineSprite(Element tagElement) { int characterId = RecordXMLReader.getCharacterId(tagElement); List controlTagElements = tagElement.elements(); DefineSprite defineSprite = new DefineSprite(characterId); for (Iterator it = controlTagElements.iterator(); it.hasNext();) { Element controlTagElement = (Element) it.next(); Tag tag;//w w w . ja v a 2 s. c o m String tagName = controlTagElement.getName(); if (tagName.equals("showframe")) { tag = readShowFrame(controlTagElement); } else if (tagName.equals("placeobject")) { tag = readPlaceObject(controlTagElement); } else if (tagName.equals("placeobject2")) { tag = readPlaceObject2(controlTagElement); } else if (tagName.equals("placeobject3")) { tag = readPlaceObject3(controlTagElement); } else if (tagName.equals("removeobject")) { tag = readRemoveObject(controlTagElement); } else if (tagName.equals("removeobject2")) { tag = readRemoveObject2(controlTagElement); } else if (tagName.equals("startsound")) { tag = readStartSound(controlTagElement); } else if (tagName.equals("framelabel")) { tag = readFrameLabel(controlTagElement); } else if (tagName.equals("soundstreamhead")) { tag = readSoundStreamHead(controlTagElement); } else if (tagName.equals("soundstreamhead2")) { tag = readSoundStreamHead2(controlTagElement); } else if (tagName.equals("soundstreamblock")) { tag = readSoundStreamBlock(controlTagElement); } else if (tagName.equals("doaction")) { tag = readDoAction(controlTagElement); } else if (tagName.equals("doinitaction")) { tag = readDoInitAction(controlTagElement); } else if (tagName.equals("settabindex")) { tag = readSetTabIndex(controlTagElement); } else if (tagName.equals("videoframe")) { tag = readVideoFrame(controlTagElement); } else if (tagName.equals("unknowntag")) { tag = readUnknownTag(controlTagElement); } else if (tagName.equals("malformedtag")) { tag = readMalformedTag(controlTagElement); } else { throw new IllegalArgumentException(tagName + " tag not expected within definesprite!"); } defineSprite.addControlTag(tag); } return defineSprite; }
From source file:com.jswiff.xml.TagXMLReader.java
License:Open Source License
private static Tag readExportAssets(Element tagElement) { List mappingElements = tagElement.elements(); int arrayLength = mappingElements.size(); ExportAssets.ExportMapping[] mappings = new ExportAssets.ExportMapping[arrayLength]; for (int i = 0; i < arrayLength; i++) { Element mappingElement = (Element) mappingElements.get(i); mappings[i] = new ExportAssets.ExportMapping(RecordXMLReader.getIntAttribute("charid", mappingElement), getStringAttribute("name", mappingElement)); }//from w w w . j av a 2 s. c om return new ExportAssets(mappings); }
From source file:com.jswiff.xml.TagXMLReader.java
License:Open Source License
private static Tag readImportAssets(Element tagElement) { List mappingElements = tagElement.elements(); String url = getStringAttribute("url", tagElement); int arrayLength = mappingElements.size(); ImportAssets.ImportMapping[] mappings = new ImportAssets.ImportMapping[arrayLength]; for (int i = 0; i < arrayLength; i++) { Element mappingElement = (Element) mappingElements.get(i); mappings[i] = new ImportAssets.ImportMapping(getStringAttribute("name", mappingElement), RecordXMLReader.getIntAttribute("charid", mappingElement)); }//ww w. j a v a 2s . c om return new ImportAssets(url, mappings); }
From source file:com.jswiff.xml.TagXMLReader.java
License:Open Source License
private static Tag readImportAssets2(Element tagElement) { List mappingElements = tagElement.elements(); String url = getStringAttribute("url", tagElement); int arrayLength = mappingElements.size(); ImportAssets2.ImportMapping[] mappings = new ImportAssets2.ImportMapping[arrayLength]; for (int i = 0; i < arrayLength; i++) { Element mappingElement = (Element) mappingElements.get(i); mappings[i] = new ImportAssets2.ImportMapping(getStringAttribute("name", mappingElement), RecordXMLReader.getIntAttribute("charid", mappingElement)); }//from w w w . j a v a2s. c om return new ImportAssets2(url, mappings); }
From source file:com.liferay.alloy.tools.builder.faces.FacesBuilder.java
License:Open Source License
private void _buildTaglibXMLFile(List<Component> components, Map<String, Object> context) throws Exception { context.put("components", components); context.put("version", PropsUtil.getString("builder.faces.version")); for (Document doc : getComponentDefinitionDocs()) { Element root = doc.getRootElement(); Element descriptionElement = root.element("description"); String description = null; if (descriptionElement != null) { description = descriptionElement.getTextTrim(); }/* ww w .j a v a 2 s. c o m*/ context.put("description", description); Element extensionElement = root.element("extension"); if (extensionElement != null) { List<Element> extensionElements = extensionElement.elements(); context.put("extensionElements", extensionElements); } String taglibXMLContent = processTemplate("taglib.xml.ftl", context); StringBuilder sb = new StringBuilder(4); sb.append(_TAGLIB_XML_OUTPUT_DIR); sb.append("/"); sb.append(_NAMESPACE); sb.append(".taglib.xml"); File taglibXMLFile = new File(sb.toString()); writeFile(taglibXMLFile, taglibXMLContent, true); } }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
License:Open Source License
public static String getContent(String fileName) throws Exception { Document document = _getContentDocument(fileName); Element rootElement = document.getRootElement(); Element authorElement = null; Element namespaceElement = null; Map<String, Element> entityElements = new TreeMap<>(); Map<String, Element> exceptionElements = new TreeMap<>(); List<Element> elements = rootElement.elements(); for (Element element : elements) { String elementName = element.getName(); if (elementName.equals("author")) { element.detach();// www . jav a 2 s . co m if (authorElement != null) { throw new IllegalArgumentException("There can only be one author element"); } authorElement = element; } else if (elementName.equals("namespace")) { element.detach(); if (namespaceElement != null) { throw new IllegalArgumentException("There can only be one namespace element"); } namespaceElement = element; } else if (elementName.equals("entity")) { element.detach(); String name = element.attributeValue("name"); entityElements.put(StringUtil.toLowerCase(name), element); } else if (elementName.equals("exceptions")) { element.detach(); List<Element> exceptionElementsList = element.elements("exception"); for (Element exceptionElement : exceptionElementsList) { exceptionElement.detach(); exceptionElements.put(exceptionElement.getText(), exceptionElement); } } } if (authorElement != null) { rootElement.add(authorElement); } if (namespaceElement == null) { throw new IllegalArgumentException("The namespace element is required"); } else { rootElement.add(namespaceElement); } _addElements(rootElement, entityElements); if (!exceptionElements.isEmpty()) { Element exceptionsElement = rootElement.addElement("exceptions"); _addElements(exceptionsElement, exceptionElements); } return document.asXML(); }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
License:Open Source License
private static Document _getContentDocument(String fileName) throws Exception { SAXReader saxReader = _getSAXReader(); Document document = saxReader.read(new File(fileName)); Element rootElement = document.getRootElement(); List<Element> elements = rootElement.elements(); for (Element element : elements) { String elementName = element.getName(); if (!elementName.equals("service-builder-import")) { continue; }/* w w w . j a va 2s. c om*/ element.detach(); String dirName = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH) + 1); String serviceBuilderImportFileName = element.attributeValue("file"); Document serviceBuilderImportDocument = _getContentDocument(dirName + serviceBuilderImportFileName); Element serviceBuilderImportRootElement = serviceBuilderImportDocument.getRootElement(); List<Element> serviceBuilderImportElements = serviceBuilderImportRootElement.elements(); for (Element serviceBuilderImportElement : serviceBuilderImportElements) { serviceBuilderImportElement.detach(); rootElement.add(serviceBuilderImportElement); } } return document; }
From source file:com.liferay.util.xml.descriptor.StrictXMLDescriptor.java
License:Open Source License
private int _compareChildren(Element el1, Element el2) { List el1Children = el1.elements(); List el2Children = el2.elements(); if (el1Children.size() < el2Children.size()) { return -1; } else if (el1Children.size() > el2Children.size()) { return 1; }/*from w ww .j av a2 s .com*/ for (int i = 0; i < el1Children.size(); i++) { Element el = (Element) el1Children.get(i); int value = _contains(el2Children, el, new ElementComparator()); if (value != 0) { return value; } } return -1; }
From source file:com.liferay.util.xml.ElementComparator.java
License:Open Source License
public int compare(Object obj1, Object obj2) { Element el1 = (Element) obj1; Element el2 = (Element) obj2; String el1Name = el1.getName(); String el2Name = el2.getName(); if (!el1Name.equals(el2Name)) { return el1Name.compareTo(el2Name); }/*w ww . j av a2 s .c o m*/ String el1Text = el1.getTextTrim(); String el2Text = el2.getTextTrim(); if (!el1Text.equals(el2Text)) { return el1Text.compareTo(el2Text); } List el1Attrs = el1.attributes(); List el2Attrs = el2.attributes(); if (el1Attrs.size() < el2Attrs.size()) { return -1; } else if (el1Attrs.size() > el2Attrs.size()) { return 1; } for (int i = 0; i < el1Attrs.size(); i++) { Attribute attr = (Attribute) el1Attrs.get(i); int value = _compare(el2Attrs, attr, new AttributeComparator()); if (value != 0) { return value; } } List el1Elements = el1.elements(); List el2Elements = el2.elements(); if (el1Elements.size() < el2Elements.size()) { return -1; } else if (el1Elements.size() > el2Elements.size()) { return 1; } for (int i = 0; i < el1Elements.size(); i++) { Element el = (Element) el1Elements.get(i); int value = _compare(el2Elements, el, new ElementComparator()); if (value != 0) { return value; } } return 0; }