use of org.mycore.common.content.MCRPathContent 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();
}
use of org.mycore.common.content.MCRPathContent 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);
}
use of org.mycore.common.content.MCRPathContent in project mycore by MyCoRe-Org.
the class MCRDFGLinkServlet method getMetsSource.
/**
* Returns the mets document wrapped in a {@link MCRContent} object.
*
* @param job
* @param useExistingMets
* @return
* @throws Exception
*/
private static MCRContent getMetsSource(MCRServletJob job, boolean useExistingMets, String derivate) throws Exception {
MCRPath metsFile = MCRPath.getPath(derivate, "/mets.xml");
try {
job.getRequest().setAttribute("XSL.derivateID", derivate);
job.getRequest().setAttribute("XSL.objectID", MCRLinkTableManager.instance().getSourceOf(derivate).iterator().next());
} catch (Exception x) {
LOGGER.warn("Unable to set \"XSL.objectID\" attribute to current request", x);
}
boolean metsExists = Files.exists(metsFile);
if (metsExists && useExistingMets) {
MCRContent content = new MCRPathContent(metsFile);
content.setDocType("mets");
return content;
} else {
Document mets = MCRMETSGeneratorFactory.create(metsFile.getParent()).generate().asDocument();
return new MCRJDOMContent(mets);
}
}
use of org.mycore.common.content.MCRPathContent in project mycore by MyCoRe-Org.
the class MCRMETSServlet method getMetsSource.
/**
* Returns the mets document wrapped in a {@link MCRContent} object.
*/
static MCRContent getMetsSource(MCRServletJob job, boolean useExistingMets, String derivate) throws Exception {
MCRPath metsPath = MCRPath.getPath(derivate, "/mets.xml");
try {
job.getRequest().setAttribute("XSL.derivateID", derivate);
String objectid = MCRLinkTableManager.instance().getSourceOf(derivate).iterator().next();
if (objectid == null || objectid.length() == 0) {
MCRDerivate derObj = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivate));
MCRObjectID ownerID = derObj.getOwnerID();
objectid = ownerID.toString();
}
job.getRequest().setAttribute("XSL.objectID", objectid);
} catch (Exception x) {
LOGGER.warn("Unable to set \"XSL.objectID\" attribute to current request", x);
}
boolean metsExists = Files.exists(metsPath);
if (metsExists && useExistingMets) {
MCRContent content = new MCRPathContent(metsPath);
content.setDocType("mets");
return content;
} else {
Document mets = MCRMETSGeneratorFactory.create(MCRPath.getPath(derivate, "/")).generate().asDocument();
if (!metsExists && STORE_METS_ON_GENERATE) {
MCRMetsSave.saveMets(mets, MCRObjectID.getInstance(derivate));
}
return new MCRJDOMContent(mets);
}
}
Aggregations