use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRSolrIndexHandlerFactory method getIndexHandler.
public MCRSolrIndexHandler getIndexHandler(MCRObjectID... ids) throws IOException {
if (ids.length == 1) {
MCRContent content = MCRXMLMetadataManager.instance().retrieveContent(ids[0]);
return getIndexHandler(content, ids[0]);
}
HashMap<MCRObjectID, MCRContent> contentMap = new HashMap<>();
for (MCRObjectID id : ids) {
MCRContent content = MCRXMLMetadataManager.instance().retrieveContent(id);
contentMap.put(id, content);
}
return getIndexHandler(contentMap);
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRSolrIndexHandlerFactory method getIndexHandler.
public MCRSolrIndexHandler getIndexHandler(MCRBase... derOrObjs) {
if (derOrObjs.length == 1) {
MCRBaseContent content = new MCRBaseContent(derOrObjs[0]);
return getIndexHandler(content, derOrObjs[0].getId());
}
HashMap<MCRObjectID, MCRContent> contentMap = new HashMap<>();
for (MCRBase derOrObj : derOrObjs) {
MCRBaseContent content = new MCRBaseContent(derOrObj);
contentMap.put(derOrObj.getId(), content);
}
return getIndexHandler(contentMap);
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRSolrTransformerInputDocumentFactory method getMergedDocument.
private Document getMergedDocument(Map<MCRObjectID, MCRContent> contentMap) throws IOException, SAXException, JDOMException {
Element rootElement = new Element("add");
Document doc = new Document(rootElement);
for (Map.Entry<MCRObjectID, MCRContent> entry : contentMap.entrySet()) {
rootElement.addContent(entry.getValue().asXML().detachRootElement());
}
return doc;
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRXEditorTransformerTest method testTransformation.
private void testTransformation(String inputFile, String editedXMLFile, MCREditorSession session, String expectedOutputFile) throws TransformerException, IOException, JDOMException, SAXException, JaxenException {
MCRParameterCollector pc = new MCRParameterCollector(false);
if (editedXMLFile != null) {
pc.setParameter("input", editedXMLFile);
}
MCRContent input = MCRSourceContent.getInstance("resource:" + inputFile);
MCRContent transformed = new MCRXEditorTransformer(session, pc).transform(input);
Document expected = MCRSourceContent.getInstance("resource:" + expectedOutputFile).asXML();
MCRBinding binding = new MCRBinding("//input[@type='hidden'][@name='_xed_session']/@value", true, new MCRBinding(expected));
binding.setValue(session.getID() + "-" + session.getChangeTracker().getChangeCounter());
String msg = "Transformed output is different to " + expectedOutputFile;
boolean isEqual = MCRXMLHelper.deepEqual(expected, transformed.asXML());
if (!isEqual)
System.out.println(transformed.asString());
assertTrue(msg, isEqual);
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRAclEditorResource method transform.
protected InputStream transform(String xmlFile) throws Exception {
InputStream guiXML = getClass().getResourceAsStream(xmlFile);
if (guiXML == null) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).build());
}
SAXBuilder saxBuilder = new SAXBuilder();
Document webPage = saxBuilder.build(guiXML);
XPathExpression<Object> xpath = XPathFactory.instance().compile("/MyCoReWebPage/section/div[@id='mycore-acl-editor2']");
Object node = xpath.evaluateFirst(webPage);
MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
String lang = mcrSession.getCurrentLanguage();
if (node != null) {
Element mainDiv = (Element) node;
mainDiv.setAttribute("lang", lang);
String bsPath = CONFIG.getString("MCR.bootstrap.path", "");
if (!bsPath.equals("")) {
bsPath = MCRFrontendUtil.getBaseURL() + bsPath;
Element item = new Element("link").setAttribute("href", bsPath).setAttribute("rel", "stylesheet").setAttribute("type", "text/css");
mainDiv.addContent(0, item);
}
}
MCRContent content = MCRJerseyUtil.transform(webPage, request);
return content.getInputStream();
}
Aggregations