Search in sources :

Example 1 with PropertyStringImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl 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)

Example 2 with PropertyStringImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl in project alfresco-remote-api by Alfresco.

the class RepoService method getProperties.

/*
     * Get (CMIS) node properties
     */
private Properties getProperties(NodeRef nodeRef) {
    CMISNodeInfoImpl nodeInfo = cmisConnector.createNodeInfo(nodeRef);
    final Properties properties = cmisConnector.getNodeProperties(nodeInfo, null);
    // fake the title property, which CMIS doesn't give us
    String title = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
    final PropertyStringImpl titleProp = new PropertyStringImpl(ContentModel.PROP_TITLE.toString(), title);
    Properties wrapProperties = new Properties() {

        @Override
        public List<CmisExtensionElement> getExtensions() {
            return properties.getExtensions();
        }

        @Override
        public void setExtensions(List<CmisExtensionElement> extensions) {
            properties.setExtensions(extensions);
        }

        @Override
        public Map<String, PropertyData<?>> getProperties() {
            Map<String, PropertyData<?>> updatedProperties = new HashMap<String, PropertyData<?>>(properties.getProperties());
            updatedProperties.put(titleProp.getId(), titleProp);
            return updatedProperties;
        }

        @Override
        public List<PropertyData<?>> getPropertyList() {
            List<PropertyData<?>> propertyList = new ArrayList<PropertyData<?>>(properties.getPropertyList());
            propertyList.add(titleProp);
            return propertyList;
        }
    };
    return wrapProperties;
}
Also used : CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) CMISNodeInfoImpl(org.alfresco.opencmis.CMISNodeInfoImpl) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Properties(org.apache.chemistry.opencmis.commons.data.Properties)

Aggregations

PropertyStringImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl)2 BigInteger (java.math.BigInteger)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SenderException (nl.nn.adapterframework.core.SenderException)1 CMISNodeInfoImpl (org.alfresco.opencmis.CMISNodeInfoImpl)1 CmisExtensionElement (org.apache.chemistry.opencmis.commons.data.CmisExtensionElement)1 Properties (org.apache.chemistry.opencmis.commons.data.Properties)1 PropertyData (org.apache.chemistry.opencmis.commons.data.PropertyData)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