List of usage examples for org.w3c.dom Document getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:io.wcm.devops.conga.generator.plugins.fileheader.XmlFileHeader.java
@Override public Void apply(FileContext file, FileHeaderContext context) { try {/*from ww w. jav a 2 s . c om*/ Document doc = documentBuilder.parse(file.getFile()); // build XML comment and add it at first position Comment comment = doc.createComment("\n" + StringUtils.join(context.getCommentLines(), "\n") + "\n"); doc.insertBefore(comment, doc.getChildNodes().item(0)); // write file file.getFile().delete(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(file.getFile()); transformer.transform(source, result); } catch (SAXException | IOException | TransformerException ex) { throw new GeneratorException("Unable to add file header to " + FileUtil.getCanonicalPath(file), ex); } return null; }
From source file:fr.ortolang.diffusion.seo.SeoServiceBean.java
@Override public Map<String, String> getServiceInfos() { Map<String, String> infos = new HashMap<String, String>(); try {// w w w. j a v a2 s . c om Document document = generateSiteMapDocument(); int sitemapEntriesNumber = document.getChildNodes().item(0).getChildNodes().getLength(); infos.put(INFO_SITEMAP_ENTRIES_ALL, String.valueOf(sitemapEntriesNumber)); } catch (Exception e) { LOGGER.log(Level.INFO, "unable to collect info: " + INFO_SITEMAP_ENTRIES_ALL, e); } return infos; }
From source file:at.ait.dme.yuma.server.enrichment.SemanticEnrichmentServiceImpl.java
private Collection<SemanticTagGroup> parseUniVieResponse(String text) throws Exception { Collection<SemanticTagGroup> resources = new ArrayList<SemanticTagGroup>(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(text.getBytes("UTF-8"))); NodeList childNodes = doc.getChildNodes(); for (int a = 0; a < childNodes.getLength(); a++) { if (childNodes.item(a).getNodeName().equals("entities")) { NodeList entities = childNodes.item(a).getChildNodes(); for (int i = 0; i < entities.getLength(); i++) { Node entity = entities.item(i); NodeList entityContent = entity.getChildNodes(); SemanticTagGroup e = new SemanticTagGroup(); resources.add(e);/*from ww w .j av a 2 s .c o m*/ for (int j = 0; j < entityContent.getLength(); j++) { Node n = entityContent.item(j); String nName = n.getNodeName(); if (nName.equals(ENTITY_NAME)) { e.setTitle(n.getTextContent()); } else if (nName.equals(ENTITY_TYPE)) { e.setType(n.getTextContent()); } else if (nName.equals(REFERENCE)) { NodeList referenceContent = n.getChildNodes(); String url = "", label = "", description = ""; for (int k = 0; k < referenceContent.getLength(); k++) { Node r = referenceContent.item(k); String nodeName = r.getNodeName(); if (nodeName.equals(LINK)) { url = r.getTextContent(); } else if (nodeName.equals(LINK_LABEL)) { label = r.getTextContent(); } else if (nodeName.equals(LINK_ABSTRACT)) { description = r.getTextContent(); } } e.addTag(new SemanticTag(e.getTitle(), e.getType(), label, description, url)); } } } } } return resources; }
From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java
public static String htmlToWiki(String html, String contextPath, int projectId) throws Exception { // Strip the nbsp because it gets converted to unicode html = StringUtils.replace(html, " ", " "); // Take the html create DOM for parsing HtmlCleaner cleaner = new HtmlCleaner(); CleanerProperties props = cleaner.getProperties(); TagNode node = cleaner.clean(html);//from ww w . j av a 2 s .c o m Document document = new DomSerializer(props, true).createDOM(node); if (LOG.isTraceEnabled()) { LOG.trace(html); } // Process each node and output the wiki equivalent StringBuffer sb = new StringBuffer(); ArrayList<Node> nodeList = new ArrayList<Node>(); for (int i = 0; i < document.getChildNodes().getLength(); i++) { Node n = document.getChildNodes().item(i); nodeList.add(n); } processChildNodes(nodeList, sb, 0, true, true, false, "", contextPath, projectId); if (sb.length() > 0) { String content = sb.toString().trim(); if (content.contains("'")) { // Determine if this is where the ' is being introduced content = StringUtils.replace(content, "'", "'"); } if (!content.endsWith(CRLF)) { return content + CRLF; } else { return content; } } else { return ""; } }
From source file:org.openhmis.oauth2.OAuth2Utils.java
public void parseXMLDoc(Element element, Document doc, Map<String, String> oauthResponse) { NodeList child = null;// ww w.java2 s. c om if (element == null) { child = doc.getChildNodes(); } else { child = element.getChildNodes(); } for (int j = 0; j < child.getLength(); j++) { if (child.item(j).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { org.w3c.dom.Element childElement = (org.w3c.dom.Element) child.item(j); if (childElement.hasChildNodes()) { System.out.println(childElement.getTagName() + " : " + childElement.getTextContent()); oauthResponse.put(childElement.getTagName(), childElement.getTextContent()); parseXMLDoc(childElement, null, oauthResponse); } } } }
From source file:de.decidr.model.XmlToolsTest.java
@Test public void testCreateDocument() { Document doc = XmlTools.createDocument(); long start = System.currentTimeMillis(); for (int i = 0; i < 100; i++) { doc = XmlTools.createDocument(); /*//from ww w .j a v a 2s . c o m * Is the new document empty? */ assertEquals(0, doc.getChildNodes().getLength()); } System.out.println("Tested 100 documents in " + (System.currentTimeMillis() - start) + " milliseconds"); }
From source file:edu.duke.cabig.c3pr.webservice.integration.StudyImportExportWebServiceTest.java
private Node getSOAPBodyFromXML(String xmlBaseFileName) throws IOException, SAXException, ParserConfigurationException { InputStream is = getResource(null, TESTDATA_PACKAGE + "/" + xmlBaseFileName + ".xml"); String xmlStr = IOUtils.toString(is); xmlStr = xmlStr.replace("${STUDY_ID}", STUDY_ID); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);/* ww w.java 2 s.com*/ dbf.setIgnoringComments(true); org.w3c.dom.Document doc = dbf.newDocumentBuilder().parse(IOUtils.toInputStream(xmlStr)); IOUtils.closeQuietly(is); return doc.getChildNodes().item(0); }
From source file:org.gvnix.dynamic.configuration.roo.addon.config.XmlDynamicConfiguration.java
/** * {@inheritDoc}//from ww w.j av a 2s . c o m */ public DynPropertyList read() { DynPropertyList dynProps = new DynPropertyList(); // Get the XML file path MutableFile file = getFile(); // If managed file not exists, nothing to do if (file != null) { // Obtain the XML file on DOM document format Document doc = getXmlDocument(file); // Create the dynamic properties list from XML document file dynProps.addAll(getProperties("", doc.getChildNodes())); } return dynProps; }
From source file:functionnality.LikerLineST2.java
public boolean createTable(String id) { CouchDBWebRequest couchDB = new CouchDBWebRequest(); Document d; //Crer le doc apres avoir vrifier qu'il existe bien dans Tisseo TisseoWebRequest tisseoR = new TisseoWebRequest("/linesList"); tisseoR.addParameterGet("lineId", id); d = tisseoR.parseResultXML(tisseoR.requestWithGet()); String shortName = "", name = "", type = ""; couchDB.addPath("/id_ligne_" + id); if (d.getChildNodes().item(0).getChildNodes().getLength() < 4) { try {//w w w.java 2 s . c o m Node n = d.getChildNodes().item(0).getChildNodes().item(1); shortName = n.getAttributes().getNamedItem("shortName").getNodeValue(); name = n.getAttributes().getNamedItem("name").getNodeValue(); type = n.getChildNodes().item(1).getAttributes().getNamedItem("name").getNodeValue(); JSONObject tableCreate = new JSONObject(); tableCreate.put("ShortName", new String(shortName.getBytes("ISO-8859-1"), Charset.forName("UTF-8"))); tableCreate.put("Name", new String(name.getBytes("ISO-8859-1"), Charset.forName("UTF-8"))); tableCreate.put("Type", new String(type.getBytes("ISO-8859-1"), Charset.forName("UTF-8"))); tableCreate.put("like", 0); tableCreate.put("unlike", 0); tableCreate.put("Voted", new JSONArray()); couchDB.requestWithPut(new String(tableCreate.toString().getBytes("UTF-8"), "UTF-8")); } catch (UnsupportedEncodingException ex) { return false; } } else { return false; } return true; }
From source file:spec.schema.SchemaCurrent_TO_2008_02_Test.java
/** * Tests the XSLT used to downgrade from current schema to 2008-02. * An XML file with an image is created and the stylesheet is applied. * @throws Exception Thrown if an error occurred. *///from w w w. j a v a2 s . com @Test(enabled = true) public void testDowngradeTo200802ImageNoMetadata() throws Exception { File inFile = File.createTempFile("testDowngradeTo200802ImageNoMetadata", "." + OME_XML_FORMAT); files.add(inFile); File middleFile = File.createTempFile("testDowngradeTo200802ImageNoMetadataMiddle", "." + OME_XML_FORMAT); files.add(middleFile); File outputFile = File.createTempFile("testDowngradeTo200802ImageNoMetadataOutput", "." + OME_XML_FORMAT); files.add(outputFile); XMLMockObjects xml = new XMLMockObjects(); XMLWriter writer = new XMLWriter(); writer.writeFile(inFile, xml.createImage(), true); transformFileWithStream(inFile, middleFile, STYLESHEET_A); transformFileWithStream(middleFile, outputFile, STYLESHEET_B); Document doc = anOmeValidator.parseFileWithStreamArray(outputFile, schemaArray); assertNotNull(doc); //Should only have one root node i.e. OME node NodeList list = doc.getChildNodes(); assertEquals(list.getLength(), 1); Node root = list.item(0); assertEquals(root.getNodeName(), XMLWriter.OME_TAG); //now analyse the root node list = root.getChildNodes(); String name; Node n; Document docSrc = anOmeValidator.parseFile(inFile, null); Node rootSrc = docSrc.getChildNodes().item(0); Node imageNode = null; NodeList listSrc = rootSrc.getChildNodes(); for (int i = 0; i < listSrc.getLength(); i++) { n = listSrc.item(i); name = n.getNodeName(); if (name != null) { if (name.contains(XMLWriter.IMAGE_TAG)) imageNode = n; } } for (int i = 0; i < list.getLength(); i++) { n = list.item(i); name = n.getNodeName(); if (name != null) { //TODO: add other node if (name.contains(XMLWriter.IMAGE_TAG) && imageNode != null) checkImageNode(n, imageNode); } } }