📄 abstractitemresource.java
字号:
} } /** * Copies the underlying repository item to the indicated destination. If * the locator of the specified destination resource indicates a different * workspace, {@link Workspace#copy(String, String, String)} is used to perform * the copy operation, {@link Workspace#copy(String, String)} otherwise. * <p/> * Note, that this implementation does not support shallow copy. * * @param destination * @param shallow * @throws DavException * @see DavResource#copy(DavResource, boolean) * @see Workspace#copy(String, String) * @see Workspace#copy(String, String, String) */ public void copy(DavResource destination, boolean shallow) throws DavException { if (!exists()) { throw new DavException(DavServletResponse.SC_NOT_FOUND); } // TODO: support shallow and deep copy is required by RFC 2518 if (shallow) { throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy."); } try { String itemPath = getLocator().getRepositoryPath(); String destItemPath = destination.getLocator().getRepositoryPath(); Workspace workspace = getRepositorySession().getWorkspace(); if (getLocator().isSameWorkspace(destination.getLocator())) { workspace.copy(itemPath, destItemPath); } else { log.error("Copy between workspaces is not yet implemented (src: '" + getHref() + "', dest: '" + destination.getHref() + "')"); throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED); } } catch (PathNotFoundException e) { // according to RFC 2518, should not occur throw new DavException(DavServletResponse.SC_NOT_FOUND, e.getMessage()); } catch (RepositoryException e) { throw new JcrDavException(e); } } //--------------------------------------< ObservationResource interface >--- /** * @see ObservationResource#init(SubscriptionManager) */ public void init(SubscriptionManager subsMgr) { this.subsMgr = subsMgr; } /** * @see ObservationResource#subscribe(org.apache.jackrabbit.webdav.observation.SubscriptionInfo, String) * @see SubscriptionManager#subscribe(org.apache.jackrabbit.webdav.observation.SubscriptionInfo, String, org.apache.jackrabbit.webdav.observation.ObservationResource) */ public Subscription subscribe(SubscriptionInfo info, String subscriptionId) throws DavException { return subsMgr.subscribe(info, subscriptionId, this); } /** * @see ObservationResource#unsubscribe(String) * @see SubscriptionManager#unsubscribe(String, org.apache.jackrabbit.webdav.observation.ObservationResource) */ public void unsubscribe(String subscriptionId) throws DavException { subsMgr.unsubscribe(subscriptionId, this); } /** * @see ObservationResource#poll(String, long) * @see SubscriptionManager#poll(String, long, org.apache.jackrabbit.webdav.observation.ObservationResource) */ public EventDiscovery poll(String subscriptionId, long timeout) throws DavException { return subsMgr.poll(subscriptionId, timeout, this); } //-------------------------------------------------------------------------- /** * Initialize the {@link org.apache.jackrabbit.webdav.lock.SupportedLock} property * with entries that are valid for any type item resources. * * @see org.apache.jackrabbit.webdav.lock.SupportedLock * @see org.apache.jackrabbit.webdav.transaction.TxLockEntry * @see AbstractResource#initLockSupport() */ protected void initLockSupport() { if (exists()) { // add supportedlock entries for local and eventually for global transaction locks supportedLock.addEntry(new TxLockEntry(true)); supportedLock.addEntry(new TxLockEntry(false)); } } /** * Fill the property set for this resource. */ protected void initProperties() { super.initProperties(); if (exists()) { try { properties.add(new DefaultDavProperty(JCR_NAME, item.getName())); properties.add(new DefaultDavProperty(JCR_PATH, item.getPath())); properties.add(new DefaultDavProperty(JCR_DEPTH, String.valueOf(item.getDepth()))); // add href-property for the items parent unless its the root item if (item.getDepth() > 0) { String parentHref = getLocatorFromItem(item.getParent()).getHref(true); properties.add(new HrefProperty(JCR_PARENT, parentHref, false)); } // protected 'definition' property revealing the item definition ItemDefinitionImpl val; if (item.isNode()) { val = NodeDefinitionImpl.create(((Node)item).getDefinition()); } else { val = PropertyDefinitionImpl.create(((Property)item).getDefinition()); } properties.add(new DefaultDavProperty(JCR_DEFINITION, val, true)); } catch (RepositoryException e) { // should not get here log.error("Error while accessing jcr properties: " + e.getMessage()); } // transaction resource additional protected properties if (item.isNew()) { properties.add(new DefaultDavProperty(JCR_ISNEW, null, true)); } else if (item.isModified()) { properties.add(new DefaultDavProperty(JCR_ISMODIFIED, null, true)); } } // observation resource SubscriptionDiscovery subsDiscovery = subsMgr.getSubscriptionDiscovery(this); properties.add(subsDiscovery); // TODO complete set of properties defined by RFC 3744 Privilege[] allPrivs = new Privilege[] {PRIVILEGE_JCR_READ, PRIVILEGE_JCR_ADD_NODE, PRIVILEGE_JCR_SET_PROPERTY, PRIVILEGE_JCR_REMOVE}; List currentPrivs = new ArrayList(); for (int i = 0; i < allPrivs.length; i++) { try { getRepositorySession().checkPermission(getLocator().getRepositoryPath(), allPrivs[i].getName()); currentPrivs.add(allPrivs[i]); } catch (AccessControlException e) { // ignore log.debug(e.toString()); } catch (RepositoryException e) { // ignore log.debug(e.toString()); } } properties.add(new CurrentUserPrivilegeSetProperty((Privilege[])currentPrivs.toArray(new Privilege[currentPrivs.size()]))); } /** * @return href of the workspace or <code>null</code> if this resource * does not represent a repository item. * * @see AbstractResource#getWorkspaceHref() */ protected String getWorkspaceHref() { String workspaceHref = null; DavResourceLocator locator = getLocator(); if (locator != null && locator.getWorkspacePath() != null) { String wspPath = locator.getWorkspacePath(); DavResourceLocator wspLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), wspPath, wspPath); workspaceHref = wspLocator.getHref(true); } log.debug(workspaceHref); return workspaceHref; } /** * If this resource exists but does not contain a transaction id, complete * will try to persist any modifications present on the underlying * repository item. * * @throws DavException if calling {@link Item#save()} fails */ void complete() throws DavException { if (exists() && getTransactionId() == null) { try { if (item.isModified()) { item.save(); } } catch (RepositoryException e) { // this includes LockException, ConstraintViolationException etc. not detected before log.error("Error while completing request: " + e.getMessage() +" -> reverting changes."); try { item.refresh(false); } catch (RepositoryException re) { log.error("Error while reverting changes: " + re.getMessage()); } throw new JcrDavException(e); } } } /** * Retrieves the last segment of the given path and removes the index if * present. * * @param itemPath * @return valid jcr item name */ protected static String getItemName(String itemPath) { if (itemPath == null) { throw new IllegalArgumentException("Cannot retrieve name from a 'null' item path."); } // retrieve the last part of the path String name = Text.getName(itemPath); // remove index if (name.endsWith("]")) { name = name.substring(0, name.lastIndexOf('[')); } return name; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -