Search in sources :

Example 16 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRMODSWrapper method removeElements.

public void removeElements(String xPath) {
    Iterator<Element> selected;
    try {
        selected = buildXPath(xPath).evaluate(getMODS()).iterator();
    } catch (JDOMException ex) {
        String msg = "Could not remove elements at " + xPath;
        throw new MCRException(msg, ex);
    }
    while (selected.hasNext()) {
        Element element = selected.next();
        element.detach();
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRMetaElement(org.mycore.datamodel.metadata.MCRMetaElement) Element(org.jdom2.Element) JDOMException(org.jdom2.JDOMException)

Example 17 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRMODSClassificationSupport method getClassCategParentLink.

public static String getClassCategParentLink(final NodeList sources) {
    if (sources.getLength() == 0) {
        LOGGER.warn("Cannot get first element of node list 'sources'.");
        return "";
    }
    final Element source = (Element) sources.item(0);
    MCRCategoryID category = MCRClassMapper.getCategoryID(source);
    if (category == null) {
        return "";
    }
    String id;
    try {
        id = MCRXMLFunctions.encodeURIPath(category.getID());
    } catch (URISyntaxException e) {
        /* This should be impossible! */
        throw new MCRException(e);
    }
    return MessageFormat.format("classification:metadata:0:parents:{0}:{1}", category.getRootID(), id);
}
Also used : MCRException(org.mycore.common.MCRException) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException)

Example 18 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRMODSClassificationSupport method getClassCategLink.

public static String getClassCategLink(final NodeList sources) {
    if (sources.getLength() == 0) {
        LOGGER.warn("Cannot get first element of node list 'sources'.");
        return "";
    }
    final Element source = (Element) sources.item(0);
    MCRCategoryID category = MCRClassMapper.getCategoryID(source);
    if (category == null) {
        return "";
    }
    String id;
    try {
        id = MCRXMLFunctions.encodeURIPath(category.getID());
    } catch (URISyntaxException e) {
        /* This should be impossible! */
        throw new MCRException(e);
    }
    return MessageFormat.format("classification:metadata:0:children:{0}:{1}", category.getRootID(), id);
}
Also used : MCRException(org.mycore.common.MCRException) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException)

Example 19 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRMODSURNPersistentIdentifierMetadataManager method insertIdentifier.

@Override
public void insertIdentifier(MCRUniformResourceName identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
    MCRObject object = checkObject(obj);
    MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
    wrapper.setElement("identifier", "type", "urn", identifier.asString()).orElseThrow(() -> new MCRException("Could not insert urn into mods document!"));
}
Also used : MCRException(org.mycore.common.MCRException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper)

Example 20 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRExternalValidator method invokeMethod.

private Boolean invokeMethod(Method method, Object param) {
    try {
        Object[] params = { param };
        Object result = method.invoke(null, params);
        return (Boolean) result;
    } catch (Exception ex) {
        throw new MCRException(ex);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

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