Search in sources :

Example 96 with Document

use of com.google.cloud.language.v1.Document in project mycore by MyCoRe-Org.

the class MCRFileNodeServlet method sendDirectory.

/**
 * Sends the contents of an MCRDirectory as XML data to the client
 * @throws SAXException
 * @throws TransformerException
 */
private MCRContent sendDirectory(HttpServletRequest request, HttpServletResponse response, MCRPath mcrPath) throws IOException, TransformerException, SAXException {
    Document directoryXML = MCRPathXML.getDirectoryXML(mcrPath);
    MCRJDOMContent source = new MCRJDOMContent(directoryXML);
    source.setLastModified(Files.getLastModifiedTime(mcrPath).toMillis());
    String fileName = mcrPath.getNameCount() == 0 ? mcrPath.getOwner() : mcrPath.getFileName().toString();
    source.setName(fileName);
    return getLayoutService().getTransformedContent(request, response, source);
}
Also used : MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document)

Example 97 with Document

use of com.google.cloud.language.v1.Document in project mycore by MyCoRe-Org.

the class MCREditorOutValidator method setDefaultObjectACLs.

/**
 * The method add a default ACL-block.
 *
 * @param service
 * @throws IOException
 * @throws JDOMException
 */
private void setDefaultObjectACLs(org.jdom2.Element service) throws JDOMException, IOException {
    if (!MCRConfiguration.instance().getBoolean("MCR.Access.AddObjectDefaultRule", true)) {
        LOGGER.info("Adding object default acl rule is disabled.");
        return;
    }
    String resourcetype = "/editor_default_acls_" + id.getTypeId() + ".xml";
    String resourcebase = "/editor_default_acls_" + id.getBase() + ".xml";
    // Read stylesheet and add user
    InputStream aclxml = MCREditorOutValidator.class.getResourceAsStream(resourcebase);
    if (aclxml == null) {
        aclxml = MCREditorOutValidator.class.getResourceAsStream(resourcetype);
        if (aclxml == null) {
            LOGGER.warn("Can't find default object ACL file {} or {}", resourcebase.substring(1), resourcetype.substring(1));
            // fallback
            String resource = "/editor_default_acls.xml";
            aclxml = MCREditorOutValidator.class.getResourceAsStream(resource);
            if (aclxml == null) {
                return;
            }
        }
    }
    Document xml = SAX_BUILDER.build(aclxml);
    Element acls = xml.getRootElement().getChild("servacls");
    if (acls == null) {
        return;
    }
    for (Element acl : acls.getChildren()) {
        Element condition = acl.getChild("condition");
        if (condition == null) {
            continue;
        }
        Element rootbool = condition.getChild("boolean");
        if (rootbool == null) {
            continue;
        }
        for (Element orbool : rootbool.getChildren("boolean")) {
            for (Element firstcond : orbool.getChildren("condition")) {
                if (firstcond == null) {
                    continue;
                }
                String value = firstcond.getAttributeValue("value");
                if (value == null) {
                    continue;
                }
                if (value.equals("$CurrentUser")) {
                    String thisuser = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID();
                    firstcond.setAttribute("value", thisuser);
                    continue;
                }
                if (value.equals("$CurrentGroup")) {
                    throw new MCRException("The parameter $CurrentGroup in default ACLs is no more supported since MyCoRe 2014.06 because it is not supported in Servlet API 3.0");
                }
                int i = value.indexOf("$CurrentIP");
                if (i != -1) {
                    String thisip = MCRSessionMgr.getCurrentSession().getCurrentIP();
                    firstcond.setAttribute("value", value.substring(0, i) + thisip + value.substring(i + 10, value.length()));
                }
            }
        }
    }
    service.addContent(acls.detach());
}
Also used : MCRException(org.mycore.common.MCRException) InputStream(java.io.InputStream) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 98 with Document

use of com.google.cloud.language.v1.Document in project mycore by MyCoRe-Org.

the class MCRBase method createXML.

/**
 * This method create a XML stream for all object data.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Document with the XML data of the object as byte array
 */
public Document createXML() throws MCRException {
    validate();
    Element elm = new Element(getRootTagName());
    Document doc = new Document(elm);
    elm.addNamespaceDeclaration(XSI_NAMESPACE);
    elm.addNamespaceDeclaration(XLINK_NAMESPACE);
    elm.setAttribute("noNamespaceSchemaLocation", mcr_schema, XSI_NAMESPACE);
    elm.setAttribute("ID", mcr_id.toString());
    if (mcr_label != null) {
        elm.setAttribute("label", mcr_label);
    }
    elm.setAttribute("version", mcr_version);
    return doc;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 99 with Document

use of com.google.cloud.language.v1.Document in project mycore by MyCoRe-Org.

the class MCRDerivate method createXML.

/**
 * This methode create a XML stream for all object data.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Document with the XML data of the object as byte array
 */
@Override
public final org.jdom2.Document createXML() throws MCRException {
    Document doc = super.createXML();
    Element elm = doc.getRootElement();
    elm.addContent(mcr_derivate.createXML());
    elm.addContent(mcr_service.createXML());
    return doc;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 100 with Document

use of com.google.cloud.language.v1.Document in project mycore by MyCoRe-Org.

the class MCRStoreBrowserRequest method buildResponseXML.

/**
 * Builds the xml output to be rendered as response
 */
Document buildResponseXML() throws Exception {
    File dir = getRequestedDirectory();
    String[] children = dir.list();
    Element xml = new Element("storeBrowser");
    if (children != null)
        for (String child : children) {
            xml.addContent(buildXML(child));
        }
    return new Document(xml);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File)

Aggregations

Document (org.jdom2.Document)402 Element (org.jdom2.Element)249 Test (org.junit.Test)108 SAXBuilder (org.jdom2.input.SAXBuilder)94 IOException (java.io.IOException)73 File (java.io.File)57 XMLOutputter (org.jdom2.output.XMLOutputter)55 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 ArrayList (java.util.ArrayList)24 DocType (org.jdom2.DocType)24 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 Document (com.google.cloud.language.v1.Document)21 MCRException (org.mycore.common.MCRException)21 HashMap (java.util.HashMap)20 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 InputStream (java.io.InputStream)18