01-21-2010 03:46 PM
<?xml version="1.0" encoding="UTF-8"?>
<webscript>
<shortname>Constrain Values</shortname>
<description>Constraint Values</description>
<url>/mydomain/myapp/constrval?prop={prop}</url>
<url>/mydomain/myapp/constrval.xml?prop={prop}</url>
<format default="html">any</format>
<authentication>user</authentication>
<transaction>requiresnew</transaction>
</webscript>
constrval.get.html.ftl in alfresco/WEB-INF/classes/alfresco/templates/webscripts/mydomaintree/myapp/:<html>
<body>
<h1>Constraint values:</h1>
<p>
<#if model.validValues??>
<#list model.validValues as value>
${value} <br/>
</#list>
</#if>
</p>
${model.status}
</body>
</html>
mydomain-scripts-context.xml in tomcat/shared/classes/alfresco/extension/:<?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="webscript.mydomaintree.myapp.constrval.get" class="mydomaintree.myapp.scripts.ConstraintValuesList" parent="webscript">
<property name="dictionaryService">
<ref bean="DictionaryService" />
</property>
</bean>
</beans>
ConstraintValuesList.class (snapshot) in alfresco/WEB-INF/classes/mydomaintree/myapp/scripts/:public class ListaValoriValidi extends DeclarativeWebScript {
private DictionaryService dictionaryService;
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
Logger logger = Logger.getLogger(ConstraintValuesList.class);
Map<String, Object> model = new HashMap<String, Object>();
logger.debug("model created");
String propName = req.getParameter("prop");
if (propName==null) {
model.put("status","Error");
logger.debug("Proprierty null");
return model;
}
logger.debug("proprietà corretta");
QName theProperty;
try {
theProperty = QName.createQName("mydomain",propName);
} catch (org.alfresco.service.namespace.InvalidQNameException e) {
logger.debug("qname creation error");
return model;
}
logger.debug("qname correct");
ListOfValuesConstraint lovConstraint = null;
PropertyDefinition propertyDef = null;
// get the property definition for the item
propertyDef = dictionaryService.getProperty(theProperty);
if (propertyDef != null) {
List<ConstraintDefinition> constraints = propertyDef
.getConstraints();
for (ConstraintDefinition constraintDef : constraints) {
Constraint constraint = constraintDef.getConstraint();
if (constraint instanceof ListOfValuesConstraint) {
lovConstraint = (ListOfValuesConstraint) constraint;
break;
}
}
} else {
logger.debug("Proprierty doesn't exist");
model.put("status","Error");
return model;
}
if (lovConstraint!=null) {
model.put("status", "Success");
model.put("validValues", lovConstraint.getAllowedValues());
logger.debug("Constraint Values returned");
} else {
model.put("status","Error");
logger.debug("No constraint");
}
return model;
}
01-22-2010 02:58 AM
01-22-2010 03:53 PM
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.