use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRDefaultAltoChangeApplier method applyChange.
@Override
public void applyChange(MCRAltoChangeSet changeSet) {
String derivateID = changeSet.getDerivateID();
changeSet.getWordChanges().stream().forEach(change -> {
List<MCRAltoWordChange> list = fileChangeMap.computeIfAbsent(change.getFile(), (k) -> new ArrayList<>());
list.add(change);
});
fileChangeMap.keySet().forEach(file -> {
LOGGER.info("Open file {} to apply changes!", file);
MCRPath altoFilePath = MCRPath.getPath(derivateID, file);
if (!Files.exists(altoFilePath)) {
LOGGER.warn("Could not find file {} which was referenced by alto change!", altoFilePath);
throw new MCRException(new IOException("Alto-File " + altoFilePath + " does not exist"));
}
Document altoDocument = readALTO(altoFilePath);
List<MCRAltoWordChange> wordChangesInThisFile = fileChangeMap.get(file);
wordChangesInThisFile.stream().forEach(wordChange -> {
String xpath = String.format(Locale.ROOT, "//alto:String[number(@HPOS)=number('%d') and number(@VPOS)=number('%d')]", wordChange.getHpos(), wordChange.getVpos());
List<Element> wordToChange = XPathFactory.instance().compile(xpath, Filters.element(), null, MCRConstants.ALTO_NAMESPACE).evaluate(altoDocument);
if (wordToChange.size() != 1) {
LOGGER.warn("Found {} words to change.", wordToChange.size());
}
wordToChange.forEach(word -> {
word.setAttribute("CONTENT", wordChange.getTo());
word.setAttribute("WC", "1");
});
});
storeALTO(altoFilePath, altoDocument);
});
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRWebPagesSynchronizer method startUp.
/* (non-Javadoc)
* @see org.mycore.common.events.MCRStartupHandler.AutoExecutable#startUp(javax.servlet.ServletContext)
*/
@Override
public void startUp(ServletContext servletContext) {
if (servletContext != null) {
SERVLET_CONTEXT = servletContext;
File wcmsDataDir = null, webappBasePath = null;
try {
// we are running in a servlet container
webappBasePath = getWebAppBaseDir();
LOGGER.info("WebAppBasePath={}", webappBasePath.getAbsolutePath());
wcmsDataDir = getWCMSDataDir();
if (!wcmsDataDir.isDirectory()) {
LOGGER.info("{} does not exist or is not a directory. Skipping synchronization.", wcmsDataDir.getAbsolutePath());
return;
}
synchronize(wcmsDataDir, webappBasePath);
} catch (IOException e) {
throw new MCRException("Error while synchronizing " + wcmsDataDir + " to " + webappBasePath, e);
}
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRXEditorTransformer method transform.
public MCRContent transform(MCRContent editorSource) throws IOException, JDOMException, SAXException {
editorSession.getValidator().clearRules();
editorSession.getSubmission().clear();
MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer("xeditor");
if (transformer instanceof MCRParameterizedTransformer) {
String key = MCRXEditorTransformerStore.storeTransformer(this);
transformationParameters.setParameter("XEditorTransformerKey", key);
MCRContent result = ((MCRParameterizedTransformer) transformer).transform(editorSource, transformationParameters);
if (result instanceof MCRWrappedContent && result.getClass().getName().contains(MCRXSLTransformer.class.getName())) {
// lazy transformation make JUnit tests fail
result = ((MCRWrappedContent) result).getBaseContent();
}
editorSession.getValidator().clearValidationResults();
return result;
} else {
throw new MCRException("Xeditor needs parameterized MCRContentTransformer: " + transformer);
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRXEditorTransformer method setPostProcessor.
public void setPostProcessor(String clazz) {
try {
MCRXEditorPostProcessor instance = ((MCRXEditorPostProcessor) Class.forName(clazz).getDeclaredConstructor().newInstance());
editorSession.setPostProcessor(instance);
} catch (ReflectiveOperationException e) {
throw new MCRException("Could not initialize Post-Processor with class" + clazz, e);
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRLayoutService method getTransformedContent.
public MCRContent getTransformedContent(HttpServletRequest req, HttpServletResponse res, MCRContent source) throws IOException, TransformerException, SAXException {
String docType = source.getDocType();
try {
MCRParameterCollector parameter = new MCRParameterCollector(req);
MCRContentTransformer transformer = getContentTransformer(docType, parameter);
String filename = getFileName(req, parameter);
return transform(transformer, source, parameter, filename);
} catch (IOException | TransformerException | SAXException ex) {
throw ex;
} catch (MCRException ex) {
// generating an error page when there is an error in the stylesheet
if (!"mcr_error".equals(docType)) {
throw ex;
}
String msg = "Error while generating error page!";
LOGGER.warn(msg, ex);
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
return null;
} catch (Exception e) {
throw new MCRException(e);
}
}
Aggregations