protected ConfigSaveState updatePartial(String xmlPartial, final String md5) throws Exception { LOGGER.debug("[Config Save] Updating partial"); Document document = documentRoot(); Element root = document.getRootElement(); Element configElement = ((Element) root.selectSingleNode(getXpath())); List nodes = configElement.getParent().content(); int index = nodes.indexOf(configElement); LOGGER.debug("[Config Save] Converting to object"); Element newConfigElement = reader.read(new StringReader(xmlPartial)).getRootElement(); nodes.set(index, newConfigElement); return saveConfig(document.asXML(), md5); }
@Override public void visit( Element node ) { // This orders only the elements from the content, which can get messy if mixed content is of importance. // At the time of writing, the content other than elements was whitespace text (for indentation), which // is safe to ignore. Collections.sort( node.content(), new ElementByOrderAttributeComparator() ); super.visit( node ); } };
for ( Object o : properties.content() ) { final Element element = (Element) o; element.setParent( null );
/** * Provides a type safe / generic wrapper for {@link Element#content()}.<p> * * @param element the element to get the content for * * @return type safe access to {@link Element#content()}.<p> */ @SuppressWarnings("unchecked") public static List<Node> content(Element element) { return element.content(); }
appendDOMTree(domDocument, domElement, element.content());
/** * Provides a type safe / generic wrapper for {@link Element#content()}.<p> * * @param element the element to get the content for * * @return type safe access to {@link Element#content()}.<p> */ @SuppressWarnings("unchecked") public static List<Node> content(Element element) { return element.content(); }
public List content() { return element.content(); }
public List content() { return element.content(); }
protected static Document mergeDocuments(final Document mainDocument, final Iterable<Document> supplementalDocuments) { Element mainRootElement = mainDocument.getRootElement(); for (Document supplementalDocument : supplementalDocuments) { Element supplementaryRoot = supplementalDocument.getRootElement(); for (Iterator<Node> iter = supplementaryRoot.content().iterator(); iter.hasNext(); ) { Node node = iter.next(); iter.remove(); mainRootElement.add(node); } } return mainDocument; }
public static boolean hasNonTextChilds(Element element) { for (Object node : element.content()) { Node e1 = (Node) node; if (e1.getNodeType() != Node.TEXT_NODE) { return true; } } return false; }
public List content() { return target().content(); }
currentParent.content().set(contentIndex, modifiedElement);
public static boolean hasTextChildsWithNonWhitespace(Element element) { for (Object node : element.content()) { Node e1 = (Node) node; if (e1.getNodeType() != Node.TEXT_NODE) { continue; } Text textNode = (Text) e1; if (!textNode.getText().trim().isEmpty()) { return true; } } return false; }
protected void loadParams(DashboardFrame resultComponent, Element element) { List<Parameter> parameters = (List<Parameter>) element.content().stream() .filter(child -> child instanceof DefaultElement && "parameter".equals(((DefaultElement) child).getName())) .map(xmlParam -> createParameter((DefaultElement) xmlParam)) .collect(Collectors.toList()); resultComponent.setXmlParameters(parameters); }
protected void mutate(Element element) throws Exception { DocumentFactory factory = DocumentFactory.getInstance(); List list = element.elements(); list.add(factory.createElement("last")); list.add(0, factory.createElement("first")); List list2 = element.elements(); assertTrue("Both lists should contain same number of elements", list .size() == list2.size()); XMLWriter writer = new XMLWriter(System.out); log("Element content is now: " + element.content()); writer.write(element); } }
public void testContent() throws Exception { Element root = document.getRootElement(); assertNotNull("Has root element", root); List<Node> content = root.content(); assertNotNull("Root has content", content); assertTrue("Root has content", content.size() >= 2); boolean iterated = false; for (Node object : content) { iterated = true; } assertTrue("Iteration completed", iterated); }
public void testBug926713() throws Exception { Document doc = getDocument("/xml/test/cdata.xml"); Element foo = doc.getRootElement(); Element bar = foo.element("bar"); List content = bar.content(); assertEquals(3, content.size()); assertEquals(Node.TEXT_NODE, ((Node) content.get(0)).getNodeType()); assertEquals(Node.CDATA_SECTION_NODE, ((Node) content.get(1)) .getNodeType()); assertEquals(Node.TEXT_NODE, ((Node) content.get(2)).getNodeType()); } }
protected void testParentRelationship(Element element) { testParentRelationship(element, element.attributes()); testParentRelationship(element, element.content()); }
public void testParentAfterSetContent() throws Exception { Document doc = DocumentHelper.parseText("<root>" + "<a>a</a>" + "<b>b</b>" + "<x>x</x>" + "<d>d</d>" + "</root>"); Node x = doc.selectSingleNode("/root/x"); List content = doc.getRootElement().content(); int position = content.indexOf(x); Element c = DocumentHelper.createElement("c"); c.setText("c"); content.add(position, c); assertNotNull(c.getParent()); doc.getRootElement().setContent(content); assertNotNull("Parent is null of setting content", c.getParent()); }