连接到存储库Hippo cms

时间:2015-02-18 12:12:35

标签: jcr hippocms

我还在尝试访问存储库以添加新用户。我的组件连接到侧面,我在FormMap中拥有所有需要的值。

问题是我不知道该怎么做。在我的上一个问题Registration users in Hippo cms我得到了答案,我需要将组件连接到/ hippo:configuration / hippo:users。

怎么办?

这是我的实际组成部分:

package org.example.components;
import javax.jcr.Session;

import org.hippoecm.hst.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.core.component.HstComponentException;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.component.support.forms.FormMap;
import org.hippoecm.hst.component.support.forms.FormUtils;
import org.hippoecm.hst.component.support.forms.FormField;
import org.hippoecm.hst.content.annotations.Persistable;
import org.hippoecm.hst.content.beans.Node;
import org.hippoecm.hst.content.beans.standard.HippoFolderBean;


public class SignUpComponent extends BaseHstComponent {

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
}

@Persistable
@Override
public void doAction(HstRequest request, HstResponse response) throws HstComponentException {
    FormMap map = new FormMap(request, new String[]{"username","email","password"});
    FormField username = map.getField("username");
    FormField password = map.getField("password");
    FormField email = map.getField("email");

    try {
        // NOTE: This session will be logged out automatically in the normal HST request processing thread.
        Session persistableSession = request.getRequestContext().getSession();
    } catch (Exception e) {

    }
    Node users = persistableSession.getNode("/hippo:configuration/hippo:users");

}

尽管导入节点不起作用

error: cannot find symbol

我也试过

Node users = getSiteContentBaseBean(request).getNode().getSession().getRootNode().getNode("/hippo:configuration/hippo:users"); 

1 个答案:

答案 0 :(得分:1)

对于对文档的持久更改,以下代码可以正常工作。我已经根据你的例子对它进行了修改。

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.hippoecm.hst.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.core.component.HstComponentException;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.repository.api.HippoNodeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PersistenceExampleComponent extends BaseHstComponent {

    public static final Logger log = LoggerFactory.getLogger(PersistenceExampleComponent.class);
    public static final String USERS_PATH = "/hippo:configuration/hippo:users";

    @Override
    public void doAction(final HstRequest request, final HstResponse response) throws HstComponentException {
        Session writableSession = null;
        try {
            writableSession = this.getPersistableSession(request);
            Node usersNode = writableSession.getRootNode().getNode(USERS_PATH);
            final Node someusername = usersNode.addNode("someusername", HippoNodeType.NT_USER);
            writableSession.save();
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        } finally {
            if(writableSession != null) {
                writableSession.logout();
            }
        }
    }
}

现在您需要注意,默认情况下,站点连接到存储库的用户可能没有正确的权限来写入此文件夹。您可能需要阅读Access rights page for HST based writes,如果这还不够,您将需要了解repository security and it's domains的概念,以更改现有域以满足您的需求。

您还可以查看follow code snippet,它是如何将组件中的信息存储到存储库中的示例。

相关问题