sessionimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,456 行 · 第 1/4 页
JAVA
1,456 行
/** * Returns the <code>AccessManager</code> associated with this session. * * @return the <code>AccessManager</code> associated with this session */ public AccessManager getAccessManager() { return accessMgr; } /** * Returns the <code>NodeTypeManager</code>. * * @return the <code>NodeTypeManager</code> */ public NodeTypeManagerImpl getNodeTypeManager() { return ntMgr; } /** * Returns the <code>ItemManager</code> of this session. * * @return the <code>ItemManager</code> */ public ItemManager getItemManager() { return itemMgr; } /** * Returns the <code>NamespaceResolver</code> of this session. * * @return the <code>NamespaceResolver</code> of this session */ public NamespaceResolver getNamespaceResolver() { return nsMappings; } /** * Returns the <code>SessionItemStateManager</code> associated with this session. * * @return the <code>SessionItemStateManager</code> associated with this session */ protected SessionItemStateManager getItemStateManager() { return itemStateMgr; } /** * Returns the <code>HierarchyManager</code> associated with this session. * * @return the <code>HierarchyManager</code> associated with this session */ public HierarchyManager getHierarchyManager() { return hierMgr; } /** * Returns the <code>VersionManager</code> associated with this session. * * @return the <code>VersionManager</code> associated with this session */ public VersionManager getVersionManager() { return versionMgr; } /** * Retrieves the referenceable node with the given <code>UUID</code>. * * @param uuid uuid of the node to be retrieved * @return referenceable node with the given uuid * @throws ItemNotFoundException if no node exists with the given uuid or * if the existing node is not referenceable. * @throws RepositoryException if another error occurs. * @see #getNodeByUUID(String) * @see #getNodeById(NodeId) */ public Node getNodeByUUID(UUID uuid) throws ItemNotFoundException, RepositoryException { NodeImpl node = getNodeById(new NodeId(uuid)); // since the uuid of a node is only exposed through jcr:uuid declared // by mix:referenceable it's rather unlikely that a client can possibly // know the internal uuid of a non-referenceable node; omitting the // check for mix:referenceable seems therefore to be a reasonable // compromise in order to improve performance./* if (node.isNodeType(QName.MIX_REFERENCEABLE)) { return node; } else { // there is a node with that uuid but the node does not expose it throw new ItemNotFoundException(uuid.toString()); }*/ return node; } /** * Retrieves the <code>Node</code> with the given id. * * @param id id of node to be retrieved * @return node with the given <code>NodeId</code>. * @throws ItemNotFoundException if no such node exists or if this * <code>Session</code> does not have permission to access the node. * @throws RepositoryException if another error occurs. */ public NodeImpl getNodeById(NodeId id) throws ItemNotFoundException, RepositoryException { // check sanity of this session sanityCheck(); try { return (NodeImpl) getItemManager().getItem(id); } catch (AccessDeniedException ade) { throw new ItemNotFoundException(id.toString()); } } /** * Returns the names of all workspaces of this repository with respect of the * access rights of this session. * * @return the names of all accessible workspaces * @throws RepositoryException if an error occurs */ protected String[] getWorkspaceNames() throws RepositoryException { // filter workspaces according to access rights ArrayList list = new ArrayList(); String[] names = rep.getWorkspaceNames(); for (int i = 0; i < names.length; i++) { try { if (getAccessManager().canAccess(names[i])) { list.add(names[i]); } } catch (NoSuchWorkspaceException nswe) { // should never happen, ignore... } } return (String[]) list.toArray(new String[list.size()]); } /** * Creates a workspace with the given name. * * @param workspaceName name of the new workspace * @throws AccessDeniedException if the current session is not allowed to * create the workspace * @throws RepositoryException if a workspace with the given name * already exists or if another error occurs */ protected void createWorkspace(String workspaceName) throws AccessDeniedException, RepositoryException { // @todo verify that this session has the right privileges for this operation rep.createWorkspace(workspaceName); } /** * Creates a workspace with the given name and a workspace configuration * template. * * @param workspaceName name of the new workspace * @param configTemplate the configuration template of the new workspace * @throws AccessDeniedException if the current session is not allowed to * create the workspace * @throws RepositoryException if a workspace with the given name already * exists or if another error occurs */ protected void createWorkspace(String workspaceName, InputSource configTemplate) throws AccessDeniedException, RepositoryException { // @todo verify that this session has the right privileges for this operation rep.createWorkspace(workspaceName, configTemplate); } /** * Notify the listeners that this session is about to be closed. */ protected void notifyLoggingOut() { // copy listeners to array to avoid ConcurrentModificationException SessionListener[] la = (SessionListener[]) listeners.values().toArray( new SessionListener[listeners.size()]); for (int i = 0; i < la.length; i++) { if (la[i] != null) { la[i].loggingOut(this); } } } /** * Notify the listeners that this session has been closed. */ protected void notifyLoggedOut() { // copy listeners to array to avoid ConcurrentModificationException SessionListener[] la = (SessionListener[]) listeners.values().toArray( new SessionListener[listeners.size()]); for (int i = 0; i < la.length; i++) { if (la[i] != null) { la[i].loggedOut(this); } } } /** * Add a <code>SessionListener</code> * * @param listener the new listener to be informed on modifications */ public void addListener(SessionListener listener) { if (!listeners.containsKey(listener)) { listeners.put(listener, listener); } } /** * Remove a <code>SessionListener</code> * * @param listener an existing listener */ public void removeListener(SessionListener listener) { listeners.remove(listener); } //--------------------------------------------------------< NameResolver > public String getJCRName(QName name) throws NamespaceException { return nsMappings.getNameResolver().getJCRName(name); } public QName getQName(String name) throws NameException, NamespaceException { return nsMappings.getNameResolver().getQName(name); } //--------------------------------------------------------< PathResolver > public String getJCRPath(Path path) throws NamespaceException { return nsMappings.getPathResolver().getJCRPath(path); } public Path getQPath(String path) throws NameException, NamespaceException { return nsMappings.getPathResolver().getQPath(path); } //--------------------------------------------------------------< Session > /** * {@inheritDoc} */ public void checkPermission(String absPath, String actions) throws AccessControlException, RepositoryException { // check sanity of this session sanityCheck(); // build the set of actions to be checked String[] strings = actions.split(","); HashSet set = new HashSet(); for (int i = 0; i < strings.length; i++) { set.add(strings[i]); } Path targetPath; try { targetPath = getQPath(absPath).getNormalizedPath(); } catch (NameException e) { String msg = "invalid path: " + absPath; log.debug(msg, e); throw new RepositoryException(msg, e); } if (!targetPath.isAbsolute()) { throw new RepositoryException("not an absolute path: " + absPath); } ItemId targetId = null; /** * "read" action: * requires READ permission on target item */ if (set.contains(READ_ACTION)) { try { targetId = hierMgr.resolvePath(targetPath); if (targetId == null) { // target does not exist, throw exception throw new AccessControlException(READ_ACTION); } accessMgr.checkPermission(targetId, AccessManager.READ); } catch (AccessDeniedException re) { // otherwise the RepositoryException catch clause will // log a warn message, which is not appropriate in this case. throw new AccessControlException(READ_ACTION); } } Path parentPath = null; ItemId parentId = null; /** * "add_node" action: * requires WRITE permission on parent item */ if (set.contains(ADD_NODE_ACTION)) { try { parentPath = targetPath.getAncestor(1); parentId = hierMgr.resolvePath(parentPath); if (parentId == null) { // parent does not exist (i.e. / was specified), throw exception throw new AccessControlException(ADD_NODE_ACTION); } accessMgr.checkPermission(parentId, AccessManager.WRITE); } catch (AccessDeniedException re) { // otherwise the RepositoryException catch clause will // log a warn message, which is not appropriate in this case. throw new AccessControlException(ADD_NODE_ACTION); } } /** * "remove" action: * requires REMOVE permission on target item */ if (set.contains(REMOVE_ACTION)) { try { if (targetId == null) { targetId = hierMgr.resolvePath(targetPath); if (targetId == null) { // parent does not exist, throw exception throw new AccessControlException(REMOVE_ACTION); } } accessMgr.checkPermission(targetId, AccessManager.REMOVE); } catch (AccessDeniedException re) { // otherwise the RepositoryException catch clause will // log a warn message, which is not appropriate in this case. throw new AccessControlException(REMOVE_ACTION); } } /** * "set_property" action: * requires WRITE permission on parent item if property is going to be * added or WRITE permission on target item if property is going to be * modified */ if (set.contains(SET_PROPERTY_ACTION)) { try { if (targetId == null) { targetId = hierMgr.resolvePath(targetPath); if (targetId == null) { // property does not exist yet, // check WRITE permission on parent if (parentPath == null) { parentPath = targetPath.getAncestor(1); } if (parentId == null) { parentId = hierMgr.resolvePath(parentPath); if (parentId == null) { // parent does not exist, throw exception throw new AccessControlException(SET_PROPERTY_ACTION); } } accessMgr.checkPermission(parentId, AccessManager.WRITE); } else { // property does already exist, // check WRITE permission on target accessMgr.checkPermission(targetId, AccessManager.WRITE); } } } catch (AccessDeniedException re) { // otherwise the RepositoryException catch clause will
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?