Search in sources :

Example 1 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManager method reload.

/**
 * Reads configuration properties, checks and creates base directories and builds the singleton
 */
public synchronized void reload() {
    MCRConfiguration config = MCRConfiguration.instance();
    String pattern = config.getString("MCR.Metadata.ObjectID.NumberPattern", "0000000000");
    defaultLayout = pattern.length() - 4 + "-2-2";
    String base = config.getString("MCR.Metadata.Store.BaseDir");
    baseDir = new File(base);
    checkDir(baseDir, "base");
    defaultClass = config.getClass("MCR.Metadata.Store.DefaultClass", MCRVersioningMetadataStore.class);
    if (MCRVersioningMetadataStore.class.isAssignableFrom(defaultClass)) {
        try {
            String svnBaseValue = config.getString("MCR.Metadata.Store.SVNBase");
            if (!svnBaseValue.endsWith("/")) {
                svnBaseValue += '/';
            }
            svnBase = new URI(svnBaseValue);
            LOGGER.info("SVN Base: {}", svnBase);
            if (svnBase.getScheme() == null) {
                String workingDirectory = (new File(".")).getAbsolutePath();
                URI root = new File(MCRConfiguration.instance().getString("MCR.datadir", workingDirectory)).toURI();
                URI resolved = root.resolve(svnBase);
                LOGGER.warn("Resolved {} to {}", svnBase, resolved);
                svnBase = resolved;
            }
        } catch (URISyntaxException ex) {
            String msg = "Syntax error in MCR.Metadata.Store.SVNBase property: " + svnBase;
            throw new MCRConfigurationException(msg, ex);
        }
        if (svnBase.getScheme().equals("file")) {
            svnDir = new File(svnBase);
            checkDir(svnDir, "svn");
        }
    }
    closeCreatedStores();
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI)

Example 2 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRExternalValidator method findMethod.

private Method findMethod(Class<?> argType) {
    try {
        Class<?> clazz = ClassUtils.getClass(className);
        Class<?>[] argTypes = { argType };
        return MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argTypes);
    } catch (ClassNotFoundException ex) {
        throw new MCRConfigurationException("class configured for external validation not found: " + className);
    }
}
Also used : MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 3 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRUploadServletDeployer method startUp.

/* (non-Javadoc)
     * @see org.mycore.common.events.MCRStartupHandler.AutoExecutable#startUp(javax.servlet.ServletContext)
     */
@Override
public void startUp(ServletContext servletContext) {
    if (servletContext != null) {
        String servletName = "MCRUploadViaFormServlet";
        MultipartConfigElement multipartConfig = getMultipartConfig();
        try {
            checkTempStoragePath(multipartConfig.getLocation());
        } catch (IOException e) {
            throw new MCRConfigurationException("Could not setup " + servletName + "!", e);
        }
        Dynamic uploadServlet = servletContext.addServlet(servletName, MCRUploadViaFormServlet.class);
        uploadServlet.addMapping("/servlets/MCRUploadViaFormServlet");
        uploadServlet.setMultipartConfig(multipartConfig);
    }
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) Dynamic(javax.servlet.ServletRegistration.Dynamic) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) IOException(java.io.IOException)

Example 4 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRUploadServletDeployer method checkTempStoragePath.

private void checkTempStoragePath(String location) throws IOException {
    Path targetDir = Paths.get(location);
    if (!targetDir.isAbsolute()) {
        throw new MCRConfigurationException("'" + MCR_FILE_UPLOAD_TEMP_STORAGE_PATH + "=" + location + "' must be an absolute path!");
    }
    if (Files.notExists(targetDir)) {
        LogManager.getLogger().info("Creating directory: {}", targetDir);
        Files.createDirectories(targetDir);
    }
    if (!Files.isDirectory(targetDir)) {
        throw new NotDirectoryException(targetDir.toString());
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 5 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRSimpleFCTDetector method parseDocumentType.

/**
 * Copy from MCRLayoutServlet, messages changed from MCRLayoutServlet to
 * MCRSimpleFCTDetector Try to detect doctype of xml data
 *
 * @param in
 *            xml data
 *
 * @return detected doctype
 */
protected String parseDocumentType(InputStream in) {
    SAXParser parser = null;
    try {
        parser = SAXParserFactory.newInstance().newSAXParser();
    } catch (Exception ex) {
        String msg = "Could not build a SAX Parser for processing XML input";
        throw new MCRConfigurationException(msg, ex);
    }
    final Properties detected = new Properties();
    final String forcedInterrupt = "mcr.forced.interrupt";
    DefaultHandler handler = new DefaultHandler() {

        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes) {
            logger.debug("MCRSimpleFCTDetector detected root element = {}", qName);
            detected.setProperty("docType", qName);
            throw new MCRException(forcedInterrupt);
        }
    };
    try {
        parser.parse(new InputSource(in), handler);
    } catch (Exception ex) {
        if (!forcedInterrupt.equals(ex.getMessage())) {
            String msg = "Error while detecting XML document type from input source";
            throw new MCRException(msg, ex);
        }
    }
    return detected.getProperty("docType");
}
Also used : MCRException(org.mycore.common.MCRException) InputSource(org.xml.sax.InputSource) Attributes(org.xml.sax.Attributes) SAXParser(javax.xml.parsers.SAXParser) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) Properties(java.util.Properties) MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Aggregations

MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)30 MCRException (org.mycore.common.MCRException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 IOException (java.io.IOException)5 MCRConfiguration (org.mycore.common.config.MCRConfiguration)5 Properties (java.util.Properties)3 File (java.io.File)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Arrays (java.util.Arrays)2 StringTokenizer (java.util.StringTokenizer)2 SAXParser (javax.xml.parsers.SAXParser)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ByteBuffer (java.nio.ByteBuffer)1 NotDirectoryException (java.nio.file.NotDirectoryException)1