workspaceimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 776 行 · 第 1/2 页
JAVA
776 行
// to 'this' workspace at destAbsPath SessionImpl srcSession = null; try { // create session on other workspace for current subject // (may throw NoSuchWorkspaceException and AccessDeniedException) srcSession = rep.createSession(session.getSubject(), srcWorkspace); WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace(); // do cross-workspace copy int mode = BatchedItemOperations.CLONE; if (removeExisting) { mode = BatchedItemOperations.CLONE_REMOVE_EXISTING; } internalCopy(srcAbsPath, srcWsp, destAbsPath, mode); } finally { if (srcSession != null) { // we don't need the other session anymore, logout srcSession.logout(); } } } /** * {@inheritDoc} */ public void copy(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { // check state of this instance sanityCheck(); // do intra-workspace copy internalCopy(srcAbsPath, this, destAbsPath, BatchedItemOperations.COPY); } /** * {@inheritDoc} */ public void copy(String srcWorkspace, String srcAbsPath, String destAbsPath) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { // check state of this instance sanityCheck(); // check workspace name if (getName().equals(srcWorkspace)) { // same as current workspace, delegate to intra-workspace copy method copy(srcAbsPath, destAbsPath); return; } // check authorization for specified workspace if (!session.getAccessManager().canAccess(srcWorkspace)) { throw new AccessDeniedException("not authorized to access " + srcWorkspace); } // copy (i.e. pull) subtree at srcAbsPath from srcWorkspace // to 'this' workspace at destAbsPath SessionImpl srcSession = null; try { // create session on other workspace for current subject // (may throw NoSuchWorkspaceException and AccessDeniedException) srcSession = rep.createSession(session.getSubject(), srcWorkspace); WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace(); // do cross-workspace copy internalCopy(srcAbsPath, srcWsp, destAbsPath, BatchedItemOperations.COPY); } finally { if (srcSession != null) { // we don't need the other session anymore, logout srcSession.logout(); } } } /** * {@inheritDoc} */ public void move(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { // check state of this instance sanityCheck(); // intra-workspace move... Path srcPath; try { srcPath = session.getQPath(srcAbsPath).getNormalizedPath(); } catch (NameException e) { String msg = "invalid path: " + srcAbsPath; log.debug(msg); throw new RepositoryException(msg, e); } if (!srcPath.isAbsolute()) { throw new RepositoryException("not an absolute path: " + srcAbsPath); } Path destPath; try { destPath = session.getQPath(destAbsPath).getNormalizedPath(); } catch (NameException e) { String msg = "invalid path: " + destAbsPath; log.debug(msg); throw new RepositoryException(msg, e); } if (!destPath.isAbsolute()) { throw new RepositoryException("not an absolute path: " + destAbsPath); } BatchedItemOperations ops = new BatchedItemOperations( stateMgr, rep.getNodeTypeRegistry(), session.getLockManager(), session, hierMgr); try { ops.edit(); } catch (IllegalStateException e) { String msg = "unable to start edit operation"; log.debug(msg); throw new RepositoryException(msg, e); } boolean succeeded = false; try { ops.move(srcPath, destPath); ops.update(); succeeded = true; } finally { if (!succeeded) { // update operation failed, cancel all modifications ops.cancel(); } } } /** * Returns the observation manager of this session. The observation manager * is lazily created if it does not exist yet. * * @return the observation manager of this session * @throws RepositoryException if a repository error occurs */ public ObservationManager getObservationManager() throws RepositoryException { // check state of this instance sanityCheck(); if (obsMgr == null) { try { obsMgr = new ObservationManagerImpl( rep.getObservationDispatcher(wspConfig.getName()), session, session.getItemManager()); } catch (NoSuchWorkspaceException nswe) { // should never get here String msg = "internal error: failed to instantiate observation manager"; log.debug(msg); throw new RepositoryException(msg, nswe); } } return obsMgr; } /** * {@inheritDoc} */ public synchronized QueryManager getQueryManager() throws RepositoryException { // check state of this instance sanityCheck(); if (queryManager == null) { SearchManager searchManager; try { searchManager = rep.getSearchManager(wspConfig.getName()); if (searchManager == null) { String msg = "no search manager configured for this workspace"; log.debug(msg); throw new RepositoryException(msg); } } catch (NoSuchWorkspaceException nswe) { // should never get here String msg = "internal error: failed to instantiate query manager"; log.debug(msg); throw new RepositoryException(msg, nswe); } queryManager = new QueryManagerImpl(session, session.getItemManager(), searchManager); } return queryManager; } /** * {@inheritDoc} */ public void restore(Version[] versions, boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException { // todo: perform restore operations direct on the node states // check state of this instance sanityCheck(); // add all versions to map of versions to restore final HashMap toRestore = new HashMap(); for (int i = 0; i < versions.length; i++) { VersionImpl v = (VersionImpl) versions[i]; VersionHistory vh = v.getContainingHistory(); // check for collision if (toRestore.containsKey(vh.getUUID())) { throw new VersionException("Unable to restore. Two or more versions have same version history."); } toRestore.put(vh.getUUID(), v); } // create a version selector to the set of versions VersionSelector vsel = new VersionSelector() { public Version select(VersionHistory versionHistory) throws RepositoryException { // try to select version as specified Version v = (Version) toRestore.get(versionHistory.getUUID()); if (v == null) { // select latest one v = DateVersionSelector.selectByDate(versionHistory, null); } return v; } }; // check for pending changes if (session.hasPendingChanges()) { String msg = "Unable to restore version. Session has pending changes."; log.debug(msg); throw new InvalidItemStateException(msg); } try { // now restore all versions that have a node in the ws int numRestored = 0; while (toRestore.size() > 0) { Version[] restored = null; Iterator iter = toRestore.values().iterator(); while (iter.hasNext()) { VersionImpl v = (VersionImpl) iter.next(); try { NodeImpl node = (NodeImpl) session.getNodeByUUID(v.getFrozenNode().getFrozenUUID()); restored = node.internalRestore(v, vsel, removeExisting); // remove restored versions from set for (int i = 0; i < restored.length; i++) { toRestore.remove(restored[i].getContainingHistory().getUUID()); } numRestored += restored.length; break; } catch (ItemNotFoundException e) { // ignore } } if (restored == null) { if (numRestored == 0) { throw new VersionException("Unable to restore. At least one version needs" + " existing versionable node in workspace."); } else { throw new VersionException("Unable to restore. All versions with non" + " existing versionable nodes need parent."); } } } } catch (RepositoryException e) { // revert session try { log.error("reverting changes applied during restore..."); session.refresh(false); } catch (RepositoryException e1) { // ignore this } throw e; } session.save(); } /** * {@inheritDoc} */ public String[] getAccessibleWorkspaceNames() throws RepositoryException { // check state of this instance sanityCheck(); return session.getWorkspaceNames(); } /** * {@inheritDoc} */ public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException { // check state of this instance sanityCheck(); Path parentPath; try { parentPath = session.getQPath(parentAbsPath).getNormalizedPath(); } catch (NameException e) { String msg = "invalid path: " + parentAbsPath; log.debug(msg); throw new RepositoryException(msg, e); } if (!parentPath.isAbsolute()) { throw new RepositoryException("not an absolute path: " + parentAbsPath); } Importer importer = new WorkspaceImporter(parentPath, this, rep.getNodeTypeRegistry(), uuidBehavior); return new ImportHandler(importer, session.getNamespaceResolver(), rep.getNamespaceRegistry()); } /** * {@inheritDoc} */ public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, InvalidSerializedDataException, LockException, RepositoryException { ImportHandler handler = (ImportHandler) getImportContentHandler(parentAbsPath, uuidBehavior); try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setFeature( "http://xml.org/sax/features/namespace-prefixes", false); SAXParser parser = factory.newSAXParser(); parser.parse(new InputSource(in), handler); } catch (SAXException se) { // check for wrapped repository exception Exception e = se.getException(); if (e != null && e instanceof RepositoryException) { throw (RepositoryException) e; } else { String msg = "failed to parse XML stream"; log.debug(msg); throw new InvalidSerializedDataException(msg, se); } } catch (ParserConfigurationException e) { throw new RepositoryException("SAX parser configuration error", e); } } /** * Create the persistent item state manager on top of the shared item * state manager. May be overridden by subclasses. * @param shared shared item state manager * @return local item state manager */ protected LocalItemStateManager createItemStateManager(SharedItemStateManager shared) { return new LocalItemStateManager(shared, this, rep.getItemStateCacheFactory()); } //------------------------------------------< EventStateCollectionFactory > /** * {@inheritDoc} * <p/> * Implemented in this object and forwarded rather than {@link #obsMgr} * since creation of the latter is lazy. */ public EventStateCollection createEventStateCollection() throws RepositoryException { return ((ObservationManagerImpl) getObservationManager()).createEventStateCollection(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?