Search in sources :

Example 1 with PropertyDateTimeImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl in project iaf by ibissource.

the class ObjectServiceImpl method processProperties.

private Properties processProperties(Element cmisElement) throws SenderException {
    PropertiesImpl properties = new PropertiesImpl();
    Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
    Iterator<Node> propertyIterator = XmlUtils.getChildTags(propertiesElement, "property").iterator();
    while (propertyIterator.hasNext()) {
        Element propertyElement = (Element) propertyIterator.next();
        String property = XmlUtils.getStringValue(propertyElement);
        String nameAttr = propertyElement.getAttribute("name");
        String typeAttr = propertyElement.getAttribute("type");
        if (StringUtils.isEmpty(typeAttr) || typeAttr.equalsIgnoreCase("string")) {
            if (nameAttr.startsWith("cmis:")) {
                properties.addProperty(new PropertyIdImpl(nameAttr, property));
            } else {
                properties.addProperty(new PropertyStringImpl(nameAttr, property));
            }
        } else if (typeAttr.equalsIgnoreCase("integer")) {
            properties.addProperty(new PropertyIntegerImpl(nameAttr, new BigInteger(property)));
        } else if (typeAttr.equalsIgnoreCase("boolean")) {
            properties.addProperty(new PropertyBooleanImpl(nameAttr, Boolean.parseBoolean(property)));
        } else if (typeAttr.equalsIgnoreCase("datetime")) {
            String formatStringAttr = propertyElement.getAttribute("formatString");
            if (StringUtils.isEmpty(formatStringAttr)) {
                formatStringAttr = CmisSender.FORMATSTRING_BY_DEFAULT;
            }
            DateFormat df = new SimpleDateFormat(formatStringAttr);
            Date date;
            try {
                date = df.parse(property);
            } catch (ParseException e) {
                throw new SenderException("exception parsing date [" + property + "] using formatString [" + formatStringAttr + "]", e);
            }
            GregorianCalendar gregorian = new GregorianCalendar();
            gregorian.setTime(date);
            properties.addProperty(new PropertyDateTimeImpl(nameAttr, gregorian));
        } else {
            log.warn("unparsable type [" + typeAttr + "] for property [" + property + "]");
        }
        log.debug("set property name [" + nameAttr + "] value [" + property + "]");
    }
    return properties;
}
Also used : PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) PropertyDateTimeImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) GregorianCalendar(java.util.GregorianCalendar) PropertyBooleanImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl) Date(java.util.Date) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) BigInteger(java.math.BigInteger) ParseException(java.text.ParseException) SenderException(nl.nn.adapterframework.core.SenderException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

BigInteger (java.math.BigInteger)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 SenderException (nl.nn.adapterframework.core.SenderException)1 PropertiesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl)1 PropertyBooleanImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl)1 PropertyDateTimeImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl)1 PropertyIdImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl)1 PropertyIntegerImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl)1 PropertyStringImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1