/** * Adds XML stream to the tabs/sidebar model. * * @param name the name. * @param in the XML input stream. * @throws Exception if an error occurs when parsing the XML or adding it to the model. */ public static void addModel(String name, InputStream in) throws Exception { SAXReader saxReader = new SAXReader(); Document doc = saxReader.read(in); addModel(name, (Element)doc.selectSingleNode("/adminconsole")); }
private static Node findMessageNode(List<Document> messageCollectionList, String xpath, String missingMsg) throws PluginException { for (Document document : messageCollectionList) { Node node = document.selectSingleNode(xpath); if (node != null) { return node; } } throw new PluginException(missingMsg); }
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; }
saxReader.setEncoding( "UTF-8" ); final Document pluginXML = saxReader.read( pluginConfig.toFile() ); final Element element = (Element) pluginXML.selectSingleNode( xpath ); if ( element != null )
SAXReader saxReader = new SAXReader(); Document doc = saxReader.read(in); coreModel = (Element)doc.selectSingleNode("/adminconsole");
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 )
Node orderingConstraintsNode = pluginDescriptor.selectSingleNode("/FindbugsPlugin/OrderingConstraints"); if (orderingConstraintsNode != null) { Node messageNode = findMessageNode(messageCollectionList, query, "messages.xml missing BugPattern element for type " + type); Node bugsUrlNode = messageNode.getDocument().selectSingleNode("/MessageCollection/Plugin/"+(experimental?"AllBugsUrl":"BugsUrl")); Node fbNode = pluginDescriptor.selectSingleNode(query); int cweid = 0; if (fbNode != null) { Node node = pluginDescriptor.selectSingleNode("/FindbugsPlugin/EngineRegistrar"); if (node != null) { String engineClassName = node.valueOf("@class");
private static Node findMessageNode(List<Document> messageCollectionList, String xpath, String missingMsg) throws PluginException { for (Document document : messageCollectionList) { Node node = document.selectSingleNode(xpath); if (node != null) { return node; } } throw new PluginException(missingMsg); }
public void setPositionCode(String positionCode) throws Exception { this.document.selectSingleNode(ConstantsTools.XPATH_POSITION_CODE).setText(positionCode); writeToXml(); } }
public void testXPaths() throws Exception { Element element = (Element) document.selectSingleNode("/root"); mutate(element); element = (Element) document.selectSingleNode("//author"); mutate(element); }
public void testAddRemove() throws Exception { Element parentElement = (Element) document.selectSingleNode("/root"); List children = parentElement.elements(); int lastPos = children.size() - 1; Element child = (Element) children.get(lastPos); try { // should throw an exception cause we cannot add same child twice children.add(0, child); fail(); } catch (IllegalAddException e) { } }
@BeforeClass public void setUp() throws Exception { super.setUp(); rootNode = document.selectSingleNode("/root"); authorNode = document.selectSingleNode("/root/author[1]"); variableContext.setVariableValue("root", rootNode); variableContext.setVariableValue("author", authorNode); } }
public void testXPaths() throws Exception { Node element = document.selectSingleNode("//author"); int size = paths.length; for (int i = 0; i < size; i++) { testXPath(document, paths[i]); testXPath(element, paths[i]); } }
public String getSystemSetting( final String path, final String settingName, final String defaultValue ) { debug( Messages.getInstance().getString( "SYSTEMSETTINGS.DEBUG_GET_SYSTEM_SETTING_PATH", File.separator + path ) ); //$NON-NLS-1$ Document doc = getSystemSettingsDocument( path ); if ( doc == null ) { return defaultValue; } Node node = doc.selectSingleNode( "//" + settingName ); //$NON-NLS-1$ if ( node == null ) { return defaultValue; } return node.getText(); }
public void testAuthorCompare1() throws Exception { Document doc2 = (Document) document.clone(); Element author = (Element) doc2.selectSingleNode("//author"); author.addAttribute("name", "James Strachan"); assertTrue("Documents are not equal", comparator .compare(document, doc2) != 0); }
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 testSetText2() throws Exception { String newName = "Strachem James"; Node authorNode = document.selectSingleNode("//root/author[1]"); authorNode.setText(newName); assertEquals(newName, authorNode.getText()); assertTrue(authorNode instanceof Element); Element urlElement = (Element) authorNode; assertEquals(1, urlElement.elements().size()); } }
public void testBug1116471() throws Exception { String xml = "<a><b>Water T & D-46816</b></a>"; String expected = "Water T & D-46816"; Document doc = DocumentHelper.parseText(xml); String result = (String) doc.selectObject("string(a/b[1])"); assertEquals("xpath result not correct", expected, result); Node node = doc.selectSingleNode("a/b"); String result2 = node.getStringValue(); assertEquals("xpath result not correct", expected, result2); }
public void testBug569927() { Document doc = DocumentHelper.createDocument(); QName elName = DocumentFactory.getInstance().createQName("a", "ns", "uri://myuri"); Element a = doc.addElement(elName); QName attName = DocumentFactory.getInstance().createQName("attribute", "ns", "uri://myuri"); a = a.addAttribute(attName, "test"); Attribute att = a.attribute(attName); assertSame(att, doc.selectSingleNode(att.getPath())); assertSame(att, doc.selectSingleNode(att.getUniquePath())); }
public void testDom4jAddNodeCreateCopy() { Document maindoc = DocumentHelper.createDocument(); Element docroot = maindoc.addElement("document"); Element header = docroot.addElement("header").addText("Some Text"); Document subdoc = DocumentHelper.createDocument(); Element docroot2 = subdoc.addElement("document"); docroot2.add(((Element) maindoc.selectSingleNode("/document/header")) .createCopy()); assertEquals(subdoc.asXML(), maindoc.asXML()); }