Example usage for org.jdom2.output XMLOutputter outputString

List of usage examples for org.jdom2.output XMLOutputter outputString

Introduction

In this page you can find the example usage for org.jdom2.output XMLOutputter outputString.

Prototype

public final String outputString(EntityRef entity) 

Source Link

Document

Return a string representing an EntityRef .

Usage

From source file:adlic.ADLic.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    try {/*w  w w  .j  a v  a 2 s.  com*/
        int n = JOptionPane.showConfirmDialog(null,
                " ?     "
                        + licenses.getAttribute(numlic, "id") + " ?",
                " !", JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.YES_OPTION) {
            licenses.getListLicense().remove(numlic);
            try {
                XMLOutputter outputter = new XMLOutputter();
                outputter.setFormat(Format.getPrettyFormat());
                try {
                    OutputStreamWriter out = new java.io.OutputStreamWriter(
                            new java.io.FileOutputStream(licenses.getFile()), "UTF-8");
                    out.write(outputter.outputString(licenses.getDocument()));
                    out.close();
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(rootPane, ex);
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, ex);
            }
            if (numlic > 0) {
                numlic -= 1;
            }
            this.getFormText(numlic);
            this.getTableKey(numlic);
            this.getTableSum(numlic);
        } else {
            System.out.println(" .");
        }
    } catch (NullPointerException ex) {
        JOptionPane.showMessageDialog(rootPane, ex);
    }
    this.getFormText(numlic);
    this.getTableKey(numlic);
    this.getTableSum(numlic);
}

From source file:adlic.licenses.java

/**
 * @see write xml file "licenses.xml"// w  w w  .  j ava2 s.co m
 */
