Search in sources :

Example 31 with Content

use of org.jdom2.Content in project mycore by MyCoRe-Org.

the class MCRMetaXML method createXML.

/**
 * This method create a XML stream for all data in this class, defined by
 * the MyCoRe XML MCRMetaLangText definition for the given subtag.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Element with the XML MCRMetaLangText part
 */
@Override
public org.jdom2.Element createXML() throws MCRException {
    Element elm = super.createXML();
    List<Content> addedContent = new ArrayList<>(content.size());
    cloneListContent(addedContent, content);
    elm.addContent(addedContent);
    return elm;
}
Also used : Content(org.jdom2.Content) JsonElement(com.google.gson.JsonElement) Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Example 32 with Content

use of org.jdom2.Content in project mycore by MyCoRe-Org.

the class MCRObjectDerivate method createXML.

/**
 * This methode create a XML stream for all derivate data.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Element with the XML data of the structure data part
 */
public final org.jdom2.Element createXML() throws MCRException {
    try {
        validate();
    } catch (MCRException exc) {
        throw new MCRException("The content is not valid.", exc);
    }
    org.jdom2.Element elm = new org.jdom2.Element("derivate");
    elm.setAttribute("display", String.valueOf(display));
    org.jdom2.Element linkmetas = new org.jdom2.Element("linkmetas");
    linkmetas.setAttribute("class", "MCRMetaLinkID");
    linkmetas.setAttribute("heritable", "false");
    linkmetas.addContent(linkmeta.createXML());
    elm.addContent(linkmetas);
    if (externals.size() != 0) {
        org.jdom2.Element extEl = new org.jdom2.Element("externals");
        extEl.setAttribute("class", "MCRMetaLink");
        extEl.setAttribute("heritable", "false");
        for (MCRMetaLink external : externals) {
            extEl.addContent(external.createXML());
        }
        elm.addContent(extEl);
    }
    if (internals != null) {
        org.jdom2.Element intEl = new org.jdom2.Element("internals");
        intEl.setAttribute("class", "MCRMetaIFS");
        intEl.setAttribute("heritable", "false");
        intEl.addContent(internals.createXML());
        elm.addContent(intEl);
    }
    if (titles.size() != 0) {
        org.jdom2.Element titEl = new org.jdom2.Element("titles");
        titEl.setAttribute("class", "MCRMetaLangText");
        titEl.setAttribute("heritable", "false");
        for (MCRMetaLangText title : titles) {
            titEl.addContent(title.createXML());
        }
        elm.addContent(titEl);
    }
    if (this.derivateURN != null || !files.isEmpty()) {
        Element fileset = new Element("fileset");
        if (this.derivateURN != null) {
            fileset.setAttribute("urn", this.derivateURN);
        }
        Collections.sort(files);
        for (MCRFileMetadata file : files) {
            fileset.addContent(file.createXML());
        }
        elm.addContent(fileset);
    }
    return elm;
}
Also used : MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 33 with Content

use of org.jdom2.Content in project mycore by MyCoRe-Org.

the class MCRObjectService method createXML.

/**
 * This method create a XML stream for all structure data.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Element with the XML data of the structure data part
 */
public final org.jdom2.Element createXML() throws MCRException {
    try {
        validate();
    } catch (MCRException exc) {
        throw new MCRException("The content is not valid.", exc);
    }
    org.jdom2.Element elm = new org.jdom2.Element("service");
    if (dates.size() != 0) {
        org.jdom2.Element elmm = new org.jdom2.Element("servdates");
        elmm.setAttribute("class", "MCRMetaISO8601Date");
        for (MCRMetaISO8601Date date : dates) {
            elmm.addContent(date.createXML());
        }
        elm.addContent(elmm);
    }
    if (rules.size() != 0) {
        org.jdom2.Element elmm = new org.jdom2.Element("servacls");
        elmm.setAttribute("class", "MCRMetaAccessRule");
        for (MCRMetaAccessRule rule : rules) {
            elmm.addContent(rule.createXML());
        }
        elm.addContent(elmm);
    }
    if (flags.size() != 0) {
        org.jdom2.Element elmm = new org.jdom2.Element("servflags");
        elmm.setAttribute("class", "MCRMetaLangText");
        for (MCRMetaLangText flag : flags) {
            elmm.addContent(flag.createXML());
        }
        elm.addContent(elmm);
    }
    if (state != null) {
        org.jdom2.Element elmm = new org.jdom2.Element("servstates");
        elmm.setAttribute("class", "MCRMetaClassification");
        MCRMetaClassification stateClass = new MCRMetaClassification("servstate", 0, null, state);
        elmm.addContent(stateClass.createXML());
        elm.addContent(elmm);
    }
    return elm;
}
Also used : MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 34 with Content

use of org.jdom2.Content in project mycore by MyCoRe-Org.

the class MCRObjectStructure method createXML.

/**
 * <em>createXML</em> is the inverse of setFromDOM and converts the
 * structure's memory copy into an XML string.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return org.jdom2.Element the structure XML string
 */
public final Element createXML() throws MCRException {
    try {
        validate();
    } catch (MCRException exc) {
        throw new MCRException("The content is not valid.", exc);
    }
    Element elm = new Element("structure");
    if (parent != null) {
        Element elmm = new Element("parents");
        elmm.setAttribute("class", "MCRMetaLinkID");
        elmm.addContent(parent.createXML());
        elm.addContent(elmm);
    }
    if (children.size() > 0) {
        Element elmm = new Element("children");
        elmm.setAttribute("class", "MCRMetaLinkID");
        for (MCRMetaLinkID child : getChildren()) {
            elmm.addContent(child.createXML());
        }
        elm.addContent(elmm);
    }
    if (derivates.size() > 0) {
        Element elmm = new Element("derobjects");
        elmm.setAttribute("class", "MCRMetaLinkID");
        for (MCRMetaLinkID derivate : getDerivates()) {
            elmm.addContent(derivate.createXML());
        }
        elm.addContent(elmm);
    }
    return elm;
}
Also used : MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element)

Example 35 with Content

use of org.jdom2.Content in project mycore by MyCoRe-Org.

the class MCRBase method createXML.

/**
 * This method create a XML stream for all object data.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Document with the XML data of the object as byte array
 */
public Document createXML() throws MCRException {
    validate();
    Element elm = new Element(getRootTagName());
    Document doc = new Document(elm);
    elm.addNamespaceDeclaration(XSI_NAMESPACE);
    elm.addNamespaceDeclaration(XLINK_NAMESPACE);
    elm.setAttribute("noNamespaceSchemaLocation", mcr_schema, XSI_NAMESPACE);
    elm.setAttribute("ID", mcr_id.toString());
    if (mcr_label != null) {
        elm.setAttribute("label", mcr_label);
    }
    elm.setAttribute("version", mcr_version);
    return doc;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Aggregations

Element (org.jdom2.Element)77 Document (org.jdom2.Document)27 IOException (java.io.IOException)18 JDOMException (org.jdom2.JDOMException)16 File (java.io.File)11 MCRException (org.mycore.common.MCRException)11 Content (org.jdom2.Content)10 MCRContent (org.mycore.common.content.MCRContent)10 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)10 XMLOutputter (org.jdom2.output.XMLOutputter)9 SAXBuilder (org.jdom2.input.SAXBuilder)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Attribute (org.jdom2.Attribute)6 MCRPath (org.mycore.datamodel.niofs.MCRPath)6 SAXException (org.xml.sax.SAXException)6 JsonElement (com.google.gson.JsonElement)5 Color (java.awt.Color)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4