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