cancel
Showing results for 
Search instead for 
Did you mean: 

OnContentRead behavior

cristianfrog
Champ in-the-making
Champ in-the-making
Three days I'm stuck on this:

I want to execute a script when users READ files on Alfresco. I read Jeff Potts guide "Implementing custom behaviors" and tried to create a behavior using OnContentRead policy.

This is what I did until now:

Modified custom-model-context.xml like this:


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <!– Registration of new models –>   
    <bean id="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/extension/customModel.xml</value>
            </list>
        </property>
    </bean>
         
<bean id="onContentReadpolicy" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
      <property name="policyName">
         <value>{http://www.alfresco.org}onContentRead</value>
      </property>
      <property name="className">
         <value>{http://www.alfresco.org/model/content/1.0}content</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/myscript.js</value>
                  </constructor-arg>
               </bean>
            </property>
         </bean>
      </property>
</bean>

</beans>


And added a simple myscript.js in alfresco/extension/scripts.

When I restart Alfresco it doesn't work, it seems to crash at all…
I'm pretty sure I'm doing something wrong, I looked at alfresco.log but can't understand what's the problem…

Hope in some help!

P.S. I'm using Alfresco Community version 4.2.e on Windows 7 machine
11 REPLIES 11

Sounds easy but I guess it isn't actually… can you provide me some example and guide me doing this?
What do you mean with "proxy operation (servlet or webscript)"? Where/How do I install this with Alfresco?
Sincerely I have no idea where to start from…

kaynezhang
World-Class Innovator
World-Class Innovator
You can try to write a custom webscript ,user send view/download file request to your webscript.
In your webscript do all that you need to do and download file from repository and send the file to user.