Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

In this page you can find the example usage for org.dom4j Element addText.

Prototype

Element addText(String text);

Source Link

Document

Adds a new Text node with the given text to this element.

Usage

From source file:com.xebia.mojo.dashboard.DashboardMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    parseConfig();//from   www .j a va2  s.  c o  m

    Document destinationFileAsDom = xmlUtil.readXhtmlDocument(destinationFile);
    Element dashboardTableDestination = xmlUtil.findElement(destinationFileAsDom, xpathToDestinationNode);

    removePlaceHolder(dashboardTableDestination);

    Element containerDiv = dashboardTableDestination.addElement("div");
    containerDiv.addAttribute("class", "section");

    Element heading = containerDiv.addElement("h2");
    heading.addText("Dashboard");

    Element dashboardTable = containerDiv.addElement("table");
    dashboardTable.addAttribute("class", "bodyTable");

    generateHeaders(dashboardTable);
    generateContent(dashboardTable);

    xmlUtil.writeDocument(destinationFileAsDom, destinationFile);
}

From source file:com.xpn.xwiki.doc.XWikiAttachment.java

License:Open Source License

/**
 * Write an XML representation of the attachment into an {@link com.xpn.xwiki.internal.xml.XMLWriter}
 *
 * @param wr the XMLWriter to write to//from  w w  w. java  2 s .c om
 * @param bWithAttachmentContent if true, binary content of the attachment is included (base64 encoded)
 * @param bWithVersions if true, all archive version is also included
 * @param context current XWikiContext
 * @throws IOException when an error occurs during streaming operation
 * @throws XWikiException when an error occurs during xwiki operation
 * @since 2.3M2
 */
public void toXML(XMLWriter wr, boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context)
        throws IOException, XWikiException {
    // IMPORTANT: we don't use SAX apis here because the specified XMLWriter could be a DOMXMLWriter for retro
    // compatibility reasons

    Element docel = new DOMElement("attachment");
    wr.writeOpen(docel);

    Element el = new DOMElement("filename");
    el.addText(getFilename());
    wr.write(el);

    el = new DOMElement("filesize");
    el.addText("" + getFilesize());
    wr.write(el);

    el = new DOMElement("author");
    el.addText(getAuthor());
    wr.write(el);

    long d = getDate().getTime();
    el = new DOMElement("date");
    el.addText("" + d);
    wr.write(el);

    el = new DOMElement("version");
    el.addText(getVersion());
    wr.write(el);

    el = new DOMElement("comment");
    el.addText(getComment());
    wr.write(el);

    if (bWithAttachmentContent) {
        el = new DOMElement("content");
        // We need to make sure content is loaded
        loadContent(context);
        XWikiAttachmentContent acontent = getAttachment_content();
        if (acontent != null) {
            wr.writeBase64(el, getAttachment_content().getContentInputStream());
        } else {
            el.addText("");
            wr.write(el);
        }
    }

    if (bWithVersions) {
        // We need to make sure content is loaded
        XWikiAttachmentArchive aarchive = loadArchive(context);
        if (aarchive != null) {
            el = new DOMElement("versions");
            try {
                el.addText(new String(aarchive.getArchive()));
                wr.write(el);
            } catch (XWikiException e) {
            }
        }
    }

    wr.writeClose(docel);
}

From source file:com.xpn.xwiki.doc.XWikiDocument.java

License:Open Source License

/**
 * Serialize the document to a {@link com.xpn.xwiki.internal.xml.XMLWriter}.
 * //from   www . jav a2 s. c  o  m
 * @param bWithObjects include XObjects
 * @param bWithRendering include the rendered content
 * @param bWithAttachmentContent include attachments content
 * @param bWithVersions include archived versions
 * @param context current XWikiContext
 * @throws XWikiException when an errors occurs during wiki operations
 * @throws IOException when an errors occurs during streaming operations
 * @since 2.3M2
 */
