Search in sources :

Example 21 with MCRConfigurationException

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

the class MCRPIRegistrationService method getMetadataManager.

public MCRPersistentIdentifierMetadataManager<T> getMetadataManager() {
    Map<String, String> properties = getProperties();
    MCRConfiguration configuration = MCRConfiguration.instance();
    String metadataManager;
    if (properties.containsKey(METADATA_MANAGER_PROPERTY_KEY)) {
        metadataManager = properties.get(METADATA_MANAGER_PROPERTY_KEY);
    } else if (properties.containsKey(METADATA_MANAGER_DEPRECATED_PROPERTY_KEY)) {
        LOGGER.warn(MessageFormat.format("You should use {0}{1}.{2} instead of {3}{4}.{5}", REGISTRATION_CONFIG_PREFIX, getRegistrationServiceID(), METADATA_MANAGER_PROPERTY_KEY, REGISTRATION_CONFIG_PREFIX, getRegistrationServiceID(), METADATA_MANAGER_DEPRECATED_PROPERTY_KEY));
        metadataManager = properties.get(METADATA_MANAGER_DEPRECATED_PROPERTY_KEY);
    } else {
        throw new MCRConfigurationException(getRegistrationServiceID() + " has no MetadataManager(or legacy Inscriber)!");
    }
    String className;
    String metadataManagerPropertyKey;
    metadataManagerPropertyKey = METADATA_MANAGER_CONFIG_PREFIX + metadataManager;
    className = configuration.getString(metadataManagerPropertyKey, null);
    if (className == null) {
        metadataManagerPropertyKey = METADATA_MANAGER_DEPRECATED_CONFIG_PREFIX + metadataManager;
        className = configuration.getString(metadataManagerPropertyKey, null);
        if (className == null) {
            throw new MCRConfigurationException("Missing property: " + METADATA_MANAGER_CONFIG_PREFIX + metadataManager + " or " + metadataManagerPropertyKey);
        }
        LOGGER.warn("You should use {} instead of {}", METADATA_MANAGER_CONFIG_PREFIX + metadataManager, METADATA_MANAGER_DEPRECATED_PROPERTY_KEY + metadataManager);
    }
    className = repairDeprecatedClassNames(className, metadataManagerPropertyKey);
    try {
        @SuppressWarnings("unchecked") Class<MCRPersistentIdentifierMetadataManager<T>> classObject = (Class<MCRPersistentIdentifierMetadataManager<T>>) Class.forName(className);
        Constructor<MCRPersistentIdentifierMetadataManager<T>> constructor = classObject.getConstructor(String.class);
        return constructor.newInstance(metadataManager);
    } catch (ClassNotFoundException e) {
        throw new MCRConfigurationException("Configurated class (" + metadataManagerPropertyKey + ") not found: " + className, e);
    } catch (NoSuchMethodException e) {
        throw new MCRConfigurationException("Configurated class (" + metadataManagerPropertyKey + ") needs a string constructor: " + className);
    } 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) MCRConfiguration(org.mycore.common.config.MCRConfiguration)

Example 22 with MCRConfigurationException

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

the class MCRRSSFeedImporter method getPattern2FindID.

private void getPattern2FindID(String prefix) {
    String patternProperty = prefix + "Pattern2FindID";
    try {
        String pattern = MCRConfiguration.instance().getString(patternProperty);
        pattern2findID = Pattern.compile(pattern);
    } catch (PatternSyntaxException ex) {
        String msg = "Regular expression syntax error: " + patternProperty;
        throw new MCRConfigurationException(msg, ex);
    }
}
Also used : MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 23 with MCRConfigurationException

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

the class MCROAIQueryToSetHandler method getSetFilterQuery.

private String getSetFilterQuery(String setId) {
    MCRConfiguration config = MCRConfiguration.instance();
    String queryProperty = getConfigPrefix() + "Sets." + setId + ".Query";
    String configQuery;
    try {
        configQuery = config.getString(queryProperty);
    } catch (MCRConfigurationException e) {
        String deprecatedProperty = getConfigPrefix() + "MapSetToQuery." + setId;
        configQuery = config.getString(deprecatedProperty, null);
        if (configQuery == null) {
            throw e;
        }
        LogManager.getLogger().warn("Property '{}' is deprecated and support will be removed. Please rename to '{}' soon!", deprecatedProperty, queryProperty);
    }
    return configQuery;
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 24 with MCRConfigurationException

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

the class MCRUtils method parseDocumentType.

public static 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("MCRLayoutService 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);
        }
    }
    String docType = detected.getProperty("docType");
    int pos = docType.indexOf(':') + 1;
    if (pos > 0) {
        // filter namespace prefix
        docType = docType.substring(pos);
    }
    return docType;
}
Also used : 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) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Example 25 with MCRConfigurationException

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

the class MCRTransformerPipe method init.

@Override
public void init(String id) {
    String steps = MCRConfiguration.instance().getString("MCR.ContentTransformer." + id + ".Steps");
    StringTokenizer tokens = new StringTokenizer(steps, " ;,");
    while (tokens.hasMoreTokens()) {
        String transformerID = tokens.nextToken();
        MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer(transformerID);
        if (transformer == null) {
            throw new MCRConfigurationException("Transformer pipe element '" + transformerID + "' is not configured.");
        }
        transformers.add(transformer);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) 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