Example usage for org.dom4j Document getXMLEncoding

List of usage examples for org.dom4j Document getXMLEncoding

Introduction

In this page you can find the example usage for org.dom4j Document getXMLEncoding.

Prototype

String getXMLEncoding();

Source Link

Document

Return the encoding of this document, as part of the XML declaration This is null when unspecified or when it is not known (such as when the Document was created in memory) or when the implementation does not support this operation.

Usage

From source file:org.pentaho.pms.ui.QueryBuilderDialog.java

License:Open Source License

public Document prettyPrint(Document document) {
    try {/*from   ww w.j  ava 2s . com*/
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding(document.getXMLEncoding());
        StringWriter stringWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(stringWriter, format);
        // XMLWriter has a bug that is avoided if we reparse the document
        // prior to calling XMLWriter.write()
        writer.write(DocumentHelper.parseText(document.asXML()));
        writer.close();
        document = DocumentHelper.parseText(stringWriter.toString());
    } catch (Exception e) {
        e.printStackTrace();
        return (null);
    }
    return (document);
}

From source file:org.xwiki.tool.xar.internal.XWikiDocument.java

License:Open Source License

/**
 * Parse XML document to extract document information.
 *
 * @param domdoc the xml document/*from   w w w .  j a  v a  2  s. c om*/
 * @throws DocumentException error when parsing XML file
 */
public void fromXML(Document domdoc) throws DocumentException {
    this.encoding = domdoc.getXMLEncoding();

    Element rootElement = domdoc.getRootElement();

    this.reference = rootElement.attributeValue("reference");
    if (this.reference == null) {
        String name = readElement(rootElement, "name");
        String space = readElement(rootElement, "web");

        this.reference = space == null ? name
                : escapeSpaceOrPageName(space) + '.' + escapeSpaceOrPageName(name);
    }

    this.locale = rootElement.attributeValue("locale");
    if (this.locale == null) {
        // Fallback on old <language> element
        this.locale = readElement(rootElement, "language");
    }

    this.defaultLanguage = readElement(rootElement, "defaultLanguage");
    this.creator = readElement(rootElement, "creator");
    this.author = readElement(rootElement, AUTHOR_TAG);
    this.contentAuthor = readElement(rootElement, "contentAuthor");
    this.version = readElement(rootElement, "version");
    this.parent = readElement(rootElement, "parent");
    this.comment = readElement(rootElement, "comment");
    this.minorEdit = readElement(rootElement, "minorEdit");
    this.attachmentAuthors = readAttachmentAuthors(rootElement);
    this.isHidden = Boolean.parseBoolean(readElement(rootElement, "hidden"));
    this.title = readElement(rootElement, "title");
}

From source file:org.xwiki.tool.xar.XWikiDocument.java

License:Open Source License

/**
 * Parse XML file to extract document information.
 *
 * @param file the xml file// w w w.j  a v  a  2 s  . c  o  m
 * @throws DocumentException error when parsing XML file
 */
public void fromXML(File file) throws DocumentException {
    SAXReader reader = new SAXReader();
    Document domdoc = reader.read(file);

    this.encoding = domdoc.getXMLEncoding();

    Element rootElement = domdoc.getRootElement();
    this.name = readElement(rootElement, "name");
    this.space = readElement(rootElement, "web");
    this.language = readElement(rootElement, "language");
    this.defaultLanguage = readElement(rootElement, "defaultLanguage");
    this.creator = readElement(rootElement, "creator");
    this.author = readElement(rootElement, "author");
    this.contentAuthor = readElement(rootElement, "contentAuthor");
    this.version = readElement(rootElement, "version");
    this.parent = readElement(rootElement, "parent");
    this.comment = readElement(rootElement, "comment");
    this.minorEdit = readElement(rootElement, "minorEdit");
}