Search in sources :

Example 71 with MCRException

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

the class MCRDateConverter method string2date.

/**
 * @param input the text string
 * @return the parsed Date matching one of the allowed date patterns, or null if the text can not be parsed
 */
public Date string2date(String input) throws MCRException {
    for (SimpleDateFormat format : formats) {
        if (format.format(CHECK_DATE).length() != input.length()) {
            continue;
        }
        try {
            ParsePosition pp = new ParsePosition(0);
            Date value = format.parse(input, pp);
            if (pp.getIndex() == input.length()) {
                return value;
            }
        } catch (Exception ignored) {
        }
    }
    return null;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) MCRException(org.mycore.common.MCRException) ParsePosition(java.text.ParsePosition)

Example 72 with MCRException

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

the class MCRMetaLinkID method setFromDOM.

/**
 * This method read the XML input stream part from a DOM part for the
 * metadata of the document.
 *
 * @param element
 *            a relevant DOM element for the metadata
 * @exception MCRException
 *                if the xlink:type is not locator or arc or if href or from
 *                and to are not a MCRObjectID
 */
@Override
public final void setFromDOM(org.jdom2.Element element) {
    super.setFromDOM(element);
    if (linktype.equals("locator")) {
        try {
            MCRObjectID hrefid = MCRObjectID.getInstance(href);
            href = hrefid.toString();
        } catch (Exception e) {
            throw new MCRException("The xlink:href is not a MCRObjectID.");
        }
    } else {
        try {
            MCRObjectID fromid = MCRObjectID.getInstance(from);
            from = fromid.toString();
        } catch (Exception e) {
            throw new MCRException("The xlink:from is not a MCRObjectID.");
        }
        try {
            MCRObjectID toid = MCRObjectID.getInstance(to);
            to = toid.toString();
        } catch (Exception e) {
            throw new MCRException("The xlink:to is not a MCRObjectID.");
        }
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRException(org.mycore.common.MCRException)

Example 73 with MCRException

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

the class MCRMetaLinkID method setBiLink.

/**
 * This method set a bidirectional link with xlink:from, xlink:to and
 * xlink:title.
 *
 * @param set_from
 *            the source MCRObjectID string
 * @param set_to
 *            the target MCRObjectID string
 * @param set_title
 *            the new title string
 * @exception MCRException
 *                if the from or to element is not a MCRObjectId
 */
@Override
public final void setBiLink(String set_from, String set_to, String set_title) throws MCRException {
    try {
        MCRObjectID fromid = MCRObjectID.getInstance(set_from);
        MCRObjectID toid = MCRObjectID.getInstance(set_to);
        super.setBiLink(fromid.toString(), toid.toString(), set_title);
    } catch (Exception e) {
        linktype = null;
        throw new MCRException("The from/to value is not a MCRObjectID.");
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRException(org.mycore.common.MCRException)

Example 74 with MCRException

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

the class MCRMetaLinkID method setReference.

/**
 * This method set a reference with xlink:href, xlink:label and xlink:title.
 *
 * @param set_href
 *            the reference as MCRObjectID string
 * @param set_label
 *            the new label string
 * @param set_title
 *            the new title string
 * @exception MCRException
 *                if the set_href value is null, empty or not a MCRObjectID
 */
@Override
public final void setReference(String set_href, String set_label, String set_title) throws MCRException {
    try {
        MCRObjectID hrefid = MCRObjectID.getInstance(set_href);
        super.setReference(hrefid.toString(), set_label, set_title);
    } catch (Exception e) {
        throw new MCRException("The href value is not a MCRObjectID: " + set_href, e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRException(org.mycore.common.MCRException)

Example 75 with MCRException

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

the class MCRMetaNumber method setNumber.

/**
 * This method set the number, if it is null or not a number, a MCRException
 * will be throw.
 *
 * @param number
 *            the number string
 * @exception MCRException
 *                if the number string is not in a number format
 */
public final void setNumber(String number) throws MCRException {
    try {
        if (number == null) {
            throw new MCRException("Number cannot be null");
        }
        String tmp_number = number.replace(',', '.');
        this.number = new BigDecimal(tmp_number);
    } catch (NumberFormatException e) {
        throw new MCRException("The format of a number is invalid.");
    }
}
Also used : MCRException(org.mycore.common.MCRException) BigDecimal(java.math.BigDecimal)

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