Search in sources :

Example 31 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project GeoGig by boundlessgeo.

the class ParseTimestamp method _call.

/**
     * Parses a string with a timestamp
     * 
     * @return a Long with the timestamp represented by the specified string
     */
@Override
protected Long _call() {
    Preconditions.checkState(string != null, "String has not been set.");
    try {
        // see if it is a timestamp in milisecs
        Long milis = new Long(string);
        return milis;
    } catch (NumberFormatException e) {
    }
    SimpleDateFormat formatter;
    final Platform platform = platform();
    if (string.equals("yesterday")) {
        // from current time
        try {
            formatter = new SimpleDateFormat("dd/MM/yyyy");
            Date today = new Date(platform.currentTimeMillis());
            long todayOnlyDate = formatter.parse(formatter.format(today)).getTime();
            long millisecsInOneDay = 60 * 60 * 24 * 1000;
            long yesterday = todayOnlyDate - millisecsInOneDay;
            return yesterday;
        } catch (ParseException e) {
        // shouldn't reach this
        }
    }
    if (string.equals("today")) {
        try {
            formatter = new SimpleDateFormat("dd/MM/yyyy");
            Date today = new Date(platform.currentTimeMillis());
            long todayOnlyDate = formatter.parse(formatter.format(today)).getTime();
            return todayOnlyDate;
        } catch (ParseException e) {
        // shouldn't reach this
        }
    }
    // parse it as a git-like time reference
    String[] tokens = string.split("\\.");
    if (tokens.length % 2 != 0) {
        if (tokens[tokens.length - 1].toLowerCase().equals("ago")) {
            long currentTime = platform.currentTimeMillis();
            int i;
            for (i = 0; i < tokens.length - 1; i++) {
                try {
                    double number = Double.parseDouble(tokens[i]);
                    i++;
                    String s = tokens[i].toLowerCase();
                    if (s.endsWith("s")) {
                        s = s.substring(0, s.length() - 1);
                    }
                    if (units.containsKey(s)) {
                        currentTime -= units.get(s) * number;
                    } else {
                        break;
                    }
                } catch (Exception e) {
                    break;
                }
            }
            if (i == tokens.length - 1) {
                return currentTime;
            }
        }
    }
    // finally, try to parse it as a Date object
    try {
        long time = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(string).toGregorianCalendar().getTimeInMillis();
        return time;
    } catch (DatatypeConfigurationException e) {
    } catch (IllegalArgumentException e) {
    }
    throw new IllegalArgumentException("Invalid timestamp string: " + string);
}
Also used : Platform(org.locationtech.geogig.api.Platform) Date(java.util.Date) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ParseException(java.text.ParseException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 32 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project xades4j by luisgoncalves.

the class ToXmlCompleteRevocRefsConverter method convertIntoObjectTree.

@Override
public void convertIntoObjectTree(PropertyDataObject propData, XmlUnsignedPropertiesType xmlProps, Document doc) {
    CompleteRevocationRefsData complRevocRefsData = (CompleteRevocationRefsData) propData;
    // Only CRL refs are supported.
    XmlCRLRefsType xmlCRLRefs = new XmlCRLRefsType();
    List<XmlCRLRefType> xmlCRLRefsList = xmlCRLRefs.getCRLRef();
    try {
        for (CRLRef crlRef : complRevocRefsData.getCrlRefs()) {
            XmlCRLIdentifierType xmlCrlId = new XmlCRLIdentifierType();
            xmlCrlId.setIssueTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(crlRef.issueTime));
            xmlCrlId.setIssuer(crlRef.issuerDN);
            // May be null.
            xmlCrlId.setNumber(crlRef.serialNumber);
            XmlDigestAlgAndValueType xmlDigest = new XmlDigestAlgAndValueType();
            XmlDigestMethodType xmlDigestMethod = new XmlDigestMethodType();
            xmlDigestMethod.setAlgorithm(crlRef.digestAlgUri);
            xmlDigest.setDigestValue(crlRef.digestValue);
            xmlDigest.setDigestMethod(xmlDigestMethod);
            XmlCRLRefType xmlCrlRef = new XmlCRLRefType();
            xmlCrlRef.setCRLIdentifier(xmlCrlId);
            xmlCrlRef.setDigestAlgAndValue(xmlDigest);
            xmlCRLRefsList.add(xmlCrlRef);
        }
    } catch (DatatypeConfigurationException ex) {
        throw new UnsupportedOperationException(ex.getMessage(), ex);
    }
    XmlCompleteRevocationRefsType xmlComplRevocRefs = new XmlCompleteRevocationRefsType();
    // Only CRL refs are supported.
    xmlComplRevocRefs.setCRLRefs(xmlCRLRefs);
    xmlProps.getUnsignedSignatureProperties().setCompleteRevocationRefs(xmlComplRevocRefs);
}
Also used : XmlCRLIdentifierType(xades4j.xml.bind.xades.XmlCRLIdentifierType) XmlDigestAlgAndValueType(xades4j.xml.bind.xades.XmlDigestAlgAndValueType) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) XmlCRLRefType(xades4j.xml.bind.xades.XmlCRLRefType) XmlCompleteRevocationRefsType(xades4j.xml.bind.xades.XmlCompleteRevocationRefsType) CRLRef(xades4j.properties.data.CRLRef) XmlDigestMethodType(xades4j.xml.bind.xmldsig.XmlDigestMethodType) XmlCRLRefsType(xades4j.xml.bind.xades.XmlCRLRefsType) CompleteRevocationRefsData(xades4j.properties.data.CompleteRevocationRefsData)

