Search in sources :

Example 86 with Content

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

the class MCRBasketPersistence method writeBasketToFile.

/**
 * Writes the basket's content to a persistent file in the given derivate.
 *
 * @param basket the basket to save.
 * @param derivate the derivate holding the file
 * @param basketFile the file holding the basket's data.
 * @throws IOException
 */
private static void writeBasketToFile(MCRBasket basket, MCRDerivate derivate, MCRPath basketFile) throws IOException {
    Document xml = new MCRBasketXMLBuilder(false).buildXML(basket);
    XMLOutputter xout = new XMLOutputter();
    xout.output(xml, Files.newOutputStream(basketFile));
    MCRMetadataManager.updateMCRDerivateXML(derivate);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Document(org.jdom2.Document)

Example 87 with Content

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

the class MCRMetaDerivateLink method createXML.

public Element createXML() throws MCRException {
    Element elm = super.createXML();
    for (String key : map.keySet()) {
        Element annotationElem = new Element(MCRMetaDerivateLink.ANNOTATION);
        annotationElem.setAttribute(MCRMetaDerivateLink.ATTRIBUTE, key, Namespace.XML_NAMESPACE);
        String content = map.get(key);
        if (content == null || content.length() == 0)
            continue;
        annotationElem.addContent(content);
        elm.addContent(annotationElem);
    }
    return elm;
}
Also used : Element(org.jdom2.Element)

Example 88 with Content

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

the class MCRMetaElement method createXML.

/**
 * This methode create a XML stream for all data in this class, defined by
 * the MyCoRe XML MCRLangText definition for the given subtag.
 *
 * @param flag
 *            true if all inherited data should be include, else false
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Element with the XML Element part
 */
public final Element createXML(boolean flag) throws MCRException {
    try {
        validate();
    } catch (MCRException exc) {
        debug();
        throw new MCRException("MCRMetaElement : The content is not valid: Tag=" + this.tag, exc);
    }
    Element elm = new Element(tag);
    elm.setAttribute("class", getClassName());
    elm.setAttribute("heritable", String.valueOf(heritable));
    elm.setAttribute("notinherit", String.valueOf(notinherit));
    list.stream().filter(metaInterface -> (flag || metaInterface.getInherited() == 0)).map(MCRMetaInterface::createXML).forEachOrdered(elm::addContent);
    return elm;
}
Also used : MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element)

Example 89 with Content

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

the class MCRMetaInstitutionName method createXML.

/**
 * This method creates a XML stream for all data in this class, defined by
 * the MyCoRe XML MCRMetaInstitutionName definition for the given subtag.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Element with the XML MCRMetaInstitutionName part
 */
@Override
public final org.jdom2.Element createXML() throws MCRException {
    Element elm = super.createXML();
    elm.addContent(new org.jdom2.Element("fullname").addContent(fullname));
    if ((nickname = nickname.trim()).length() != 0) {
        elm.addContent(new org.jdom2.Element("nickname").addContent(nickname));
    }
    if ((property = property.trim()).length() != 0) {
        elm.addContent(new org.jdom2.Element("property").addContent(property));
    }
    return elm;
}
Also used : Element(org.jdom2.Element)

Example 90 with Content

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

the class MCRDerivateLinkServlet method doGetPost.

@Override
protected void doGetPost(MCRServletJob job) throws Exception {
    @SuppressWarnings("unchecked") Map<String, String[]> pMap = job.getRequest().getParameterMap();
    String webpage = pMap.get("subselect.webpage")[0];
    String mcrId = getSubParameterValueOfBrowserAddressParameter(webpage, "mcrid");
    String parentId = getSubParameterValueOfBrowserAddressParameter(webpage, "parentID");
    // create a new root element
    Element rootElement = new Element("derivateLinks-parentList");
    MCRObjectID objId = MCRObjectID.getInstance(mcrId);
    if (MCRMetadataManager.exists(objId)) {
        /* mcr object exists in datastore -> add all parent with their
             * derivates to the jdom tree */
        addParentsToElement(rootElement, objId);
    } else if (parentId != null && MCRMetadataManager.exists(MCRObjectID.getInstance(parentId))) {
        /* mcr object doesnt exists in datastore -> use the parent id
             * to create the content */
        Element firstParent = getMyCoReObjectElement(MCRObjectID.getInstance(parentId));
        if (firstParent != null) {
            rootElement.addContent(firstParent);
        }
        addParentsToElement(rootElement, MCRObjectID.getInstance(parentId));
    }
    // check if root element has content -> if not, show an error page
    if (rootElement.getContentSize() == 0) {
        job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(MCRFrontendUtil.getBaseURL() + derivateLinkErrorPage));
        return;
    }
    // set some important attributes to the root element
    rootElement.setAttribute("session", pMap.get("subselect.session")[0]);
    rootElement.setAttribute("varpath", pMap.get("subselect.varpath")[0]);
    rootElement.setAttribute("webpage", webpage);
    // transform & display the generated xml document
    getLayoutService().doLayout(job.getRequest(), job.getResponse(), new MCRJDOMContent(rootElement));
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

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