Search in sources :

Example 41 with MCRException

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);
    });
}
Also used : MCRAltoWordChange(org.mycore.viewer.alto.model.MCRAltoWordChange) MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element) IOException(java.io.IOException) MCRPath(org.mycore.datamodel.niofs.MCRPath) Document(org.jdom2.Document)

Example 42 with MCRException

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);
        }
    }
}
Also used : MCRException(org.mycore.common.MCRException) IOException(java.io.IOException) File(java.io.File)

Example 43 with MCRException

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);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRParameterizedTransformer(org.mycore.common.content.transformer.MCRParameterizedTransformer) MCRWrappedContent(org.mycore.common.content.MCRWrappedContent) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRContent(org.mycore.common.content.MCRContent)

Example 44 with MCRException

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);
    }
}
Also used : MCRException(org.mycore.common.MCRException)

Example 45 with MCRException

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);
    }
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRException(org.mycore.common.MCRException) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) MCRException(org.mycore.common.MCRException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Aggregations

MCRException (org.mycore.common.MCRException)131 IOException (java.io.IOException)39 Element (org.jdom2.Element)26 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)19 Document (org.jdom2.Document)18 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)18 File (java.io.File)15 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)12 MCRObject (org.mycore.datamodel.metadata.MCRObject)12 ArrayList (java.util.ArrayList)11 JDOMException (org.jdom2.JDOMException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 SAXException (org.xml.sax.SAXException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 List (java.util.List)7 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)7 SAXParseException (org.xml.sax.SAXParseException)7 URI (java.net.URI)6 Path (java.nio.file.Path)6