Example usage for org.dom4j DocumentHelper parseText

List of usage examples for org.dom4j DocumentHelper parseText

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper parseText.

Prototype

public static Document parseText(String text) throws DocumentException 

Source Link

Document

parseText parses the given text as an XML document and returns the newly created Document.

Usage

From source file:gov.abrs.etms.tag.ProcessImageTag.java

License:Open Source License

private void writeTable() throws IOException, DocumentException {

    int borderWidth = 0;
    Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
    int[] boxConstraint;
    int[] imageDimension = extractImageDimension(rootDiagramElement);
    String imageLink = "processimage?definitionId=" + processDefinition.getId();
    JspWriter jspOut = pageContext.getOut();
    HttpServletRequest hsr = (HttpServletRequest) pageContext.getRequest();
    String contextPath = hsr.getContextPath() + "/";
    imageLink = contextPath + imageLink;

    boxConstraint = extractBoxConstraint(rootDiagramElement);

    jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height="
            + imageDimension[1] + ">");

    jspOut.println("  <tr>");
    jspOut.println("    <td width=" + imageDimension[0] + " height=" + imageDimension[1]
            + " style=\"background-image:url(" + imageLink + ")\" valign=top>");
    jspOut.println("      <table border=0 cellspacing=0 cellpadding=0>");
    jspOut.println("        <tr>");
    jspOut.println("          <td style=\"background-color:transparent;\">");
    jspOut.println("      <table border=0 cellspacing=0 cellpadding=0>");
    jspOut.println("        <tr>");
    jspOut.println("          <td width=" + (imageDimension[0] - 5)
            + " style=\"background-color:transparent;text-align:right;text-valign:bottom\">");
    jspOut.println("           <img src='" + contextPath + "img/star_level1.gif'/>??");
    jspOut.println("         </td>");
    jspOut.println("        </tr>");
    jspOut.println("      </table>");
    jspOut.println("         </td>");
    jspOut.println("        </tr>");
    jspOut.println("        <tr>");
    jspOut.println("          <td style=\"background-color:transparent;\">");
    jspOut.println("      <table border=0 cellspacing=0 cellpadding=0>");

    jspOut.println("        <tr>");
    jspOut.println("          <td width=" + (boxConstraint[0] - borderWidth) + " height="
            + (boxConstraint[1] - borderWidth - 20) + " style=\"background-color:transparent;\">&nbsp;</td>");
    jspOut.println("        </tr>");

    jspOut.println("        <tr>");
    jspOut.println("          <td style=\"background-color:transparent;\">&nbsp;</td>");
    jspOut.println("          <td style=\"border-color:#ff9900; border-width:" + borderWidth
            + "px; border-style:solid; background-color:transparent;\" width=" + boxConstraint[2] + " height="
            + (boxConstraint[3] + (2 * borderWidth)) + "><img src='" + contextPath
            + "img/star_level1.gif'/></td>");
    jspOut.println("        </tr>");

    jspOut.println("      </table>");

    jspOut.println("         </td>");
    jspOut.println("        </tr>");
    jspOut.println("      </table>");

    jspOut.println("    </td>");
    jspOut.println("  </tr>");
    jspOut.println("</table>");
}

From source file:gr.abiss.calipso.util.XmlUtils.java

License:Open Source License

/**
 * Converts a String into XML by parsing into a DOM Document
 * uses Dom4j/* www . j a  va 2 s  .c o  m*/
 */
public static Document parse(String xmlString) {
    try {
        return DocumentHelper.parseText(xmlString);
    } catch (DocumentException de) {
        throw new RuntimeException(de);
    }
}

From source file:hudson.plugins.filesfoundtrigger.XStreamUtil.java

License:Open Source License

/**
 * Construct an object from the given XML element using {@link XStream2}.
 * /*from   ww w.  j a  v a  2 s.co  m*/
 * @param xml
 *          the XML element as a string
 * @return the newly constructed object
 * @throws Exception
 */
