use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRDerivateContentTransformerServlet method getContent.
@Override
public MCRContent getContent(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String pathInfo = req.getPathInfo();
if (pathInfo.startsWith("/")) {
pathInfo = pathInfo.substring(1);
}
String[] pathTokens = pathInfo.split("/");
String derivate = pathTokens[0];
String path = pathInfo.substring(derivate.length());
LOGGER.debug("Derivate : {}", derivate);
LOGGER.debug("Path : {}", path);
MCRPath mcrPath = MCRPath.getPath(derivate, path);
MCRContent pc = new MCRPathContent(mcrPath);
FileTime lastModifiedTime = Files.getLastModifiedTime(mcrPath);
MCRFrontendUtil.writeCacheHeaders(resp, (long) CACHE_TIME, lastModifiedTime.toMillis(), true);
try {
return getLayoutService().getTransformedContent(req, resp, pc);
} catch (TransformerException | SAXException e) {
throw new IOException("could not transform content", e);
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRDOIRegistrationService method transformToDatacite.
protected Document transformToDatacite(MCRDigitalObjectIdentifier doi, MCRBase mcrBase) throws MCRPersistentIdentifierException {
MCRObjectID id = mcrBase.getId();
MCRBaseContent content = new MCRBaseContent(mcrBase);
try {
MCRContent transform = MCRContentTransformerFactory.getTransformer(this.transformer).transform(content);
Document dataciteDocument = transform.asXML();
insertDOI(dataciteDocument, doi);
Schema dataciteSchema = loadDataciteSchema();
try {
dataciteSchema.newValidator().validate(new JDOMSource(dataciteDocument));
} catch (SAXException e) {
String translatedInformation = MCRTranslation.translate(TRANSLATE_PREFIX + ERR_CODE_1_2);
throw new MCRPersistentIdentifierException("The document " + id + " does not generate well formed Datacite!", translatedInformation, ERR_CODE_1_2, e);
}
return dataciteDocument;
} catch (IOException | JDOMException | SAXException e) {
throw new MCRPersistentIdentifierException("Could not transform the content of " + id + " with the transformer " + transformer, e);
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRWorksPublisher method buildWorkXMLFrom.
/**
* Retrieves the MyCoRe object, transforms it to ORCID work xml and validates
*/
private Document buildWorkXMLFrom(MCRObjectID objectID) throws IOException, SAXParseException {
MCRContent mcrObject = MCRXMLMetadataManager.instance().retrieveContent(objectID);
MCRContent workXML = T_MCR2WORK.transform(mcrObject);
return MCRXMLParserFactory.getValidatingParser().parseXML(workXML);
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRNormalizeUnicodeTransformer method process.
public Document process(Document xml) throws IOException, JDOMException, SAXException {
if (stylesheet == null)
return xml.clone();
MCRContent source = new MCRJDOMContent(xml);
MCRContent transformed = MCRXSL2XMLTransformer.getInstance("xsl/" + stylesheet).transform(source);
MCRContent normalized = new MCRNormalizeUnicodeTransformer().transform(transformed);
return normalized.asXML();
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRXEditorTransformer method transform.
public MCRContent transform(MCRContent editorSource) throws IOException, JDOMException, SAXException {
editorSession.getValidator().clearRules();
editorSession.getSubmission().clear();
MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer("xeditor");
if (transformer instanceof MCRParameterizedTransformer) {
String key = MCRXEditorTransformerStore.storeTransformer(this);
transformationParameters.setParameter("XEditorTransformerKey", key);
MCRContent result = ((MCRParameterizedTransformer) transformer).transform(editorSource, transformationParameters);
if (result instanceof MCRWrappedContent && result.getClass().getName().contains(MCRXSLTransformer.class.getName())) {
// lazy transformation make JUnit tests fail
result = ((MCRWrappedContent) result).getBaseContent();
}
editorSession.getValidator().clearValidationResults();
return result;
} else {
throw new MCRException("Xeditor needs parameterized MCRContentTransformer: " + transformer);
}
}
Aggregations