public void toXML(XMLWriter wr, boolean bWithObjects, boolean bWithRendering, boolean bWithAttachmentContent,
        boolean bWithVersions, XWikiContext context) throws XWikiException, IOException {
    // IMPORTANT: we don't use SAX apis here because the specified XMLWriter could be a DOMXMLWriter for retro
    // compatibility reasons

    Element docel = new DOMElement("xwikidoc");
    wr.writeOpen(docel);

    Element el = new DOMElement("web");
    el.addText(getDocumentReference().getLastSpaceReference().getName());
    wr.write(el);

    el = new DOMElement("name");
    el.addText(getDocumentReference().getName());
    wr.write(el);

    el = new DOMElement("language");
    el.addText(getLanguage());
    wr.write(el);

    el = new DOMElement("defaultLanguage");
    el.addText(getDefaultLanguage());
    wr.write(el);

    el = new DOMElement("translation");
    el.addText("" + getTranslation());
    wr.write(el);

    el = new DOMElement("parent");
    if (getRelativeParentReference() == null) {
        // No parent have been specified
        el.addText("");
    } else {
        el.addText(this.defaultEntityReferenceSerializer.serialize(getRelativeParentReference()));
    }
    wr.write(el);

    el = new DOMElement("creator");
    el.addText(getCreator());
    wr.write(el);

    el = new DOMElement("author");
    el.addText(getAuthor());
    wr.write(el);

    el = new DOMElement("customClass");
    el.addText(getCustomClass());
    wr.write(el);

    el = new DOMElement("contentAuthor");
    el.addText(getContentAuthor());
    wr.write(el);

    long d = getCreationDate().getTime();
    el = new DOMElement("creationDate");
    el.addText("" + d);
    wr.write(el);

    d = getDate().getTime();
    el = new DOMElement("date");
    el.addText("" + d);
    wr.write(el);

    d = getContentUpdateDate().getTime();
    el = new DOMElement("contentUpdateDate");
    el.addText("" + d);
    wr.write(el);

    el = new DOMElement("version");
    el.addText(getVersion());
    wr.write(el);

    el = new DOMElement("title");
    el.addText(getTitle());
    wr.write(el);

    el = new DOMElement("template");
    if (getTemplateDocumentReference() == null) {
        // No template doc have been specified
        el.addText("");
    } else {
        el.addText(this.localEntityReferenceSerializer.serialize(getTemplateDocumentReference()));
    }
    wr.write(el);

    el = new DOMElement("defaultTemplate");
    el.addText(getDefaultTemplate());
    wr.write(el);

    el = new DOMElement("validationScript");
    el.addText(getValidationScript());
    wr.write(el);

    el = new DOMElement("comment");
    el.addText(getComment());
    wr.write(el);

    el = new DOMElement("minorEdit");
    el.addText(String.valueOf(isMinorEdit()));
    wr.write(el);

    el = new DOMElement("syntaxId");
    el.addText(getSyntaxId());
    wr.write(el);

    el = new DOMElement("hidden");
    el.addText(String.valueOf(isHidden()));
    wr.write(el);

    for (XWikiAttachment attach : getAttachmentList()) {
        attach.toXML(wr, bWithAttachmentContent, bWithVersions, context);
    }

    if (bWithObjects) {
        // Add Class
        BaseClass bclass = getXClass();
        if (!bclass.getFieldList().isEmpty()) {
            // If the class has fields, add class definition and field information to XML
            wr.write(bclass.toXML(null));
        }

        // Add Objects (THEIR ORDER IS MOLDED IN STONE!)
        for (List<BaseObject> objects : getXObjects().values()) {
            for (BaseObject obj : objects) {
                if (obj != null) {
                    BaseClass objclass;
                    if (getDocumentReference() == obj.getXClassReference()) {
                        objclass = bclass;
                    } else {
                        objclass = obj.getXClass(context);
                    }
                    wr.write(obj.toXML(objclass));
                }
            }
        }
    }

    // Add Content
    el = new DOMElement("content");

    // Filter filter = new CharacterFilter();
    // String newcontent = filter.process(getContent());
    // String newcontent = encodedXMLStringAsUTF8(getContent());
    String newcontent = this.content;
    el.addText(newcontent);
    wr.write(el);

    if (bWithRendering) {
        el = new DOMElement("renderedcontent");
        try {
            el.addText(getRenderedContent(context));
        } catch (XWikiException e) {
            el.addText("Exception with rendering content: " + e.getFullMessage());
        }
        wr.write(el);
    }

    if (bWithVersions) {
        el = new DOMElement("versions");
        try {
            el.addText(getDocumentArchive(context).getArchive(context));
            wr.write(el);
        } catch (XWikiException e) {
            LOGGER.error("Document [" + this.defaultEntityReferenceSerializer.serialize(getDocumentReference())
                    + "] has malformed history");
        }
    }
}

From source file:com.xpn.xwiki.internal.xml.DOMXMLWriter.java

License:Open Source License

/**
 * {@inheritDoc}/*w w  w .  j a  v  a  2s.c o  m*/
 * <p>
 * Add the element into the <code>{@link Document}</code> as a children of the element at the top of the stack of
 * opened elements, putting the whole stream content as text in the content of the <code>{@link Element}</code>. The
 * stream is converted to a String encoded in the current encoding.
 * 
 * @see com.xpn.xwiki.internal.xml.XMLWriter#write(org.dom4j.Element, java.io.InputStream)
 */
@Override
public void write(Element element, InputStream is) throws IOException {
    element.addText(IOUtils.toString(is, this.format.getEncoding()));
    write(element);
}

From source file:com.xpn.xwiki.internal.xml.DOMXMLWriter.java

License:Open Source License

/**
 * {@inheritDoc}/*www  .j  a va2s  . com*/
 * <p>
 * Add the element into the <code>{@link Document}</code> as a children of the element at the top of the stack of of
 * the <code>{@link Element}</code>.
 * 
 * @see com.xpn.xwiki.internal.xml.XMLWriter#write(org.dom4j.Element, java.io.Reader)
 */
@Override
public void write(Element element, Reader rd) throws IOException {
    element.addText(IOUtils.toString(rd));
    write(element);
}

