Search in sources :

Example 1 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRFileNodeServlet method sendDirectory.

/**
 * Sends the contents of an MCRDirectory as XML data to the client
 * @throws SAXException
 * @throws TransformerException
 */
private MCRContent sendDirectory(HttpServletRequest request, HttpServletResponse response, MCRPath mcrPath) throws IOException, TransformerException, SAXException {
    Document directoryXML = MCRPathXML.getDirectoryXML(mcrPath);
    MCRJDOMContent source = new MCRJDOMContent(directoryXML);
    source.setLastModified(Files.getLastModifiedTime(mcrPath).toMillis());
    String fileName = mcrPath.getNameCount() == 0 ? mcrPath.getOwner() : mcrPath.getFileName().toString();
    source.setName(fileName);
    return getLayoutService().getTransformedContent(request, response, source);
}
Also used : MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document)

Example 2 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRFileCollection method saveAdditionalData.

protected void saveAdditionalData() throws IOException {
    FileObject target = VFS.getManager().resolveFile(fo, dataFile);
    new MCRJDOMContent(data.getDocument()).sendTo(target);
}
Also used : MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) FileObject(org.apache.commons.vfs2.FileObject)

Example 3 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRMetadataStoreTest method getNextFreeID.

@Test
public void getNextFreeID() throws Exception {
    int id1 = getMetaDataStore().getNextFreeID();
    assertTrue(id1 >= 0);
    assertFalse(getMetaDataStore().exists(id1));
    Document xml1 = new Document(new Element("root"));
    int id2 = getMetaDataStore().create(new MCRJDOMContent(xml1)).getID();
    assertTrue(id2 > id1);
    assertTrue(getMetaDataStore().getNextFreeID() > id2);
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 4 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRMetadataStoreTest method retrieve.

@Test
public void retrieve() throws Exception {
    Document xml1 = new Document(new Element("root"));
    int id = getMetaDataStore().create(new MCRJDOMContent(xml1)).getID();
    MCRStoredMetadata sm1 = getMetaDataStore().retrieve(id);
    MCRContent xml2 = sm1.getMetadata();
    assertEquals(new MCRJDOMContent(xml1).asString(), xml2.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)

Example 5 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRMetadataStoreTest method createDocumentInt.

@Test
public void createDocumentInt() throws Exception {
    Document xml1 = new Document(new Element("root"));
    try {
        getMetaDataStore().create(new MCRJDOMContent(xml1), 0);
        fail("metadata store allows to save with id \"0\".");
    } catch (Exception e) {
    // test passed
    }
    int id = getMetaDataStore().getNextFreeID();
    assertTrue(id > 0);
    MCRStoredMetadata sm1 = getMetaDataStore().create(new MCRJDOMContent(xml1), id);
    assertNotNull(sm1);
    MCRContent xml2 = getMetaDataStore().retrieve(id).getMetadata();
    assertEquals(new MCRJDOMContent(xml1).asString(), xml2.asString());
    getMetaDataStore().create(new MCRJDOMContent(xml1), id + 1);
    MCRContent xml3 = getMetaDataStore().retrieve(id + 1).getMetadata();
    assertEquals(new MCRJDOMContent(xml1).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

MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)54 Document (org.jdom2.Document)33 Element (org.jdom2.Element)28 Test (org.junit.Test)21 MCRContent (org.mycore.common.content.MCRContent)20 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)6 IOException (java.io.IOException)5 File (java.io.File)4 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4 Date (java.util.Date)3 JDOMException (org.jdom2.JDOMException)3 MCRContentTransformer (org.mycore.common.content.transformer.MCRContentTransformer)3 MCRPath (org.mycore.datamodel.niofs.MCRPath)3 FileObject (org.apache.commons.vfs2.FileObject)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 MCRException (org.mycore.common.MCRException)2 MCRPersistenceException (org.mycore.common.MCRPersistenceException)2 MCRFileContent (org.mycore.common.content.MCRFileContent)2