Search in sources :

Example 46 with MCRJDOMContent

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();
}
Also used : MCRXSL2XMLTransformer(org.mycore.common.content.transformer.MCRXSL2XMLTransformer) MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRContent(org.mycore.common.content.MCRContent)

Example 47 with MCRJDOMContent

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;
}
Also used : MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRXMLContent(org.mycore.common.content.MCRXMLContent) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) SAXException(org.xml.sax.SAXException)

Example 48 with MCRJDOMContent

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;
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) MCRObject(org.mycore.datamodel.metadata.MCRObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Example 49 with MCRJDOMContent

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));
}
Also used : MCRFileContent(org.mycore.common.content.MCRFileContent) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) File(java.io.File)

Example 50 with MCRJDOMContent

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);
}
Also used : BibtexFile(bibtex.dom.BibtexFile) Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent)

Aggregations

MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)54 Document (org.jdom2.Document)33 Element (org.jdom2.Element)28 Test (org.junit.Test)21 MCRContent (org.mycore.common.content.MCRContent)20 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)6 IOException (java.io.IOException)5 File (java.io.File)4 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4 Date (java.util.Date)3 JDOMException (org.jdom2.JDOMException)3 MCRContentTransformer (org.mycore.common.content.transformer.MCRContentTransformer)3 MCRPath (org.mycore.datamodel.niofs.MCRPath)3 FileObject (org.apache.commons.vfs2.FileObject)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 MCRException (org.mycore.common.MCRException)2 MCRPersistenceException (org.mycore.common.MCRPersistenceException)2 MCRFileContent (org.mycore.common.content.MCRFileContent)2