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:org.infoglue.igide.helper.Utils.java
License:Open Source License
/** * @deprecated Method uglyParseRepositoryId is deprecated */// w w w. j a v a 2s . c o m public static Integer uglyParseRepositoryId(String returnData) { Integer value = null; for (int tStart = returnData.indexOf("name=\"repositoryId\""); tStart > 0;) if (returnData.charAt(tStart--) == '<') { returnData = returnData.substring(tStart + 1, returnData.indexOf(">", tStart + 1) + 1); Document doc = null; try { doc = DocumentHelper.parseText(returnData); } catch (DocumentException documentexception) { } if (doc == null) try { doc = DocumentHelper.parseText( (new StringBuilder(String.valueOf(returnData))).append("</input>").toString()); } catch (DocumentException documentexception1) { } if (doc != null) { Element r = doc.getRootElement(); if (r.getName().equals("input") && r.valueOf("@name").equals("repositoryId")) try { value = new Integer(doc.getRootElement().valueOf("@value")); } catch (Exception exception) { } } break; } return value; }
From source file:org.infoglue.igide.helper.Utils.java
License:Open Source License
/** * Make this method go away as soon as possible (I have tried to make it * as safe as possible, but its far from great.) * @deprecated//from w w w . j a va 2s. c om */ public static Integer uglyParseContentId(String returnData) { Integer value = null; int tStart = returnData.indexOf("name=\"contentId\""); while (tStart > 0) { if (returnData.charAt(tStart--) == '<') { returnData = returnData.substring(tStart + 1, returnData.indexOf(">", tStart + 1) + 1); Document doc = null; try { doc = DocumentHelper.parseText(returnData); } catch (DocumentException e) { } if (doc == null) { try { doc = DocumentHelper.parseText(returnData + "</input>"); } catch (DocumentException e) { } } if (doc != null) { Element r = doc.getRootElement(); if (r.getName().equals("input") && r.valueOf("@name").equals("contentId")) { try { value = new Integer(doc.getRootElement().valueOf("@value")); } catch (Exception e) { } } } break; } } return value; }
From source file:org.jboss.console.util.XMLToHTMLTreeBuilder.java
License:Open Source License
/** * Expects the xml to string to be in same format as calling JNDIView.listXML(). * Will then build a tree in html that uses javascript. Depends on dtree.js script * being available./*from w w w.j av a2s .c om*/ * * @param xml * @return * @throws DocumentException */ public static String convertJNDIXML(String xml) throws DocumentException { Document jndiXml = DocumentHelper.parseText(xml); String scriptHead = "<div class=\"dtree\"><script type=\"text/javascript\" src=\"dtree.js\"></script>\n"; String ejbTree = convertEjbModule(jndiXml); String contextTree = convertContext(jndiXml); return scriptHead + ejbTree + "<p>" + contextTree; }
From source file:org.jbpm.instantiation.Delegation.java
License:Open Source License
public void write(Element element) { element.addAttribute("class", className); element.addAttribute("config-type", configType); String configuration = this.configuration; if (configuration != null) { try {// w ww. j ava 2s .c om Element actionElement = DocumentHelper.parseText("<action>" + configuration + "</action>") .getRootElement(); Iterator iter = new ArrayList(actionElement.content()).iterator(); while (iter.hasNext()) { Node node = (Node) iter.next(); node.setParent(null); element.add(node); } } catch (DocumentException e) { log.error("couldn't create dom-tree for action configuration '" + configuration + "'", e); } } }
From source file:org.jbpm.instantiation.FieldInstantiator.java
License:Open Source License
protected Element parseConfiguration(String configuration) { Element element = null;//from w w w . ja v a 2 s. co m try { element = DocumentHelper.parseText("<action>" + configuration + "</action>").getRootElement(); } catch (DocumentException e) { log.error("couldn't parse bean configuration : " + configuration, e); throw new JbpmException(e); } return element; }
From source file:org.jbpm.jpdl.convert.Converter.java
License:Open Source License
public String convertPar(ProcessArchive pa) { try {//from w w w. j a va 2s . c om // Parse the process definition XML into a DOM document Document doc = DocumentHelper.parseText(new String(pa.getEntry("processdefinition.xml"))); // Convert from 2.0 to 3.0 PDL Document doc30 = convert(doc); // Serialize the resulting document as the result ByteArrayOutputStream bos = new ByteArrayOutputStream(); serializetoXML(bos, doc30); return bos.toString(); } catch (DocumentException de) { log.error("Conversion had trouble parsing the 2.0 process definition", de); } catch (Exception ex) { log.error("Unexpected error in conversion", ex); } return null; // things did not go well }
From source file:org.jbpm.jpdl.xml.AbstractXmlTestCase.java
License:Open Source License
static Element toXmlAndParse(ProcessDefinition processDefinition) throws Exception { StringWriter stringWriter = new StringWriter(); JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter); jpdlWriter.write(processDefinition); String xml = stringWriter.toString(); return DocumentHelper.parseText(xml).getRootElement(); }
From source file:org.jbpm.jpdl.xml.AbstractXmlTestCase.java
License:Open Source License
static Element toXmlAndParseWithNamespace(ProcessDefinition processDefinition) throws Exception { StringWriter stringWriter = new StringWriter(); JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter); jpdlWriter.setUseNamespace(true);/* w w w . ja va 2s. c om*/ jpdlWriter.write(processDefinition); String xml = stringWriter.toString(); return DocumentHelper.parseText(xml).getRootElement(); }
From source file:org.jcommon.com.jsip.utils.SipUtil.java
License:Apache License
public static PresenceType getStatus(String body) throws IOException { String presence = ""; if (body == null) return PresenceType.unavailable; try {/*from ww w . j a v a2s .com*/ Document doc = DocumentHelper.parseText(body); Element root = doc.getRootElement(); if (root != null) { root = root.element("person"); if (root != null) { root = root.element("activities"); if (root != null) { Iterator<?> it = root.elementIterator(); for (; it.hasNext();) { Object e = it.next(); presence = ((Element) e).asXML(); } } } } } catch (Throwable t) { logger.error("parse to doc error :\n" + body, t); t.printStackTrace(); } if (presence.indexOf(" ") != -1) presence = presence.substring(0, presence.indexOf(" ")) + "/>"; return notify2Type(presence); }
From source file:org.jcommon.com.jsip.utils.SipUtil.java
License:Apache License
public static String getPresences(String str) throws IOException { String presence = ""; try {/*from w w w.jav a 2s. c o m*/ if (str == null) return presence; Document doc = DocumentHelper.parseText(str); Element root = doc.getRootElement(); if (root != null) { root = root.element("person"); if (root != null) { root = root.element("note"); if (root != null) { presence = root.getTextTrim(); } } } } catch (Throwable t) { logger.error("parse to doc error :\n" + str, t); t.printStackTrace(); } return presence; }