📄 defaultitemcollection.java
字号:
the lock exception thrown by Node.getLock() was circumvented by the init test if there is a lock applied... NOTE: UnsupportedRepositoryOperationException should not occur */ throw new JcrDavException(e); } } else { return super.refreshLock(reqLockInfo, lockToken); } } /** * Remove the write lock from this resource by unlocking the underlying * {@link javax.jcr.Node node}. * * @param lockToken * @throws org.apache.jackrabbit.webdav.DavException * @see org.apache.jackrabbit.webdav.DavResource#unlock(String) * @see javax.jcr.Node#unlock() */ public void unlock(String lockToken) throws DavException { ActiveLock lock = getWriteLock(); if (lock != null && lockToken.equals(lock.getToken())) { try { ((Node) item).unlock(); } catch (RepositoryException e) { throw new JcrDavException(e); } } else { super.unlock(lockToken); } } /** * Returns the write lock present on this resource or <code>null</code> if * no write lock exists. NOTE: that the scope of a write lock may either * be {@link org.apache.jackrabbit.webdav.lock.Scope#EXCLUSIVE} or * {@link ItemResourceConstants#EXCLUSIVE_SESSION}. * * @return write lock or <code>null</code> * @throws DavException if this resource does not represent a repository item. */ private ActiveLock getWriteLock() throws DavException { if (!exists()) { throw new DavException(DavServletResponse.SC_NOT_FOUND, "Unable to retrieve write lock for non existing repository item (" + getResourcePath() + ")"); } ActiveLock writeLock = getLock(Type.WRITE, Scope.EXCLUSIVE); if (writeLock == null) { writeLock = getLock(Type.WRITE, EXCLUSIVE_SESSION); } return writeLock; } //-----------------------------------------< OrderingResource interface >--- /** * Returns true if this resource exists and the nodetype defining the * underlying repository node allow to reorder this nodes children. * * @return true if {@link DefaultItemCollection#orderMembers(OrderPatch)} * can be called on this resource. * @see org.apache.jackrabbit.webdav.ordering.OrderingResource#isOrderable() * @see javax.jcr.nodetype.NodeType#hasOrderableChildNodes() */ public boolean isOrderable() { boolean orderable = false; if (exists()) { try { orderable = ((Node) item).getPrimaryNodeType().hasOrderableChildNodes(); } catch (RepositoryException e) { log.warn(e.getMessage()); } } return orderable; } /** * Reorder the child nodes of the repository item represented by this * resource as indicated by the specified {@link OrderPatch} object. * * @param orderPatch * @throws org.apache.jackrabbit.webdav.DavException * @see org.apache.jackrabbit.webdav.ordering.OrderingResource#orderMembers(org.apache.jackrabbit.webdav.ordering.OrderPatch) * @see Node#orderBefore(String, String) */ public void orderMembers(OrderPatch orderPatch) throws DavException { if (!isOrderable()) { throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED); } // only custom ordering is allowed if (!OrderingConstants.ORDERING_TYPE_CUSTOM.equalsIgnoreCase(orderPatch.getOrderingType())) { throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Only DAV:custom ordering type supported."); } OrderPatch.Member[] instructions = orderPatch.getOrderInstructions(); Node n = (Node)item; try { for (int i = 0; i < instructions.length; i++) { String srcRelPath = Text.unescape(instructions[i].getMemberHandle()); Position pos = instructions[i].getPosition(); String destRelPath = getRelDestinationPath(pos, n.getNodes()); // preform the reordering n.orderBefore(srcRelPath, destRelPath); } complete(); } catch (RepositoryException e) { // UnsupportedRepositoryException should not occur throw new JcrDavException(e); } } /** * Retrieve the relative path of the child node that acts as destination. * A <code>null</code> destination path is used to place the child node indicated * by the source path at the end of the list. * * @param position * @param childNodes * @return the relative path of the child node used as destination or <code>null</code> * if the source node should be placed at the last position. * @throws javax.jcr.RepositoryException */ private String getRelDestinationPath(Position position, NodeIterator childNodes) throws RepositoryException { String destRelPath = null; if (OrderingConstants.XML_FIRST.equals(position.getType())) { if (childNodes.hasNext()) { Node firstChild = childNodes.nextNode(); // use last segment of node-path instead of name. destRelPath = Text.getName(firstChild.getPath()); } // no child nodes available > reordering to 'first' position fails. if (destRelPath == null) { throw new ItemNotFoundException("No 'first' item found for reordering."); } } else if (OrderingConstants.XML_AFTER.equals(position.getType())) { String afterRelPath = position.getSegment(); boolean found = false; // jcr only knows order-before > retrieve the node that follows the // one incidated by the 'afterRelPath'. while (childNodes.hasNext() && destRelPath == null) { // compare to last segment of node-path instead of name. String childRelPath = Text.getName(childNodes.nextNode().getPath()); if (found) { destRelPath = childRelPath; } else { found = afterRelPath.equals(childRelPath); } } } else { // before or last. in the latter case the segmet is 'null' destRelPath = position.getSegment(); } if (destRelPath != null) { destRelPath = Text.unescape(destRelPath); } return destRelPath; } //-------------------------------------------------------------------------- /** * Extend the general {@link AbstractResource#supportedLock} field by * lock entries specific for this resource: write locks (exclusive or * exclusive session-scoped) in case the underlying node has the node * type mix:lockable. * * @see org.apache.jackrabbit.JcrConstants#MIX_LOCKABLE */ protected void initLockSupport() { super.initLockSupport(); // add exclusive write lock if allowed for the given node try { if (exists() && ((Node)item).isNodeType(JcrConstants.MIX_LOCKABLE)) { supportedLock.addEntry(Type.WRITE, Scope.EXCLUSIVE); supportedLock.addEntry(new SessionScopedLockEntry()); } } catch (RepositoryException e) { log.warn(e.getMessage()); } } /** * Defines the additional reports supported by this resource (reports * specific for resources representing a repository {@link Node node}): * <ul> * <li>{@link ExportViewReport export view report}</li> * <li>{@link LocateCorrespondingNodeReport locate corresponding node report}</li> * </ul> * * @see org.apache.jackrabbit.webdav.version.report.SupportedReportSetProperty */ protected void initSupportedReports() { super.initSupportedReports(); if (exists()) { supportedReports.addReportType(ExportViewReport.EXPORTVIEW_REPORT); supportedReports.addReportType(LocateCorrespondingNodeReport.LOCATE_CORRESPONDING_NODE_REPORT); } } /** * Fill the property set for this resource. */ protected void initProperties() { super.initProperties(); if (exists()) { // resource is serialized as system-view (xml) properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, "text/xml")); Node n = (Node)item; // overwrite the default creation date if possible try { if (n.hasProperty(JcrConstants.JCR_CREATED)) { long creationTime = n.getProperty(JcrConstants.JCR_CREATED).getValue().getLong(); properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, DavConstants.creationDateFormat.format(new Date(creationTime)))); } } catch (RepositoryException e) { log.warn("Error while accessing jcr:created property"); } // add node-specific resource properties try { properties.add(new NodeTypeProperty(JCR_PRIMARYNODETYPE, n.getPrimaryNodeType(), false)); properties.add(new NodeTypeProperty(JCR_MIXINNODETYPES, n.getMixinNodeTypes(), false)); properties.add(new DefaultDavProperty(JCR_INDEX, new Integer(n.getIndex()), true)); addHrefProperty(JCR_REFERENCES, n.getReferences(), true); if (n.isNodeType(JcrConstants.MIX_REFERENCEABLE)) { properties.add(new DefaultDavProperty(JCR_UUID, n.getUUID(), true)); } } catch (RepositoryException e) { log.error("Failed to retrieve primary nodetype property: " + e.getMessage()); } try { Item primaryItem = n.getPrimaryItem(); addHrefProperty(JCR_PRIMARYITEM, new Item[] {primaryItem}, true); } catch (ItemNotFoundException e) { log.debug("No primary item present on this node '" + getResourcePath() + "'"); } catch (RepositoryException e) { log.error("Error while retrieving primary item: " + e.getMessage()); } // property defined by RFC 3648: this resource always has custom ordering! if (isOrderable()) { properties.add(new OrderingType(OrderingConstants.ORDERING_TYPE_CUSTOM)); } } } /** * Add a {@link org.apache.jackrabbit.webdav.property.HrefProperty} with the * specified property name and values. Each item present in the specified * values array is referenced in the resulting property. * * @param name * @param values * @param isProtected */ protected void addHrefProperty(DavPropertyName name, Item[] values, boolean isProtected) { if (values == null) { return; } String[] pHref = new String[values.length]; for (int i = 0; i < values.length; i++) { pHref[i] = getLocatorFromItem(values[i]).getHref(true); } properties.add(new HrefProperty(name, pHref, isProtected)); } /** * Add a new {@link HrefProperty href property} to the property set, where * all items present in the specifed iterator are referenced in the * resulting property. * * @param name * @param itemIterator * @param isProtected * @see #addHrefProperty(DavPropertyName, Item[], boolean) */ protected void addHrefProperty(DavPropertyName name, Iterator itemIterator, boolean isProtected) { ArrayList l = new ArrayList(); while (itemIterator.hasNext()) { l.add(itemIterator.next()); } addHrefProperty(name, (Item[]) l.toArray(new Item[l.size()]), isProtected); } /** * Tries to parse the given input stream as xml document and build a * {@link ValuesProperty} out of it. * * @param in * @return values property or 'null' if the given stream cannot be parsed * into an XML document or if build the property fails. */ private ValuesProperty buildValuesProperty(InputStream in) { String errorMsg = "Cannot parse stream into a 'ValuesProperty'."; try { Document reqBody = DomUtil.BUILDER_FACTORY.newDocumentBuilder().parse(in); DavProperty defaultProp = DefaultDavProperty.createFromXml(reqBody.getDocumentElement()); ValuesProperty vp = new ValuesProperty(defaultProp, PropertyType.STRING, getRepositorySession().getValueFactory()); return vp; } catch (IOException e) { log.debug(errorMsg, e); } catch (ParserConfigurationException e) { log.debug(errorMsg, e); } catch (SAXException e) { log.debug(errorMsg, e); } catch (DavException e) { log.debug(errorMsg, e); } catch (RepositoryException e) { log.debug(errorMsg, e); } // cannot parse request body into a 'values' property return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -