use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRDefaultConfigurationLoader method loadFromFile.
/**
* Loads configuration properties from a specified properties file and adds
* them to the properties currently set. This method scans the <CODE>
* CLASSPATH</CODE> for the properties file, it may be a plain file, but
* may also be located in a zip or jar file. If the properties file contains
* a property called <CODE>MCR.Configuration.Include</CODE>, the files
* specified in that property will also be read. Multiple include files have
* to be separated by spaces or colons.
*
* @param filename
* the properties file to be loaded
* @throws MCRConfigurationException
* if the file can not be loaded
*/
private void loadFromFile(String filename) {
File mycoreProperties = new File(filename);
MCRContent input = null;
try {
if (mycoreProperties.canRead()) {
input = new MCRFileContent(mycoreProperties);
} else {
URL url = this.getClass().getResource("/" + filename);
if (url == null) {
throw new MCRConfigurationException("Could not find file or resource:" + filename);
}
input = new MCRURLContent(url);
}
loadFromContent(input);
} catch (IOException e) {
String name = input == null ? filename : input.getSystemId();
throw new MCRConfigurationException("Could not load configuration from: " + name, e);
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRXMLMetadataManager method retrieveContent.
public MCRContent retrieveContent(MCRObjectID mcrid) throws IOException {
MCRContent metadata;
MCRStoredMetadata storedMetadata = retrieveStoredMetadata(mcrid);
if (storedMetadata == null || storedMetadata.isDeleted()) {
return null;
}
metadata = storedMetadata.getMetadata();
return metadata;
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRObjectUtils method restore.
/**
* Restores a MyCoRe Object to the selected revision. Please note that children and derivates
* are not deleted or reverted!
*
* @param mcrId the mycore object identifier
* @param revision The revision to restore to. If this is lower than zero, the last revision is used.
* @return the new {@link MCRObject}
*
* @throws IOException An error occurred while retrieving the revision information. This is most
* likely due an svn error.
* @throws MCRPersistenceException There is no such object with the given id and revision.
* @throws ClassCastException The returning type must be the same as the type of the restored object
*/
public static <T extends MCRBase> T restore(MCRObjectID mcrId, Long revision) throws IOException, MCRPersistenceException {
@SuppressWarnings("unchecked") T mcrBase = (T) (mcrId.getTypeId().equals("derivate") ? new MCRDerivate() : new MCRObject());
// get content
MCRXMLMetadataManager xmlMetadataManager = MCRXMLMetadataManager.instance();
MCRContent content = xmlMetadataManager.retrieveContent(mcrId, revision);
if (content == null) {
throw new MCRPersistenceException("No such object " + mcrId + " with revision " + revision + ".");
}
// store it
try {
mcrBase.setFromJDOM(content.asXML());
if (MCRMetadataManager.exists(mcrId)) {
MCRMetadataManager.update(mcrBase);
} else {
if (mcrBase instanceof MCRObject) {
MCRMetadataManager.create((MCRObject) mcrBase);
} else {
MCRMetadataManager.create((MCRDerivate) mcrBase);
}
}
return mcrBase;
} catch (Exception exc) {
throw new MCRException("Unable to get object " + mcrId + " with revision " + revision + ".", exc);
}
}
use of org.mycore.common.content.MCRContent 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());
}
use of org.mycore.common.content.MCRContent 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());
}
Aggregations