Example usage for org.jdom2.output XMLOutputter XMLOutputter

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

Introduction

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

Prototype

public XMLOutputter() 

Source Link

Document

This will create an XMLOutputter with a default Format and XMLOutputProcessor .

Usage

From source file:org.isima.carsharing.launcher.Launcher.java

public static void addConfigComment(SettingsDelegate settingsDelegate, File out) {
    try {//from  www  .  j  ava2  s. c  o m
        SAXBuilder builder = new SAXBuilder();

        Document doc = (Document) builder.build(out);
        Element rootNode = doc.getRootElement();
        Element rootNodeCopy = rootNode.clone();

        doc.removeContent(rootNode);
        rootNodeCopy.detach();

        Comment comment = new Comment(settingsDelegate.usedConfigsToXMLComment());
        doc.addContent(comment);
        doc.addContent(rootNodeCopy);

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter(out));
    } catch (JDOMException | IOException ex) {
        Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.isisaddons.module.docx.fixture.dom.templates.CustomerConfirmation.java

License:Apache License

@Action(semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING)
@ActionLayout(contributed = Contributed.AS_ACTION)
@MemberOrder(sequence = "11")
public Clob downloadCustomerConfirmationInputHtml(final Order order)
        throws IOException, JDOMException, MergeException {

    final Document orderAsHtmlJdomDoc = asInputDocument(order);

    final XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());

    final String html = xmlOutput.outputString(orderAsHtmlJdomDoc);

    final String clobName = "customerConfirmation-" + order.getNumber() + ".html";
    final String clobMimeType = "text/html";
    final String clobBytes = html;

    return new Clob(clobName, clobMimeType, clobBytes);
}

From source file:org.jreserve.gui.wrapper.jdom.JDomUtil.java

License:Open Source License

public static void save(final FileObject file, Document document) throws IOException {
    synchronized (file) {
        XMLOutputter output = new XMLOutputter();
        OutputStream os = null;//from w  w  w  .  ja  va2s .  c  om

        try {
            os = file.getOutputStream();
            output.output(document, os);
            os.flush();
        } catch (IOException ex) {
            String msg = "Unable to save document to file '%s'!";
            msg = String.format(msg, file.getPath());
            logger.log(Level.SEVERE, msg, ex);
            throw new IOException(msg, ex);
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException ex) {
                    String msg = String.format("Unable to close outputstream for file '%s'!", file.getPath());
                    logger.log(Level.SEVERE, msg, ex);
                    throw ex;
                }
            }
        }
    }
}

From source file:org.jumpmind.metl.core.runtime.component.AbstractXMLComponentRuntime.java

License:Open Source License

protected String toXML(Element element) {
    XMLOutputter xmlOutputter = new XMLOutputter();
    return xmlOutputter.outputString(element);
}

From source file:org.jumpmind.metl.core.runtime.component.XmlFormatter.java

License:Open Source License

private void createXml(ISendMessageCallback callback) {

    Document generatedXml = new Document();
    Stack<DocElement> parentStack = new Stack<DocElement>();
    ArrayList<String> outboundPayload = new ArrayList<String>();

    for (Message msg : messagesToProcess) {
        processMsgEntities(parentStack, msg, generatedXml);
    }//from   w  ww.ja  va 2s  .  c o m
    XMLOutputter xmlOutputter = new XMLOutputter();
    Format format = null;
    if (xmlFormat.equals(COMPACT_FORMAT)) {
        format = Format.getCompactFormat();
    } else if (xmlFormat.equals(RAW_FORMAT)) {
        format = Format.getRawFormat();
    } else {
        format = Format.getPrettyFormat();
    }
    xmlOutputter.setFormat(format);
    outboundPayload.add(xmlOutputter.outputString(generatedXml));
    callback.sendTextMessage(null, outboundPayload);
}

From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java

License:Open Source License