static Object unmarshal(String xml) throws Exception {
    XStream2 xStream2 = new XStream2();
    Dom4JReader reader = null;
    try {
        reader = new Dom4JReader(DocumentHelper.parseText(xml));
        return xStream2.unmarshal(reader);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

From source file:info.smartkit.hairy_batman.plain.WxSogou.java

License:Apache License

public ArrayList<WxSogouSimple> getTitlesUrls() {
    // XML travel to title element,and push it to titles;
    titlesUrls = new ArrayList<WxSogouSimple>();
    for (Object item : this.items) {
        try {/*from  w w  w .j a v  a 2  s.c o  m*/
            Document doc = DocumentHelper.parseText(item.toString());
            Element root = doc.getRootElement();

            @SuppressWarnings("rawtypes")
            List aa = root.selectNodes("//item//display");

            @SuppressWarnings("rawtypes")
            Iterator iters = aa.iterator();
            //
            while (iters.hasNext()) {

                Element itemEle = (Element) iters.next();

                String title = itemEle.elementTextTrim("title");
                // String title1 = itemEle.elementTextTrim("title1");
                LOG.info("item title:" + title);
                String date = itemEle.elementTextTrim("date");
                LOG.info("item date:" + date);
                String url = itemEle.elementTextTrim("url");
                // String title1 = itemEle.elementTextTrim("title1");
                LOG.info("item url:" + url);
                // Store values.
                this.titlesUrls.add(new WxSogouSimple(title, date, url));
                // System.out.println("title1:" + title1);
            }
        } catch (DocumentException e) {
            // e.printStackTrace();
            LOG.error(e.toString());
        }
    }
    return this.titlesUrls;
}

From source file:io.mashin.oep.model.node.action.extended.CustomActionNode.java

License:Open Source License

@Override
public void write(Element parentNode) {
    super.write(parentNode);

    Element element = (Element) hpdlModel.get();
    String xmlContent = xml.getStringValue();
    if (xmlContent.isEmpty()) {
        xmlContent = "<EMPTY_CUSTOM_NODE xmlns=\"uri:oozie:EMPTY_CUSTOM_NODE:0.1\"/>";
    }/*from  ww w  . j a  v a2s .com*/
    try {
        element.add(DocumentHelper.parseText(xmlContent).getRootElement());
    } catch (Throwable t) {
        element.setText(xmlContent);
    }

    writeConnections(element);
}

From source file:io.mashin.oep.parts.WorkflowNodeEditPart.java

License:Open Source License

private void performOpen() {
    if (getCastedModel() instanceof CustomActionNode) {
        CustomActionNode customActionNode = (CustomActionNode) getCastedModel();
        String customActionNodeXML = "";

        try {//from  ww  w  .  j a  v a  2  s.  c  o  m
            StringWriter stringWriter = new StringWriter();
            XMLWriter writer = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint());
            writer.write(DocumentHelper
                    .parseText((String) customActionNode.getPropertyValue(CustomActionNode.PROP_XML))
                    .getRootElement());
            writer.flush();
            customActionNodeXML = stringWriter.toString();
        } catch (Exception e) {
            e.printStackTrace();
            customActionNodeXML = (String) customActionNode.getPropertyValue(CustomActionNode.PROP_XML);
        }

        XMLEditor.getInstance().open(customActionNode, customActionNodeXML, customActionNode.getName(),
                xml -> getViewer().getEditDomain().getCommandStack()
                        .execute(new CustomActionNodeXMLEditCommand(customActionNode, xml)));
    }
}

From source file:it.unibz.inf.xmlssd.metadator.helpers.UIHelper.java

License:Apache License

/**
 * Method which return a pretty formated string. If it fails the untouched
 * string is given back.//from  ww w. j  a  v  a 2  s  .  co  m
 * @param str
 * @return
 */
public static String prettyPrintString(String str) {
    try {
        Document document = DocumentHelper.parseText(str);
        OutputFormat format = OutputFormat.createPrettyPrint();

        // remove <?xml version="1.0" encoding="UTF-8"?>
        format.setSuppressDeclaration(true);

        StringWriter strWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(strWriter, format);

        writer.write(document);

        return strWriter.toString();
    } catch (IOException e) {
    } catch (DocumentException e) {
    }

    return str;
}

From source file:main.java.info.jtrac.util.XmlUtils.java

License:Apache License

/**
 * Converts a String into XML by parsing into a DOM Document
 * uses Dom4j//from   ww  w  .ja va 2s . c  om
 */
public static Document parse(String xmlString) throws RuntimeException {
    try {
        return DocumentHelper.parseText(xmlString);
    } catch (DocumentException de) {
        throw new RuntimeException(de);
    }
}

From source file:meddle.RString.java

License:Open Source License

public ArrayList<String> tryXml(String text) {
    if (text.startsWith("<?xml")) {
        xmlTerms = new ArrayList<String>();
        try {//  www .j av  a 2  s  .c  o m
            Document d = DocumentHelper.parseText(text);
            treeWalk(d);
        } catch (DocumentException e) {
            //            e.printStackTrace();
            System.err.println("XML decode failed");
            System.err.println(text);
        }
        return xmlTerms;
    } else {
        return null;
    }
}

From source file:mesquite.lib.XMLUtil.java

License:Open Source License

public static Document getDocumentFromString(String rootElementName, String contents, boolean stripSchema) {
    if (stripSchema)
        contents = stripSchema(contents);
    Document doc = null;// w ww.j a v  a 2 s. co m
    try {
        doc = DocumentHelper.parseText(contents);
    } catch (Exception e) {
        return null;
    }

    if (doc == null || doc.getRootElement() == null) {
        return null;
    } else if (!StringUtil.blank(rootElementName) && !doc.getRootElement().getName().equals(rootElementName)) {
        return null;
    }
    return doc;
}