Search in sources :

Example 56 with MCRContent

use of org.mycore.common.content.MCRContent 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 57 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRConfigurationInputStream method getPropertyStream.

private static InputStream getPropertyStream(String filename) throws IOException {
    File mycoreProperties = new File(filename);
    MCRContent input = null;
    if (mycoreProperties.canRead()) {
        input = new MCRFileContent(mycoreProperties);
    } else {
        URL url = MCRConfigurationInputStream.class.getClassLoader().getResource(filename);
        if (url != null) {
            input = new MCRURLContent(url);
        }
    }
    return input == null ? null : input.getInputStream();
}
Also used : MCRFileContent(org.mycore.common.content.MCRFileContent) MCRURLContent(org.mycore.common.content.MCRURLContent) File(java.io.File) MCRContent(org.mycore.common.content.MCRContent) URL(java.net.URL)

Example 58 with MCRContent

use of org.mycore.common.content.MCRContent 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 59 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRMetsIIIFPresentationImpl method getMets.

public Document getMets(String id) throws IOException, JDOMException, SAXException {
    String objectid = MCRLinkTableManager.instance().getSourceOf(id).iterator().next();
    MCRContentTransformer transformer = getTransformer();
    MCRParameterCollector parameter = new MCRParameterCollector();
    if (objectid != null && objectid.length() != 0) {
        MCRDerivate derObj = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(id));
        MCRObjectID ownerID = derObj.getOwnerID();
        objectid = ownerID.toString();
        parameter.setParameter("objectID", objectid);
        parameter.setParameter("derivateID", id);
    }
    MCRPath metsPath = MCRPath.getPath(id, "mets.xml");
    if (!Files.exists(metsPath)) {
        throw new MCRException("File not found: " + id);
    }
    MCRPathContent source = new MCRPathContent(metsPath);
    MCRContent content = transformer instanceof MCRParameterizedTransformer ? ((MCRParameterizedTransformer) transformer).transform(source, parameter) : transformer.transform(source);
    return content.asXML();
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRException(org.mycore.common.MCRException) MCRPathContent(org.mycore.common.content.MCRPathContent) MCRParameterizedTransformer(org.mycore.common.content.transformer.MCRParameterizedTransformer) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRContent(org.mycore.common.content.MCRContent)

Example 60 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRDFGLinkServlet method doGetPost.

@Override
protected void doGetPost(MCRServletJob job) throws Exception {
    HttpServletRequest request = job.getRequest();
    HttpServletResponse response = job.getResponse();
    String filePath = request.getParameter("file") == null ? "" : request.getParameter("file");
    String derivateID = request.getParameter("deriv") == null ? "" : request.getParameter("deriv");
    if (derivateID.equals("")) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Derivate is not set");
    }
    String encodedMetsURL = URLEncoder.encode(MCRServlet.getServletBaseURL() + "MCRMETSServlet/" + derivateID + "?XSL.Style=dfg", "UTF-8");
    LOGGER.info(request.getPathInfo());
    MCRPath rootPath = MCRPath.getPath(derivateID, "/");
    if (!Files.isDirectory(rootPath)) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, MessageFormat.format("Derivate {0} does not exist.", derivateID));
        return;
    }
    request.setAttribute("XSL.derivateID", derivateID);
    Collection<String> linkList = MCRLinkTableManager.instance().getSourceOf(derivateID);
    if (linkList.isEmpty()) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, MessageFormat.format("Derivate {0} is not linked with a MCRObject. Please contact an administrator.", derivateID));
        return;
    }
    // TODO: this seems very very wrong
    if (filePath == "") {
        MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivateID));
        filePath = derivate.getDerivate().getInternals().getMainDoc();
    }
    MCRPath metsPath = (MCRPath) rootPath.resolve("mets.xml");
    int imageNumber = -2;
    if (Files.exists(metsPath)) {
        imageNumber = getOrderNumber(new MCRPathContent(metsPath).asXML(), filePath);
    } else {
        MCRContent metsContent = getMetsSource(job, useExistingMets(request), derivateID);
        imageNumber = getOrderNumber(metsContent.asXML(), filePath);
    }
    String dfgURL = "";
    switch(imageNumber) {
        case -1:
            response.sendError(HttpServletResponse.SC_CONFLICT, MessageFormat.format("Image \"{0}\" not found in the MCRDerivate. Please contact an administrator.", filePath));
            return;
        case -2:
            dfgURL = "http://dfg-viewer.de/show/?set[mets]=" + encodedMetsURL;
            break;
        default:
            dfgURL = "http://dfg-viewer.de/show/?set[mets]=" + encodedMetsURL + "&set[image]=" + imageNumber;
            break;
    }
    response.sendRedirect(dfgURL);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MCRPathContent(org.mycore.common.content.MCRPathContent) HttpServletResponse(javax.servlet.http.HttpServletResponse) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRContent(org.mycore.common.content.MCRContent)

Aggregations

MCRContent (org.mycore.common.content.MCRContent)63 Document (org.jdom2.Document)21 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)20 IOException (java.io.IOException)16 Element (org.jdom2.Element)13 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 Test (org.junit.Test)8 MCRPathContent (org.mycore.common.content.MCRPathContent)7 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JDOMException (org.jdom2.JDOMException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 MCRException (org.mycore.common.MCRException)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 URL (java.net.URL)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3