use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRMetadataStoreTest method createDocument.
@Test
public void createDocument() throws Exception {
Document xml1 = new Document(new Element("root"));
MCRStoredMetadata sm = getMetaDataStore().create(new MCRJDOMContent(xml1));
assertNotNull(sm);
int id1 = sm.getID();
assertTrue(id1 > 0);
MCRStoredMetadata sm2 = getMetaDataStore().retrieve(id1);
MCRContent xml2 = sm2.getMetadata();
assertEquals(new MCRJDOMContent(xml1).asString(), xml2.asString());
int id2 = getMetaDataStore().create(new MCRJDOMContent(xml1)).getID();
assertTrue(id2 > id1);
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRVersioningMetadataStoreTest method update.
@Test
public void update() throws Exception {
Document xml1 = new Document(new Element("root"));
MCRVersionedMetadata vm = getVersStore().create(new MCRJDOMContent(xml1));
Document xml3 = new Document(new Element("update"));
long rev = vm.getRevision();
vm.update(new MCRJDOMContent(xml3));
assertTrue(vm.getRevision() > rev);
MCRContent xml4 = getVersStore().retrieve(vm.getID()).getMetadata();
assertEquals(new MCRJDOMContent(xml3).asString(), xml4.asString());
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRLayoutServiceTarget method handleSubmission.
@Override
public void handleSubmission(ServletContext context, MCRServletJob job, MCREditorSession session, String style) throws Exception {
session.getSubmission().setSubmittedValues(job.getRequest().getParameterMap());
Document result = session.getEditedXML();
if (session.getValidator().isValid()) {
result = MCRChangeTracker.removeChangeTracking(result);
result = session.getXMLCleaner().clean(result);
result = session.getPostProcessor().process(result);
if ((style != null) && (!style.isEmpty()))
job.getRequest().setAttribute("XSL.Style", style);
MCRContent editedXML = new MCRJDOMContent(result);
MCRLayoutService.instance().doLayout(job.getRequest(), job.getResponse(), editedXML);
session.setBreakpoint("After handling target layout " + style);
} else {
session.setBreakpoint("After validation failed, target layout " + style);
job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(session.getRedirectURL(null)));
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRViewerResource method show.
@GET
@Path("{derivate}{path: (/[^?#]*)?}")
public Response show(@Context HttpServletRequest request, @Context Request jaxReq, @Context ServletContext context, @Context ServletConfig config) throws Exception {
MCRContent content = getContent(request);
String contentETag = content.getETag();
Response.ResponseBuilder responseBuilder = null;
EntityTag eTag = contentETag == null ? null : new EntityTag(contentETag);
if (eTag != null) {
responseBuilder = jaxReq.evaluatePreconditions(eTag);
}
if (responseBuilder == null) {
responseBuilder = Response.ok(content.asByteArray(), MediaType.valueOf(content.getMimeType()));
}
if (eTag != null) {
responseBuilder.tag(eTag);
}
if (content.isUsingSession()) {
CacheControl cc = new CacheControl();
cc.setPrivate(true);
cc.setMaxAge(0);
cc.setMustRevalidate(true);
responseBuilder.cacheControl(cc);
}
return responseBuilder.build();
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRDerivateCommands method transformXMLMatchingPatternWithStylesheet.
@MCRCommand(syntax = "transform xml matching file name pattern {0} in derivate {1} with stylesheet {2}", help = "Finds all files in Derivate {1} which match the pattern {0} (the complete path with regex: or glob:*.xml syntax) and transforms them with stylesheet {2}")
public static void transformXMLMatchingPatternWithStylesheet(String pattern, String derivate, String stylesheet) throws IOException {
MCRXSLTransformer transformer = new MCRXSLTransformer(stylesheet);
MCRPath derivateRoot = MCRPath.getPath(derivate, "/");
PathMatcher matcher = derivateRoot.getFileSystem().getPathMatcher(pattern);
Files.walkFileTree(derivateRoot, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (matcher.matches(file)) {
LOGGER.info("The file {} matches the pattern {}", file, pattern);
MCRContent sourceContent = new MCRPathContent(file);
MCRContent resultContent = transformer.transform(sourceContent);
try {
Document source = sourceContent.asXML();
Document result = resultContent.asXML();
LOGGER.info("Transforming complete!");
if (!MCRXMLHelper.deepEqual(source, result)) {
LOGGER.info("Writing result..");
resultContent.sendTo(file, StandardCopyOption.REPLACE_EXISTING);
} else {
LOGGER.info("Result and Source is the same..");
}
} catch (JDOMException | SAXException e) {
throw new IOException("Error while processing file : " + file, e);
}
}
return FileVisitResult.CONTINUE;
}
});
}
Aggregations