Search in sources :

Example 91 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project pwm by pwm-project.

the class StoredConfigurationImpl method fromXml.

public static StoredConfigurationImpl fromXml(final InputStream xmlData) throws PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    // validateXmlSchema(xmlData);
    final Document inputDocument = XmlUtil.parseXml(xmlData);
    final StoredConfigurationImpl newConfiguration = StoredConfigurationImpl.newStoredConfiguration();
    try {
        newConfiguration.document = inputDocument;
        // verify create time;
        newConfiguration.createTime();
        ConfigurationCleaner.cleanup(newConfiguration);
    } catch (Exception e) {
        final String errorMsg = "error reading configuration file format, error=" + e.getMessage();
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { errorMsg });
        throw new PwmUnrecoverableException(errorInfo);
    }
    checkIfXmlRequiresUpdate(newConfiguration);
    LOGGER.debug("successfully loaded configuration (" + TimeDuration.compactFromCurrent(startTime) + ")");
    return newConfiguration;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Instant(java.time.Instant) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Document(org.jdom2.Document) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 92 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project pwm by pwm-project.

the class XmlUtil method parseXml.

public static Document parseXml(final Reader inputStream) throws PwmUnrecoverableException {
    final SAXBuilder builder = getBuilder();
    final Document inputDocument;
    try {
        inputDocument = builder.build(inputStream);
    } catch (Exception e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "error parsing xml data: " + e.getMessage() }));
    }
    return inputDocument;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) SAXBuilder(org.jdom2.input.SAXBuilder) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Document(org.jdom2.Document) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 93 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project pwm by pwm-project.

the class PwmSettingXml method readXml.

private static Document readXml() {
    final Document docRefCopy = xmlDocCache;
    if (docRefCopy == null) {
        // validateXmlSchema();
        final InputStream inputStream = PwmSetting.class.getClassLoader().getResourceAsStream(SETTING_XML_FILENAME);
        final SAXBuilder builder = new SAXBuilder();
        try {
            final Document newDoc = builder.build(inputStream);
            xmlDocCache = newDoc;
            // clear cached dom after 30 seconds.
            final Thread t = new Thread("PwmSettingXml static cache clear thread") {

                @Override
                public void run() {
                    JavaHelper.pause(30 * 1000);
                    xmlDocCache = null;
                }
            };
            t.setDaemon(true);
            t.start();
            return newDoc;
        } catch (JDOMException e) {
            throw new IllegalStateException("error parsing " + SETTING_XML_FILENAME + ": " + e.getMessage());
        } catch (IOException e) {
            throw new IllegalStateException("unable to load " + SETTING_XML_FILENAME + ": " + e.getMessage());
        }
    }
    return docRefCopy;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 94 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.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 95 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.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)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18