露天 javascript 继承和路径

alfresco javascript inheritance and paths

我正在 javascript 上为 Alfresco 社区编写一个简单的脚本。每次上传新文件时,我都会运行脚本。

我需要检查文件夹中是否存在特定文件名 (label.txt)。如果存在,我将使用文件中包含的信息进行后续处理。

如果我单独设置文件名,只要文件夹本身是分配了脚本的文件夹,它就可以正常工作。

var labelFile = space.childByNamePath("label.txt");
   if (labelFile != null)
   {
   ...
   }

当我将脚本的继承设置为较低级别的文件夹时,脚本会运行但仍会尝试在根文件夹中查找 label.txt 文件。我正在尝试定位上传文档的实际路径:

var dpath = document.displayPath  + "/label.txt";
var labelFile = space.childByNamePath(dpath);
logFile.content += "labelFile: " + labelFile.displayPath + "\r\n";
   if (labelFile != null)
   {
   ...
   }

我在 dpath var 中得到了一条理应正确的路径,但我在文件对象上得到了 NULL 结果,因此我无法读取文件及其内容。

我做错了什么?

那里有什么"space"?尝试使用 "companyhome",请参阅此以获得更多想法。 http://docs.alfresco.com/4.0/references/API-JS-rootscoped.html

The current space ScriptNode (if any). For a script executing from a rule, the space object is the space in which the rule resides. If the rule is inherited, this may not be the expected space.

问题不在于继承,而是 space.childByNamePath 只接受相对路径,而不是绝对路径,所以我要从 space 根计算:

var dpath = document.displayPath;
var dpatharray = dpath.split("/");
var dpathlength = dpatharray.length;
var spath = space.displayPath;
var spatharray = spath.split("/");
var spathlength = spatharray.length;
var labelpath = "";
for (var i=spathlength + 1; i<dpathlength; i++)
{
    labelpath += dpatharray[i] + "/";
}

var labelFile = space.childByNamePath(labelpath + "label.txt");