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);
}
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;
}
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;
}
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;
}
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));
}
Aggregations