⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 versioncontrolleditemcollection.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public void uncheckout() throws DavException {        throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);    }    /**     * Perform an update on this resource. Depending on the format of the <code>updateInfo</code>     * this is translated to one of the following methods defined by the JCR API:     * <ul>     * <li>{@link Node#restore(javax.jcr.version.Version, boolean)}</li>     * <li>{@link Node#restore(javax.jcr.version.Version, String, boolean)}</li>     * <li>{@link Node#restoreByLabel(String, boolean)}</li>     * <li>{@link Node#update(String)}</li>     * </ul>     * </p>     * Limitation: note that the <code>MultiStatus</code> returned by this method     * will not list any nodes that have been removed due to an Uuid conflict.     *     * @param updateInfo     * @return     * @throws org.apache.jackrabbit.webdav.DavException     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#update(org.apache.jackrabbit.webdav.version.UpdateInfo)     */    //TODO: with jcr the node must not be versionable in order to perform Node.update.    public MultiStatus update(UpdateInfo updateInfo) throws DavException {        if (updateInfo == null) {            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid update request body required.");        }        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        MultiStatus ms = new MultiStatus();        try {            Node node = (Node)item;            Element udElem = updateInfo.getUpdateElement();            boolean removeExisting = DomUtil.hasChildElement(udElem, XML_REMOVEEXISTING, NAMESPACE);            // register eventListener in order to be able to report the modified resources.            EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);            registerEventListener(el, node.getPath());            // perform the update/restore according to the update info            if (updateInfo.getVersionHref() != null) {                String[] hrefs = updateInfo.getVersionHref();                if (hrefs.length != 1) {                    throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body missing version href or containing multiple version hrefs.");                }                String versionPath = getLocatorFromHref(hrefs[0]).getRepositoryPath();                String versionName = getItemName(versionPath);                String relPath = DomUtil.getChildText(udElem, XML_RELPATH, NAMESPACE);                if (relPath == null) {                    // restore version by name                    node.restore(versionName, removeExisting);                } else {                    Version v = node.getVersionHistory().getVersion(versionName);                    node.restore(v, relPath, removeExisting);                }            } else if (updateInfo.getLabelName() != null) {                String[] labels = updateInfo.getLabelName();                if (labels.length != 1) {                    throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body: Multiple labels specified.");                }                node.restoreByLabel(labels[0], removeExisting);            } else if (updateInfo.getWorkspaceHref() != null) {                String workspaceName = getLocatorFromHref(updateInfo.getWorkspaceHref()).getWorkspaceName();                node.update(workspaceName);            } else {                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body.");            }            // unregister the event listener again            unregisterEventListener(el);        } catch (RepositoryException e) {            throw new JcrDavException(e);        }        return ms;    }    /**     * Merge the repository node represented by this resource according to the     * information present in the given {@link MergeInfo} object.     *     * @param mergeInfo     * @return <code>MultiStatus</code> recording all repository items modified     * by this merge call as well as the resources that a client must modify to     * complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)     * @throws org.apache.jackrabbit.webdav.DavException     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)     * @see Node#merge(String, boolean)     */    //TODO: with jcr the node must not be versionable in order to perform Node.merge    public MultiStatus merge(MergeInfo mergeInfo) throws DavException {        if (mergeInfo == null) {            throw new DavException(DavServletResponse.SC_BAD_REQUEST);        }        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        MultiStatus ms = new MultiStatus();        try {            Node node = (Node)item;            // register eventListener in order to be able to report all            // modified resources.            EventListener el = new EListener(mergeInfo.getPropertyNameSet(), ms);            registerEventListener(el, node.getPath());            // todo: RFC allows multiple href elements inside the DAV:source element            String workspaceName = getLocatorFromHref(mergeInfo.getSourceHrefs()[0]).getWorkspaceName();            NodeIterator failed = node.merge(workspaceName, !mergeInfo.isNoAutoMerge());            // unregister the event listener again            unregisterEventListener(el);            // add resources to the multistatus, that failed to be merged            while (failed.hasNext()) {                Node failedNode = failed.nextNode();                DavResourceLocator loc = getLocatorFromItem(failedNode);                DavResource res = createResourceFromLocator(loc);                ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));            }        } catch (RepositoryException e) {            throw new JcrDavException(e);        }        return ms;    }    /**     * Modify the labels present with the versions of this resource.     *     * @param labelInfo     * @throws DavException     * @see VersionHistory#addVersionLabel(String, String, boolean)     * @see VersionHistory#removeVersionLabel(String)     */    public void label(LabelInfo labelInfo) throws DavException {        if (labelInfo == null) {            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid label request body required.");        }        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        try {            if (!isVersionControlled() || ((Node)item).isCheckedOut()) {                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "A LABEL request may only be applied to a version-controlled, checked-in resource.");            }            DavResource[] resArr = this.getReferenceResources(CHECKED_IN);            if (resArr.length == 1 && resArr[0] instanceof VersionResource) {                ((VersionResource)resArr[0]).label(labelInfo);            } else {                throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:checked-in property on '" + getHref() + "' did not point to a single VersionResource.");            }        } catch (RepositoryException e) {            throw new JcrDavException(e);        }    }    /**     * Returns the {@link VersionHistory} associated with the repository node.     * If the node is not versionable an exception is thrown.     *     * @return the {@link VersionHistoryResource} associated with this resource.     * @throws org.apache.jackrabbit.webdav.DavException     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()     * @see javax.jcr.Node#getVersionHistory()     */    public VersionHistoryResource getVersionHistory() throws DavException {        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        try {            VersionHistory vh = ((Node)item).getVersionHistory();            DavResourceLocator loc = getLocatorFromItem(vh);            return (VersionHistoryResource) createResourceFromLocator(loc);        } catch (RepositoryException e) {            throw new JcrDavException(e);        }    }    //--------------------------------------------------------------------------    /**     * Define the set of reports supported by this resource.     *     * @see SupportedReportSetProperty     */    protected void initSupportedReports() {        super.initSupportedReports();        if (exists()) {	    supportedReports.addReportType(ReportType.LOCATE_BY_HISTORY);            if (this.isVersionControlled()) {            supportedReports.addReportType(ReportType.VERSION_TREE);	    }                    }    }    /**     * Fill the property set for this resource.     */    protected void initProperties() {        super.initProperties();        if (exists()) {            Node n = (Node)item;            // properties defined by RFC 3253 for version-controlled resources            if (isVersionControlled()) {                // workspace property already set in AbstractResource.initProperties()                try {                    // DAV:version-history (computed)                    String vhHref = getLocatorFromItem(n.getVersionHistory()).getHref(true);                    properties.add(new HrefProperty(VERSION_HISTORY, vhHref, true));                    // DAV:auto-version property: there is no auto version, explicit CHECKOUT is required.                    properties.add(new DefaultDavProperty(AUTO_VERSION, null, false));                    String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);                    if (n.isCheckedOut()) {                        // DAV:checked-out property (protected)                        properties.add(new HrefProperty(CHECKED_OUT, baseVHref, true));                        // DAV:predecessors property                        if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {                            Value[] predec = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();                            addHrefProperty(PREDECESSOR_SET, predec, false);                        }                        // DAV:auto-merge-set property. NOTE: the DAV:merge-set                        // never occurs, because merging without bestEffort flag                        // being set results in an exception on failure.                        if (n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {                            Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();                            addHrefProperty(AUTO_MERGE_SET, mergeFailed, false);                        }                        // todo: checkout-fork, checkin-fork                    } else {                        // DAV:checked-in property (protected)                        properties.add(new HrefProperty(CHECKED_IN, baseVHref, true));                    }                } catch (RepositoryException e) {                    log.error(e.getMessage());                }            }        }    }    /**     * Add a {@link org.apache.jackrabbit.webdav.property.HrefProperty} with the     * specified property name and values.     *     * @param name     * @param values Array of {@link Value}s.     * @param isProtected     * @throws javax.jcr.ValueFormatException     * @throws IllegalStateException     * @throws javax.jcr.RepositoryException     */    private void addHrefProperty(DavPropertyName name, Value[] values,                                 boolean isProtected)            throws ValueFormatException, IllegalStateException, RepositoryException {        Node[] nodes = new Node[values.length];        for (int i = 0; i < values.length; i++) {            nodes[i] = getRepositorySession().getNodeByUUID(values[i].getString());        }        addHrefProperty(name, nodes, isProtected);    }    /**     * @return true, if this resource represents an existing repository node     * that has the mixin nodetype 'mix:versionable' set.     */    private boolean isVersionControlled() {        boolean vc = false;        if (exists()) {            try {                vc = ((Node) item).isNodeType(JcrConstants.MIX_VERSIONABLE);            } catch (RepositoryException e) {                log.warn(e.getMessage());            }        }        return vc;    }    /**     * Build a new locator for the given href.     *      * @param href     * @return     */    private DavResourceLocator getLocatorFromHref(String href) {        DavLocatorFactory f = getLocator().getFactory();        String prefix = getLocator().getPrefix();        return f.createResourceLocator(prefix, href);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -