List of usage examples for org.w3c.dom Node getFirstChild
public Node getFirstChild();
From source file:com.prowidesoftware.swift.io.parser.XMLParserTest.java
/** * Test for w3 dom parsing behavior/*from w w w . j a v a 2 s .c o m*/ * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ @Test public void testNode() throws ParserConfigurationException, SAXException, IOException { final String text = "<tag>line1\r\nline2</tag>"; final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8")); final Document doc = db.parse(is); Node n = doc.getFirstChild(); //this proves that DOM parser removes original carriage return characters from XML assertEquals("line1\nline2", n.getFirstChild().getNodeValue()); }
From source file:org.alfresco.web.config.ConfigRuntime.java
/** * @param parent// w w w. j ava 2s . c o m * @param child * @param sibling */ protected void insertChildBefore(Node parent, Node child, Node sibling) { if (sibling == null) { if (parent.getFirstChild() == null) { appendChild(parent, child); } else { parent.getFirstChild().insertBefore(child, parent.getFirstChild()); } } else { sibling.insertBefore(child, sibling); } }
From source file:org.alfresco.web.config.ConfigRuntime.java
protected void insertChildAfter(Node parent, Node child, Node sibling) { if (sibling == null) { if (parent.getFirstChild() != null) { parent.insertBefore(child, parent.getFirstChild()); } else {//from w w w . j a v a2 s .com appendChild(parent, child); } } else { if (sibling.getNextSibling() == null) { appendChild(parent, child); } else { parent.insertBefore(child, sibling.getNextSibling()); } } }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
@SuppressWarnings("unchecked") private XTeeHeader parseXteeHeader(SOAPMessage paringMessage) throws SOAPException { XTeeHeader pais = new XTeeHeader(); if (paringMessage.getSOAPHeader() == null) { return pais; }/*from w w w . j a v a 2 s .co m*/ SOAPHeader header = paringMessage.getSOAPHeader(); for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext();) { Node headerElement = headerElemendid.next(); if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) { String localName = headerElement.getLocalName(); String value = headerElement.getFirstChild().getNodeValue(); pais.addElement(new QName(headerElement.getNamespaceURI(), localName), value); } } return pais; }
From source file:org.joy.config.Configuration.java
private String parseElementNodeValue(Node node) { if (node.getFirstChild() != null) { return node.getFirstChild().getNodeValue(); } else {/* ww w . ja v a2 s.co m*/ return null; } }
From source file:com.netspective.commons.lang.MethodJavaDoc.java
protected void setName(String name) { super.setName(name); if (!getClassDoc().isValid() || getClassDoc().isFound()) { setFound(false);// ww w . ja va 2 s . co m return; } locator = JavaDocs.getInstance().getMethodDocXmlNodeLocator(getClassDoc().getOwner(), getName(), true); if (locator.getRetrievalError() != null) { setRetrievalError(locator.getRetrievalError()); return; } try { if (locator.isFound()) { Node methodDocNode = locator.getLocatedNode(); Node descrLeadNode = XPathAPI.selectSingleNode(methodDocNode, "description/lead"); Node descrDetailNode = XPathAPI.selectSingleNode(methodDocNode, "description/detail"); if (descrLeadNode != null) setDescriptionLead(descrLeadNode.getFirstChild().getNodeValue()); if (descrDetailNode != null) setDescriptionDetail(descrDetailNode.getFirstChild().getNodeValue()); setFound(true); } } catch (Exception e) { log.error("Unable to get method documentation for " + getClassDoc().getOwner() + " method " + getName(), e); setRetrievalError(e); } }
From source file:de.betterform.xml.dom.DOMUtil.java
/** * This is a workaround for very strange behaviour of xerces-1.4.2 DOM importNode. *///w ww .j a v a 2s . c o m public static Node importNode(Document document, Node toImport) { if (toImport != null) { Node root = toImport.cloneNode(false); // no deep cloning! root = document.importNode(root, false); for (Node n = toImport.getFirstChild(); n != null; n = n.getNextSibling()) { root.appendChild(document.importNode(n, true)); } return root; } return null; }
From source file:com.eucalyptus.objectstorage.pipeline.WalrusSoapUserAuthenticationHandler.java
public void handle(MappingHttpRequest httpRequest, Document doc) throws AuthenticationException { NodeList childNodes = doc.getChildNodes(); Element bodyElem = doc.getDocumentElement(); Node operationElem = bodyElem.getFirstChild(); String operationName = operationElem.getNodeName(); if (operationName.length() > 0) { NodeList authNodes = operationElem.getChildNodes(); String queryId = null, timestamp = null, signature = null; for (int i = 0; i < authNodes.getLength(); ++i) { Node node = authNodes.item(i); if (node.getNodeName().equals(WalrusProperties.RequiredSOAPTags.AWSAccessKeyId.toString())) { queryId = node.getFirstChild().getNodeValue().trim(); } else if (node.getNodeName().equals(WalrusProperties.RequiredSOAPTags.Timestamp.toString())) { timestamp = node.getFirstChild().getNodeValue().trim(); } else if (node.getNodeName().equals(WalrusProperties.RequiredSOAPTags.Signature.toString())) { signature = node.getFirstChild().getNodeValue().trim(); }/*from w w w . j av a 2 s . co m*/ } if (queryId == null) throw new AuthenticationException("Unable to parse access key id"); if (signature == null) throw new AuthenticationException("Unable to parse signature"); if (timestamp == null) throw new AuthenticationException("Unable to parse timestamp"); //check timestamp verifyTimestamp(timestamp); String data = "AmazonS3" + operationName + timestamp; //check signature authenticate(httpRequest, queryId, signature, data); } else { throw new AuthenticationException("Invalid operation specified"); } }
From source file:marytts.tools.voiceimport.AllophonesExtractor.java
/** * /* w ww . j av a 2s. c o m*/ * @param basename * @throws IOException */ public void generateAllophonesFile(String basename) throws IOException, MaryConfigurationException { Locale localVoice = MaryUtils.string2locale(locale); String xmlLocale = MaryUtils.locale2xmllang(localVoice); String inputDir = db.getProp(db.TEXTDIR); String outputDir = promptAllophonesDir.getAbsolutePath(); String fullFileName = inputDir + File.separator + basename + db.getProp(db.TEXTEXT); // this string controls whether style attributes are inserted into the prompt_allophones ("" -> disabled): String style = ""; if (styleDefinition != null) { style = getStyleFromStyleDefinition(basename); } File textFile = new File(fullFileName); String text = FileUtils.readFileToString(textFile, "UTF-8"); // First, test if there is a corresponding .rawmaryxml file in textdir: File rawmaryxmlFile = new File( db.getProp(db.MARYXMLDIR) + File.separator + basename + db.getProp(db.MARYXMLEXT)); if (rawmaryxmlFile.exists()) { if (style.isEmpty()) { // just pass through the raw file: text = FileUtils.readFileToString(rawmaryxmlFile, "UTF-8"); } else { // parse the .rawmaryxml file: Document document = null; try { document = DomUtils.parseDocument(rawmaryxmlFile); } catch (Exception e) { throw new IOException("Error parsing RAWMARYXML file: " + rawmaryxmlFile.getName(), e); } // get the <maryxml> node: Node maryXmlNode = document.getDocumentElement(); Node firstMaryXmlChild = maryXmlNode.getFirstChild(); Node lastMaryXmlChild = maryXmlNode.getLastChild(); // wrap the <maryxml>'s content in new <prosody> element... Element topLevelProsody = DomUtils.encloseNodesWithNewElement(firstMaryXmlChild, lastMaryXmlChild, MaryXML.PROSODY); // ...and set its style attribute: topLevelProsody.setAttribute("style", style); // convert the document to the text string: text = DomUtils.document2String(document); } } else { String prosodyOpeningTag = ""; String prosodyClosingTag = ""; if (!style.isEmpty()) { prosodyOpeningTag = String.format("<%s style=\"%s\">\n", MaryXML.PROSODY, style); prosodyClosingTag = String.format("</%s>\n", MaryXML.PROSODY); } text = getMaryXMLHeaderWithInitialBoundary(xmlLocale) + prosodyOpeningTag + text + prosodyClosingTag + "</maryxml>"; } OutputStream os = new BufferedOutputStream(new FileOutputStream(new File(outputDir, basename + featsExt))); MaryHttpClient maryClient = getMaryClient(); maryClient.process(text, maryInputType, maryOutputType, db.getProp(db.LOCALE), null, null, os); os.flush(); os.close(); }
From source file:Main.java
public static int getAllChildren(Node start, int offset) { //String spacers = " "; String tagOpen = "<"; String tagClose = ">"; String tagEndOpen = "</"; String tagEndClose = ">"; String tagName = start.getNodeName(); String tagValue = (start.getNodeValue() == null ? "" : start.getNodeValue()); if (start.getNodeName().trim().equals("#text")) { tagOpen = ""; tagClose = ""; tagName = ""; tagEndOpen = ""; tagEndClose = ""; } else if (start.getNodeName().trim().equals("#comment")) { tagOpen = "<!--"; tagClose = ""; tagName = ""; tagEndOpen = ""; tagEndClose = "-->"; }//from w w w .ja va2s. c om if (offset == 0) HTMLString = ""; HTMLString += tagOpen + tagName; if (start.getNodeType() == Element.ELEMENT_NODE) { NamedNodeMap startAttr = start.getAttributes(); for (int i = 0; i < startAttr.getLength(); i++) { Node attr = startAttr.item(i); HTMLString += " " + attr.getNodeName() + "=\"" + attr.getNodeValue() + "\""; } } HTMLString += tagClose + tagValue; for (Node child = start.getFirstChild(); child != null; child = child.getNextSibling()) { getAllChildren(child, offset + 1); } //if (offset > 0 && tagName.length() > 0) { if (tagName.length() > 0 || start.getNodeName().trim().equals("#comment")) { HTMLString += tagEndOpen + tagName + tagEndClose; } return ++offset; }