Example usage for org.dom4j Node asXML

List of usage examples for org.dom4j Node asXML

Introduction

In this page you can find the example usage for org.dom4j Node asXML.

Prototype

String asXML();

Source Link

Document

asXML returns the textual XML representation of this node.

Usage

From source file:org.pentaho.platform.uifoundation.chart.FlashChartComponent.java

License:Open Source License

private String setRadialTicks(final Node node, final String template) {
    try {/*from   ww w  .  j a  v a2 s.co  m*/
        String xml = setRadialTicks(XmlDom4JHelper.getNodeText("@x", node, (width / 2.0)), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@y", node, (height / 2.0)), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@radius", node, (height / 2.0)), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@length", node, 8.0), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@start_angle", node, 0.0), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@end_angle", node, 350.0), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@tick_count", node, 36), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@thickness", node, 2), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@color", node, "000000") //$NON-NLS-1$ //$NON-NLS-2$
        );
        String param_name = XmlDom4JHelper.getNodeText("@param_name", node, null); //$NON-NLS-1$
        return (template.replaceAll("\\{" + param_name + "\\}", xml)); //$NON-NLS-1$ //$NON-NLS-2$
    } catch (Throwable t) {
        error(Messages.getInstance().getString("FlashChartComponent.ERROR_0003_INVALID_XML_ATTRIBUTES_FOR_DIAL", //$NON-NLS-1$
                "radial_ticks", node.asXML())); //$NON-NLS-1$
    }
    return (template);
}

From source file:org.pentaho.platform.uifoundation.chart.FlashChartComponent.java

License:Open Source License

private String setRadialNumbers(final Node node, final String template) {
    try {/*from www  .  jav a 2 s .c  o m*/
        String xml = setRadialNumbers(XmlDom4JHelper.getNodeText("@x", node, (width / 2.0)), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@y", node, (height / 2.0)), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@radius", node, (height / 2.0)), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@start_angle", node, 0.0), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@end_angle", node, 350.0), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@start_number", node, 0), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@end_number", node, 340), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@tick_count", node, 18), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@font_size", node, 12), //$NON-NLS-1$
                XmlDom4JHelper.getNodeText("@color", node, "000000") //$NON-NLS-1$ //$NON-NLS-2$
        );
        String param_name = XmlDom4JHelper.getNodeText("@param_name", node, null); //$NON-NLS-1$
        return (template.replaceAll("\\{" + param_name + "\\}", xml)); //$NON-NLS-1$ //$NON-NLS-2$
    } catch (Throwable t) {
        error(Messages.getInstance().getString("FlashChartComponent.ERROR_0003_INVALID_XML_ATTRIBUTES_FOR_DIAL", //$NON-NLS-1$
                "radial_numbers", node.asXML())); //$NON-NLS-1$
    }
    return (template);
}

From source file:org.pentaho.platform.uifoundation.component.xml.InputFormComponent.java

License:Open Source License

