use of org.mycore.common.MCRException 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");
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRCStoreVFS method init.
@Override
public void init(String storeId) {
super.init(storeId);
uri = MCRConfiguration.instance().getString(storeConfigPrefix + "URI");
String check = MCRConfiguration.instance().getString(storeConfigPrefix + "StrictHostKeyChecking", "no");
try {
fsManager = VFS.getManager();
opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, check);
FileObject baseDir = getBase();
// Create a folder, if it does not exist or throw an
// exception, if baseDir is not a folder
baseDir.createFolder();
if (!baseDir.isWriteable()) {
String msg = "Content store base directory is not writeable: " + uri;
throw new MCRConfigurationException(msg);
}
} catch (FileSystemException ex) {
throw new MCRException(ex.getCode(), ex);
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRContentStoreFactory method buildExtender.
/**
* If the MCRContentStore of the MCRFile given provides an
* MCRAudioVideoExtender implementation, this method creates and initializes
* the MCRAudioVideoExtender instance for the MCRFile. The instance that is
* returned is configured by the property
* <tt>MCR.IFS.AVExtender.<StoreID>.Class</tt> in mycore.properties.
*
* @param file
* the non-null MCRFile that should get an MCRAudioVideoExtender
* @return the MCRAudioVideoExtender for the MCRFile given, or null
* @throws MCRConfigurationException
* if the MCRAudioVideoExtender implementation class could not
* be loaded
*/
static MCRAudioVideoExtender buildExtender(MCRFile file) {
if (file == null || !providesAudioVideoExtender(file.getStoreID())) {
return null;
}
Class<? extends MCRAudioVideoExtender> cl = getExtenderClass(file.getStoreID());
try {
MCRAudioVideoExtender ext = cl.getDeclaredConstructor().newInstance();
ext.init(file);
return ext;
} catch (Exception exc) {
if (exc instanceof MCRException) {
throw (MCRException) exc;
}
String msg = "Could not build MCRAudioVideoExtender instance";
throw new MCRConfigurationException(msg, exc);
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRURNOAIRegistrationService method isRegistered.
@Override
public boolean isRegistered(MCRObjectID id, String additional) {
boolean registered = super.isRegistered(id, additional);
if (registered)
return true;
if (!isCreated(id, additional)) {
return false;
}
// URN is created. Now we need to check if it is resolvable
MCRPI mcrpi = getTableEntry(id, additional);
MCRDNBURN dnburn = new MCRDNBURNParser().parse(mcrpi.getIdentifier()).orElseThrow(() -> new MCRException("Cannot parse Identifier from table: " + mcrpi.getIdentifier()));
try {
// Find register date in dnb rest
Date dnbRegisteredDate = MCRURNUtils.getDNBRegisterDate(dnburn);
if (dnbRegisteredDate == null) {
return false;
}
mcrpi.setRegistered(dnbRegisteredDate);
updateFlag(id, additional, mcrpi);
return true;
} catch (ParseException e) {
LOGGER.error("Could not parse Date from PIDEF ! URN wont be marked as registered because of this! ", e);
return false;
} catch (MCRIdentifierUnresolvableException e) {
return false;
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRPIRegistrationService method getGenerator.
private MCRPersistentIdentifierGenerator<T> getGenerator() {
Supplier<? extends RuntimeException> generatorPropertiesNotSetError = () -> new MCRConfigurationException("Configuration property " + REGISTRATION_CONFIG_PREFIX + registrationServiceID + ".Generator is not set");
String generatorName = Optional.ofNullable(getProperties().get("Generator")).orElseThrow(generatorPropertiesNotSetError);
String inscriberPropertyKey = GENERATOR_CONFIG_PREFIX + generatorName;
String className = MCRConfiguration.instance().getString(inscriberPropertyKey);
try {
@SuppressWarnings("unchecked") Class<MCRPersistentIdentifierGenerator<T>> classObject = (Class<MCRPersistentIdentifierGenerator<T>>) Class.forName(className);
Constructor<MCRPersistentIdentifierGenerator<T>> constructor = classObject.getConstructor(String.class);
return constructor.newInstance(generatorName);
} catch (ClassNotFoundException e) {
throw new MCRConfigurationException("Configurated class (" + inscriberPropertyKey + ") not found: " + className, e);
} catch (NoSuchMethodException e) {
throw new MCRConfigurationException("Configurated class (" + inscriberPropertyKey + ") needs a string constructor: " + className);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new MCRException(e);
}
}
Aggregations