@Test public void withoutItemsEnumBindTarget() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.tag.setPath("testEnum"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = "<div>" + getOutput() + "</div>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("//input[@value = 'VALUE_1']"); Node value2 = rootElement.selectSingleNode("//input[@value = 'VALUE_2']"); assertEquals("TestEnum: VALUE_1", rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText()); assertEquals("TestEnum: VALUE_2", rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText()); assertEquals(value2, rootElement.selectSingleNode("//input[@checked]")); }
private void addLoopXPath( Node node, IProgressMonitor monitor ) { Element ce = (Element) node; monitor.worked( 1 ); // List child for ( int j = 0; j < ce.nodeCount(); j++ ) { if ( monitor.isCanceled() ) { return; } Node cnode = ce.node( j ); if ( !Utils.isEmpty( cnode.getName() ) ) { Element cce = (Element) cnode; if ( !listpath.contains( cnode.getPath() ) ) { nr++; monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes", String.valueOf( nr ) ) ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.AddingNode", cnode.getPath() ) ); listpath.add( cnode.getPath() ); } // let's get child nodes if ( cce.nodeCount() > 1 ) { addLoopXPath( cnode, monitor ); } } } }
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE:
private Map<String, String> readInitParams(Node configData) { Map<String, String> paramMap = new HashMap<>(); List<Node> params = configData.selectNodes("init-params/init-param"); for (Node param : params) { String paramName = param.selectSingleNode("param-name").getStringValue(); String paramValue = param.selectSingleNode("param-value").getStringValue(); paramMap.put(paramName, paramValue); } return paramMap; }
public Object getParentNode(Object contextNode) { if ( contextNode instanceof Node ) { Node node = (Node) contextNode; Object answer = node.getParent(); if ( answer == null ) { answer = node.getDocument(); if (answer == contextNode) { return null; } } return answer; } return null; }
private static String getChildText(Node node, String childName) throws PluginException { Node child = node.selectSingleNode(childName); if (child == null) { throw new PluginException("Could not find child \"" + childName + "\" for node"); } return child.getText(); }
final SAXReader saxReader = new SAXReader(); saxReader.setEncoding( "UTF-8" ); final Document pluginXML = saxReader.read( pluginConfig.toFile() ); final String className = pluginXML.selectSingleNode( "/plugin/class" ).getText().trim(); final Plugin plugin = (Plugin) pluginLoader.loadClass( className ).newInstance(); final Element adminElement = (Element) pluginXML.selectSingleNode( "/plugin/adminconsole" ); if ( adminElement != null ) final Element appName = (Element) adminElement.selectSingleNode( "/plugin/adminconsole/global/appname" ); if ( appName != null ) appName.addAttribute( "plugin", canonicalName ); Element imageEl = (Element) adminElement.selectSingleNode( "/plugin/adminconsole/global/logo-image" ); if ( imageEl != null )
Object result; try { Document dom = new SAXReader().read(new StringReader(sw.toString())); XPath xExclude = dom.createXPath(exclude); xExclude.setFunctionContext(functionContext); List<org.dom4j.Node> list = (List<org.dom4j.Node>)xExclude.selectNodes(dom); for (org.dom4j.Node n : list) { Element parent = n.getParent(); if(parent!=null) parent.remove(n); result = dom; } else { XPath comp = dom.createXPath(xpath); comp.setFunctionContext(functionContext); List list = comp.selectNodes(dom); for (Object o : list) { if (o instanceof String) { root.addText(o.toString()); } else { root.add(((org.dom4j.Node)o).detach());
SAXReader reader = new SAXReader(); Document document = reader.read(file); List<Node> nodes = document.selectNodes("/options/category/option"); for (Node node : nodes) { System.out.println("caption: " + node.selectSingleNode("control/caption").getText()); System.out.println("value : " + node.selectSingleNode("value").getText()); }
List<Node> componentNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/PluginComponent"); for (Node componentNode : componentNodeList) { @DottedClassName String componentKindname = componentNode.valueOf("@componentKind"); if (componentKindname == null) { throw new PluginException("Missing @componentKind for " + plugin.getPluginId() + " loaded from " + loadedFrom); @DottedClassName String componentClassname = componentNode.valueOf("@componentClass"); if (componentClassname == null) { throw new PluginException("Missing @componentClassname for " + plugin.getPluginId() + " loaded from " + loadedFrom); String componentId = componentNode.valueOf("@id"); if (componentId == null) { throw new PluginException("Missing @id for " + plugin.getPluginId() String propertiesLocation = componentNode.valueOf("@properties"); boolean disabled = Boolean.valueOf(componentNode.valueOf("@disabled")); String key = node.valueOf("@key"); String value = node.getText(); properties.setProperty(key, value); List<Node> findBugsMainList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/FindBugsMain"); for (Node main : findBugsMainList) { String className = main.valueOf("@class"); if (className == null) { throw new PluginException("Missing @class for FindBugsMain in plugin" + plugin.getPluginId() + " loaded from " + loadedFrom);
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()); } }
public void testSetText1() throws Exception { String newURL = "newURL"; Node urlNode = document.selectSingleNode("//root/author[1]/url"); urlNode.setText(newURL); assertEquals(newURL, urlNode.getText()); assertTrue(urlNode instanceof Element); Element urlElement = (Element) urlNode; assertEquals(0, urlElement.elements().size()); }
public void setNodeValue(String xpath, String value) { Element rootElement = document.getRootElement(); String namespace = rootElement.getNamespaceURI(); if (namespace != null) { DefaultXPath defaultXPath = new DefaultXPath(xpath); Map<String, String> namespaces = new TreeMap<String, String>(); namespaces.put("ns", namespace); defaultXPath.setNamespaceURIs(namespaces); defaultXPath.selectSingleNode(document).setText(value); } else { rootElement.selectSingleNode(xpath).setText(value); } }
public static DefaultNamespaceContext create(Object node) { Element element = null; if (node instanceof Element) { element = (Element) node; } else if (node instanceof Document) { Document doc = (Document) node; element = doc.getRootElement(); } else if (node instanceof Node) { element = ((Node) node).getParent(); } if (element != null) { return new DefaultNamespaceContext(element); } return null; }
@NotNull private static Map<String, Node> cacheUnitTestNodes(final Node document, final String namespacePrefix) { final Map<String, Node> cachedTestInfo = new HashMap<>(); final List<Element> cachedNodes = document.selectNodes("//" + namespacePrefix + "UnitTest"); for (final Element e : cachedNodes) { cachedTestInfo.put(e.attributeValue("id"), e); } return cachedTestInfo; }
Element e = (Element) node; List<Attribute> lista = e.attributes(); for ( int i = 0; i < lista.size(); i++ ) { setAttributeField( lista.get( i ), monitor ); String nodename = node.getName(); String nodenametxt = cleanString( node.getPath() ); String valueNode = node.getText();
public NameOrg getOrgName(Node node) { Node orgNameN = node.selectSingleNode("organization-name"); NameOrg name = orgNameN != null ? new NameOrg(orgNameN.getText()) : null; if (name != null) { try { name.validate(); } catch (InvalidDataException e) { LOGGER.warn("Org Name Invalid: {}", node.getParent().asXML(), e); } } return name; }
public Examiner getExaminer(Node examinerNode, ExaminerType type) { if (examinerNode == null) { return null; } Node dataNode = examinerNode.selectSingleNode("PARTY-US"); Name name = new NameNode(dataNode).read(); Node artUnitN = examinerNode.getParent().selectSingleNode("B748US"); String artUnit = artUnitN != null ? artUnitN.getText() : null; Examiner examiner = new Examiner(name, artUnit, type); return examiner; }
private static String findMessageText(List<Document> messageCollectionList, String xpath, String missingMsg) { for (Document document : messageCollectionList) { Node node = document.selectSingleNode(xpath); if (node != null) { return node.getText().trim(); } } return missingMsg; }