Search in sources :

Example 1 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project opennms by OpenNMS.

the class Requisition method setDate.

public void setDate(final Date date) {
    final GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {
        setDateStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
    } catch (final DatatypeConfigurationException e) {
        LOG.warn("Failed to turn {} into an XML date.", date);
    }
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 2 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project opennms by OpenNMS.

the class TsrmTicketerPlugin method updateIncidentWithTicket.

private void updateIncidentWithTicket(SHSIMPINCINCIDENTType incident, Ticket ticket) {
    if (!StringUtils.isEmpty(ticket.getAttribute(AFFECTED_PERSON))) {
        MXStringType affectedPerson = new MXStringType();
        affectedPerson.setValue(ticket.getAttribute(AFFECTED_PERSON));
        incident.setAFFECTEDPERSON(affectedPerson);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(ASSET_NUM))) {
        MXStringType assetNum = new MXStringType();
        assetNum.setValue(ticket.getAttribute(ASSET_NUM));
        incident.setASSETNUM(assetNum);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(CLASS_ID))) {
        MXStringType classId = new MXStringType();
        classId.setValue(ticket.getAttribute(CLASS_ID));
        incident.setCLASS(classId);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(CLASS_STRUCTURE_ID))) {
        MXStringType classStructureId = new MXStringType();
        classStructureId.setValue(ticket.getAttribute(CLASS_STRUCTURE_ID));
        incident.setCLASSSTRUCTUREID(classStructureId);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(COMMODITY))) {
        MXStringType commodity = new MXStringType();
        commodity.setValue(ticket.getAttribute(COMMODITY));
        incident.setCOMMODITY(commodity);
    }
    if (!StringUtils.isEmpty(ticket.getSummary())) {
        MXStringType description = new MXStringType();
        description.setValue(ticket.getSummary());
        incident.setDESCRIPTION(description);
    }
    if (!StringUtils.isEmpty(ticket.getDetails())) {
        MXStringType longDescription = new MXStringType();
        longDescription.setValue(ticket.getDetails());
        incident.setDESCRIPTIONLONGDESCRIPTION(longDescription);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(LOCATION))) {
        MXStringType location = new MXStringType();
        location.setValue(ticket.getAttribute(LOCATION));
        incident.setLOCATION(location);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(OWNER_GROUP))) {
        MXStringType ownerGroup = new MXStringType();
        ownerGroup.setValue(ticket.getAttribute(OWNER_GROUP));
        incident.setOWNERGROUP(ownerGroup);
    }
    if (!StringUtils.isEmpty(ticket.getUser())) {
        if (StringUtils.isEmpty(ticket.getId())) {
            MXStringType reportedBy = new MXStringType();
            reportedBy.setValue(ticket.getUser());
            incident.setREPORTEDBY(reportedBy);
        } else {
            MXDateTimeType date = new MXDateTimeType();
            GregorianCalendar calendarTime = new GregorianCalendar();
            calendarTime.setTime(new Date());
            XMLGregorianCalendar value;
            @SuppressWarnings({ "unchecked", "rawtypes" }) JAXBElement<MXDateTimeType> jaxbElement = new JAXBElement(new QName(MXDateTimeType.class.getName()), MXDateTimeType.class, date);
            try {
                value = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendarTime);
                date.setValue(value);
                incident.setCHANGEDATE(jaxbElement);
            } catch (DatatypeConfigurationException e) {
                LOG.error("Unable to create changedDate", e);
            }
        }
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_CALLER_TYPE))) {
        MXStringType shsCallerType = new MXStringType();
        shsCallerType.setValue(ticket.getAttribute(SHS_CALLER_TYPE));
        incident.setSHSCALLERTYPE(shsCallerType);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_REASON_FOR_OUTAGE))) {
        MXStringType shsReasonForOutage = new MXStringType();
        shsReasonForOutage.setValue(ticket.getAttribute(SHS_REASON_FOR_OUTAGE));
        incident.setSHSREASONFOROUTAGE(shsReasonForOutage);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_RESOLUTION))) {
        MXStringType shsResolution = new MXStringType();
        shsResolution.setValue(ticket.getAttribute(SHS_RESOLUTION));
        incident.setSHSRESOLUTION(shsResolution);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_ROOM_NUMBER))) {
        MXStringType shsRoomNumber = new MXStringType();
        shsRoomNumber.setValue(ticket.getAttribute(SHS_ROOM_NUMBER));
        incident.setSHSROOMNUMBER(shsRoomNumber);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SITE_ID))) {
        MXStringType siteId = new MXStringType();
        siteId.setValue(ticket.getAttribute(SITE_ID));
        incident.setSITEID(siteId);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SOURCE))) {
        MXStringType source = new MXStringType();
        source.setValue(ticket.getAttribute(SOURCE));
        incident.setSOURCE(source);
    }
    MXStringType status = new MXStringType();
    try {
        if (ticket.getState().equals(Ticket.State.OPEN)) {
            status.setValue(getProperties().getProperty("tsrm.status.open"));
        } else if (ticket.getState().equals(Ticket.State.CLOSED)) {
            status.setValue(getProperties().getProperty("tsrm.status.close"));
        }
    } catch (IOException e) {
        LOG.error("Unable to load tsrm.status from properties ", e);
    }
    incident.setSTATUS(status);
    if (!StringUtils.isEmpty(ticket.getAttribute(STATUS_IFACE))) {
        MXBooleanType statusIface = new MXBooleanType();
        statusIface.setValue(Boolean.parseBoolean(ticket.getAttribute(STATUS_IFACE)));
        incident.setSTATUSIFACE(statusIface);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) MXBooleanType(com.ibm.maximo.MXBooleanType) QName(javax.xml.namespace.QName) MXDateTimeType(com.ibm.maximo.MXDateTimeType) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) MXStringType(com.ibm.maximo.MXStringType) Date(java.util.Date)

Example 3 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project jabref by JabRef.

the class BibTeXMLExportFormat method parseInbook.

/**
     * Contains same logic as the {@link parse()} method, but inbook needs a special treatment, because
     * the contents of inbook are stored in a List of JAXBElements. So we first need to create
     * a JAXBElement for every field and then add it to the content list.
     */
private void parseInbook(Inbook inbook, BibEntry bibEntry, Entry entry) {
    Map<String, String> fieldMap = bibEntry.getFieldMap();
    for (Map.Entry<String, String> entryField : fieldMap.entrySet()) {
        String value = entryField.getValue();
        String key = entryField.getKey();
        if ("year".equals(key)) {
            XMLGregorianCalendar calendar;
            try {
                calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
                JAXBElement<XMLGregorianCalendar> year = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, "year"), XMLGregorianCalendar.class, calendar);
                inbook.getContent().add(year);
            } catch (DatatypeConfigurationException e) {
                LOGGER.error("A configuration error occured");
            }
        } else if ("number".equals(key)) {
            JAXBElement<BigInteger> number = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, "number"), BigInteger.class, new BigInteger(value));
            inbook.getContent().add(number);
        } else {
            JAXBElement<String> element = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, key), String.class, value);
            inbook.getContent().add(element);
        }
    }
    //set the entryType to the entry
    entry.setInbook(inbook);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) QName(javax.xml.namespace.QName) BigInteger(java.math.BigInteger) JAXBElement(javax.xml.bind.JAXBElement) Map(java.util.Map)

Example 4 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project sic by belluccifranco.

the class AfipWebServiceSOAPClient method crearTicketRequerimientoAcceso.

public String crearTicketRequerimientoAcceso(String service, long ticketTime) {
    Date now = new Date();
    GregorianCalendar genenerationTime = new GregorianCalendar();
    GregorianCalendar expirationTime = new GregorianCalendar();
    DatatypeFactory datatypeFactory = null;
    String uniqueId = Long.toString(now.getTime() / 1000);
    expirationTime.setTime(new Date(now.getTime() + ticketTime));
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        LOGGER.error(ex.getMessage());
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_xml_factory"));
    }
    XMLGregorianCalendar XMLGenTime = datatypeFactory.newXMLGregorianCalendar(genenerationTime);
    XMLGregorianCalendar XMLExpTime = datatypeFactory.newXMLGregorianCalendar(expirationTime);
    String LoginTicketRequest_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<loginTicketRequest version=\"1.0\">" + "<header>" + "<uniqueId>" + uniqueId + "</uniqueId>" + "<generationTime>" + XMLGenTime + "</generationTime>" + "<expirationTime>" + XMLExpTime + "</expirationTime>" + "</header>" + "<service>" + service + "</service>" + "</loginTicketRequest>";
    return LoginTicketRequest_xml;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) BusinessServiceException(sic.service.BusinessServiceException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Date(java.util.Date)

Example 5 with DatatypeConfigurationException

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

the class SubscriptionManagerImpl method processExpiration.

/**
 * process the stuff concerning expiration request (wse:Expires)
 */
protected void processExpiration(ExpirationType request, SubscriptionTicket ticket, SubscriptionTicketGrantingResponse response) {
    XMLGregorianCalendar granted;
    if (request != null) {
        Object expirationTypeValue;
        try {
            expirationTypeValue = DurationAndDateUtil.parseDurationOrTimestamp(request.getValue());
        } catch (IllegalArgumentException ex) {
            throw new SoapFault("Cannot parse expiration", new QName("http://cxf.apache.org/eventing", "Error"));
        }
        Boolean bestEffort = request.isBestEffort();
        if (bestEffort != null && bestEffort) {
            if (expirationTypeValue instanceof javax.xml.datatype.Duration) {
                granted = grantExpirationFor((javax.xml.datatype.Duration) expirationTypeValue);
            } else if (expirationTypeValue instanceof XMLGregorianCalendar) {
                granted = grantExpirationFor((XMLGregorianCalendar) expirationTypeValue);
            } else {
                throw new Error("expirationTypeValue of unexpected type: " + expirationTypeValue.getClass());
            }
        } else {
            // or throw a UnsupportedExpirationValue fault
            if (expirationTypeValue instanceof javax.xml.datatype.Duration) {
                try {
                    if (DurationAndDateUtil.isPT0S((javax.xml.datatype.Duration) expirationTypeValue)) {
                        ticket.setNonExpiring(true);
                    }
                    granted = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
                    granted.add((javax.xml.datatype.Duration) expirationTypeValue);
                } catch (DatatypeConfigurationException e) {
                    throw new Error(e);
                }
            } else if (expirationTypeValue instanceof XMLGregorianCalendar) {
                granted = (XMLGregorianCalendar) expirationTypeValue;
            } else {
                throw new Error("expirationTypeValue of unexpected type: " + expirationTypeValue.getClass());
            }
        }
    } else {
        granted = grantExpiration();
    }
    ticket.setExpires(granted);
    response.setExpires(granted);
    LOG.info("[subscription=" + ticket.getUuid() + "] Granted Expiration date: " + granted.toString());
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) QName(javax.xml.namespace.QName) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException)

Aggregations

DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)50 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)34 GregorianCalendar (java.util.GregorianCalendar)31 DatatypeFactory (javax.xml.datatype.DatatypeFactory)18 Date (java.util.Date)14 ParseException (java.text.ParseException)5 JAXBException (javax.xml.bind.JAXBException)5 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 QName (javax.xml.namespace.QName)3 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 BigDecimal (java.math.BigDecimal)2