List of usage examples for org.dom4j Node getNodeType
short getNodeType();
From source file:com.eurelis.opencms.workflows.workflows.A_OSWorkflowManager.java
License:Open Source License
/** * Get the OpenCMS RFS OSWorkflow configuration file and update it with the given filepath. * /*from w ww . j a va 2s. com*/ * @param listOfWorkflowsFilepath * the path of the file containing the list of available workflow descriptions * @return the path in RFS of the updated file * @throws DocumentException * this exception is thrown if an error occurs during the parsing of the document * @throws IOException * this exception is thrown if a problem occurs during overwriting of the config file */ private String updateOSWorkflowConfigFile(String listOfWorkflowsFilepath) throws CmsException, DocumentException, IOException { // get file path String configFilePath = this.getWebINFPath() + ModuleSharedVariables.SYSTEM_FILE_SEPARATOR + OSWORKFLOWCONFIGFILE_RFSFILEPATH; File listOfWorkflowsFile = new File(listOfWorkflowsFilepath); // Load Jdom parser SAXReader reader = new SAXReader(); Document document = reader.read(configFilePath); Node propertyNode = document.selectSingleNode(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH); if (propertyNode != null) { if (propertyNode.getNodeType() == Node.ELEMENT_NODE) { // convert Node into element Element propertyElement = (Element) propertyNode; // update the Attribute Attribute valueAttribute = propertyElement .attribute(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_ATTRIBUTNAME); valueAttribute.setValue(listOfWorkflowsFile.toURI().toString()); } else { LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH + " in the file " + configFilePath + " doesn't correspond to an element"); } } else { Node parentNode = document.selectSingleNode(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_PARENT_XPATH); if (parentNode != null) { if (parentNode.getNodeType() == Node.ELEMENT_NODE) { // convert Node into element Element parentElement = (Element) parentNode; // add new property Element propertyElement = parentElement.addElement("property"); // add attributs propertyElement.addAttribute("key", "resource"); propertyElement.addAttribute("value", listOfWorkflowsFile.toURI().toString()); } else { LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH + " in the file " + configFilePath + " doesn't correspond to an element"); } } else { LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_PARENT_XPATH + " in the file " + configFilePath + " has not been found."); } } /* * Get a string of the resulting file */ // creating of a buffer that will collect result ByteArrayOutputStream xmlContent = new ByteArrayOutputStream(); // Pretty print the document to xmlContent OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(xmlContent, format); writer.write(document); writer.flush(); writer.close(); // get the config file content as a String String documentContent = new String(xmlContent.toByteArray()); /* * Overwrite the config file */ FileWriter.writeFile(configFilePath, documentContent); return configFilePath; }
From source file:com.finderbots.miner2.pinterest.AnalyzeHtml.java
License:Apache License
private String getTextFromNode(Node node) { String attributeValue = null; if (node.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) node; attributeValue = e.getTextTrim(); }//w w w. j a va 2s . co m return (attributeValue == null ? "" : attributeValue); }
From source file:com.flaptor.util.parser.HtmlParser.java
License:Apache License
@SuppressWarnings("unchecked") private void removeNamespace(List list) { if (null != list) { for (Node node : (List<Node>) list) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { ((Attribute) node).setNamespace(Namespace.NO_NAMESPACE); } else if (node.getNodeType() == Node.ELEMENT_NODE) { removeNamespace((Element) node); }/*from w w w. j av a2 s .co m*/ } } }
From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag./*from w w w. ja v a2 s. c o m*/ */ @SuppressWarnings("unchecked") private static String getInnerXml(Element p_node) { StringBuffer result = new StringBuffer(); List<Node> content = p_node.content(); for (Node node : content) { if (node.getNodeType() == Node.TEXT_NODE) { result.append(EditUtil.encodeXmlEntities(node.getText())); } else { StringWriter out = new StringWriter(); result.append(out.toString()); } } return result.toString(); }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
/** * Parse main contents/*w w w .jav a2 s . c om*/ * * @param p_element */ private void domNodehandler(Node p_node, boolean isSource) { // public static final short ANY_NODE 0 // public static final short ATTRIBUTE_NODE 2 // public static final short CDATA_SECTION_NODE 4 // public static final short COMMENT_NODE 8 // public static final short DOCUMENT_NODE 9 // public static final short DOCUMENT_TYPE_NODE 10 // public static final short ELEMENT_NODE 1 // public static final short ENTITY_REFERENCE_NODE 5 // public static final short MAX_NODE_TYPE 14 // public static final short NAMESPACE_NODE 13 // public static final short PROCESSING_INSTRUCTION_NODE 7 // public static final short TEXT_NODE 3 // public static final short UNKNOWN_NODE 14 if (p_node == null) { return; } switch (p_node.getNodeType()) { case Node.ELEMENT_NODE: elementNodeProcessor(p_node, isSource); break; case Node.TEXT_NODE: String nodeValue = p_node.getStringValue(); if (nodeValue.startsWith("#")) { nodeValue = nodeValue.replaceFirst("#", OfflineConstants.PONUD_SIGN); } if (isParsingTTXForGS) { boolean isInTargetTuv = isInTargetTuv(p_node); if (nodeValue != null && isInTargetTuv) { results.append(nodeValue); } else if (nodeValue != null && isLockedSegment(p_node)) { results.append(AmbassadorDwUpConstants.SEGMENT_MATCH_TYPE_KEY).append(" ") .append("DO NOT TRANSLATE OR MODIFY (Locked).").append(TTXConstants.NEW_LINE); results.append(nodeValue); } } else { results.append(nodeValue); } break; default: return; } }
From source file:com.globalsight.everest.projecthandler.ProjectTmTuvT.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag.// w ww . j a va 2s .c om */ @SuppressWarnings("unchecked") private String getInnerXml(Element p_node) { StringBuffer result = new StringBuffer(); List<Node> content = p_node.content(); for (Node node : content) { if (node.getNodeType() == Node.TEXT_NODE) { result.append(EditUtil.encodeXmlEntities(node.getText())); } else { StringWriter out = new StringWriter(); result.append(out.toString()); } } return result.toString(); }
From source file:com.globalsight.everest.tm.exporter.TmxWriter.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag./*from w ww. jav a2s.c o m*/ */ private static String getInnerXml(Element p_node, OutputFormat outputFormat) { StringBuffer result = new StringBuffer(); List content = p_node.content(); for (int i = 0, max = content.size(); i < max; i++) { Node node = (Node) content.get(i); // Work around a specific behaviour of DOM4J text nodes: // The text node asXML() returns the plain Unicode string, // so we need to encode entities manually. if (node.getNodeType() == Node.TEXT_NODE) { result.append(EditUtil.encodeXmlEntities(node.getText())); } else { // Note: DOM4J's node.asXML() constructs the same 2 objects. StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, outputFormat); try { writer.write(node); } catch (IOException ignore) { } result.append(out.toString()); } } return result.toString(); }
From source file:com.globalsight.everest.tm.importer.ImportUtil.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag./*from w ww.j av a 2 s . c o m*/ */ static public String getInnerXml(Element p_node) { StringBuffer result = new StringBuffer(); List content = p_node.content(); for (int i = 0, max = content.size(); i < max; i++) { Node node = (Node) content.get(i); // Work around a specific behaviour of DOM4J text nodes: // The text node asXML() returns the plain Unicode string, // so we need to encode entities manually. if (node.getNodeType() == Node.TEXT_NODE) { result.append(encodeXmlEntities(node.getText())); } else { // Element nodes write their text nodes correctly. result.append(node.asXML()); } } return result.toString(); }
From source file:com.globalsight.everest.tm.util.ttx.TtxClean.java
License:Apache License
/** * Returns the inner text like Element.getText() but for all * embedded text nodes./*w w w.j a v a 2s . co m*/ */ static public String getInnerText(Element p_node) { StringBuffer result = new StringBuffer(); List content = p_node.content(); for (int i = 0, max = content.size(); i < max; i++) { Node node = (Node) content.get(i); if (node.getNodeType() == Node.TEXT_NODE) { result.append(node.getText()); } else if (node.getNodeType() == Node.ELEMENT_NODE) { result.append(getInnerText((Element) node)); } } return result.toString(); }
From source file:com.globalsight.ling.docproc.DiplomatWordCounter.java
License:Apache License
static public String getTranslateInnerXml(Element p_node) { StringBuilder result = new StringBuilder(); List content = p_node.content(); for (int i = 0; i < content.size(); i++) { Node node = (Node) content.get(i); if (node.getNodeType() == Node.TEXT_NODE) { result.append(encodeXmlEntities(node.getText())); }//from ww w. j a v a 2 s . c om } return result.toString(); }