如何在 Alfresco 的 companyhome 上创建文件夹节点?

发布于 2024-11-17 02:40:16 字数 1097 浏览 3 评论 0原文

我很难找到我的问题的答案。我正在尝试在 Alfresco 中创建一个文件夹/空间。但我没有任何想法这样做?有人可以帮我解决这个问题吗?我正在使用 Java 网页脚本。

我所关心的是:

package org.alfresco.module.demoscripts;

import java.io.IOException;

import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.json.JSONException;
import org.json.JSONObject;

public class SimpleWebScript extends AbstractWebScript
{
    public void execute(WebScriptRequest req, WebScriptResponse res)
        throws IOException
    {
        try
        {
            // build a json object
            JSONObject obj = new JSONObject();

            // put some data on it
            obj.put("field1", "data1");

            // build a JSON string and send it back
            String jsonString = obj.toString();
            res.getWriter().write(jsonString);
        }
        catch(JSONException e)
        {
            throw new WebScriptException("Unable to serialize JSON");
        }
    }    
}

I am having a hard time looking for an answer to my question. I am trying to create a folder/space in Alfresco. But I don't have any idea doing it? Can someone help me with this? I'm using Java webscript.

All I am at is this:

package org.alfresco.module.demoscripts;

import java.io.IOException;

import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.json.JSONException;
import org.json.JSONObject;

public class SimpleWebScript extends AbstractWebScript
{
    public void execute(WebScriptRequest req, WebScriptResponse res)
        throws IOException
    {
        try
        {
            // build a json object
            JSONObject obj = new JSONObject();

            // put some data on it
            obj.put("field1", "data1");

            // build a JSON string and send it back
            String jsonString = obj.toString();
            res.getWriter().write(jsonString);
        }
        catch(JSONException e)
        {
            throw new WebScriptException("Unable to serialize JSON");
        }
    }    
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

⊕婉儿 2024-11-24 02:40:16

如果您对 Java 和 Alfresco 都不熟悉,您可能会发现在 WebScript 中编写 < a href="http://wiki.alfresco.com/wiki/JavaScript_API" rel="nofollow">JavaScript 对您来说是更好的选择。通常更容易上手。还有很多示例可以帮助您。

如果您决定继续使用 Java,Alfresco wiki 中的起点是 Java 支持的 WebScriptJava Foundation API。 Java webscript 示例之一向您展示了如何创建节点(您可以使用 NodeService 或 FileFolderService,具体取决于您想要完全控制还是简单的方法)。

您可能还想查看 Alfresco Wiki 和论坛中有关如何构建数据的一些建议,因为直接在公司主页下创建大量新节点可能是也可能不是您的最佳选择。

If you're new to both Java and Alfresco, you may well find that writing your WebScript in JavaScript is a better bet for you. It's normally easier to get started with. There are lots of examples too to help you.

If you do decide to stick with Java, the starting points in the Alfresco wiki for you are Java Backed WebScripts and the Java Foundation API. One of the Java webscript examples show you how to create nodes (you can use either the NodeService or the FileFolderService, depending on if you want full control or an easy way).

You might also want to look at some of the advice in the Alfresco Wiki and on the forums for how to structure your data, as creating lots of new nodes straight under Company Home may or may not be the best option for you.

泪是无色的血 2024-11-24 02:40:16

正如所指出的,您可能希望从使用 JavaScript 而不是 Java 开始。另外,我注意到您正在代码中创建一个新的 JSON 对象,但我不确定为什么。

例如,使用 JavaScript,接受要在公司主页下创建的文件夹名称的 Web 脚本可能具有如下所示的控制器:

    function main() {
        var folderName = args.folderName;
        if (folderName != null && folderName != "") {
        // continue
        } else {
        status.setCode(500);
        status.setMessage("Missing folder name argument");
        status.setRedirect(true);
        return;
        }

        var createdFolder = companyhome.createFolder(folderName);

        model.createdFolder = createdFolder;
    }

