Search in sources :

Example 1 with MCRStringContent

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

the class MCRToJSONTransformer method transform.

/* (non-Javadoc)
     * @see org.mycore.common.content.transformer.MCRContentTransformer#transform(org.mycore.common.content.MCRContent)
     */
@Override
public MCRContent transform(MCRContent source) throws IOException {
    JsonObject jsonObject = toJSON(source);
    MCRStringContent result = new MCRStringContent(jsonObject.toString());
    result.setMimeType(mimeType);
    result.setEncoding(getEncoding());
    result.setUsingSession(source.isUsingSession());
    return result;
}
Also used : MCRStringContent(org.mycore.common.content.MCRStringContent) JsonObject(com.google.gson.JsonObject)

Example 2 with MCRStringContent

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

the class MCRFileStoreTest method repairMetadata.

@Test
public void repairMetadata() throws Exception {
    MCRFileCollection col = getStore().create();
    Document xml1 = col.getMetadata().clone();
    col.repairMetadata();
    Document xml2 = col.getMetadata().clone();
    assertTrue(equals(xml1, xml2));
    MCRDirectory dir = col.createDir("foo");
    xml1 = col.getMetadata().clone();
    assertFalse(equals(xml1, xml2));
    dir.delete();
    xml1 = col.getMetadata().clone();
    assertTrue(equals(xml1, xml2));
    MCRDirectory dir2 = col.createDir("dir");
    MCRFile file1 = col.createFile("test1.txt");
    file1.setContent(new MCRStringContent("Test 1"));
    MCRFile readme = dir2.createFile("readme.txt");
    readme.setContent(new MCRStringContent("Hallo Welt!"));
    MCRFile file3 = col.createFile("test2.txt");
    file3.setContent(new MCRStringContent("Test 2"));
    file3.setLabel("de", "Die Testdatei");
    xml2 = col.getMetadata().clone();
    col.repairMetadata();
    xml1 = col.getMetadata().clone();
    assertTrue(equals(xml1, xml2));
    file3.clearLabels();
    xml2 = col.getMetadata().clone();
    col.fo.getChild("mcrdata.xml").delete();
    col = getStore().retrieve(col.getID());
    xml1 = col.getMetadata().clone();
    assertTrue(equals(xml1, xml2));
    col.fo.getChild("test1.txt").delete();
    FileObject tmp = col.fo.resolveFile("test3.txt");
    tmp.createFile();
    new MCRStringContent("Hallo Welt!").sendTo(tmp);
    col.repairMetadata();
    String xml3 = new MCRJDOMContent(col.getMetadata()).asString();
    assertFalse(xml3.contains("name=\"test1.txt\""));
    assertTrue(xml3.contains("name=\"test3.txt\""));
}
Also used : MCRStringContent(org.mycore.common.content.MCRStringContent) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) FileObject(org.apache.commons.vfs2.FileObject) Document(org.jdom2.Document) Test(org.junit.Test)

Example 3 with MCRStringContent

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

the class MCRWorksFetcher method bibTeX2MODS.

/**
 * Parses the bibTeX code that may be included in the work entry
 * and returns its transformation to MODS
 */
private Optional<Element> bibTeX2MODS(String bibTeX) {
    if ((bibTeX != null) && !bibTeX.isEmpty()) {
        try {
            MCRContent result = T_BIBTEX2MODS.transform(new MCRStringContent(bibTeX));
            Element modsCollection = result.asXML().getRootElement();
            Element modsFromBibTeX = modsCollection.getChild("mods", MCRConstants.MODS_NAMESPACE);
            // Remove mods:extension containing the original BibTeX:
            modsFromBibTeX.removeChildren("extension", MCRConstants.MODS_NAMESPACE);
            return Optional.of(modsFromBibTeX);
        } catch (Exception ex) {
            String msg = "Exception parsing BibTeX: " + bibTeX;
            LOGGER.warn("{} {}", msg, ex.getMessage());
        }
    }
    return Optional.empty();
}
Also used : MCRStringContent(org.mycore.common.content.MCRStringContent) Element(org.jdom2.Element) MCRContent(org.mycore.common.content.MCRContent) JDOMException(org.jdom2.JDOMException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

MCRStringContent (org.mycore.common.content.MCRStringContent)3 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 FileObject (org.apache.commons.vfs2.FileObject)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 JDOMException (org.jdom2.JDOMException)1 Test (org.junit.Test)1 MCRContent (org.mycore.common.content.MCRContent)1 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)1 SAXException (org.xml.sax.SAXException)1