本文介绍了从行为中读取文档属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述和代码已更新

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

Question 1: would be with what do I replace the dummy int attachmentid = 123; in the code below in order to read custom property sc:OpenERPattachmentID1 to get the id value stored in it?(Question 1 was Answered by 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:我将DeleteAsset.class放在哪里?

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

I'm a Java and Alfresco novice, I'd be great if someone could tell me if alfresco-4.2.c/tomcat/webapps/alfresco/WEB-INF/classes/com/openerp/behavior/ is the right folder to put the compiled DeleteAsset.class

问题3:我应该在NAMESPACE和ASSET_CONTENT_TYPE中输入什么?
我想在没有模型的情况下工作类,因为我还没有关于它的教程,我该怎么替换 scOpenERPModel.NAMESPACE,scOpenERPModel.ASSET_CONTENT_TYPE

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

This is my full custom-web-context file:

<?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>

推荐答案

嗯,您还有很长的路要走...您希望通过 oracle连接实现什么?

Well, you have a long way to go...what do you like to achieve with your "oracle" connection?

要回答您的主要问题:如何读取属性:

To answer your main questions: How to read a property:


  1. 不要将XML模型放入com / openerp / model / scOpenERPModel-一个Java类,该类定义用于访问您的自定义类型,方面&的常量。道具(例如:)
    但这不是强制性的,它只是对您有所帮助。

  1. Don't put the XML Model into com/openerp/model/scOpenERPModel - it should be a java class that defines constants to access your custom types, aspects & props (example: https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/data-model/source/java/org/alfresco/model/ContentModel.java)But that is not mandatory - it just helps you.

读取属性


  1. 注入NodeService:

  1. inject NodeService:

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


  • 在您的beforeDeleteNode中

  • in your beforeDeleteNode

    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);
    



  • 这篇关于从行为中读取文档属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-20 05:57