use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRXSL2XMLTransformer method getTransformedContent.
@Override
protected MCRContent getTransformedContent(MCRContent source, XMLReader reader, TransformerHandler transformerHandler) throws IOException, SAXException {
JDOMResult result = new JDOMResult();
transformerHandler.setResult(result);
// Parse the source XML, and send the parse events to the
// TransformerHandler.
reader.parse(source.getInputSource());
Document resultDoc = getDocument(result);
if (resultDoc == null) {
throw new MCRConfigurationException("Stylesheets " + Arrays.asList(templateSources) + " does not return any content for " + source.getSystemId());
}
return new MCRJDOMContent(resultDoc);
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRDynamicURIResolver method resolveVariablesFromElement.
/**
* This method runs through the whole content of the startElement and
* tries to resolve all variables in texts and attributes.
*
* @param startElement where to start to resolve the variables
* @param variablesMap a map of all variables
*/
protected void resolveVariablesFromElement(Element startElement, Hashtable<String, String> variablesMap) {
Iterator<Element> it = startElement.getDescendants(Filters.element());
MCRTextResolver varResolver = new MCRTextResolver(variablesMap);
while (it.hasNext()) {
Element element = it.next();
// text
String text = element.getText();
if (text != null && !text.equals("") && text.contains("{")) {
element.setText(varResolver.resolve(text));
}
// attributes
for (Attribute attrib : element.getAttributes()) {
String attribValue = attrib.getValue();
if (attribValue.contains("{")) {
attrib.setValue(varResolver.resolve(attribValue));
}
}
}
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRCompressServlet method sendObject.
private void sendObject(MCRObjectID id, MCRServletJob job, T container) throws Exception {
MCRContent content = MCRXMLMetadataManager.instance().retrieveContent(id);
if (content == null) {
throw new FileNotFoundException("Could not find object: " + id);
}
long lastModified = MCRXMLMetadataManager.instance().getLastModified(id);
HttpServletRequest req = job.getRequest();
byte[] metaDataContent = getMetaDataContent(content, req);
sendMetadataCompressed("metadata.xml", metaDataContent, lastModified, container);
// zip all derivates
List<Element> li = content.asXML().getRootElement().getChild("structure").getChild("derobjects").getChildren("derobject");
for (Element el : li) {
if (el.getAttributeValue("inherited").equals("0")) {
String ownerID = el.getAttributeValue("href", XLINK_NAMESPACE);
// here the access check is tested only against the derivate
if (MCRAccessManager.checkPermission(ownerID, PERMISSION_READ) && MCRXMLFunctions.isDisplayedEnabledDerivate(ownerID)) {
sendDerivate(MCRObjectID.getInstance(ownerID), null, container);
}
}
}
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MyCoReWebPageProvider method addSection.
/**
* Adds a section to the MyCoRe webpage
* @param title the title of the section
* @param content list of content added to the section
* @param lang the language of the section specified by a language key.
* @return added section
*/
public Element addSection(String title, List<Content> content, String lang) {
Element section = new Element(XML_SECTION);
if (lang != null) {
section.setAttribute(XML_LANG, lang, Namespace.XML_NAMESPACE);
}
if (title != null && !title.equals("")) {
section.setAttribute(XML_TITLE, title);
}
section.addContent(content);
this.xml.getRootElement().addContent(section);
return section;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRMetsSave method saveMets.
/**
* Saves the content of the given document to file, if no mets present and then adds the file to
* the derivate with the given id. The name of the file depends on property
* 'MCR.Mets.Filename'. If this property has not been set 'mets.xml' is used
* as a default filename.
*
* @param overwrite
* if true existing mets-file will be overwritten
* @param validate
* if true the document will be validated before its stored
* @return
* true if the given document was successfully saved, otherwise false
*/
public static synchronized boolean saveMets(Document document, MCRObjectID derivateId, boolean overwrite, boolean validate) {
// add the file to the existing derivate in ifs
MCRPath metsFile = getMetsFile(derivateId.toString());
if (metsFile == null) {
metsFile = createMetsFile(derivateId.toString());
} else if (!overwrite) {
return false;
}
if (validate && !Mets.isValid(document)) {
LOGGER.warn("Storing mets.xml for {} failed cause the given document was invalid.", derivateId);
return false;
}
try (OutputStream metsOut = Files.newOutputStream(metsFile)) {
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
xout.output(document, metsOut);
LOGGER.info("Storing file content from \"{}\" to derivate \"{}\"", getMetsFileName(), derivateId);
} catch (Exception e) {
LOGGER.error(e);
return false;
}
return true;
}
Aggregations