import java.util.TreeSet;
import javax.jcr.Node;
-import javax.jcr.Repository;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
+import javax.xml.namespace.QName;
import org.argeo.api.acr.Content;
import org.argeo.api.acr.ContentRepository;
-import org.argeo.api.acr.ContentSession;
import org.argeo.api.acr.spi.ProvidedSession;
import org.argeo.api.cms.CmsConstants;
import org.argeo.api.cms.CmsLog;
import org.argeo.app.api.EntityNames;
import org.argeo.app.api.EntityType;
import org.argeo.app.api.RankedObject;
-import org.argeo.app.core.SuiteUtils;
import org.argeo.cms.AbstractCmsApp;
import org.argeo.cms.CmsUserManager;
import org.argeo.cms.LocaleUtils;
import org.argeo.cms.Localized;
+import org.argeo.cms.acr.ContentUtils;
import org.argeo.cms.jcr.CmsJcrUtils;
import org.argeo.cms.jcr.acr.JcrContent;
-import org.argeo.cms.jcr.acr.JcrContentProvider;
import org.argeo.cms.swt.CmsSwtUtils;
import org.argeo.cms.swt.dialogs.CmsFeedback;
import org.argeo.cms.ui.CmsUiProvider;
import org.argeo.cms.ux.CmsUxUtils;
import org.argeo.eclipse.ui.specific.UiContext;
-import org.argeo.jcr.Jcr;
import org.argeo.jcr.JcrException;
import org.argeo.util.LangUtils;
import org.eclipse.swt.SWT;
// ACR
private ContentRepository contentRepository;
- private JcrContentProvider jcrContentProvider;
+// private JcrContentProvider jcrContentProvider;
// JCR
- private Repository repository;
+// private Repository repository;
public void init(Map<String, Object> properties) {
if (log.isDebugEnabled())
throw new IllegalStateException("UI name should not be null");
CmsView cmsView = CmsSwtUtils.getCmsView(ui);
- ContentSession contentSession = CmsUxUtils.getContentSession(contentRepository, cmsView);
+ ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository, cmsView);
CmsUiProvider headerUiProvider = findUiProvider(headerPid);
CmsUiProvider footerUiProvider = findUiProvider(footerPid);
ui.setUserDir(userDir);
// ui.initSessions(getRepository(), publicBasePath);
} else {
- Session adminSession = null;
- try {
- adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), null);
- Node userDirNode = SuiteUtils.getOrCreateCmsSessionNode(adminSession, cmsSession);
- Content userDir = contentSession.get(CmsConstants.SYS_WORKSPACE + userDirNode.getPath());
- ui.setUserDir(userDir);
-// ui.initSessions(getRepository(), userDirNode.getPath());
- } finally {
- Jcr.logout(adminSession);
- }
+// Session adminSession = null;
+// try {
+// adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), null);
+// Node userDirNode = SuiteUtils.getOrCreateCmsSessionNode(adminSession, cmsSession);
+// Content userDir = contentSession.get(CmsConstants.SYS_WORKSPACE + userDirNode.getPath());
+// ui.setUserDir(userDir);
+//// ui.initSessions(getRepository(), userDirNode.getPath());
+// } finally {
+// Jcr.logout(adminSession);
+// }
+ Content userDir = contentSession.getSessionRunDir();
+ ui.setUserDir(userDir);
}
}
initLocale(cmsSession);
private <T> T findByType(Map<String, RankedObject<T>> byType, Content content) {
if (content == null)
throw new IllegalArgumentException("A node should be provided");
-
- if(content instanceof JcrContent) {
- Node context = ((JcrContent)content).getJcrNode();
- try {
- // mixins
- Set<String> types = new TreeSet<>();
- for (NodeType mixinType : context.getMixinNodeTypes()) {
- String mixinTypeName = mixinType.getName();
- if (byType.containsKey(mixinTypeName)) {
- types.add(mixinTypeName);
+
+ if (content instanceof JcrContent) {
+ Node context = ((JcrContent) content).getJcrNode();
+ try {
+ // mixins
+ Set<String> types = new TreeSet<>();
+ for (NodeType mixinType : context.getMixinNodeTypes()) {
+ String mixinTypeName = mixinType.getName();
+ if (byType.containsKey(mixinTypeName)) {
+ types.add(mixinTypeName);
+ }
+ for (NodeType superType : mixinType.getDeclaredSupertypes()) {
+ if (byType.containsKey(superType.getName())) {
+ types.add(superType.getName());
+ }
+ }
}
- for (NodeType superType : mixinType.getDeclaredSupertypes()) {
+ // primary node type
+ NodeType primaryType = context.getPrimaryNodeType();
+ String primaryTypeName = primaryType.getName();
+ if (byType.containsKey(primaryTypeName)) {
+ types.add(primaryTypeName);
+ }
+ for (NodeType superType : primaryType.getDeclaredSupertypes()) {
if (byType.containsKey(superType.getName())) {
types.add(superType.getName());
}
}
- }
- // primary node type
- NodeType primaryType = context.getPrimaryNodeType();
- String primaryTypeName = primaryType.getName();
- if (byType.containsKey(primaryTypeName)) {
- types.add(primaryTypeName);
- }
- for (NodeType superType : primaryType.getDeclaredSupertypes()) {
- if (byType.containsKey(superType.getName())) {
- types.add(superType.getName());
- }
- }
- // entity type
- if (context.isNodeType(EntityType.entity.get())) {
- if (context.hasProperty(EntityNames.ENTITY_TYPE)) {
- String entityTypeName = context.getProperty(EntityNames.ENTITY_TYPE).getString();
- if (byType.containsKey(entityTypeName)) {
- types.add(entityTypeName);
+ // entity type
+ if (context.isNodeType(EntityType.entity.get())) {
+ if (context.hasProperty(EntityNames.ENTITY_TYPE)) {
+ String entityTypeName = context.getProperty(EntityNames.ENTITY_TYPE).getString();
+ if (byType.containsKey(entityTypeName)) {
+ types.add(entityTypeName);
+ }
}
}
- }
// if (context.getPath().equals("/")) {// root node
// types.add("nt:folder");
// }
- if (CmsJcrUtils.isUserHome(context) && byType.containsKey("nt:folder")) {// home node
- types.add("nt:folder");
+ if (CmsJcrUtils.isUserHome(context) && byType.containsKey("nt:folder")) {// home node
+ types.add("nt:folder");
+ }
+
+ if (types.size() == 0)
+ throw new IllegalArgumentException(
+ "No type found for " + context + " (" + listTypes(context) + ")");
+ String type = types.iterator().next();
+ if (!byType.containsKey(type))
+ throw new IllegalArgumentException("No component found for " + context + " with type " + type);
+ return byType.get(type).get();
+ } catch (RepositoryException e) {
+ throw new IllegalStateException(e);
}
+ } else {
+
+ List<QName> objectClasses = content.getTypes();
+ Set<String> types = new TreeSet<>();
+ for (QName cc : objectClasses) {
+ String type = cc.getPrefix() + ":" + cc.getLocalPart();
+ if (byType.containsKey(type))
+ types.add(type);
+ }
if (types.size() == 0)
- throw new IllegalArgumentException("No type found for " + context + " (" + listTypes(context) + ")");
+ throw new IllegalArgumentException("No type found for " + content + " (" + objectClasses + ")");
String type = types.iterator().next();
if (!byType.containsKey(type))
- throw new IllegalArgumentException("No component found for " + context + " with type " + type);
+ throw new IllegalArgumentException("No component found for " + content + " with type " + type);
return byType.get(type).get();
- } catch (RepositoryException e) {
- throw new IllegalStateException(e);
- }
-
- }else {
- throw new UnsupportedOperationException("Content "+content.getClass().getName()+" is not supported.");
+ // throw new UnsupportedOperationException("Content " +
+ // content.getClass().getName() + " is not supported.");
}
}
if (state == null || !state.startsWith("/"))
return null;
- String path=state;
+ String path = state;
// String path = state.substring(1);
// String workspace;
// if (path.equals("")) {
ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository,
ui.getCmsView());
- String path = get(event,SuiteEvent.CONTENT_PATH);
-
+ String path = get(event, SuiteEvent.CONTENT_PATH);
+
// String nodePath = get(event, SuiteEvent.NODE_PATH);
if (path != null && path.equals(HOME_STATE))
return ui.getUserDir();
User user = cmsUserManager.getUser(username);
if (user == null)
return null;
- LdapName userDn;
- try {
- userDn = new LdapName(user.getName());
- } catch (InvalidNameException e) {
- throw new IllegalArgumentException("Badly formatted username", e);
- }
- String userNodePath = SuiteUtils.getUserNodePath(userDn);
+ node = ContentUtils.roleToContent(cmsUserManager, contentSession, user);
+// LdapName userDn;
+// try {
+// userDn = new LdapName(user.getName());
+// } catch (InvalidNameException e) {
+// throw new IllegalArgumentException("Badly formatted username", e);
+// }
+// String userNodePath = SuiteUtils.getUserNodePath(userDn);
// FIXME deal with home path
- return null;
+// return null;
// if (Jcr.itemExists(session, userNodePath))
// node = Jcr.getNode(session, userNodePath);
// else {
this.cmsUserManager = cmsUserManager;
}
- protected Repository getRepository() {
- return repository;
- }
-
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
+// protected Repository getRepository() {
+// return repository;
+// }
+//
+// public void setRepository(Repository repository) {
+// this.repository = repository;
+// }
protected ContentRepository getContentRepository() {
return contentRepository;
this.contentRepository = contentRepository;
}
- public void setJcrContentProvider(JcrContentProvider jcrContentProvider) {
- this.jcrContentProvider = jcrContentProvider;
- }
+// public void setJcrContentProvider(JcrContentProvider jcrContentProvider) {
+// this.jcrContentProvider = jcrContentProvider;
+// }
}