Search in sources :

Example 41 with MCRContent

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;
}
Also used : MCRContent(org.mycore.common.content.MCRContent) BufferedImage(java.awt.image.BufferedImage) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 42 with MCRContent

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);
            }
        }
    }
}
Also used : ValidationException(org.mycore.mets.validator.validators.ValidationException) InputStream(java.io.InputStream) MCRPathContent(org.mycore.common.content.MCRPathContent) METSValidator(org.mycore.mets.validator.METSValidator) IOException(java.io.IOException) MCRPath(org.mycore.datamodel.niofs.MCRPath) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 43 with MCRContent

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());
}
Also used : MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRContent(org.mycore.common.content.MCRContent)

Example 44 with MCRContent

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;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Example 45 with MCRContent

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());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent) Test(org.junit.Test)

Aggregations

MCRContent (org.mycore.common.content.MCRContent)63 Document (org.jdom2.Document)21 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)20 IOException (java.io.IOException)16 Element (org.jdom2.Element)13 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 Test (org.junit.Test)8 MCRPathContent (org.mycore.common.content.MCRPathContent)7 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JDOMException (org.jdom2.JDOMException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 MCRException (org.mycore.common.MCRException)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 URL (java.net.URL)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3