Search in sources :

Example 31 with MCRContent

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

the class MCRObjectServlet method requestVersionedObject.

private MCRContent requestVersionedObject(final MCRObjectID mcrid, final HttpServletResponse resp, final long rev) throws IOException {
    MCRXMLMetadataManager xmlMetadataManager = MCRXMLMetadataManager.instance();
    MCRMetadataStore metadataStore = xmlMetadataManager.getStore(mcrid);
    if (metadataStore instanceof MCRVersioningMetadataStore) {
        MCRContent content = xmlMetadataManager.retrieveContent(mcrid, rev);
        if (content != null) {
            return content;
        }
        resp.sendError(HttpServletResponse.SC_NOT_FOUND, getErrorI18N(I18N_ERROR_PREFIX, "revisionNotFound", rev, mcrid));
        return null;
    }
    resp.sendError(HttpServletResponse.SC_BAD_REQUEST, getErrorI18N(I18N_ERROR_PREFIX, "noVersions", mcrid));
    return null;
}
Also used : MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRContent(org.mycore.common.content.MCRContent) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore)

Example 32 with MCRContent

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

the class MCRObjectServlet method getContent.

@Override
public MCRContent getContent(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final MCRObjectID mcrid = getMCRObjectID(req, resp);
    if (mcrid == null) {
        return null;
    }
    if (!MCRAccessManager.checkPermission(mcrid, PERMISSION_READ)) {
        // check read permission for ID
        final MCRSession currentSession = MCRSessionMgr.getCurrentSession();
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, getErrorI18N(I18N_ERROR_PREFIX, "accessDenied", mcrid.toString(), currentSession.getUserInformation().getUserID(), currentSession.getCurrentIP()));
        return null;
    }
    long rev = REV_CURRENT;
    final String revision = getProperty(req, "r");
    if (revision != null) {
        rev = Long.parseLong(revision);
    }
    MCRContent localObject = (rev == REV_CURRENT) ? requestLocalObject(mcrid, resp) : requestVersionedObject(mcrid, resp, rev);
    if (localObject == null) {
        return null;
    }
    try {
        return getLayoutService().getTransformedContent(req, resp, localObject);
    } catch (TransformerException | SAXException e) {
        throw new IOException(e);
    }
}
Also used : MCRSession(org.mycore.common.MCRSession) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) MCRContent(org.mycore.common.content.MCRContent) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 33 with MCRContent

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

the class MCRQRCodeServlet method getContent.

@Override
public MCRContent getContent(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    String pathInfo = req.getPathInfo();
    Matcher matcher = REQUEST_PATTERN.matcher(pathInfo);
    if (!matcher.matches()) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Path info does not comply to " + REQUEST_PATTERN + ": " + pathInfo);
        return null;
    }
    int size = Integer.parseInt(matcher.group(1));
    String relativeURL = matcher.group(2);
    String queryString = req.getQueryString();
    String url = MCRFrontendUtil.getBaseURL() + relativeURL;
    if (queryString != null) {
        url += '?' + queryString;
    }
    LOGGER.info("Generating QR CODE: {}", url);
    MCRContent content = getPNGContent(url, size);
    content.setLastModified(0);
    if (!"HEAD".equals(req.getMethod())) {
        MCRFrontendUtil.writeCacheHeaders(resp, CACHE_TIME, (long) 0, true);
    }
    return content;
}
Also used : Matcher(java.util.regex.Matcher) MCRContent(org.mycore.common.content.MCRContent)

Example 34 with MCRContent

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

the class MCRStaticXMLFileServlet method doGetPost.

@Override
public void doGetPost(MCRServletJob job) throws java.io.IOException, MCRException, SAXException, JDOMException, URISyntaxException, TransformerException {
    String ruleID = MCRLayoutUtilities.getWebpageACLID(job.getRequest().getServletPath());
    if (MCRAccessManager.hasRule(ruleID, READ_WEBPAGE_PERMISSION) && !MCRAccessManager.checkPermission(ruleID, READ_WEBPAGE_PERMISSION)) {
        job.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }
    URL resource = resolveResource(job);
    if (resource != null) {
        HttpServletRequest request = job.getRequest();
        HttpServletResponse response = job.getResponse();
        setXSLParameters(resource, request);
        MCRContent content = getResourceContent(request, response, resource);
        getLayoutService().doLayout(request, response, content);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) MCRContent(org.mycore.common.content.MCRContent) URL(java.net.URL)

Example 35 with MCRContent

use of org.mycore.common.content.MCRContent 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);
            }
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Element(org.jdom2.Element) FileNotFoundException(java.io.FileNotFoundException) 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