List of usage examples for org.dom4j DocumentHelper parseText
public static Document parseText(String text) throws DocumentException
parseText
parses the given text as an XML document and returns the newly created Document.
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function returns a Document with the value of the property set by * path/*from w w w.j av a2 s .c o m*/ * * @param xml * String containing the property file * @param path * The path for the desired value * @return Document with the value of the property */ public static Document getValueOfProperty(String xml, String path) { String xpath = "/fsxml/" + path; Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } Element elem = (Element) doc.selectSingleNode(xpath).clone(); Document newDoc = DocumentHelper.createDocument(); Element root = DocumentHelper.createElement("fsxml"); newDoc.setRootElement(root); Element fsxml = (Element) newDoc.selectSingleNode("/fsxml"); fsxml.add(elem); return newDoc; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function will add a property with the specified value to the xml * passed as parameter/*from w w w .ja va2 s . c om*/ * * @param xml * @param property * @param value * @return */ public static String addPropertyValue(String xml, String property, String value) { Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } Element elem = (Element) doc.selectSingleNode("/fsxml/properties"); elem.addElement(property).addText(value); Element fsxml = (Element) doc.selectSingleNode("/fsxml"); xml = fsxml.asXML(); return xml; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function will check if a given property is defined * * @param xml/*from ww w . ja v a 2 s . c o m*/ * @param property * @return */ public static boolean propertyExists(String xml, String property) { boolean exists = false; Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } String xpath = "/fsxml/properties/" + property; Element elem = (Element) doc.selectSingleNode(xpath); if (elem != null) { exists = true; } return exists; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
public static String getPropertyValue(String xml, String propertyName) { String value = ""; Document doc = null;/* ww w .java 2 s . com*/ try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } Node propNode = null; propNode = doc.selectSingleNode("//" + propertyName); if (propNode != null) value = propNode.getText(); return value; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function will set the extension value (in the XML) obtained from the * ingested file.//from w w w . jav a2 s. c o m * * @param xml * @param ext * @return */ public static String setExtensionProperty(String xml, String ext) { Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } if (doc.selectSingleNode("//extension") != null) { doc.selectSingleNode("//extension").setText(ext); } else { Node props = doc.selectSingleNode("//properties"); if (props != null) { ((Element) props).addElement("extension"); doc.selectSingleNode("//extension").setText(ext); } } if (doc != null) { xml = doc.selectSingleNode("/fsxml").asXML(); } return xml; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function will set the mount value (in the XML) * * @param xml/*from w w w. java 2 s . co m*/ * @param ext * @return */ public static String setMountProperty(String xml, String mount) { Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } if (doc.selectSingleNode("//mount") != null) { doc.selectSingleNode("//mount").setText(mount); } else { Node props = doc.selectSingleNode("//properties"); if (props != null) { ((Element) props).addElement("mount"); doc.selectSingleNode("//mount").setText(mount); } } if (doc != null) { xml = doc.selectSingleNode("/fsxml").asXML(); } return xml; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
public static String getClassName(String xml) { String dest = ""; Document doc = null;//from w w w.j av a2 s. co m try { doc = DocumentHelper.parseText(xml); dest = doc.selectSingleNode("//class").getText(); } catch (DocumentException e) { e.printStackTrace(); } return dest; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function will extract the props part of the xml String * passed as parameter and return it as fsxml compatible properties. * * If the node is not found, a default (empty) node will be returned * * @param xml/* w w w . j a v a 2s. com*/ * @return */ public static String getPropsFromXml(String xml) { String props = "<fsxml>" + "<properties>" + "</properties>" + "</fsxml>"; Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { logger.error("", e); } Element properties = (Element) doc.selectSingleNode("/fsxml/ingest/props/properties").clone(); if (properties != null) { Document newDoc = DocumentHelper.createDocument(); Element fsxml = (Element) newDoc.addElement("fsxml"); fsxml.add(properties); props = fsxml.asXML(); } return props; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * this function will build a representation with the error message passed * as argument. The result will be an xml file * * @param error/* ww w .ja v a 2 s. co m*/ * @return */ public static DomRepresentation buildErrorRep(String error) { DomRepresentation res = null; try { res = new DomRepresentation(MediaType.TEXT_XML); Document errDoc = DocumentHelper.parseText("<error>" + error + "</error>"); res.setDocument(XmlHelper.convert(errDoc)); } catch (IOException e) { logger.error("", e); } catch (DocumentException e) { logger.error("", e); } return res; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * this function will return a boolean corresponding to the use or not of the FTP * @param ingest// w w w . j a va 2s .c o m * @param type * @return */ public static boolean useFtp(String ingest, String type) { boolean use = false; Document doc = null; try { doc = DocumentHelper.parseText(ingest); } catch (DocumentException e) { logger.error("", e); } String xpath = "/fsxml/properties/" + type + "/ftp/enabled"; Element isEnabled = (Element) doc.selectSingleNode(xpath); if (isEnabled != null) { String enabled = isEnabled.getText(); if (enabled.equals("true")) use = true; } return use; }