1 17 package org.alfresco.jcr.session; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import javax.jcr.AccessDeniedException; 25 import javax.jcr.InvalidItemStateException; 26 import javax.jcr.InvalidSerializedDataException; 27 import javax.jcr.ItemExistsException; 28 import javax.jcr.NamespaceRegistry; 29 import javax.jcr.NoSuchWorkspaceException; 30 import javax.jcr.PathNotFoundException; 31 import javax.jcr.RepositoryException; 32 import javax.jcr.Session; 33 import javax.jcr.UnsupportedRepositoryOperationException; 34 import javax.jcr.Workspace; 35 import javax.jcr.lock.LockException; 36 import javax.jcr.nodetype.ConstraintViolationException; 37 import javax.jcr.nodetype.NodeTypeManager; 38 import javax.jcr.observation.ObservationManager; 39 import javax.jcr.query.QueryManager; 40 import javax.jcr.version.Version; 41 import javax.jcr.version.VersionException; 42 43 import org.alfresco.jcr.item.ItemResolver; 44 import org.alfresco.jcr.item.JCRPath; 45 import org.alfresco.jcr.query.QueryManagerImpl; 46 import org.alfresco.jcr.util.JCRProxyFactory; 47 import org.alfresco.service.cmr.repository.ChildAssociationRef; 48 import org.alfresco.service.cmr.repository.CopyService; 49 import org.alfresco.service.cmr.repository.NodeRef; 50 import org.alfresco.service.cmr.repository.NodeService; 51 import org.alfresco.service.cmr.repository.Path; 52 import org.alfresco.service.cmr.repository.StoreRef; 53 import org.alfresco.service.namespace.QName; 54 import org.alfresco.util.ParameterCheck; 55 import org.xml.sax.ContentHandler ; 56 57 62 public class WorkspaceImpl implements Workspace 63 { 64 65 private SessionImpl session; 66 private Workspace proxy = null; 67 private QueryManagerImpl queryManager = null; 68 69 74 public WorkspaceImpl(SessionImpl session) 75 { 76 this.session = session; 77 } 78 79 84 public Workspace getProxy() 85 { 86 if (proxy == null) 87 { 88 proxy = (Workspace)JCRProxyFactory.create(this, Workspace.class, session); 89 } 90 return proxy; 91 } 92 93 94 97 public Session getSession() 98 { 99 return session.getProxy(); 100 } 101 102 105 public String getName() 106 { 107 return session.getWorkspaceStore().getIdentifier(); 108 } 109 110 113 public void copy(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException 114 { 115 ParameterCheck.mandatoryString("srcAbsPath", srcAbsPath); 116 ParameterCheck.mandatoryString("destAbsPath", destAbsPath); 117 118 NodeService nodeService = session.getRepositoryImpl().getServiceRegistry().getNodeService(); 120 NodeRef rootRef = nodeService.getRootNode(session.getWorkspaceStore()); 121 NodeRef sourceRef = ItemResolver.getNodeRef(session, rootRef, srcAbsPath); 122 if (sourceRef == null) 123 { 124 throw new PathNotFoundException("Source path " + srcAbsPath + " cannot be found."); 125 } 126 127 NodeRef destRef = null; 129 QName destName = null; 130 Path destPath = new JCRPath(session.getNamespaceResolver(), destAbsPath).getPath(); 131 if (destPath.size() == 1) 132 { 133 destRef = rootRef; 134 destName = ((JCRPath.SimpleElement)destPath.get(0)).getQName(); 135 } 136 else 137 { 138 Path destParentPath = destPath.subPath(destPath.size() -2); 139 destRef = ItemResolver.getNodeRef(session, rootRef, destParentPath.toPrefixString(session.getNamespaceResolver())); 140 if (destRef == null) 141 { 142 throw new PathNotFoundException("Destination path " + destParentPath + " cannot be found."); 143 } 144 destName = ((JCRPath.SimpleElement)destPath.get(destPath.size() -1)).getQName(); 145 } 146 147 if (destName.getLocalName().indexOf('[') != -1 || destName.getLocalName().indexOf(']') != -1) 150 { 151 throw new RepositoryException("Node name '" + destName + "' is invalid"); 152 } 153 154 ChildAssociationRef childAssocRef = nodeService.getPrimaryParent(sourceRef); 156 157 CopyService copyService = session.getRepositoryImpl().getServiceRegistry().getCopyService(); 159 copyService.copy(sourceRef, destRef, childAssocRef.getTypeQName(), destName); 160 161 session.save(); 163 } 164 165 168 public void copy(String srcWorkspace, String srcAbsPath, String destAbsPath) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException 169 { 170 throw new UnsupportedRepositoryOperationException(); 171 } 172 173 176 public void clone(String srcWorkspace, String srcAbsPath, String destAbsPath, boolean removeExisting) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException 177 { 178 throw new UnsupportedRepositoryOperationException(); 179 } 180 181 184 public void move(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException 185 { 186 session.move(srcAbsPath, destAbsPath); 187 session.save(); 188 } 189 190 193 public void restore(Version[] versions, boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException 194 { 195 throw new UnsupportedRepositoryOperationException(); 196 } 197 198 201 public QueryManager getQueryManager() throws RepositoryException 202 { 203 if (queryManager == null) 204 { 205 queryManager = new QueryManagerImpl(session); 206 } 207 return queryManager; 208 } 209 210 213 public NamespaceRegistry getNamespaceRegistry() throws RepositoryException 214 { 215 return session.getRepositoryImpl().getNamespaceRegistry(); 216 } 217 218 221 public NodeTypeManager getNodeTypeManager() throws RepositoryException 222 { 223 return session.getTypeManager(); 224 } 225 226 229 public ObservationManager getObservationManager() throws UnsupportedRepositoryOperationException, RepositoryException 230 { 231 throw new UnsupportedRepositoryOperationException(); 232 } 233 234 237 public String [] getAccessibleWorkspaceNames() throws RepositoryException 238 { 239 NodeService nodeService = session.getRepositoryImpl().getServiceRegistry().getNodeService(); 240 List <StoreRef> storeRefs = nodeService.getStores(); 241 List <String > workspaceStores = new ArrayList <String >(); 242 for (StoreRef storeRef : storeRefs) 243 { 244 if (storeRef.getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE)) 245 { 246 workspaceStores.add(storeRef.getIdentifier()); 247 } 248 } 249 return workspaceStores.toArray(new String [workspaceStores.size()]); 250 } 251 252 255 public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, AccessDeniedException, RepositoryException 256 { 257 return session.getImportContentHandler(parentAbsPath, uuidBehavior); 258 } 259 260 263 public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException , PathNotFoundException, ItemExistsException, ConstraintViolationException, InvalidSerializedDataException, LockException, AccessDeniedException, RepositoryException 264 { 265 session.importXML(parentAbsPath, in, uuidBehavior); 266 } 267 268 } 269 | Popular Tags |