Search in sources :

Example 11 with MCRContent

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);
}
Also used : HashMap(java.util.HashMap) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRContent(org.mycore.common.content.MCRContent)

Example 12 with MCRContent

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);
}
Also used : HashMap(java.util.HashMap) MCRBaseContent(org.mycore.common.content.MCRBaseContent) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRContent(org.mycore.common.content.MCRContent)

Example 13 with MCRContent

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;
}
Also used : Element(org.jdom2.Element) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Map(java.util.Map) MCRContent(org.mycore.common.content.MCRContent)

Example 14 with MCRContent

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);
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Example 15 with MCRContent

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();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) MCRSession(org.mycore.common.MCRSession) WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) Element(org.jdom2.Element) JsonObject(com.google.gson.JsonObject) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Aggregations

MCRContent (org.mycore.common.content.MCRContent)63 Document (org.jdom2.Document)21 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)20 IOException (java.io.IOException)16 Element (org.jdom2.Element)13 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 Test (org.junit.Test)8 MCRPathContent (org.mycore.common.content.MCRPathContent)7 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JDOMException (org.jdom2.JDOMException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 MCRException (org.mycore.common.MCRException)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 URL (java.net.URL)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3