use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRDFGLinkServlet method getMetsSource.
/**
* Returns the mets document wrapped in a {@link MCRContent} object.
*
* @param job
* @param useExistingMets
* @return
* @throws Exception
*/
private static MCRContent getMetsSource(MCRServletJob job, boolean useExistingMets, String derivate) throws Exception {
MCRPath metsFile = MCRPath.getPath(derivate, "/mets.xml");
try {
job.getRequest().setAttribute("XSL.derivateID", derivate);
job.getRequest().setAttribute("XSL.objectID", MCRLinkTableManager.instance().getSourceOf(derivate).iterator().next());
} catch (Exception x) {
LOGGER.warn("Unable to set \"XSL.objectID\" attribute to current request", x);
}
boolean metsExists = Files.exists(metsFile);
if (metsExists && useExistingMets) {
MCRContent content = new MCRPathContent(metsFile);
content.setDocType("mets");
return content;
} else {
Document mets = MCRMETSGeneratorFactory.create(metsFile.getParent()).generate().asDocument();
return new MCRJDOMContent(mets);
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRMETSServlet method getMetsSource.
/**
* Returns the mets document wrapped in a {@link MCRContent} object.
*/
static MCRContent getMetsSource(MCRServletJob job, boolean useExistingMets, String derivate) throws Exception {
MCRPath metsPath = MCRPath.getPath(derivate, "/mets.xml");
try {
job.getRequest().setAttribute("XSL.derivateID", derivate);
String objectid = MCRLinkTableManager.instance().getSourceOf(derivate).iterator().next();
if (objectid == null || objectid.length() == 0) {
MCRDerivate derObj = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivate));
MCRObjectID ownerID = derObj.getOwnerID();
objectid = ownerID.toString();
}
job.getRequest().setAttribute("XSL.objectID", objectid);
} catch (Exception x) {
LOGGER.warn("Unable to set \"XSL.objectID\" attribute to current request", x);
}
boolean metsExists = Files.exists(metsPath);
if (metsExists && useExistingMets) {
MCRContent content = new MCRPathContent(metsPath);
content.setDocType("mets");
return content;
} else {
Document mets = MCRMETSGeneratorFactory.create(MCRPath.getPath(derivate, "/")).generate().asDocument();
if (!metsExists && STORE_METS_ON_GENERATE) {
MCRMetsSave.saveMets(mets, MCRObjectID.getInstance(derivate));
}
return new MCRJDOMContent(mets);
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRXMLMetadataEventHandler method handleStoreEvent.
private void handleStoreEvent(MCREvent evt, MCRBase obj) {
String eventType = evt.getEventType();
MCRObjectID id = obj.getId();
try {
switch(eventType) {
case MCREvent.REPAIR_EVENT:
case MCREvent.UPDATE_EVENT:
case MCREvent.CREATE_EVENT:
MCRBaseContent content = new MCRBaseContent(obj);
Date modified = obj.getService().getDate(MCRObjectService.DATE_TYPE_MODIFYDATE);
switch(eventType) {
case MCREvent.REPAIR_EVENT:
MCRContent retrieveContent = metaDataManager.retrieveContent(id);
if (isUptodate(retrieveContent, content)) {
return;
}
case MCREvent.UPDATE_EVENT:
metaDataManager.update(id, content, modified);
break;
case MCREvent.CREATE_EVENT:
metaDataManager.create(id, content, modified);
break;
}
evt.put("content", content);
break;
case MCREvent.DELETE_EVENT:
metaDataManager.delete(id);
break;
default:
throw new IllegalArgumentException("Invalid event type " + eventType + " for object " + id);
}
} catch (IOException e) {
throw new MCRPersistenceException("Error while handling '" + eventType + "' event of '" + id + "'", e);
}
}
Aggregations