Search in sources :

Example 21 with DatatypeConfigurationException

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

the class AbstractSearchConditionParser method convertToDate.

private Object convertToDate(Class<?> valueType, String value) throws SearchParseException {
    Message m = JAXRSUtils.getCurrentMessage();
    Object obj = InjectionUtils.createFromParameterHandler(value, valueType, valueType, new Annotation[] {}, m);
    if (obj != null) {
        return obj;
    }
    try {
        if (Timestamp.class.isAssignableFrom(valueType)) {
            return convertToTimestamp(value);
        } else if (Time.class.isAssignableFrom(valueType)) {
            return convertToTime(value);
        } else {
            return convertToDefaultDate(value);
        }
    } catch (ParseException e) {
        // is that duration?
        try {
            Date now = new Date();
            DatatypeFactory.newInstance().newDuration(value).addTo(now);
            return now;
        } catch (DatatypeConfigurationException e1) {
            throw new SearchParseException(e1);
        } catch (IllegalArgumentException e1) {
            throw new SearchParseException("Can parse " + value + " neither as date nor duration", e);
        }
    }
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Message(org.apache.cxf.message.Message) Time(java.sql.Time) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) OffsetTime(java.time.OffsetTime) OffsetDateTime(java.time.OffsetDateTime) ParseException(java.text.ParseException) DateTimeParseException(java.time.format.DateTimeParseException) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 22 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)

Example 23 with DatatypeConfigurationException

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

the class SubscriptionManagerImpl method grantExpiration.

/**
 * Decide what expiration time to grant to the subscription, if
 * the client did not specify any particular wish for subscription length.
 */
public XMLGregorianCalendar grantExpiration() {
    try {
        // by default, we grant an expiration time of 2 years
        DatatypeFactory factory = DatatypeFactory.newInstance();
        XMLGregorianCalendar granted = factory.newXMLGregorianCalendar(new GregorianCalendar());
        granted.add(factory.newDurationYearMonth(true, 2, 0));
        return granted;
    } catch (DatatypeConfigurationException ex) {
        throw new Error(ex);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 24 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project alfresco-repository by Alfresco.

the class CMISConnector method setAspectProperties.

private void setAspectProperties(NodeRef nodeRef, boolean isNameChanging, CmisExtensionElement aspectExtension) {
    if (aspectExtension.getChildren() == null) {
        return;
    }
    List<String> aspectsToAdd = new ArrayList<String>();
    List<String> aspectsToRemove = new ArrayList<String>();
    Map<QName, List<Serializable>> aspectProperties = new HashMap<QName, List<Serializable>>();
    for (CmisExtensionElement extension : aspectExtension.getChildren()) {
        if (!ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace())) {
            continue;
        }
        if (ASPECTS_TO_ADD.equals(extension.getName()) && (extension.getValue() != null)) {
            aspectsToAdd.add(extension.getValue());
        } else if (ASPECTS_TO_REMOVE.equals(extension.getName()) && (extension.getValue() != null)) {
            aspectsToRemove.add(extension.getValue());
        } else if (PROPERTIES.equals(extension.getName()) && (extension.getChildren() != null)) {
            for (CmisExtensionElement property : extension.getChildren()) {
                if (!property.getName().startsWith("property")) {
                    continue;
                }
                String propertyId = (property.getAttributes() == null ? null : property.getAttributes().get("propertyDefinitionId"));
                if ((propertyId == null) || (property.getChildren() == null)) {
                    continue;
                }
                PropertyType propertyType = PropertyType.STRING;
                DatatypeFactory df = null;
                if (property.getName().equals("propertyBoolean")) {
                    propertyType = PropertyType.BOOLEAN;
                } else if (property.getName().equals("propertyInteger")) {
                    propertyType = PropertyType.INTEGER;
                } else if (property.getName().equals("propertyDateTime")) {
                    propertyType = PropertyType.DATETIME;
                    try {
                        df = DatatypeFactory.newInstance();
                    } catch (DatatypeConfigurationException e) {
                        throw new CmisRuntimeException("Aspect conversation exception: " + e.getMessage(), e);
                    }
                } else if (property.getName().equals("propertyDecimal")) {
                    propertyType = PropertyType.DECIMAL;
                }
                ArrayList<Serializable> values = new ArrayList<Serializable>();
                if (property.getChildren() != null) {
                    // {
                    for (CmisExtensionElement valueElement : property.getChildren()) {
                        if ("value".equals(valueElement.getName())) {
                            switch(propertyType) {
                                case BOOLEAN:
                                    try {
                                        values.add(Boolean.parseBoolean(valueElement.getValue()));
                                    } catch (Exception e) {
                                        throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
                                    }
                                    break;
                                case DATETIME:
                                    try {
                                        values.add(df.newXMLGregorianCalendar(valueElement.getValue()).toGregorianCalendar());
                                    } catch (Exception e) {
                                        throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
                                    }
                                    break;
                                case INTEGER:
                                    BigInteger value = null;
                                    try {
                                        value = new BigInteger(valueElement.getValue());
                                    } catch (Exception e) {
                                        throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
                                    }
                                    // overflow check
                                    PropertyDefinitionWrapper propDef = getOpenCMISDictionaryService().findProperty(propertyId);
                                    if (propDef == null) {
                                        throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
                                    }
                                    QName propertyQName = propDef.getPropertyAccessor().getMappedProperty();
                                    if (propertyQName == null) {
                                        throw new CmisConstraintException("Unable to set property " + propertyId + "!");
                                    }
                                    org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService.getProperty(propertyQName);
                                    QName dataDef = def.getDataType().getName();
                                    if (dataDef.equals(DataTypeDefinition.INT) && (value.compareTo(maxInt) > 0 || value.compareTo(minInt) < 0)) {
                                        throw new CmisConstraintException("Value is out of range for property " + propertyId);
                                    }
                                    if (dataDef.equals(DataTypeDefinition.LONG) && (value.compareTo(maxLong) > 0 || value.compareTo(minLong) < 0)) {
                                        throw new CmisConstraintException("Value is out of range for property " + propertyId);
                                    }
                                    values.add(value);
                                    break;
                                case DECIMAL:
                                    try {
                                        values.add(new BigDecimal(valueElement.getValue()));
                                    } catch (Exception e) {
                                        throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
                                    }
                                    break;
                                default:
                                    values.add(valueElement.getValue());
                            }
                        }
                    }
                }
                aspectProperties.put(QName.createQName(propertyId, namespaceService), values);
            }
        }
    }
    // remove and add aspects
    String aspectType = null;
    try {
        for (String aspect : aspectsToRemove) {
            aspectType = aspect;
            TypeDefinitionWrapper type = getType(aspect);
            if (type == null) {
                throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
            }
            QName typeName = type.getAlfrescoName();
            // if aspect is hidden aspect, remove only if hidden node is not client controlled
            if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
                if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect only if client controlled
                    nodeService.removeAspect(nodeRef, typeName);
                }
            // if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
            // {
            // nodeService.removeAspect(nodeRef, typeName);
            // }
            } else {
                nodeService.removeAspect(nodeRef, typeName);
            }
        }
        for (String aspect : aspectsToAdd) {
            aspectType = aspect;
            TypeDefinitionWrapper type = getType(aspect);
            if (type == null) {
                throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
            }
            QName typeName = type.getAlfrescoName();
            // if aspect is hidden aspect, remove only if hidden node is not client controlled
            if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
                if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect only if client controlled
                    nodeService.addAspect(nodeRef, type.getAlfrescoName(), Collections.<QName, Serializable>emptyMap());
                }
            // if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
            // {
            // nodeService.addAspect(nodeRef, type.getAlfrescoName(),
            // Collections.<QName, Serializable> emptyMap());
            // }
            } else {
                nodeService.addAspect(nodeRef, type.getAlfrescoName(), Collections.<QName, Serializable>emptyMap());
            }
        }
    } catch (InvalidAspectException e) {
        throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
    } catch (InvalidNodeRefException e) {
        throw new CmisInvalidArgumentException("Invalid node: " + nodeRef);
    }
    // set property
    for (Map.Entry<QName, List<Serializable>> property : aspectProperties.entrySet()) {
        QName propertyQName = property.getKey();
        if (property.getValue().isEmpty()) {
            if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
                if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect property only if client controlled
                    nodeService.removeProperty(nodeRef, propertyQName);
                }
            } else {
                nodeService.removeProperty(nodeRef, property.getKey());
            }
        } else {
            if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
                if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect property only if client controlled
                    nodeService.setProperty(nodeRef, property.getKey(), property.getValue().size() == 1 ? property.getValue().get(0) : (Serializable) property.getValue());
                }
            } else {
                Serializable value = (Serializable) property.getValue();
                nodeService.setProperty(nodeRef, property.getKey(), property.getValue().size() == 1 ? property.getValue().get(0) : value);
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) HashMap(java.util.HashMap) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) ArrayList(java.util.ArrayList) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) QName(org.alfresco.service.namespace.QName) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) InvalidAspectException(org.alfresco.service.cmr.dictionary.InvalidAspectException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) BigDecimal(java.math.BigDecimal) InvalidAspectException(org.alfresco.service.cmr.dictionary.InvalidAspectException) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) BigInteger(java.math.BigInteger) Map(java.util.Map) HashMap(java.util.HashMap)

Example 25 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project alfresco-repository by Alfresco.

the class CMISConnector method convertAspectPropertyValue.

private String convertAspectPropertyValue(Object value) {
    if (value instanceof Date) {
        GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        cal.setTime((Date) value);
        value = cal;
    }
    if (value instanceof GregorianCalendar) {
        DatatypeFactory df;
        try {
            df = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException("Aspect conversation exception: " + e.getMessage(), e);
        }
        return df.newXMLGregorianCalendar((GregorianCalendar) value).toXMLFormat();
    }
    // Filter for AtomPub and Web services bindings only. Browser/json binding already encodes.
    if (AlfrescoCmisServiceCall.get() != null && (CallContext.BINDING_ATOMPUB.equals(AlfrescoCmisServiceCall.get().getBinding()) || CallContext.BINDING_WEBSERVICES.equals(AlfrescoCmisServiceCall.get().getBinding()))) {
        return filterXmlRestrictedCharacters(value.toString());
    } else {
        return value.toString();
    }
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

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