From source file:com.xpn.xwiki.internal.xml.DOMXMLWriter.java

License:Open Source License

/**
 * {@inheritDoc}/*from   ww  w.  j ava 2s.  c  om*/
 * <p>
 * Add the element into the <code>{@link Document}</code> as a children of the element at the top of the stack of
 * opened elements, putting the whole stream content as Base64 text in the content of the
 * <code>{@link Element}</code>.
 * 
 * @see com.xpn.xwiki.internal.xml.XMLWriter#writeBase64(org.dom4j.Element, java.io.InputStream)
 */
@Override
public void writeBase64(Element element, InputStream is) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Base64OutputStream out = new Base64OutputStream(baos, true, 0, null);
    IOUtils.copy(is, out);
    out.close();
    element.addText(baos.toString(this.format.getEncoding()));
    write(element);
}

From source file:com.xpn.xwiki.objects.BaseObject.java

License:Open Source License

private Element exportProperty(String propertyName, String propertyValue) {
    Element propertyElement = new DOMElement(propertyName);
    propertyElement.addText(StringUtils.defaultString(propertyValue));
    return propertyElement;
}

From source file:com.xpn.xwiki.objects.classes.BaseClass.java

License:Open Source License

public Element toXML() {
    Element cel = new DOMElement("class");

    Element el = new DOMElement("name");
    el.addText((getName() == null) ? "" : getName());
    cel.add(el);//from  w  w  w  . j  av  a  2s .c o  m

    el = new DOMElement("customClass");
    el.addText((getCustomClass() == null) ? "" : getCustomClass());
    cel.add(el);

    el = new DOMElement("customMapping");
    el.addText((getCustomMapping() == null) ? "" : getCustomMapping());
    cel.add(el);

    el = new DOMElement("defaultViewSheet");
    el.addText((getDefaultViewSheet() == null) ? "" : getDefaultViewSheet());
    cel.add(el);

    el = new DOMElement("defaultEditSheet");
    el.addText((getDefaultEditSheet() == null) ? "" : getDefaultEditSheet());
    cel.add(el);

    el = new DOMElement("defaultWeb");
    el.addText((getDefaultWeb() == null) ? "" : getDefaultWeb());
    cel.add(el);

    el = new DOMElement("nameField");
    el.addText((getNameField() == null) ? "" : getNameField());
    cel.add(el);

    el = new DOMElement("validationScript");
    el.addText((getValidationScript() == null) ? "" : getValidationScript());
    cel.add(el);

    // Iterate over values sorted by field name so that the values are
    // exported to XML in a consistent order.
    Iterator it = getSortedIterator();
    while (it.hasNext()) {
        PropertyClass bprop = (PropertyClass) it.next();
        cel.add(bprop.toXML());
    }
    return cel;
}

From source file:com.xpn.xwiki.objects.classes.PropertyClass.java

License:Open Source License

public Element toXML() {
    Element pel = new DOMElement(getName());

    // Iterate over values sorted by field name so that the values are
    // exported to XML in a consistent order.
    Iterator it = getSortedIterator();
    while (it.hasNext()) {
        BaseProperty bprop = (BaseProperty) it.next();
        pel.add(bprop.toXML());//from w w w. j  av  a  2  s .  c om
    }
    Element el = new DOMElement("classType");
    el.addText(getClassType());
    pel.add(el);
    return pel;
}

From source file:com.xpn.xwiki.plugin.packaging.Package.java

License:Open Source License

/**
 * Write the package.xml file to an {@link XMLWriter}.
 *
 * @param wr the writer to write to/* w  w  w  .  j  av a2  s . c  o m*/
 * @throws IOException when an error occurs during streaming operation
 * @since 2.3M2
 */
public void toXML(XMLWriter wr) throws IOException {
    Element docel = new DOMElement("package");
    wr.writeOpen(docel);

    Element elInfos = new DOMElement("infos");
    wr.write(elInfos);

    Element el = new DOMElement("name");
    el.addText(this.name);
    wr.write(el);

    el = new DOMElement("description");
    el.addText(this.description);
    wr.write(el);

    el = new DOMElement("licence");
    el.addText(this.licence);
    wr.write(el);

    el = new DOMElement("author");
    el.addText(this.authorName);
    wr.write(el);

    el = new DOMElement("version");
    el.addText(this.version);
    wr.write(el);

    el = new DOMElement("backupPack");
    el.addText(new Boolean(this.backupPack).toString());
    wr.write(el);

    el = new DOMElement("preserveVersion");
    el.addText(new Boolean(this.preserveVersion).toString());
    wr.write(el);

    Element elfiles = new DOMElement("files");
    wr.writeOpen(elfiles);

    for (DocumentInfo docInfo : this.files) {
        Element elfile = new DOMElement("file");
        elfile.addAttribute("defaultAction", String.valueOf(docInfo.getAction()));
        elfile.addAttribute("language", String.valueOf(docInfo.getLanguage()));
        elfile.addText(docInfo.getFullName());
        wr.write(elfile);
    }
}