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;
}
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.");
}
}
}
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.");
}
}
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);
}
}
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.");
}
}
Aggregations