从行为中读取文档属性的值

时间:2013-10-02 12:31:36

标签: alfresco alfresco-share

问题描述和代码已更新

问题1:我将如何替换下面代码中的虚拟int attachmentid = 123;以读取自定义属性sc:OpenERPattachmentID1以获取存储在其中的id值? (问题1由alfrescian回答!)

package com.openerp.behavior;



import java.util.List;
import java.net.*;
import java.io.*;


import org.alfresco.repo.node.NodeServicePolicies;

import org.alfresco.repo.policy.Behaviour;

import org.alfresco.repo.policy.JavaBehaviour;

import org.alfresco.repo.policy.PolicyComponent;

import org.alfresco.repo.policy.Behaviour.NotificationFrequency;

import org.alfresco.repo.security.authentication.AuthenticationUtil;

import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;

import org.alfresco.service.cmr.repository.ChildAssociationRef;

import org.alfresco.service.cmr.repository.NodeRef;

import org.alfresco.service.cmr.repository.NodeService;

import org.alfresco.service.namespace.NamespaceService;

import org.alfresco.service.namespace.QName;

import org.alfresco.service.transaction.TransactionService;

import org.apache.log4j.Logger;



//import com.openerp.model.scOpenERPModel;

public class DeleteAsset implements NodeServicePolicies.BeforeDeleteNodePolicy  {



    private PolicyComponent policyComponent;

    private Behaviour beforeDeleteNode;
    private NodeService nodeService;



    public void init() {

        this.beforeDeleteNode = new JavaBehaviour(this,"beforeDeleteNode",NotificationFrequency.EVERY_EVENT);

        this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI,"beforeDeleteNode"), 

                QName.createQName(scOpenERPModel.NAMESPACE,scOpenERPModel.ASSET_CONTENT_TYPE), this.beforeDeleteNode);

    }
    public setNodeService(NodeService nodeService){
           this.nodeService = nodeService;  
        }




    @Override

    public void beforeDeleteNode(NodeRef node) {

        System.out.println("beforeDeleteNode!");

        try {
            QName attachmentID1= QName.createQName("http://www.someco.com/model/content/1.0", "OpenERPattachmentID1"); // this could/shoul be defined in your OpenERPModel-class
            int attachmentid = (Integer)nodeService.getProperty(node, attachmentID1);
            //int attachmentid = 123;
            URL oracle = new URL("http://0.0.0.0:1885/delete/%20?attachmentid=" + attachmentid);
            URLConnection yc = oracle.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                        yc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) 
            //System.out.println(inputLine);
                in.close(); 

        } catch(Exception e) {

            e.printStackTrace();

        }



    }

}

问题2:我在哪里放置Del​​eteAsset.class?

我是Java和Alfresco新手,如果有人能告诉我alfresco-4.2.c / tomcat / webapps / alfresco / WEB-INF / classes / com / openerp / behavior /是否合适,我会很高兴用于放置已编译的DeleteAsset.class的文件夹

问题3:我应该在NAMESPACE和ASSET_CONTENT_TYPE中添加什么内容? 我想在没有模型课的情况下工作,因为我还没有教程,我该用scOpenERPModel.NAMESPACE,scOpenERPModel.ASSET_CONTENT_TYPE替换什么?

这是我的完整自定义网络上下文文件:

<?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="smartsolution.dictionaryBootstrap" parent="dictionaryModelBootstrap"
 depends-on="dictionaryBootstrap">
    <property name="models">
        <list>
                <value>alfresco/extension/scOpenERPModel.xml</value>
        </list>
    </property>
</bean>

<!-- deletion of attachments within openERP when delete is initiated in Alfresco-->
<bean id="deletionBehavior" class="com.openerp.behavior.DeleteAsset" init-method="init">
    <property name="nodeService">
        <ref bean="nodeService" />
    </property>
    <property name="policyComponent">
        <ref bean="policyComponent" />
    </property>
</bean>

1 个答案:

答案 0 :(得分:3)

嗯,你还有很长的路要走...你想通过“oracle”连接达到什么目的?

回答您的主要问题:如何阅读财产:

  1. 不要将XML模型放入com / openerp / model / scOpenERPModel - 它应该是一个java类,它定义了访问自定义类型,方面和方法的常量。道具(例如:https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/data-model/source/java/org/alfresco/model/ContentModel.java) 但这不是强制性的 - 它只是对你有帮助。

  2. 阅读属性

    1. 注入NodeService:

      private NodeService nodeService;
      public setNodeService(NodeService nodeService){
         this.nodeService = nodeService;  
      }
      
    2. 你的beforeDeleteNode

      中的
    3. QName attachmentID1= QName.createQName("your sc NS uri", "OpenERPattachmentID1"); // this could/shoul be defined in your OpenERPModel-class
      int attachmentid = (Integer) nodeService.getProperty(node, attachmentID1);