【问题标题】:Web script to get the properties of the document获取文档属性的 Web 脚本
【发布时间】:2021-09-29 11:34:54
【问题描述】:

创建一个web脚本来获取java中文档的参数示例url:

localhost:8080/alfresco/s/get-document-data?nodeRef=workspace://SpacesStore/3b3597e5-b5ec-41d5-b63b-54b050dccd1b&property=cm:name

因此脚本应该返回一种 Json 对象:

{
"nodeRef": "workspace: // SpacesStore / 3b3597e5-b5ec-41d5-b63b-54b050dccd1b",
"value": "value property - the one we got from nodRef"
}

创建一个网络脚本以检索所有子文件夹设置。请帮忙!

DocumentScript.java

import org.activiti.engine.impl.util.json.JSONException;
import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
import org.springframework.extensions.webscripts.*;
import java.io.IOException;

public class DocumentScript extends AbstractWebScript {
    public static JSONObject obj = new JSONObject();
    @Override
    public void execute(WebScriptRequest req, WebScriptResponse res)  throws IOException {
        try {
            String noderef = req.getParameter("nodeRef");
            String valueRef = res.getEncodeResourceUrlFunction("value");
            obj.put("nodeRef", noderef);
            obj.put("value", valueRef);
            String jsonString = obj.toString();
            res.getWriter().write(jsonString);
        } catch (JSONException e) {
            throw new WebScriptException("Unable to serialize JSON");

        }
    }
}

文档脚本上下文.xml

<bean class="alfresco.extension.templates.webscripts.repository.DocumentScript"
      parent="templates.webscripts.repository">
</bean>

文档脚本.get.desc.xml

<webscript>
    <shortname>Documents</shortname>
    <description>JSON data
    </description>
    <url>/script-document?q={keyword}</url>
    <authentication>user</authentication>
    <format default="html"/>
    <family>Alfresco Script</family>
</webscript>

文档脚本.get.html.ftl

{
"obj" : [
<#list obj as Obj>
    {
    "nodeRef" : "${Obj.nodeRef}",
    "value" : "${Obj.value}"
    }
    <#if Obj_has_next>,</#if>
</#list>
]
}

这里我要获取文档的参数,这里是代码但是不行,是什么问题?

06220015 Wrapped Exception (with status template): 06220002 Error during processing of the template 'The following has evaluated to null or missing: ==> obj [in template "repository/document-script.get.html.ftl" at line 3, column 8] Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)?? The failing instruction: ==> #list obj as Obj [in template "repository/document-script.get.html.ftl" at line 3, column 1]'. 

【问题讨论】:

    标签: javascript java alfresco freemarker


    【解决方案1】:

    您可以先为 JSON 对象创建一个类,然后执行以下操作:

    String url = localhost:8080/alfresco/s/get-document-data?nodeRef=workspace://SpacesStore/3b3597e5-b5ec-41d5-b63b-54b050dccd1b&property=cm:name;
    String[] values = url.split('?');
    String[] value = values[0].split('=');
    jsonObject.setNodeRef(value[1]);
    .....
    

    如果您知道您的网址具有您提到的完全相同的参数,这将起作用。只需使用正则表达式。我自己没有测试过代码,试试看吧。

    【讨论】:

    • URL (String url = localhost:8080/alfresco/s/get-document-data?nodeRef=workspace://SpacesStore/3b3597e5-b5ec-41d5-b63b-54b050dccd1b&property=cm:name; ) 不能在代码中拼出,必须在浏览器的地址栏中输入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 2019-02-19
    • 2023-04-02
    相关资源
    最近更新 更多