public void writeLicenses(Document savingDocument, String filePath) {
    try {
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        try {
            OutputStreamWriter out = new java.io.OutputStreamWriter(new java.io.FileOutputStream(filePath),
                    "UTF-8");
            out.write(outputter.outputString(savingDocument));
            out.close();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, ex);
        }

        //outputter.output(savingDocument, new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8"));
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:adlic.NewJDialog.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    try {//from   ww w  . java2 s. c  om
        licenses.getElementLicense(numlicsave).setAttribute("id", this.jTextField1.getText());
        licenses.getElementLicense(numlicsave).setAttribute("key", this.jTextField5.getText());
        licenses.getElementLicense(numlicsave).setAttribute("sum", this.jTextField6.getText());
        licenses.getElementLicense(numlicsave).getChild("product").setText(this.jTextField2.getText());
        licenses.getElementLicense(numlicsave).getChild("type").setText(this.jTextField3.getText());
        licenses.getElementLicense(numlicsave).getChild("numberlic").setText(this.jTextField4.getText());
        try {
            if (jModelKey.getRowCount() > (new Integer(this.jTextField5.getText()))) {
                JOptionPane.showMessageDialog(rootPane,
                        "?     ?  .");
            } else {
                licenses.getElementKey(numlicsave).removeContent();
                for (int i = 0; i < this.jModelKey.getRowCount(); i++) {
                    if ((this.jModelKey.getValueAt(i, 0) == null) && (this.jModelKey.getValueAt(i, 1) == null)
                            && (this.jModelKey.getValueAt(i, 2) == null)) {
                        JOptionPane.showMessageDialog(rootPane,
                                "? ?   .  ? ?.");
                    } else {
                        if (this.jModelKey.getValueAt(i, 0) == null) {
                            this.jModelKey.setValueAt(" ", i, 0);
                            JOptionPane.showMessageDialog(rootPane,
                                    "?  <?>   .  .");
                        }
                        if (this.jModelKey.getValueAt(i, 1) == null) {
                            this.jModelKey.setValueAt(" ", i, 1);
                            JOptionPane.showMessageDialog(rootPane,
                                    "?  <>   .  .");
                        }
                        if (this.jModelKey.getValueAt(i, 2) == null) {
                            this.jModelKey.setValueAt(" ", i, 2);
                            JOptionPane.showMessageDialog(rootPane,
                                    "?  <>   .  .");
                        }
                        licenses.getElementKey(numlicsave).addContent(new Element("product-key")
                                .addContent(this.jModelKey.getValueAt(i, 2).toString()));
                        licenses.getElementProductKey(numlicsave, i).setAttribute("name",
                                this.jModelKey.getValueAt(i, 0).toString());
                        licenses.getElementProductKey(numlicsave, i).setAttribute("type",
                                this.jModelKey.getValueAt(i, 1).toString());
                    }
                }
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
        try {
            if (jModelSum.getRowCount() > (new Integer(this.jTextField6.getText()))) {
                JOptionPane.showMessageDialog(rootPane,
                        "?   ?  .");
            } else {
                licenses.getElementSum(numlicsave).removeContent();
                for (int i = 0; i < this.jModelSum.getRowCount(); i++) {
                    if ((this.jModelSum.getValueAt(i, 0) == null)
                            && (this.jModelSum.getValueAt(i, 1) == null)) {
                        JOptionPane.showMessageDialog(rootPane,
                                "? ?   .  ? ?.");
                    } else {
                        if (this.jModelSum.getValueAt(i, 0) == null) {
                            this.jModelSum.setValueAt(" ", i, 0);
                            JOptionPane.showMessageDialog(rootPane,
                                    "?  <? ??>   .  .");
                        }
                        if (this.jModelSum.getValueAt(i, 1) == null) {
                            this.jModelSum.setValueAt(" ", i, 1);
                            JOptionPane.showMessageDialog(rootPane,
                                    "?  < >   .  .");
                        }
                        licenses.getElementSum(numlicsave).addContent(new Element("invent-number")
                                .addContent(this.jModelSum.getValueAt(i, 1).toString()));
                        licenses.getElementInventSum(numlicsave, i).setAttribute("type",
                                this.jModelSum.getValueAt(i, 0).toString());
                    }
                }
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
        try {
            XMLOutputter outputter = new XMLOutputter();
            outputter.setFormat(Format.getPrettyFormat());
            try {
                OutputStreamWriter out = new java.io.OutputStreamWriter(
                        new java.io.FileOutputStream(licenses.getFile()), "UTF-8");
                out.write(outputter.outputString(licenses.getDocument()));
                out.close();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(rootPane, ex);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
        this.jLabel5.setText("? ?.");
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(rootPane, ex);
    }
}

From source file:adlic.NewJDialogInvent.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    try {/*from w  w  w .j av a 2  s . c  o  m*/
        this.jLabel1.setText("...");
        licenses.getElementInvent().removeContent();
        try {
            for (int i = 0; i < jModelInvent.getRowCount(); i++) {
                if (this.jModelInvent.getValueAt(i, 0) == null) {
                    jLabel1.setText(
                            "! ? ?  ??  ????.");
                } else {
                    licenses.getElementInvent().addContent(
                            new Element("type").addContent(jModelInvent.getValueAt(i, 0).toString()));
                }
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
        try {
            XMLOutputter outputter = new XMLOutputter();
            outputter.setFormat(Format.getPrettyFormat());
            try {
                OutputStreamWriter out = new java.io.OutputStreamWriter(
                        new java.io.FileOutputStream(licenses.getFile()), "UTF-8");
                out.write(outputter.outputString(licenses.getDocument()));
                out.close();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(rootPane, ex);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(rootPane, ex);
    }
}

From source file:adlic.NewJDialogKeyType.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    try {/*from w w  w.j  a  v a 2  s  .c  o m*/
        this.jLabel1.setText("...");
        licenses.getElementKeyType().removeContent();
        try {
            for (int i = 0; i < this.jModelType.getRowCount(); i++) {
                if (this.jTable1.getValueAt(i, 0) == null) {
                    this.jLabel1.setText(
                            "! ? ?  ??  ????");
                } else {
                    licenses.getElementKeyType().addContent(
                            new Element("type").addContent(this.jModelType.getValueAt(i, 0).toString()));
                }
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
        try {
            XMLOutputter outputter = new XMLOutputter();
            outputter.setFormat(Format.getPrettyFormat());
            try {
                OutputStreamWriter out = new java.io.OutputStreamWriter(
                        new java.io.FileOutputStream(licenses.getFile()), "UTF-8");
                out.write(outputter.outputString(licenses.getDocument()));
                out.close();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(rootPane, ex);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(rootPane, ex);
    }
}

From source file:adlic.NewJDialogProduct.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    try {//  ww  w.j a va  2 s .  com
        this.jLabel1.setText("...");
        licenses.getElementProduct().removeContent();
        try {
            for (int i = 0; i < this.jModelProduct.getRowCount(); i++) {
                if (this.jTable1.getValueAt(i, 0) == null) {
                    this.jLabel1.setText(
                            "! ? ?  ??  ????");
                } else {
                    licenses.getElementProduct().addContent(
                            new Element("name").addContent(this.jModelProduct.getValueAt(i, 0).toString()));
                }
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
        try {
            XMLOutputter outputter = new XMLOutputter();
            outputter.setFormat(Format.getPrettyFormat());
            try {
                OutputStreamWriter out = new java.io.OutputStreamWriter(
                        new java.io.FileOutputStream(licenses.getFile()), "UTF-8");
                out.write(outputter.outputString(licenses.getDocument()));
                out.close();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(rootPane, ex);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex);
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(rootPane, ex);
    }
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.FormulaConverter.java

License:Open Source License

/**
 * Replaces all formulas with the html representation of the mapped formula objects
 *
 * @param doc        JDOM Document where to replace the formulas
 * @param formulaMap Map of the indexed Formula Objects
 * @return JDOM Document with replaced formulas
 *///from   w  w w . j a va2  s .  c  o  m
public Document replaceFormulas(Document doc, Map<Integer, Formula> formulaMap) {
    List<Element> foundFormulas = xpath.evaluate(doc);

    if (foundFormulas.size() > 0) {
        Map<String, Element> formulaMarkupMap = new HashMap<>();

        // Initialize markup map
        for (Element element : foundFormulas) {
            formulaMarkupMap.put(element.getAttribute("id").getValue(), element);
        }

        // Replace all found formulas
        Iterator<Integer> formulaIterator = formulaMap.keySet().iterator();
        while (formulaIterator.hasNext()) {
            Integer id = formulaIterator.next();

            Element formulaMarkupRoot = formulaMarkupMap.get(FORMULA_ID_PREFIX + id);
            Formula formula = formulaMap.get(id);

            formulaMarkupRoot.removeAttribute("class");
            formulaMarkupRoot.removeContent();
            formulaMarkupRoot.setName("div");

            Element div = (Element) formulaMarkupRoot.getParent();
            div.setName("div");
            div.setAttribute("class", "formula");

            // Potentially there's text inside the paragraph...
            List<Text> texts = div.getContent(Filters.textOnly());
            if (texts.isEmpty() == false) {
                String textString = "";
                for (Text text : texts) {
                    textString += text.getText();
                }
                Element textSpan = new Element("span");
                textSpan.setAttribute("class", "text");
                textSpan.setText(textString);
                div.addContent(textSpan);

                List<Content> content = div.getContent();
                content.removeAll(texts);
            }

            if (generateDebugMarkup) {
                div.setAttribute("style", "border: 1px solid black;");

                // Header
                Element h4 = new Element("h4");
                h4.setText("DEBUG - Formula #" + formula.getId());
                div.addContent(h4);

                // Render LaTeX source
                Element latexPre = new Element("pre");
                latexPre.setAttribute("class", "debug-latex");
                latexPre.setText(formula.getLatexCode());
                div.addContent(latexPre);

                // Render MathML markup
                Element mathmlPre = new Element("pre");
                mathmlPre.setAttribute("class", "debug-mathml");
                mathmlPre.setText(formula.getMathMl());
                div.addContent(mathmlPre);

                // Render HTML Markup
                Element htmlPre = new Element("pre");
                htmlPre.setAttribute("class", "debug-html");
                XMLOutputter xmlOutputter = new XMLOutputter();
                xmlOutputter.setFormat(Format.getRawFormat());
                htmlPre.setText(xmlOutputter.outputString(formula.getHtml()));

                div.addContent(htmlPre);

            }

            // Set formula into
            formulaMarkupRoot.addContent(formula.getHtml());
        }
    }
    return doc;
}

From source file:at.newmedialab.ldpath.model.functions.XPathFunction.java

License:Apache License

private LinkedList<String> doFilter(String in, Set<String> xpaths) throws IOException {
    LinkedList<String> result = new LinkedList<String>();
    try {//from w ww  .  java  2s.co m
        Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(new StringReader(in));
        XMLOutputter out = new XMLOutputter();

        for (String xp : xpaths) {
            XPathExpression<Content> xpath = XPathFactory.instance().compile(xp, Filters.content());
            for (Content node : xpath.evaluate(doc)) {
                if (node instanceof Element)
                    result.add(out.outputString((Element) node));
                else if (node instanceof Text)
                    result.add(out.outputString((Text) node));
            }
        }
        return result;
    } catch (JDOMException xpe) {
        throw new IllegalArgumentException("error while processing xpath expressions: '" + xpaths + "'", xpe);
    }
}

From source file:broadwick.graph.writer.GraphMl.java

License:Apache License

/**
 * Get the string representation of the network.
 * @param network  the network object to be written.
 * @param directed a boolean flag, true if the network is directed.
 * @return a string representing a document.
 *///  w w  w . j  a v a 2  s .  c om
public static String toString(final Graph<? extends Vertex, ? extends Edge<?>> network,
        final boolean directed) {
    // graphml document header
    final Element graphml = new Element("graphml", "http://graphml.graphdrawing.org/xmlns");
    final Document document = new Document(graphml);
    final Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    final Namespace schemLocation = Namespace.getNamespace("schemLocation",
            "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0rc/graphml.xsd");

    // add Namespace
    graphml.addNamespaceDeclaration(xsi);
    graphml.addNamespaceDeclaration(schemLocation);

    // keys for graphic representation
    for (VertexAttribute attr : network.getVertexAttributes()) {
        final Element element = new Element("key");
        element.setAttribute("id", attr.getName());
        element.setAttribute("for", "node");
        element.setAttribute("attr.name", attr.getName());
        element.setAttribute("attr.type", attr.getType().getName());
        if (attr.getDefaultValue() != null) {
            final Element defaultValueElement = new Element("default");
            defaultValueElement.addContent(attr.getDefaultValue().toString());
            element.addContent(defaultValueElement);
        }
        graphml.addContent(element);
    }

    for (EdgeAttribute attr : network.getEdgeAttributes()) {
        final Element element = new Element("key");
        element.setAttribute("id", attr.getName());
        element.setAttribute("for", "edge");
        element.setAttribute("attr.name", attr.getName());
        element.setAttribute("attr.type", attr.getType().getName());
        if (attr.getDefaultValue() != null) {
            final Element defaultValueElement = new Element("default");
            defaultValueElement.addContent(attr.getDefaultValue());
            element.addContent(defaultValueElement);
        }
        graphml.addContent(element);
    }

    final Element graph = new Element("graph");
    graph.setAttribute("id", "G");
    if (directed) {
        graph.setAttribute("edgedefault", "directed");
    } else {
        graph.setAttribute("edgedefault", "undirected");
    }
    graphml.addContent(graph);

    final ImmutableList<Vertex> vertices = ImmutableList.copyOf(network.getVertices());
    final Iterator<Vertex> vertexIterator = vertices.iterator();
    while (vertexIterator.hasNext()) {
        final Vertex vertex = vertexIterator.next();
        addNode(vertex, graph);
    }

    final ImmutableList<Edge<? extends Vertex>> edges;
    edges = (ImmutableList<Edge<? extends Vertex>>) ImmutableList.copyOf(network.getEdges());
    final UnmodifiableIterator<Edge<? extends Vertex>> edgeIterator = edges.iterator();
    while (edgeIterator.hasNext()) {
        addEdge(edgeIterator.next(), graph);
    }

    final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    return outputter.outputString(document).replaceAll("xmlns=\"\" ", "");
}

From source file:ca.nrc.cadc.conformance.uws.Util.java

License:Open Source License

/**
 * Get the XML string of an XML Document object.
 *  //from  www .  jav a 2s  .c  om
 * @param document
 * @return String
 * @author zhangsa
 */
public static String getXmlString(Document document) {
    XMLOutputter xmlOutputter = new XMLOutputter();
    return xmlOutputter.outputString(document);
}