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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations