List of usage examples for org.w3c.dom Node getTextContent
public String getTextContent() throws DOMException;
From source file:com.amalto.workbench.widgets.SchematronExpressBuilder.java
private void parseFunxml() throws Exception { InputStream in = null;// ww w . j a va 2 s . c om try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); org.w3c.dom.Document document; if (isSchematron) { in = SchematronExpressBuilder.class.getResourceAsStream("XPathFunc.xml");//$NON-NLS-1$ } else { in = SchematronExpressBuilder.class.getResourceAsStream("StandardXPathFunc.xml");//$NON-NLS-1$ } document = builder.parse(in); NodeList list = document.getElementsByTagName("category");//$NON-NLS-1$ categories = new ArrayList<XPathFunc>(); for (int i = 0; i < list.getLength(); i++) { XPathFunc xpathFunc = new XPathFunc(); Node node = list.item(i);// get the number i node NamedNodeMap map = node.getAttributes(); Node nameNode = map.getNamedItem("name");//$NON-NLS-1$ xpathFunc.setCategory(nameNode.getTextContent()); java.util.List<KeyValue> keylist = new ArrayList<KeyValue>(); for (int j = 0; j < node.getChildNodes().getLength(); j++) { Node n = node.getChildNodes().item(j); NamedNodeMap fmap = n.getAttributes(); if (fmap != null && fmap.getLength() > 0) { Node n1 = fmap.getNamedItem("name");//$NON-NLS-1$ Node n2 = fmap.getNamedItem("help");//$NON-NLS-1$ String help = n2.getTextContent(); help = help.replaceAll("\\n", "\n");//$NON-NLS-1$//$NON-NLS-2$ KeyValue kv = new KeyValue(n1.getTextContent(), help); keylist.add(kv); } } Collections.sort(keylist, new Comparator<KeyValue>() { public int compare(KeyValue o1, KeyValue o2) { if (o1 != null && o2 != null) { return o1.key.compareTo(o2.key); } return 0; } }); xpathFunc.setFuncs(keylist); categories.add(xpathFunc); } } finally { if (in != null) { in.close(); } } }
From source file:edu.toronto.cs.cidb.ncbieutils.NCBIEUtilsAccessService.java
private Map<String, String> getNameForId(Node source) { Map<String, String> result = new HashMap<String, String>(); String id = null, name = null; NodeList data = source.getChildNodes(); for (int i = 0; i < data.getLength(); ++i) { Node n = data.item(i); if (n.getNodeType() != Node.ELEMENT_NODE) { continue; }/*from w w w . ja v a2 s . c o m*/ if ("Id".equals(n.getNodeName())) { id = n.getTextContent(); } else if ("Item".equals(n.getNodeName())) { NamedNodeMap attrs = n.getAttributes(); if (attrs.getNamedItem("Name") != null && "Title".equals(attrs.getNamedItem("Name").getNodeValue())) { name = n.getTextContent(); } } } if (id != null) { if (name != null) { result.put(id, fixCase(name)); } else { result.put(id, id); } } return result; }
From source file:fi.helsinki.lib.simplerest.BundleResource.java
@Put public Representation editBundle(InputRepresentation rep) { Context c = null;//from w w w. j ava 2 s . c o m Bundle bundle = null; try { c = getAuthenticatedContext(); bundle = Bundle.find(c, this.bundleId); if (bundle == null) { return errorNotFound(c, "Could not find the bundle."); } } catch (SQLException e) { return errorInternal(c, "SQLException"); } DomRepresentation dom = new DomRepresentation(rep); Node attributesNode = dom.getNode("//dl[@id='attributes']"); if (attributesNode == null) { return error(c, "Did not find dl tag with a id 'attributes'.", Status.CLIENT_ERROR_BAD_REQUEST); } int nameFound = 0; int primarybitstreamidFound = 0; NodeList nodes = attributesNode.getChildNodes(); LinkedList<String> dtList = new LinkedList(); LinkedList<String> ddList = new LinkedList(); int nNodes = nodes.getLength(); for (int i = 0; i < nNodes; i++) { Node node = nodes.item(i); String nodeName = node.getNodeName(); if (nodeName.equals("dt")) { dtList.add(node.getTextContent()); } else if (nodeName.equals("dd")) { ddList.add(node.getTextContent()); } } if (dtList.size() != ddList.size()) { return error(c, "The number of <dt> and <dd> elements do not match.", Status.CLIENT_ERROR_BAD_REQUEST); } int size = dtList.size(); for (int i = 0; i < size; i++) { String dt = dtList.get(i); String dd = ddList.get(i); if (dt.equals("name")) { nameFound = 1; bundle.setName(dd); } else if (dt.equals("primarybitstreamid")) { primarybitstreamidFound = 1; Integer id = Integer.parseInt(dd); boolean validBitstreamId = false; Bitstream[] bitstreams = bundle.getBitstreams(); if (id == -1) { // -1 means that we do not want to validBitstreamId = true; // specify the primary bitstream. } else { for (Bitstream bitstream : bitstreams) { if (id == bitstream.getID()) { validBitstreamId = true; break; } } } if (!validBitstreamId) { return error(c, "Invalid primarybitstreamid.", Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY); } if (id == -1) { bundle.unsetPrimaryBitstreamID(); } else { bundle.setPrimaryBitstreamID(id); } } else { return error(c, "Unexpected data in attributes: " + dt, Status.CLIENT_ERROR_BAD_REQUEST); } } // If the was data missing, report it: String[] problems = { "'nameFound' and 'primarybitstreamid'", "'nameFound'", "'primarybitstreamid'", "" }; String problem = problems[primarybitstreamidFound + 2 * nameFound]; if (!problem.equals("")) { return error(c, problem + " was not found from the request.", Status.CLIENT_ERROR_BAD_REQUEST); } try { bundle.update(); c.complete(); } catch (AuthorizeException ae) { return error(c, "Unauthorized", Status.CLIENT_ERROR_UNAUTHORIZED); } catch (Exception e) { return errorInternal(c, e.toString()); } return successOk("Bundle updated."); }
From source file:au.com.ors.rest.dao.JobAppDAO.java
@PostConstruct public void init() throws DAOException, ParserConfigurationException, SAXException, IOException { if (servletContext == null) { throw new DAOException( "Cannot autowire ServletContext to JobAppDAO when injecting JobAppDAO into JobAppController: NullPointerException"); }//from w w w.j a v a2 s. co m // get jobposting data file path String dataPath = dataProperties.getProperty("data.jobapp.path"); dataUrl = servletContext.getRealPath("/WEB-INF/db/" + dataPath); System.out.println("jobapp_db_path=" + dataUrl); if (StringUtils.isEmpty(dataUrl)) { throw new DAOException("Cannot find data.jobappdata.path in properties file."); } File jobPostingDataFile = new File(dataUrl); if (!jobPostingDataFile.exists()) { throw new DAOLoadingXmlFileException("Cannot load job application XML file from path " + dataUrl); } // Make an instance of the DocumentBuilderFactory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; db = dbf.newDocumentBuilder(); dom = db.parse(dataUrl); Element root = dom.getDocumentElement(); NodeList nodeList = root.getChildNodes(); for (int i = 0; i < nodeList.getLength(); ++i) { Node node = nodeList.item(i); if (!node.getNodeName().equalsIgnoreCase("JobApplication")) { continue; } JobApplication app = new JobApplication(); NodeList jobAppInfoList = node.getChildNodes(); for (int j = 0; j < jobAppInfoList.getLength(); ++j) { Node current = jobAppInfoList.item(j); // load list if (current.getNodeType() == Node.ELEMENT_NODE) { String content = current.getTextContent(); if (current.getNodeName().equals("_appId")) { app.set_appId(content); } else if (current.getNodeName().equals("_jobId")) { app.set_jobId(content); } else if (current.getNodeName().equals("driverLicenseNumber")) { app.setDriverLicenseNumber(content); } else if (current.getNodeName().equals("fullName")) { app.setFullName(content); } else if (current.getNodeName().equals("postCode")) { app.setPostCode(content); } else if (current.getNodeName().equals("textCoverLetter")) { app.setTextCoverLetter(content); } else if (current.getNodeName().equals("textBriefResume")) { app.setTextBriefResume(content); } else if (current.getNodeName().equals("status")) { app.setStatus(content); } } } if (!StringUtils.isEmpty(app.get_appId())) { jobAppList.add(app); } } System.out.println( "================================== print all job applications =================================="); for (JobApplication app : jobAppList) { System.out.println(app.toString()); } System.out.println( "================================== print all job applications end =================================="); }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handleEventTypes(Configuration configuration, Element element) { String name = getRequiredAttribute(element, "name"); Node classNode = element.getAttributes().getNamedItem("class"); String optionalClassName = null; if (classNode != null) { optionalClassName = classNode.getTextContent(); configuration.addEventType(name, optionalClassName); }// w ww .jav a2 s. c om handleEventTypeDef(name, optionalClassName, configuration, element); }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handleDefaultsEventMeta(Configuration configuration, Element parentElement) { DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes()); while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("class-property-resolution")) { Node styleNode = subElement.getAttributes().getNamedItem("style"); if (styleNode != null) { String styleText = styleNode.getTextContent(); Configuration.PropertyResolutionStyle value = Configuration.PropertyResolutionStyle .valueOf(styleText.toUpperCase()); configuration.getEngineDefaults().getEventMeta().setClassPropertyResolutionStyle(value); }/*from w ww. j a va 2s .c o m*/ Node accessorStyleNode = subElement.getAttributes().getNamedItem("accessor-style"); if (accessorStyleNode != null) { String accessorStyleText = accessorStyleNode.getTextContent(); ConfigurationEventTypeLegacy.AccessorStyle value = ConfigurationEventTypeLegacy.AccessorStyle .valueOf(accessorStyleText.toUpperCase()); configuration.getEngineDefaults().getEventMeta().setDefaultAccessorStyle(value); } } if (subElement.getNodeName().equals("event-representation")) { Node typeNode = subElement.getAttributes().getNamedItem("type"); if (typeNode != null) { String typeText = typeNode.getTextContent(); Configuration.EventRepresentation value = Configuration.EventRepresentation .valueOf(typeText.toUpperCase()); configuration.getEngineDefaults().getEventMeta().setDefaultEventRepresentation(value); } } if (subElement.getNodeName().equals("anonymous-cache")) { Node sizeNode = subElement.getAttributes().getNamedItem("size"); if (sizeNode != null) { configuration.getEngineDefaults().getEventMeta() .setAnonymousCacheSize(Integer.parseInt(sizeNode.getTextContent())); } } } }
From source file:com.cloudbees.sdk.CommandServiceImpl.java
private Plugin parsePluginFile(File file) throws FileNotFoundException, XPathExpressionException { InputStream inputStream = new FileInputStream(file); try {/*w w w .j a v a 2 s . co m*/ InputSource input = new InputSource(inputStream); Document doc = XmlHelper.readXML(input); Plugin plugin = new Plugin(); Element e = doc.getDocumentElement(); if (e.getTagName().equalsIgnoreCase("plugin")) { if (e.hasAttribute("artifact")) plugin.setArtifact(e.getAttribute("artifact")); NodeList nodes = e.getChildNodes(); List<String> jars = new ArrayList<String>(); plugin.setJars(jars); List<CommandProperties> commands = new ArrayList<CommandProperties>(); plugin.setProperties(commands); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeName().equals("jar")) jars.add(node.getTextContent().trim()); else if (node.getNodeName().equals("command")) { CommandProperties commandProperties = new CommandProperties(); commandProperties.setGroup(getAttribute(node, "group")); commandProperties.setName(getAttribute(node, "name")); commandProperties.setPattern(getAttribute(node, "pattern")); commandProperties.setDescription(getAttribute(node, "description")); commandProperties.setClassName(getAttribute(node, "className")); String str = getAttribute(node, "experimental"); if (str != null) commandProperties.setExperimental(Boolean.parseBoolean(str)); str = getAttribute(node, "priority"); if (str != null) commandProperties.setPriority(Integer.parseInt(str)); commands.add(commandProperties); } } } return plugin; } finally { IOUtils.closeQuietly(inputStream); } }
From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceProviderCatalogTests.java
@Test public void serviceProviderCatalogsHaveValidTitles() throws XPathException { //Check root/* www .j a v a 2s . c o m*/ Node rootCatalogTitle = (Node) OSLCUtils.getXPath().evaluate("/oslc_disc:ServiceProviderCatalog/dc:title", doc, XPathConstants.NODE); assertNotNull(rootCatalogTitle); assertFalse(rootCatalogTitle.getTextContent().isEmpty()); NodeList titleSub = (NodeList) OSLCUtils.getXPath().evaluate("/oslc_disc:ServiceProviderCatalog/dc:title/*", doc, XPathConstants.NODESET); assertTrue(titleSub.getLength() == 0); //Get all entries, parse out which have embedded catalogs and check the titles NodeList catalogs = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_disc:entry/*", doc, XPathConstants.NODESET); for (int i = 0; i < catalogs.getLength(); i++) { Node catalog = (Node) OSLCUtils.getXPath().evaluate( "//oslc_disc:entry[" + (i + 1) + "]/oslc_disc:ServiceProviderCatalog", doc, XPathConstants.NODE); //This entry has a catalog, check that it has a title if (catalog != null) { Node cTitle = (Node) OSLCUtils.getXPath().evaluate( "//oslc_disc:entry[" + (i + 1) + "]/oslc_disc:ServiceProviderCatalog/dc:title", doc, XPathConstants.NODE); assertNotNull(cTitle); //Make sure the child isn't empty assertFalse(cTitle.getTextContent().isEmpty()); Node child = (Node) OSLCUtils.getXPath().evaluate( "//oslc_disc:entry[" + (i + 1) + "]/oslc_disc:ServiceProviderCatalog/dc:title/*", doc, XPathConstants.NODE); //Make sure the title has no child elements assertTrue(child == null); } } }
From source file:com.cloud.hypervisor.kvm.resource.wrapper.LibvirtMigrateCommandWrapper.java
private String getSourceFileDevText(Node diskNode) { NodeList diskChildNodes = diskNode.getChildNodes(); for (int i = 0; i < diskChildNodes.getLength(); i++) { Node diskChildNode = diskChildNodes.item(i); if ("source".equals(diskChildNode.getNodeName())) { NamedNodeMap diskNodeAttributes = diskChildNode.getAttributes(); Node diskNodeAttribute = diskNodeAttributes.getNamedItem("file"); if (diskNodeAttribute != null) { return diskNodeAttribute.getTextContent(); }/*from w ww. jav a 2 s .co m*/ diskNodeAttribute = diskNodeAttributes.getNamedItem("dev"); if (diskNodeAttribute != null) { return diskNodeAttribute.getTextContent(); } } } return null; }
From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.QueryTests.java
@Test public void fulltextSearchReturnsScoreValueInResults() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { String query = getQueryBase(); query = query + "oslc_cm.query=oslc_cm:searchTerms=" + URLEncoder.encode("\"" + fullTextSearchTerm + "\"", "UTF-8"); //Get response HttpResponse resp = OSLCUtils.getResponseFromUrl(baseUrl, currentUrl + query, basicCreds, "application/xml"); String respBody = EntityUtils.toString(resp.getEntity()); Document doc = OSLCUtils.createXMLDocFromResponseBody(respBody); //Verify that each score element is non-negative NodeList scores = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_cm:score", doc, XPathConstants.NODESET); assertTrue(scores.getLength() > 0); for (int i = 0; i < scores.getLength(); i++) { Node score = scores.item(i); assertNotNull(score);/*from w w w.j a va2s .c o m*/ assertTrue(Integer.parseInt(score.getTextContent()) >= 0); } }