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;
}
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);
}
}
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;
}
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);
}
}
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);
}
}
}
}
Aggregations