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