@Override
public Document getXmlContent() {

    ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(getSession());
    IActionSequence actionSequence = actionHelper.getActionSequence(
            ActionInfo.buildSolutionPath(solution, path, actionName), getLoggingLevel(),
            RepositoryFilePermission.READ);

    if (actionSequence == null) {
        // TODO log this
        error(Messages.getInstance().getString("InputForm.ERROR_0004_ACTION_NOT_FOUND") + solution + path //$NON-NLS-1$
                + actionName);//from  w  w w .j av a 2s  .co m
        return null;
    }

    List actions = actionSequence.getActionDefinitionsAndSequences();
    ISolutionActionDefinition action = (ISolutionActionDefinition) actions.get(0);

    Node node = action.getComponentSection();
    if (node == null) {
        error(Messages.getInstance().getString("InputForm.ERROR_0005_INBOX_DEFINITION_MISSING") + solution //$NON-NLS-1$
                + path + actionName);
        return null;
    }

    if (templateName == null) {

        // see if the template is specified in the action document
        Node templateNode = node.selectSingleNode("//template"); //$NON-NLS-1$
        if (templateNode != null) {
            templateName = templateNode.getText();
        }
        if (templateName == null) {
            error(Messages.getInstance().getString("InputForm.ERROR_0006_TEMPLATE_NOT_SPECIFIED")); //$NON-NLS-1$
            return null;
        }
    }
    Node xFormNode = node.selectSingleNode("//xForm"); //$NON-NLS-1$

    try {

        String actionTitle = actionSequence.getTitle();
        if (actionTitle != null) {
            setXslProperty("title", actionTitle); //$NON-NLS-1$
        }

        String description = actionSequence.getDescription();
        if (description != null) {
            setXslProperty("description", description); //$NON-NLS-1$
        }

        String xFormHtml = XForm.transformSnippet(xFormNode, getSession(), new SolutionURIResolver());
        if (xFormHtml == null) {
            error(Messages.getInstance().getString("InputForm.ERROR_0007_INBOX_DEFINITION_INVALID") + solution //$NON-NLS-1$
                    + path + actionName);
            return null;
        }
        Document document = DocumentHelper.parseText(xFormHtml);
        Node xFormHtmlNode = document.selectSingleNode("//xForm"); //$NON-NLS-1$

        setXslProperty("xForm", xFormHtmlNode.asXML()); //$NON-NLS-1$

        if ((stylesheetName != null) && !"".equals(stylesheetName)) { //$NON-NLS-1$
            setXslProperty("css", stylesheetName); //$NON-NLS-1$
        }
        setXsl("text/html", templateName); //$NON-NLS-1$

        return document;

    } catch (Exception e) {
        return null;
    }

}

From source file:org.pentaho.platform.util.xml.XForm.java

License:Open Source License

public static String transformSnippet(final Node xForm, final IPentahoSession session,
        final IDocumentResourceLoader loader) throws TransformerException {

    return XForm.transformSnippet(xForm.asXML(), null, session, loader);

}

From source file:pt.lsts.neptus.mp.maneuvers.CompassCalibration.java

License:Open Source License

