11-14-2007 04:48 AM
<import resource="classpath:alfresco/extension/scripts/md5.js">
function computeContentHash(node) {
if (!node.hasAspect("{http://www.cayman.com/model/content/1.0}autoversionable")) {
logger.log("Node does not have the autoversionable aspect");
return;
}
var c = new String(node.content);
var hash = hex_md5©;
node.properties.contenthash = hash;
node.save();
return;
}
<import resource="classpath:alfresco/extension/scripts/contenthash.js">
var scriptFailed = false;
logger.log("-=-=-=-=-=-=-=- onContentHash.js called -=-=-=-=-=-=-=-");
// Have a look at the behaviour object that should have been passed
if (behaviour == null) {
logger.log("The behaviour object has not been set.");
scriptFailed = true;
}
// Check the name of the behaviour
if (behaviour.name == null) {
logger.log("The behaviour name has not been set correctly.");
scriptFailed = true;
}
// check the behaviour arguments
if (behaviour.args == null) {
logger.log("The args have not been set.");
scriptFailed = true;
}
// check which behaviour was called
if (behaviour.name == "onContentUpdate") {
if (behaviour.args.length == 2) {
var node = behaviour.args[0];
var update = behaviour.args[1];
} else {
logger.log("The number of arguments is incorrect.");
scriptFailed = true;
}
} else if (behaviour.name == "onAddAspect") {
if (behaviour.args.length == 2) {
var node = behaviour.args[0];
var aspectname = behaviour.args[1];
} else {
logger.log("The number of arguments is incorrect.");
scriptFailed = true;
}
if (aspectname != "autoversionable") {
logger.log("The aspect added was not autoversionable.");
scriptFailed = true;
}
} else {
logger.log("The behaviour name has not been set correctly.");
scriptFailed = true;
}
// call the content hash functions
if (!scriptFailed) {
logger.log("Calling compute contenthash");
computeContentHash(node);
}
<bean id="onAddAspectContentHash" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
<property name="policyName">
<value>{http://www.alfresco.org}onAddAspect</value>
</property>
<property name="className">
<value>{http://www.cayman.com/model/content/1.0}doc</value>
</property>
<property name="behaviour">
<bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
<property name="location">
<bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
<constructor-arg>
<value>alfresco/extension/scripts/onContentHash.js</value>
</constructor-arg>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="onContentUpdateContentHash" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
<property name="policyName">
<value>{http://www.alfresco.org}onContentUpdate</value>
</property>
<property name="className">
<value>{http://www.cayman.com/model/content/1.0}doc</value>
</property>
<property name="behaviour">
<bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
<property name="location">
<bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
<constructor-arg>
<value>alfresco/extension/scripts/onContentHash.js</value>
</constructor-arg>
</bean>
</property>
</bean>
</property>
</bean>
11-26-2007 05:10 AM
<bean id="onAddAspectContentHash" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
<property name="policyName">
<value>{http://www.alfresco.org}onAddAspect</value>
</property>
<property name="className">
<value>{http://www.cayman.com/model/content/1.0}autoversionable</value>
</property>
<property name="behaviour">
<bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
<property name="location">
<bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
<constructor-arg>
<value>alfresco/extension/scripts/onContentHash.js</value>
</constructor-arg>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="onContentUpdateContentHash" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
<property name="policyName">
<value>{http://www.alfresco.org}onContentUpdate</value>
</property>
<property name="className">
<value>{http://www.cayman.com/model/content/1.0}autoversionable</value>
</property>
<property name="behaviour">
<bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
<property name="location">
<bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
<constructor-arg>
<value>alfresco/extension/scripts/onContentHash.js</value>
</constructor-arg>
</bean>
</property>
</bean>
</property>
</bean>
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.