public static String getBatchXml(Model model, ArrayList<EntityData> inputRows, boolean outputAllAttributes) {
    SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
    Element root = new Element("batch");
    Document doc = new Document(root);

    for (ModelEntity entity : getModelEntities(model, inputRows)) {
        Element entityElement = new Element("entity");
        entityElement.setAttribute("name", entity.getName());
        root.addContent(entityElement);//  w ww .  j  av a 2 s.com

        for (EntityData entityData : inputRows) {
            List<ModelAttribute> attributes = null;
            if (outputAllAttributes) {
                attributes = entity.getModelAttributes();
            } else {
                attributes = getModelAttributes(model, entity.getId(), entityData.keySet());
            }

            Element recordElement = new Element("record");
            if (attributes.size() > 0) {
                entityElement.addContent(recordElement);
            }

            for (ModelAttribute attribute : attributes) {
                if (attribute != null && attribute.getEntityId().equals(entity.getId())) {
                    Element attributeElement = new Element("attribute");
                    attributeElement.setAttribute("name", attribute.getName());
                    Object object = entityData.get(attribute.getId());
                    String value = null;
                    DataType type = attribute.getDataType();

                    if (object != null) {
                        if (type.isTimestamp() && object instanceof Date) {
                            value = df.format(object);
                        } else {
                            value = object.toString();
                        }
                    }
                    attributeElement.setAttribute("value", value == null ? "" : value);
                    recordElement.addContent(attributeElement);
                }
            }
        }
    }

    StringWriter writer = new StringWriter();
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    try {
        xmlOutput.output(doc, writer);
        writer.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}

From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java

License:Open Source License

public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat,
        boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {// w  ww .  j  ava2s . c  o  m
        Document inputDoc = builder.build(new StringReader(inputXml));
        StringReader reader = new StringReader(stylesheetXml);
        XSLTransformer transformer = new XSLTransformer(reader);
        Document outputDoc = transformer.transform(inputDoc);
        XMLOutputter xmlOutput = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }

        format.setOmitDeclaration(omitXmlDeclaration);
        xmlOutput.setFormat(format);
        xmlOutput.output(outputDoc, writer);
        writer.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}

From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java

License:Apache License

/**
 *
 * @param aDoc//from w  ww . j  av a  2s .  c o m
 * @param aPath
 * @throws IOException
 */
protected void saveChange(Document aDoc, String aPath) throws IOException {
    XMLOutputter lXmlOutput = new XMLOutputter();
    lXmlOutput.setFormat(Format.getPrettyFormat());
    lXmlOutput.output(aDoc, new FileWriter(aPath));
}

From source file:org.kdp.word.transformer.OPFTransformer.java

License:Apache License

private void writeOPFDocument(Context context, Document doc) {
    Options options = context.getOptions();
    Path basedir = context.getBasedir();
    Path filePath = options.getOpfTarget();
    if (filePath == null) {
        String filename = context.getSource().getFileName().toString();
        filename = filename.substring(0, filename.lastIndexOf('.')) + ".opf";
        filePath = options.getBookDir().resolve(filename);
    }//  ww  w.j  a v a 2 s  .c  o  m
    try {
        log.info("Writing OPF: {}", filePath);
        File outfile = basedir.resolve(filePath).toFile();
        outfile.getParentFile().mkdirs();
        FileOutputStream fos = new FileOutputStream(outfile);

        XMLOutputter xo = new XMLOutputter();
        Format format = Format.getPrettyFormat();
        xo.setFormat(format.setOmitDeclaration(false));
        format.setEncoding("UTF-8");
        xo.output(doc, fos);

        fos.close();
    } catch (IOException ex) {
        throw new IllegalStateException("Cannot write OPF file: " + filePath, ex);
    }
}

From source file:org.kdp.word.utils.IOUtils.java

License:Apache License

public static void writeDocument(Context context, Document doc, OutputStream out) throws IOException {
    Parser parser = context.getParser();
    String outputEncoding = parser.getProperty(Parser.PROPERTY_OUTPUT_ENCODING);
    outputEncoding = outputEncoding != null ? outputEncoding : "UTF-8";
    String outputFormat = parser.getProperty(Parser.PROPERTY_OUTPUT_FORMAT);
    boolean pretty = Parser.OUTPUT_FORMAT_PRETTY.equals(outputFormat);

    XMLOutputter xo = new XMLOutputter();
    Format format = pretty ? Format.getPrettyFormat() : Format.getCompactFormat();
    format.setEncoding(outputEncoding);//from   w  ww.  j a  v a 2s  .co m
    EscapeStrategy strategy = new OutputEscapeStrategy(context, format.getEscapeStrategy());
    format.setEscapeStrategy(strategy);
    xo.setFormat(format.setOmitDeclaration(true));
    xo.output(doc, out);
}