05-03-2014 05:05 PM
package com.custom.decorators;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.alfresco.repo.jscript.app.BasePropertyDecorator;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
public class CustomDateAttributesDecorator extends BasePropertyDecorator {
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef,
Serializable value) {
JSONObject map = new JSONObject();
if (value instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format((Date) value);
map.put("formattedDate", date);
}
return map;
}
@Override
public Set<QName> getPropertyNames() {
return propertyNames;
}
@Override
public void setPropertyName(String propertyName) {
propertyNames = new HashSet<QName>(1);
propertyNames.add(QName.createQName(propertyName));
}
@Override
public void setPropertyNames(Set<String> propertyNames) {
this.propertyNames = new HashSet<QName>(propertyNames.size());
for (String propertyName : propertyNames) {
this.propertyNames.add(QName.createQName(propertyName));
}
}
}
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="customDatePropertiesDecorator" parent="baseDecorator"
class="com.custom.decorators.CustomDateAttributesDecorator">
<property name="propertyNames">
<set>
<value>{http://www.custom.com/model/content/1.0}dateField1</value>
<value>{http://www.custom.com/model/content/1.0}dateField2</value>
<value>{http://www.custom.com/model/content/1.0}dateField3</value>
</set>
</property>
</bean>
</beans>
<template id="isPpra">
<evaluator>evaluator.doclib.action.isCustom</evaluator>
<line index="110" id="date">{custom:dateField1 prop.custom_dateField1}</line>
<line index="170" id="created">{date}{size}</line>
</template>
"properties": {
"cm:author": "user1",
"custom:dateField1": {
"formattedDate": "16/10/2013"
},
"cm:modified": {
"value": "Thu Apr 11 16:22:09 GMT-03:00 2013",
"iso8601": "2013-04-11T19:22:09.131Z"
},
05-05-2014 01:03 AM
05-05-2014 03:49 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.