连接到存储库 Hippo cms
Connection to repository Hippo cms
我仍在尝试访问存储库以添加新用户。我的组件连接到侧面,我在 FormMap 中拥有所有需要的值。
问题是我不知道该怎么做。在我的最后一个问题 中,我得到的答案是我需要将组件连接到 /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");
对于持久化文档更改,以下代码有效。我已经针对您的示例对其进行了一些修改。
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 and if that's not enough you will need to learn the concept of repository security and it's domains 来更改现有域以满足您的需求。
您可能还想看一下 follow code snippet,这是一个如何将信息从组件存储到存储库的示例。
我仍在尝试访问存储库以添加新用户。我的组件连接到侧面,我在 FormMap 中拥有所有需要的值。
问题是我不知道该怎么做。在我的最后一个问题
怎么办?
这是我的实际组件:
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");
对于持久化文档更改,以下代码有效。我已经针对您的示例对其进行了一些修改。
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 and if that's not enough you will need to learn the concept of repository security and it's domains 来更改现有域以满足您的需求。
您可能还想看一下 follow code snippet,这是一个如何将信息从组件存储到存储库的示例。