Example 33 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project sis by apache.

the class UniversalTimeAdapter method marshal.

/**
 * Converts the date to the object to be marshalled in a XML file or stream.
 * JAXB calls automatically this method at marshalling time.
 *
 * @param  value  the {@code java.util} date value, or {@code null}.
 * @return the XML date, or {@code null}.
 */
@Override
public XMLGregorianCalendar marshal(final Date value) {
    if (value != null) {
        final GregorianCalendar calendar = new GregorianCalendar(UTC, Locale.ROOT);
        calendar.setTime(value);
        try {
            final XMLGregorianCalendar gc = getDatatypeFactory().newXMLGregorianCalendar(calendar);
            if (gc.getMillisecond() == 0) {
                gc.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
            }
            return gc;
        } catch (DatatypeConfigurationException e) {
            Context.warningOccured(Context.current(), XmlAdapter.class, "marshal", e, true);
        }
    }
    return null;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)

Example 34 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project incubator-rya by apache.

the class DateTimeTtlValueConverter method convert.

@Override
public void convert(String ttl, String startTime) {
    try {
        long start_l, stop_l;
        long ttl_l = Long.parseLong(ttl);
        stop_l = System.currentTimeMillis();
        if (startTime != null)
            stop_l = Long.parseLong(startTime);
        start_l = stop_l - ttl_l;
        GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
        cal.setTimeZone(getTimeZone());
        cal.setTimeInMillis(start_l);
        DatatypeFactory factory = DatatypeFactory.newInstance();
        start = vf.createLiteral(factory.newXMLGregorianCalendar(cal));
        cal.setTimeInMillis(stop_l);
        stop = vf.createLiteral(factory.newXMLGregorianCalendar(cal));
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("Exception occurred creating DataTypeFactory", e);
    }
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar)

Example 35 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project TranskribusCore by Transkribus.

the class JaxbUtils method getXmlCalendar.

public static XMLGregorianCalendar getXmlCalendar(Date date) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    XMLGregorianCalendar xmlCal = null;
    try {
        xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
    } catch (DatatypeConfigurationException e) {
        logger.error("DatatypeFactory:  implementation is not available or cannot be instantiated. CreateDate will be null!", e);
    }
    return xmlCal;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Aggregations

DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)56 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)35 GregorianCalendar (java.util.GregorianCalendar)33 DatatypeFactory (javax.xml.datatype.DatatypeFactory)20 Date (java.util.Date)18 BigInteger (java.math.BigInteger)6 ParseException (java.text.ParseException)6 JAXBException (javax.xml.bind.JAXBException)5 QName (javax.xml.namespace.QName)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)2 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)2 NumericType (ch.interlis.ili2c.metamodel.NumericType)2 PrecisionDecimal (ch.interlis.ili2c.metamodel.PrecisionDecimal)2 IomObject (ch.interlis.iom.IomObject)2 ArrayOfString (com.marketo.mktows.ArrayOfString)2 LastUpdateAtSelector (com.marketo.mktows.LastUpdateAtSelector)2 File (java.io.File)2