在JCR Node中保存数据,我在做什么错? [英] Saving Data in JCR Node, what am I doing wrong?

查看:151
本文介绍了在JCR Node中保存数据,我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功创建并部署了一个接受用户名和密码的bundle(Servlet),现在我想将其保存在/content/mydata/下的JCR Repository中 我收到异常

I have created and deployed a bundle(Servlet) successfully that accepts username and password from user, now I want to save it in JCR Repository under /content/mydata/ I am getting Exception

java.lang.IllegalArgumentException: relPath is not a relative path: {}  {}oliver

这是我的代码

  public class CustomerJCRAccessImp implements CustomerService {
        @Reference
        protected SlingRepository repository;

    protected static final Logger log = LoggerFactory.getLogger(CustomerJCRAccessImp.class);

    public void insertData(String username, String password) throws Exception {

        log.error("Username ::"+username+" Password ::"+password);
        log.error("XXX:: Inside the Service Method");
        Session session=    repository.loginAdministrative(null);
        Node node= session.getRootNode();
        Node contentNode = node.getNode("content");
        //node.i
        Node  myAppNode = contentNode.getNode("myApp");
        log.error("THE VALUE OF myApp NODE ::"+myAppNode);


        Node user = myAppNode.addNode("/"+username);
        user.setProperty("Roll No", "1");
        user.setProperty("Age", "10");
        user.setPrimaryType("nt:unstructured");

        session.save();
        session.logout();




    }
    protected void bindRepository(SlingRepository repository) {
        this.repository = repository; 
    }
}

我通过引用此链接来完成此操作 http://helpx.adobe.com/experience -manager/using/persisting-cq-data-java-content.html 预先感谢.

I have done this by referring this link http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content.html Thanks in Advance.

推荐答案

The relative path parameter for the addNode() method shouldn't start with a "/". Try

Node user = videojetNode.addNode(username);

尽管我同意文档中的" relPath "一词具有误导性,但relPath应该是您要在当前节点下创建的节点的名称,或者应该以子节点的名称,并包含要在其下创建节点的目标节点的相对路径.

Though i agree that the term "relPath" in the docs is quite misleading, the relPath should either be the name of the node you would like to create under the current node or should start with the name of the child node and contains the relative path to the target node under which you want to create your node.

例如.如果当前节点是 content 并且您有以下树

For example. In case the current node is content and you have the following tree

/
|_content
    |_x
       |_y

如果您希望添加一个名为z的节点作为y的子代,则可以将relPath指定为

and if you wish to add a node called z as a child of y, then the relPath can be specified as

Node myNode = contentNode.addNode("x/y/z");

注意:如果任何中间节点不可用,将抛出PathNotFoundException

Note : A PathNotFoundException will be thrown in case any of the intermediary nodes are not available

这篇关于在JCR Node中保存数据,我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