use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRPDFTools method getThumnail.
MCRContent getThumnail(Path pdfFile, BasicFileAttributes attrs, int thumbnailSize, boolean centered) throws IOException {
BufferedImage thumbnail = MCRPDFTools.getThumbnail(pdfFile, thumbnailSize, centered);
MCRContent pngContent = pngTools.toPNGContent(thumbnail);
BasicFileAttributes fattrs = attrs != null ? attrs : Files.readAttributes(pdfFile, BasicFileAttributes.class);
pngContent.setLastModified(fattrs.lastModifiedTime().toMillis());
return pngContent;
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRMetsCommands method validateSelectedMets.
@MCRCommand(syntax = "validate selected mets", help = "validates all mets.xml of selected derivates", order = 10)
public static void validateSelectedMets() {
List<String> selectedObjectIDs = MCRObjectCommands.getSelectedObjectIDs();
for (String objectID : selectedObjectIDs) {
LOGGER.info("Validate mets.xml of {}", objectID);
MCRPath metsFile = MCRPath.getPath(objectID, "/mets.xml");
if (Files.exists(metsFile)) {
try {
MCRContent content = new MCRPathContent(metsFile);
InputStream metsIS = content.getInputStream();
METSValidator mv = new METSValidator(metsIS);
List<ValidationException> validationExceptionList = mv.validate();
if (validationExceptionList.size() > 0) {
invalidMetsQueue.add(objectID);
}
for (ValidationException validationException : validationExceptionList) {
LOGGER.error(validationException.getMessage());
}
} catch (IOException e) {
LOGGER.error("Error while reading mets.xml of {}", objectID, e);
} catch (JDOMException e) {
LOGGER.error("Error while parsing mets.xml of {}", objectID, e);
}
}
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRMailEventHandler method handleCategoryEvent.
private void handleCategoryEvent(MCREvent evt, MCRCategory obj) {
MCRContent xml = new MCRJDOMContent(MCRCategoryTransformer.getMetaDataDocument(obj, false));
handleEvent(evt, xml, obj.toString());
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRDirectoryXML method getDirectoryXML.
/**
* Sends the contents of an MCRDirectory as XML data to the client
*/
protected Document getDirectoryXML(MCRDirectory dir, boolean withAdditionalData) {
LOGGER.info("MCRDirectoryXML: start listing of directory {}", dir.getName());
Element root = new Element("mcr_directory");
Document doc = new org.jdom2.Document(root);
root.setAttribute("ID", dir.getID());
addString(root, "path", dir.getPath());
addString(root, "ownerID", dir.getOwnerID());
addDate(root, "lastModified", dir.getLastModified());
addString(root, "size", String.valueOf(dir.getSize()));
String label = dir.getLabel();
if (label != null) {
addString(root, "label", label);
}
Element numChildren = new Element("numChildren");
root.addContent(numChildren);
Element ncHere = new Element("here");
numChildren.addContent(ncHere);
addString(ncHere, "directories", String.valueOf(dir.getNumChildren(MCRDirectory.DIRECTORIES, MCRDirectory.HERE)));
addString(ncHere, "files", String.valueOf(dir.getNumChildren(MCRDirectory.FILES, MCRDirectory.HERE)));
Element ncTotal = new Element("total");
numChildren.addContent(ncTotal);
addString(ncTotal, "directories", String.valueOf(dir.getNumChildren(MCRDirectory.DIRECTORIES, MCRDirectory.TOTAL)));
addString(ncTotal, "files", String.valueOf(dir.getNumChildren(MCRDirectory.FILES, MCRDirectory.TOTAL)));
Element nodes = new Element("children");
root.addContent(nodes);
MCRFilesystemNode[] children = dir.getChildren();
for (MCRFilesystemNode element : children) {
Element node = new Element("child");
node.setAttribute("ID", element.getID());
nodes.addContent(node);
addString(node, "name", element.getName());
label = element.getLabel();
if (label != null) {
addString(node, "label", label);
}
addString(node, "size", String.valueOf(element.getSize()));
addDate(node, "lastModified", element.getLastModified());
if (element instanceof MCRFile) {
node.setAttribute("type", "file");
MCRFile file = (MCRFile) element;
addString(node, "contentType", file.getContentTypeID());
addString(node, "md5", file.getMD5());
if (file.hasAudioVideoExtender()) {
MCRAudioVideoExtender ext = file.getAudioVideoExtender();
Element xExtender = new Element("extender");
node.addContent(xExtender);
addExtenderData(xExtender, ext);
}
} else {
node.setAttribute("type", "directory");
}
if (withAdditionalData) {
try {
MCRContent additional = element.getAllAdditionalData();
if (additional != null) {
node.addContent(additional.asXML().detachRootElement());
}
} catch (Exception ignored) {
}
}
}
LOGGER.info("MCRDirectoryXML: end listing of directory {}", dir.getName());
return doc;
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRMetadataStoreTest method update.
@Test
public void update() throws Exception {
Document xml1 = new Document(new Element("root"));
MCRStoredMetadata sm = getMetaDataStore().create(new MCRJDOMContent(xml1));
Document xml2 = new Document(new Element("update"));
sm.update(new MCRJDOMContent(xml2));
MCRContent xml3 = getMetaDataStore().retrieve(sm.getID()).getMetadata();
assertEquals(new MCRJDOMContent(xml2).asString(), xml3.asString());
}
Aggregations