List of usage examples for org.jdom2 Element sortChildren
public void sortChildren(Comparator<? super Element> comparator)
From source file:com.izforge.izpack.util.xmlmerge.merge.DefaultXmlMerge.java
License:Open Source License
private static void sortRootChildrenRecursive(Element root, Comparator<Element> comparator) { for (Element element : root.getChildren()) { sortRootChildrenRecursive(element, comparator); }/*from w ww.ja v a2s. c o m*/ root.sortChildren(comparator); }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
public void addActivity(ManifestActivity activity) { ConsoleUtils.displayDebug(String.format("Add activity %s to manifest.", activity.getName())); // Load Root element final Element rootNode = this.getDocument().getRootElement(); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); // Find Application Node Element findActivity = null;//from w ww . ja v a 2s.co m // Find a element final Element applicationNode = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); if (applicationNode != null) { findActivity = this.findActivityNamed(activity.getName(), ns); // If not found Node, create it if (findActivity == null) { applicationNode.addContent(activity.toElement(ns)); // Clean manifest applicationNode.sortChildren(ABC_COMPARATOR); } } }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.JSONTypesExtractorImpl.java
License:Apache License
/** * This mehod sorts all the {@link Element} descendants of an element * by calling {@link Element#sortChildren(Comparator)} recursively. * @param rootElement the element to start at. * @param comparator the comparator used. *///w w w . j a va2 s. c o m private void sortElementsRecursive(Element rootElement, Comparator<Element> comparator) { rootElement.sortChildren(comparator); for (Element element : rootElement.getChildren()) { sortElementsRecursive(element, comparator); } }
From source file:es.upm.dit.xsdinferencer.generation.generatorimpl.statisticsgeneration.StatisticResultsDocGeneratorImpl.java
License:Apache License
/** * This method is intended to generate the "atPath" information of elements and attributes. * It takes a {@link Map} between String and {@link BasicStatisticsEntry} which contains the information of the node at a concrete path and generates an element with the given elementName * and, for each mapping, a child element is generated via {@link StatisticResultsDocGeneratorImpl#generateBasicStatisticsEntryBasedElement(String, String, String, String, String, BasicStatisticsEntry, boolean, boolean)} * to represent the info of that element. If a Table of values info or a Map of numericValues info is passed, the corresponding entries are also generated and attached as children of the child which * describes the path.<br/>/*from w w w. j av a 2 s . co m*/ * Here is an example of what is going to be generated:<br/> * <pre> * <![CDATA[ * <elementName> * <subElementName> * Info from the BasicStatisticsEntry related to occurrences of a node at the path (as children or attributes) * <valueElementName> * <valueSubElementName> * Info from the BasicStatisticsEntry related to occurrences of a value occurrences of the node at the path (as children or attributes) * </valueSubElementName> * ... * </valueElementName> * <numericValuesStatistics> * Statistics of numeric values for the node * </numericValuesStatistics> * </subElementName> * ... * </elementName> * ]]> * </pre><br/> * Where valueElementName and numericValuesStatistics are optional elements which may not be generated if there are info about values or there are no numeric values for the path, * respectively. * @param elementName The name of the generated element. * @param subElementName The name of each the element which contains the info of the node at a path. * @param sourceMap The map that contains the info of the nodes at a path * @param valuesElementName The name of the child element with the values info * @param valuesSubElementName The name of each child of the valuesElementName child, with the info of a concrete value * @param valuesTable the table that contains the info of each value at each path * @param numericValuesInfo The info of numeric values * @param numericValuesStatisticsElementName The element of the child which will contain the numeric statistics info * @return An element with all the information described */ protected Element generateNodesAtPathElements(String elementName, String subElementName, Map<String, BasicStatisticsEntry> sourceMap, String valuesElementName, String valuesSubElementName, Table<String, String, BasicStatisticsEntry> valuesTable, Map<String, BasicStatisticsEntry> numericValuesInfo, String numericValuesStatisticsElementName) { Element element = new Element(elementName, STATISTICS_NAMESPACE); for (String path : sourceMap.keySet()) { Element currentElement = generateBasicStatisticsEntryBasedElement(subElementName, path, sourceMap.get(path), true, true); element.addContent(currentElement); Map<String, BasicStatisticsEntry> values = valuesTable.row(path); if (!values.isEmpty()) { Element valuesAtPathElement = new Element(valuesElementName, STATISTICS_NAMESPACE); for (String value : values.keySet()) { Element currentValueElement = generateBasicStatisticsEntryBasedElement(valuesSubElementName, path, null, null, value, valuesTable.get(path, value), true, true); valuesAtPathElement.addContent(currentValueElement); } currentElement.addContent(valuesAtPathElement); } BasicStatisticsEntry numericValuesInfoOfPath = numericValuesInfo.get(path); if (numericValuesInfoOfPath != null) { Element numericValuesInfoOfPathElement = generateBasicStatisticsEntryBasedElement( numericValuesStatisticsElementName, numericValuesInfoOfPath, false, false); currentElement.addContent(numericValuesInfoOfPathElement); } } element.sortChildren(BASIC_ENTRY_ELEMENT_COMPARATOR); return element; }
From source file:es.upm.dit.xsdinferencer.generation.generatorimpl.statisticsgeneration.StatisticResultsDocGeneratorImpl.java
License:Apache License
/** * This method generates an element with info of the nodes under a complex type (either elements of the complex type or attributes of elements of a concrete complex type). * For each node, a child element is generated with all the info of its occurrences, a child with the info of its values (if there is any info about them) which will contain one child per value * with its info and a child with the numericValuesInfo, if any. * @param elementName The name of the generated element. * @param subElementName The name of each the element which contains the info of the node at a path. * @param sourceMap The map that contains the info of the nodes of the complex type * @param valuesElementName The name of the child element with the values info * @param valuesSubElementName The name of each child of the valuesElementName child, with the info of a concrete value * @param valuesTable the table that contains the info of each value of each node * @param numericValuesInfo The info of numeric values * @param numericValuesStatisticsElementName The element of the child which will contain the numeric statistics info * @return An element with all the information described *//*from www .j ava2 s. co m*/ protected <T extends SchemaNode> Element generateNodesOfComplexTypesInfoElements(String elementName, String subElementName, Map<T, BasicStatisticsEntry> sourceMap, String valuesElementName, String valuesSubElementName, Table<String, SchemaNode, BasicStatisticsEntry> valuesTable, Map<SchemaNode, BasicStatisticsEntry> numericValuesInfo, String numericValuesStatisticsElementName) { Element element = new Element(elementName, STATISTICS_NAMESPACE); for (T node : sourceMap.keySet()) { String nodeName = node.getName(); String nodeNamespace = node.getNamespace(); Map<String, BasicStatisticsEntry> valuesOfNode = valuesTable.column(node); Element currentElement = generateBasicStatisticsEntryBasedElement(subElementName, null, nodeName, nodeNamespace, null, sourceMap.get(node), true, true); element.addContent(currentElement); if (!valuesOfNode.isEmpty()) { Element valuesOfNodeElement = new Element("values", STATISTICS_NAMESPACE); for (String value : valuesOfNode.keySet()) { Element currentValueElement = generateBasicStatisticsEntryBasedElement("value", null, nodeName, nodeNamespace, value, valuesOfNode.get(value), true, true); valuesOfNodeElement.addContent(currentValueElement); } currentElement.addContent(valuesOfNodeElement); } BasicStatisticsEntry numericValuesInfoOfNode = numericValuesInfo.get(node); if (numericValuesInfoOfNode != null) { Element numericValuesInfoOfNodeElement = generateBasicStatisticsEntryBasedElement( "numericValuesStatistics", numericValuesInfoOfNode, false, false); currentElement.addContent(numericValuesInfoOfNodeElement); } } element.sortChildren(BASIC_ENTRY_ELEMENT_COMPARATOR); return element; }
From source file:org.knoxcraft.database.xml.XmlDatabase.java
License:Open Source License
private void sortElements(Document doc) { // Need tableProperties to be at the top doc.getRootElement().sortChildren(new Comparator<Element>() { @Override/*from w w w. ja v a 2s .c o m*/ public int compare(Element o1, Element o2) { if (o1.getName().equals("tableProperties")) { return -1; } else if (o2.getName().equals("tableProperties")) { return 1; } else { return Integer.valueOf(o1.getChildText("id")).compareTo(Integer.valueOf(o2.getChildText("id"))); } } }); /* Why is this necessary? */ for (Element e : doc.getRootElement().getChildren()) { e.sortChildren(new Comparator<Element>() { @Override public int compare(Element o1, Element o2) { return o1.getName().compareTo(o2.getName()); } }); } }
From source file:org.mycore.user2.utils.MCRUserTransformer.java
License:Open Source License
private static void sortAttributes(Document userXML) { Element attributes = userXML.getRootElement().getChild("attributes"); if (attributes == null) { return;/* w ww. j a v a 2s . c o m*/ } attributes.sortChildren((o1, o2) -> o1.getAttributeValue("name").compareTo(o2.getAttributeValue("name"))); }