Search in sources :

Example 26 with MCRConfigurationException

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

the class MCRXSL2JAXBTransformer method init.

@Override
public void init(String id) {
    super.init(id);
    String property = "MCR.ContentTransformer." + id + ".Context";
    String contextPath = MCRConfiguration.instance().getString(property);
    try {
        JAXBContext context = JAXBContext.newInstance(contextPath, getClass().getClassLoader());
        setContext(context);
    } catch (JAXBException e) {
        throw new MCRConfigurationException("Error while creating JAXBContext.", e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 27 with MCRConfigurationException

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

the class MCRIIIFImageImpl method getInstance.

public static synchronized MCRIIIFImageImpl getInstance(String implName) {
    if (implHolder.containsKey(implName)) {
        return implHolder.get(implName);
    }
    String classPropertyName = MCR_IIIF_IMAGE_CONFIG_PREFIX + implName;
    Class<? extends MCRIIIFImageImpl> classObject = MCRConfiguration.instance().getClass(classPropertyName);
    try {
        Constructor<? extends MCRIIIFImageImpl> constructor = classObject.getConstructor(String.class);
        MCRIIIFImageImpl imageImpl = constructor.newInstance(implName);
        implHolder.put(implName, imageImpl);
        return imageImpl;
    } catch (NoSuchMethodException e) {
        throw new MCRConfigurationException("Configurated class (" + classObject.getName() + ") needs a string constructor: " + classPropertyName);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new MCRException(e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 28 with MCRConfigurationException

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

the class MCRIIIFPresentationImpl method getInstance.

public static synchronized MCRIIIFPresentationImpl getInstance(String implName) {
    if (implHolder.containsKey(implName)) {
        return implHolder.get(implName);
    }
    String classPropertyName = MCR_IIIF_PRESENTATION_CONFIG_PREFIX + implName;
    Class<? extends MCRIIIFPresentationImpl> classObject = MCRConfiguration.instance().getClass(classPropertyName);
    try {
        Constructor<? extends MCRIIIFPresentationImpl> constructor = classObject.getConstructor(String.class);
        MCRIIIFPresentationImpl presentationImpl = constructor.newInstance(implName);
        implHolder.put(implName, presentationImpl);
        return presentationImpl;
    } catch (NoSuchMethodException e) {
        throw new MCRConfigurationException("Configurated class (" + classObject.getName() + ") needs a string constructor: " + classPropertyName);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new MCRException(e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 29 with MCRConfigurationException

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

the class MCRVersioningMetadataStore method setupSVN.

private void setupSVN(String type) {
    URI repositoryURI;
    String repositoryURIString = MCRConfiguration.instance().getString("MCR.IFS2.Store." + type + ".SVNRepositoryURL");
    try {
        repositoryURI = new URI(repositoryURIString);
    } catch (URISyntaxException e) {
        String msg = "Syntax error in MCR.IFS2.Store." + type + ".SVNRepositoryURL property: " + repositoryURIString;
        throw new MCRConfigurationException(msg, e);
    }
    try {
        LOGGER.info("Versioning metadata store {} repository URL: {}", type, repositoryURI);
        repURL = SVNURL.create(repositoryURI.getScheme(), repositoryURI.getUserInfo(), repositoryURI.getHost(), repositoryURI.getPort(), repositoryURI.getPath(), true);
        LOGGER.info("repURL: {}", repURL);
        File dir = new File(repURL.getPath());
        if (!dir.exists() || (dir.isDirectory() && dir.list().length == 0)) {
            LOGGER.info("Repository does not exist, creating new SVN repository at {}", repositoryURI);
            repURL = SVNRepositoryFactory.createLocalRepository(dir, true, false);
        }
    } catch (SVNException ex) {
        String msg = "Error initializing SVN repository at URL " + repositoryURI;
        throw new MCRConfigurationException(msg, ex);
    }
}
Also used : MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) URISyntaxException(java.net.URISyntaxException) SVNException(org.tmatesoft.svn.core.SVNException) URI(java.net.URI) File(java.io.File)

Example 30 with MCRConfigurationException

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

the class MCRStore method init.

protected void init(final MCRStoreConfig config) {
    setStoreConfig(config);
    idLength = 0;
    final StringTokenizer st = new StringTokenizer(getStoreConfig().getSlotLayout(), "-");
    slotLength = new int[st.countTokens() - 1];
    int i = 0;
    while (st.countTokens() > 1) {
        slotLength[i] = Integer.parseInt(st.nextToken());
        idLength += slotLength[i++];
    }
    idLength += Integer.parseInt(st.nextToken());
    try {
        baseDirectory = VFS.getManager().resolveFile(getStoreConfig().getBaseDir());
        if (!baseDirectory.exists()) {
            baseDirectory.createFolder();
        } else {
            if (!baseDirectory.isReadable()) {
                final String msg = "Store directory " + getStoreConfig().getBaseDir() + " is not readable";
                throw new MCRConfigurationException(msg);
            }
            if (baseDirectory.getType() != FileType.FOLDER) {
                final String msg = "Store " + getStoreConfig().getBaseDir() + " is a file, not a directory";
                throw new MCRConfigurationException(msg);
            }
        }
    } catch (final FileSystemException e) {
        e.printStackTrace();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) FileSystemException(org.apache.commons.vfs2.FileSystemException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

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