    main();

该代码查找传递给它的名为folderName 的参数,然后使用内置的用于创建新文件夹的“companyhome”根范围变量。然后,它将新创建的文件夹节点传递给模型,以便可以将有关新节点的一些数据回显给用户。

JavaScript 控制器(如上所示)的名称是 createFolder.post.js。我将其签入到数据字典/Web 脚本/示例下的存储库中。除此之外,我还签入了一个名为 createFolder.post.desc.xml 的文件,它是 Web 脚本描述符:

    <webscript>
        <shortname>Create folder example</shortname>
        <description>
        <![CDATA[
        Creates a new folder in Company Home using the name specified in the folderName argument.
        ]]>
        </description>
        <url>/example/createFolder?folderName={folderName}</url>
        <format default="html">argument</format>
        <authentication>user</authentication>
        <transaction>required</transaction>
        <family>Example</family>
    </webscript>

以及一个名为 createFolder.post.html.ftl 的文件,它是 Web 脚本视图的 HTML 版本:

    <html>
    <head>
        <title>Create folder web script</title>
    </head>
    <body>
        Successfully created a folder with the following metadata:<br />
        Name: ${createdFolder.name}<br />
        ID: ${createdFolder.id}<br />
        Noderef: ${createdFolder.nodeRef}<br />
    </body>
    </html>

检查后在中,我通过访问 http://localhost:8080/alfresco/s/index 并单击“刷新 Web 脚本”按钮。

然后,我使用 CuRL 调用 Web 脚本,如下所示:

    curl -uadmin:admin -X POST "http://localhost:8080/alfresco/s/example/createFolder?folderName=foobar"

您会注意到我选择让我的 Web 脚本接受 POST。如果您想使用不同的 HTTP 方法,只需相应地更改文件名即可。

杰夫

As was pointed out, you may want to start by using JavaScript instead of Java. Also, I'm noticing that you are creating a new JSON object in your code, but I'm not sure why.

For example, using JavaScript, a web script that accepts the name of a folder to be created under company home might have a controller that would look like this:

    function main() {
        var folderName = args.folderName;
        if (folderName != null && folderName != "") {
        // continue
        } else {
        status.setCode(500);
        status.setMessage("Missing folder name argument");
        status.setRedirect(true);
        return;
        }

        var createdFolder = companyhome.createFolder(folderName);

        model.createdFolder = createdFolder;
    }

    main();

The code looks for an argument passed to it called folderName and then uses the built-in "companyhome" root scoped variable to create the new folder. It then passes the newly-created folder node to the model so that some data about the new node can be echoed back to the user.

The name of the JavaScript controller (shown above) is createFolder.post.js. I checked it in to the repository under Data Dictionary/Web Scripts/example. Along with that, I checked in a file called createFolder.post.desc.xml, which is the web script descriptor:

    <webscript>
        <shortname>Create folder example</shortname>
        <description>
        <![CDATA[
        Creates a new folder in Company Home using the name specified in the folderName argument.
        ]]>
        </description>
        <url>/example/createFolder?folderName={folderName}</url>
        <format default="html">argument</format>
        <authentication>user</authentication>
        <transaction>required</transaction>
        <family>Example</family>
    </webscript>

And a file called createFolder.post.html.ftl, which is the HTML version of the web script view:

    <html>
    <head>
        <title>Create folder web script</title>
    </head>
    <body>
        Successfully created a folder with the following metadata:<br />
        Name: ${createdFolder.name}<br />
        ID: ${createdFolder.id}<br />
        Noderef: ${createdFolder.nodeRef}<br />
    </body>
    </html>

Once checked in, I refreshed the web script index by going to http://localhost:8080/alfresco/s/index and clicking the "refresh web scripts" button.

I then invoked the web script using CuRL, like this:

    curl -uadmin:admin -X POST "http://localhost:8080/alfresco/s/example/createFolder?folderName=foobar"

You'll notice that I chose to make my web script accept POSTs. If you wanted to use a different HTTP method, you'd simply change the file names accordingly.

Jeff

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文