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;
}
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\""));
}
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();
}
Aggregations