如何在 Alfresco 的 companyhome 上创建文件夹节点?
我很难找到我的问题的答案。我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对 Java 和 Alfresco 都不熟悉,您可能会发现在 WebScript 中编写 < a href="http://wiki.alfresco.com/wiki/JavaScript_API" rel="nofollow">JavaScript 对您来说是更好的选择。通常更容易上手。还有很多示例可以帮助您。
如果您决定继续使用 Java,Alfresco wiki 中的起点是 Java 支持的 WebScript 和Java 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.
正如所指出的,您可能希望从使用 JavaScript 而不是 Java 开始。另外,我注意到您正在代码中创建一个新的 JSON 对象,但我不确定为什么。
例如,使用 JavaScript,接受要在公司主页下创建的文件夹名称的 Web 脚本可能具有如下所示的控制器:
该代码查找传递给它的名为folderName 的参数,然后使用内置的用于创建新文件夹的“companyhome”根范围变量。然后,它将新创建的文件夹节点传递给模型,以便可以将有关新节点的一些数据回显给用户。
JavaScript 控制器(如上所示)的名称是 createFolder.post.js。我将其签入到数据字典/Web 脚本/示例下的存储库中。除此之外,我还签入了一个名为 createFolder.post.desc.xml 的文件,它是 Web 脚本描述符:
以及一个名为 createFolder.post.html.ftl 的文件,它是 Web 脚本视图的 HTML 版本:
检查后在中,我通过访问 http://localhost:8080/alfresco/s/index 并单击“刷新 Web 脚本”按钮。
然后,我使用 CuRL 调用 Web 脚本,如下所示:
您会注意到我选择让我的 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:
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:
And a file called createFolder.post.html.ftl, which is the HTML version of the web script view:
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:
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