use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRMailer method transform.
/**
* Transforms the given input element using xsl stylesheet.
*
* @param input the input document to transform.
* @param stylesheet the name of the xsl stylesheet to use, without the ".xsl" ending.
* @param parameters the optionally empty table of xsl parameters
* @return the output document generated by the transformation process
*/
private static Document transform(Document input, String stylesheet, Map<String, String> parameters) throws Exception {
MCRJDOMContent source = new MCRJDOMContent(input);
MCRXSL2XMLTransformer transformer = MCRXSL2XMLTransformer.getInstance("xsl/" + stylesheet + ".xsl");
MCRParameterCollector parameterCollector = MCRParameterCollector.getInstanceFromUserSession();
parameterCollector.setParameters(parameters);
MCRContent result = transformer.transform(source, parameterCollector);
return result.asXML();
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRToPrettyXML method transform.
@Override
public MCRContent transform(MCRContent source) throws IOException {
MCRXMLContent content;
try {
content = (source instanceof MCRXMLContent ? (MCRXMLContent) source : new MCRJDOMContent(source.asXML()));
} catch (JDOMException | SAXException e) {
throw new IOException(e);
}
if (content != source) {
content.setName(source.getName());
content.setLastModified(source.lastModified());
}
content.setFormat(Format.getPrettyFormat().setEncoding(getEncoding()));
return content;
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRTransferPackage method getContent.
/**
* Returns the content for this transfer package. You have to call {@link #build()}
* before you can retrieve this data.
*
* @return a map where key = filename; value = MCRContent
*/
public Map<String, MCRContent> getContent() throws IOException {
Map<String, MCRContent> content = new HashMap<>();
// config
content.put(IMPORT_CONFIG_FILENAME, new MCRJDOMContent(buildImportConfiguration()));
// objects
for (MCRObject object : this.objects) {
String fileName = CONTENT_PATH + object.getId() + ".xml";
Document xml = object.createXML();
content.put(fileName, new MCRJDOMContent(xml));
}
// file containers
for (MCRTransferPackageFileContainer fc : this.fileContainers) {
// derivate
MCRObjectID derivateId = fc.getDerivateId();
MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateId);
Document derivateXML = derivate.createXML();
String folder = CONTENT_PATH + fc.getName();
String derivateFileName = folder + "/" + fc.getName() + ".xml";
content.put(derivateFileName, new MCRJDOMContent(derivateXML));
// files of derivate
for (MCRFile file : fc.getFiles()) {
content.put(folder + file.getAbsolutePath(), file.getContent());
}
}
// classifications
for (String classId : this.classifications) {
Document classification = MCRClassificationUtils.asDocument(classId);
String path = CLASS_PATH + classId + ".xml";
content.put(path, new MCRJDOMContent(classification));
}
return content;
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRGoogleSitemapServlet method doGetPost.
/**
* This method implement the doGetPost method of MCRServlet. It build a XML
* file for the Google search engine.
*
* @param job
* a MCRServletJob instance
*/
public void doGetPost(MCRServletJob job) throws Exception {
File baseDir = MCRFrontendUtil.getWebAppBaseDir(getServletContext()).orElseGet(() -> new File(MCRConfiguration.instance().getString("MCR.WebApplication.basedir")));
MCRGoogleSitemapCommon common = new MCRGoogleSitemapCommon(MCRFrontendUtil.getBaseURL(job.getRequest()), baseDir);
int number = common.checkSitemapFile();
LOGGER.debug("Build Google number of URL files {}.", Integer.toString(number));
Document jdom = null;
// check if sitemap_google.xml exist
String fnsm = common.getFileName(1, true);
LOGGER.debug("Build Google check file {}", fnsm);
File fi = new File(fnsm);
if (fi.isFile()) {
jdom = MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRFileContent(fi));
if (jdom == null) {
if (number == 1) {
jdom = common.buildSingleSitemap();
} else {
jdom = common.buildSitemapIndex(number);
}
}
// send XML output
getLayoutService().doLayout(job.getRequest(), job.getResponse(), new MCRJDOMContent(jdom));
return;
}
// remove old files
common.removeSitemapFiles();
// build new return and URL files
if (number == 1) {
jdom = common.buildSingleSitemap();
} else {
for (int i = 0; i < number; i++) {
String fn = common.getFileName(i + 2, true);
File xml = new File(fn);
jdom = common.buildPartSitemap(i);
LOGGER.info("Write Google sitemap file {}.", fn);
new MCRJDOMContent(jdom).sendTo(xml);
}
jdom = common.buildSitemapIndex(number);
}
// send XML output
getLayoutService().doLayout(job.getRequest(), job.getResponse(), new MCRJDOMContent(jdom));
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRBibTeX2MODSTransformer method transform.
@Override
public MCRJDOMContent transform(MCRContent source) throws IOException {
String input = source.asString();
input = fixMissingEntryKeys(input);
BibtexFile bibtexFile = parse(input);
Element collection = new MCRBibTeXFileTransformer().transform(bibtexFile);
return new MCRJDOMContent(collection);
}
Aggregations