@Override
public void loadFromXML(String xml) {
    try {/*from  w ww  .  jav a2 s.  c  o  m*/
        Document doc = DocumentHelper.parseText(xml);
        Node node = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/finalPoint/point");
        if (node == null)
            node = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/initialPoint/point"); // to read old elevator specs
        ManeuverLocation loc = new ManeuverLocation();
        loc.load(node.asXML());
        setManeuverLocation(loc);

        Node pitchNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/pitch");
        pitchDegs = Double.parseDouble(pitchNode.getText());

        Node amplitudeNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/amplitude");
        amplitude = Double.parseDouble(amplitudeNode.getText());

        Node durationNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/duration");
        duration = Integer.parseInt(durationNode.getText());

        Node speedNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/speed");
        speed = Double.parseDouble(speedNode.getText());
        speedUnits = speedNode.valueOf("@unit");

        radius = Float.parseFloat(doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/radius").getText());

    } catch (Exception e) {
        NeptusLog.pub().error(this, e);
        return;
    }
}

From source file:pt.lsts.neptus.mp.maneuvers.ExpandingSquarePattern.java

License:Open Source License

@Override
public void loadFromXML(String xml) {
    try {/*  www. j a  v  a 2 s. c  om*/
        Document doc = DocumentHelper.parseText(xml);
        Node node = doc.selectSingleNode("//basePoint/point");
        ManeuverLocation loc = new ManeuverLocation();
        loc.load(node.asXML());
        setManeuverLocation(loc);

        // Speed
        Node speedNode = doc.selectSingleNode("//speed");
        speed = Double.parseDouble(speedNode.getText());
        //            speed_units = speedNode.valueOf("@unit");
        SPEED_UNITS sUnits = ManeuversXMLUtil.parseSpeedUnits((Element) speedNode);
        setSpeedUnits(sUnits);

        bearingDeg = Double.parseDouble(doc.selectSingleNode("//bearing").getText());

        // area
        width = Double.parseDouble(doc.selectSingleNode("//width").getText());
        //steps
        hstep = Double.parseDouble(doc.selectSingleNode("//hstep").getText());

        node = doc.selectSingleNode("//firstCurveRight");
        if (node != null)
            firstCurveRight = Boolean.parseBoolean(node.getText());
        else
            firstCurveRight = true;
    } catch (Exception e) {
        NeptusLog.pub().error(this, e);
        return;
    } finally {
        recalcPoints();
    }
}

From source file:pt.lsts.neptus.mp.maneuvers.ManeuversXMLUtil.java

License:Open Source License

public static ManeuverLocation parseLocation(Element root, String locElementName) {
    Node node = root.selectSingleNode("//" + locElementName + "/point");
    ManeuverLocation loc = new ManeuverLocation();
    loc.load(node.asXML());
    return loc;/*from  www  . j a  v a 2s  .  c om*/
}

From source file:tokyo.northside.jrst.JRSTReader.java

License:Open Source License

/**
 * Parse text in element and replace text with parse result
 * /*from  w  ww.  j ava 2s .c  om*/
 * @param e element
 * @throws DocumentException
 * @throws UnsupportedEncodingException 
 */

private void inline(Element e) throws DocumentException, UnsupportedEncodingException {
    String text = e.getText();

    text = StringEscapeUtils.escapeXml(text);
    // search all LITERAL and replace it with special mark
    // this prevent substitution in literal, example **something** must not
    // change in literal
    Map<String, String> temporaries = new HashMap<String, String>();
    Matcher matcher = REGEX_LITERAL.matcher(text);
    int index = 0;
    while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        String literal = "<" + LITERAL + ">" + matcher.group(1) + "</" + LITERAL + ">";
        String key = LITERAL + index++;
        temporaries.put(key, literal);
        text = text.substring(0, start) + "<tmp>" + key + "</tmp>" + text.substring(end);
        matcher = REGEX_LITERAL.matcher(text);
    }
    // search all REGEX_INLINE_REFERENCE and replace it with special mark
    // this prevent substitution of URL with REGEX_REFERENCE. Use same
    // mechanisme as literal for that
    matcher = REGEX_INLINE_REFERENCE.matcher(text);
    index = 0;
    while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        Element ref = DocumentHelper.createElement(REFERENCE);
        ref.addAttribute(REFURI, StringEscapeUtils.unescapeXml(matcher.group(2)));
        ref.setText(StringEscapeUtils.unescapeXml(matcher.group(1)));
        String key = "inlineReference" + index++;
        temporaries.put(key, ref.asXML());
        text = text.substring(0, start) + "<tmp>" + key + "</tmp>" + text.substring(end);
        matcher = REGEX_INLINE_REFERENCE.matcher(text);

    }
    // do all substitution inline
    text = REGEX_EMAIL.matcher(text)
            .replaceAll("$1<" + REFERENCE + " refuri='mailto:$2'>$2</" + REFERENCE + ">$3");
    text = REGEX_STRONG.matcher(text).replaceAll("<" + STRONG + ">$1</" + STRONG + ">");
    text = REGEX_EMPHASIS.matcher(text).replaceAll("<" + EMPHASIS + ">$1</" + EMPHASIS + ">");
    text = REGEX_REFERENCE.matcher(text).replaceAll("<" + REFERENCE + " refuri='$1'>$1</" + REFERENCE + ">$2");
    // _[#]truc
    matcher = REGEX_FOOTNOTE_REFERENCE.matcher(text);
    while (matcher.find()) {
        String txtDebut = text.substring(0, matcher.start());
        String txtFin = text.substring(matcher.end() - 1, text.length() - 1);
        Element footnote = DocumentHelper.createElement(FOOTNOTE_REFERENCE);
        String sFootnote = matcher.group();
        boolean done = false;
        for (int i = 0; i < sFootnote.length() && !done; i++) {
            if (sFootnote.charAt(i) == ']') {
                String id = sFootnote.substring(1, i);
                if (id.equals("*")) {
                    int nb = Math.abs(symbolMaxRef / 10) + 1;
                    char symbol = FOOTNOTE_SYMBOL.charAt(symbolMaxRef % 10);
                    String label = "";
                    for (int j = 0; j < nb; j++) {
                        label += symbol;
                    }
                    symbolMaxRef++;
                    footnote.addAttribute(AUTO, "*");
                    for (int j = 0; j < eFootnotes.size(); j++) {
                        Element eFootnote = eFootnotes.get(j);
                        if (eFootnote.attributeValue(LABEL).equals(label)) {

                            footnote.addAttribute(ATTR_IDS, eFootnote.attributeValue(BACKREFS));
                            footnote.addAttribute(ATTR_REFID, eFootnote.attributeValue(ATTR_IDS));

                        }
                    }
                    footnote.setText(label);

                } else if (id.matches("[1-9]+")) {

                    for (int j = 0; j < eFootnotes.size(); j++) {
                        Element eFootnote = eFootnotes.get(j);
                        if (eFootnote.attributeValue(LABEL).equals(id)) {
                            footnote.addAttribute(ATTR_IDS, eFootnote.attributeValue(BACKREFS));
                            footnote.addAttribute(ATTR_REFID, eFootnote.attributeValue(ATTR_IDS));
                        }
                    }
                    footnote.setText(id);
                    lblFootnotesRef.add(Integer.parseInt(id));

                } else if (id.equals("#")) {
                    int lblMax = 0;
                    for (int j = 0; j < lblFootnotesRef.size(); j++) {
                        lblMax = Math.max(lblMax, lblFootnotesRef.get(j));
                    }

                    boolean[] lbls = new boolean[lblMax];
                    for (int j = 0; j < lbls.length; j++) {
                        lbls[j] = false;
                    }
                    for (int j = 0; j < lblFootnotesRef.size(); j++) {
                        lbls[lblFootnotesRef.get(j) - 1] = true;
                    }
                    boolean valide = false;
                    do {
                        boolean trouve = false;
                        String label = null;
                        for (int j = 0; j < lbls.length && !trouve; j++) {

                            if (!lbls[j]) {
                                trouve = true;
                                label = "" + (j + 1);
                            }
                        }
                        if (!trouve) {
                            label = "" + (lbls.length + 1);
                        }
                        footnote.addAttribute(AUTO, "1");
                        for (int j = 0; j < eFootnotes.size(); j++) {
                            Element eFootnote = eFootnotes.get(j);
                            if (eFootnote.attributeValue(LABEL).equals(label)) {
                                if (!(eFootnote.attributeValue(TYPE).equals(AUTONUMLABEL))) {
                                    footnote.addAttribute(ATTR_IDS, eFootnote.attributeValue(BACKREFS));
                                    footnote.addAttribute(ATTR_REFID, eFootnote.attributeValue(ATTR_IDS));
                                    footnote.setText(label);
                                    lblFootnotesRef.add(Integer.parseInt(label));
                                    valide = true;
                                } else {
                                    valide = false;
                                    lbls[Integer.parseInt(label) - 1] = true;
                                }
                            }
                        }
                    } while (!valide);

                }

                else {
                    footnote.addAttribute(AUTO, "1");

                    String name = id.substring(1);
                    boolean trouve = false;
                    for (int j = 0; j < eFootnotes.size() && !trouve; j++) {
                        Element eFootnote = eFootnotes.get(j);
                        if (eFootnote.attributeValue(NAMES).equals(name)) {
                            footnote.addAttribute(ATTR_IDS, eFootnote.attributeValue(BACKREFS));
                            footnote.addAttribute(ATTR_REFID, eFootnote.attributeValue(ATTR_IDS));
                            String label = eFootnote.attributeValue(LABEL);
                            footnote.setText(label);
                            lblFootnotesRef.add(Integer.parseInt(label));
                            trouve = true;
                        }
                    }

                    footnote.addAttribute(NAMES, name);
                }
                done = true;
            }
        }
        text = txtDebut + footnote.asXML() + txtFin;
        matcher = REGEX_FOOTNOTE_REFERENCE.matcher(text);
    }
    // .. __http://truc.html
    matcher = REGEX_ANONYMOUS_HYPERLINK_REFERENCE.matcher(text);
    while (matcher.find()) {
        String txtDebut = text.substring(0, matcher.start());
        String txtFin = text.substring(matcher.end(), text.length());
        String ref = text.substring(matcher.start(), matcher.end() - 2);
        ref = ref.replaceAll("`", "");
        Element anonym = DocumentHelper.createElement(REFERENCE);
        anonym.addAttribute(ANONYMOUS, "1");
        anonym.addAttribute(NAME, ref.trim());
        if (!eTargetAnonymous.isEmpty()) {
            Element target = eTargetAnonymous.getFirst();
            eTargetAnonymous.removeFirst();
            anonym.addAttribute(REFURI, target.attributeValue(REFURI));
        }
        anonym.setText(ref);
        text = txtDebut + anonym.asXML() + txtFin;
        matcher = REGEX_ANONYMOUS_HYPERLINK_REFERENCE.matcher(text);
    }
    // .. _truc: http://truc.html
    matcher = REGEX_HYPERLINK_REFERENCE.matcher(text);
    while (matcher.find()) {
        String txtDebut = text.substring(0, matcher.start());
        String txtFin = text.substring(matcher.end(), text.length());
        String ref = text.substring(matcher.start(), matcher.end() - 1);
        ref = StringEscapeUtils.unescapeXml(ref);
        ref = ref.replaceAll("(&apos;|_)", "");
        ref = ref.replaceAll("`", "");
        Element hyper = DocumentHelper.createElement(REFERENCE);
        hyper.addAttribute(NAME, ref);
        boolean trouve = false;
        for (int i = 0; i < eTarget.size() && !trouve; i++) {
            Element el = eTarget.get(i);
            String refTmp = URLEncoder.encode(ref.replaceAll("\\s", "-").toLowerCase(), "UTF-8");
            if (el.attributeValue(ID).equalsIgnoreCase((refTmp))) {
                hyper.addAttribute(REFURI, el.attributeValue(REFURI));
                trouve = true;
            }
        }
        if (!trouve) {
            hyper.addAttribute(ATTR_REFID, ref);
        }
        hyper.setText(ref);
        text = txtDebut + hyper.asXML() + " " + txtFin;
        matcher = REGEX_HYPERLINK_REFERENCE.matcher(text);

    }

    // substitution reference
    matcher = REGEX_SUBSTITUTION_REFERENCE.matcher(text);
    int begin = 0;
    while (matcher.find(begin)) {
        String start = text.substring(0, matcher.start());
        String end = text.substring(matcher.end());
        String ref = matcher.group(1);

        Node subst = e.selectSingleNode("//" + SUBSTITUTION_DEFINITION + "[@name='" + ref + "']/child::node()");

        if (subst == null) {
            text = start + "|" + ref + "|";
        } else {
            text = start + subst.asXML();
        }

        begin = text.length();
        text += end;
        matcher = REGEX_SUBSTITUTION_REFERENCE.matcher(text);

    }
    // undo substitution in LITERAL
    Pattern p = Pattern.compile("<tmp>([^<>]+)</tmp>");

    matcher = p.matcher(text);
    while (matcher.find()) {
        String start = text.substring(0, matcher.start());
        String end = text.substring(matcher.end());

        String tempKey = matcher.group(1);
        text = start + temporaries.get(tempKey) + end;
        matcher = p.matcher(text);
    }

    String resultElementText = text.trim();
    Element result = DocumentHelper.parseText("<TMP>" + resultElementText + "</TMP>").getRootElement();

    e.setText("");
    e.appendContent(result);
}