📄 abstractitemresource.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.jackrabbit.webdav.jcr;import org.apache.jackrabbit.util.Text;import org.apache.jackrabbit.webdav.DavException;import org.apache.jackrabbit.webdav.DavResource;import org.apache.jackrabbit.webdav.DavResourceFactory;import org.apache.jackrabbit.webdav.DavResourceLocator;import org.apache.jackrabbit.webdav.DavServletResponse;import org.apache.jackrabbit.webdav.DavCompliance;import org.apache.jackrabbit.webdav.io.OutputContext;import org.apache.jackrabbit.webdav.observation.ObservationResource;import org.apache.jackrabbit.webdav.observation.SubscriptionManager;import org.apache.jackrabbit.webdav.observation.Subscription;import org.apache.jackrabbit.webdav.observation.SubscriptionInfo;import org.apache.jackrabbit.webdav.observation.EventDiscovery;import org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery;import org.apache.jackrabbit.webdav.jcr.nodetype.ItemDefinitionImpl;import org.apache.jackrabbit.webdav.jcr.nodetype.NodeDefinitionImpl;import org.apache.jackrabbit.webdav.jcr.nodetype.PropertyDefinitionImpl;import org.apache.jackrabbit.webdav.property.DefaultDavProperty;import org.apache.jackrabbit.webdav.property.HrefProperty;import org.apache.jackrabbit.webdav.property.DavProperty;import org.apache.jackrabbit.webdav.property.DavPropertyName;import org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty;import org.apache.jackrabbit.webdav.security.Privilege;import org.apache.jackrabbit.webdav.transaction.TxLockEntry;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import javax.jcr.Item;import javax.jcr.Node;import javax.jcr.PathNotFoundException;import javax.jcr.Property;import javax.jcr.RepositoryException;import javax.jcr.Workspace;import java.security.AccessControlException;import java.util.ArrayList;import java.util.List;import java.io.IOException;/** * <code>AbstractItemResource</code> covers common functionality for the various * resources, that represent a repository item. */abstract class AbstractItemResource extends AbstractResource implements ObservationResource, ItemResourceConstants { private static Logger log = LoggerFactory.getLogger(AbstractItemResource.class); private SubscriptionManager subsMgr; protected final Item item; /** * Create a new <code>AbstractItemResource</code>. * * @param locator * @param session */ AbstractItemResource(DavResourceLocator locator, JcrDavSession session, DavResourceFactory factory, Item item) { super(locator, session, factory); this.item = item; // initialize the supported locks and reports initLockSupport(); initSupportedReports(); } //----------------------------------------------< DavResource interface >--- /** * @see org.apache.jackrabbit.webdav.DavResource#getComplianceClass() */ public String getComplianceClass() { String cc = super.getComplianceClass() + "," + DavCompliance.OBSERVATION; return cc; } /** * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods() */ public String getSupportedMethods() { return ItemResourceConstants.METHODS; } /** * Returns true if there exists a {@link Item repository item} with the given * resource path, false otherwise. * * @see org.apache.jackrabbit.webdav.DavResource#exists() */ public boolean exists() { return item != null; } /** * Retrieves the last segment of the item path (or the resource path if * this resource does not exist). An item path is in addition first translated * to the corresponding resource path.<br> * NOTE: the displayname is not equivalent to {@link Item#getName() item name} * which is exposed with the {@link ItemResourceConstants#JCR_NAME * {http://www.day.com/jcr/webdav/1.0}name} property. * * @see org.apache.jackrabbit.webdav.DavResource#getDisplayName() */ public String getDisplayName() { String resPath = getResourcePath(); return (resPath != null) ? Text.getName(resPath) : resPath; } /** * Spools the properties of this resource to the context. Note that subclasses * are in charge of spooling the data to the output stream provided by the * context. * * @see DavResource#spool(OutputContext) */ public void spool(OutputContext outputContext) throws IOException { if (!initedProps) { initProperties(); } // export properties outputContext.setModificationTime(getModificationTime()); DavProperty etag = getProperty(DavPropertyName.GETETAG); if (etag != null) { outputContext.setETag(String.valueOf(etag.getValue())); } DavProperty contentType = getProperty(DavPropertyName.GETCONTENTTYPE); if (contentType != null) { outputContext.setContentType(String.valueOf(contentType.getValue())); } DavProperty contentLength = getProperty(DavPropertyName.GETCONTENTLENGTH); if (contentLength != null) { try { long length = Long.parseLong(contentLength.getValue() + ""); if (length > 0) { outputContext.setContentLength(length); } } catch (NumberFormatException e) { log.error("Could not build content length from property value '" + contentLength.getValue() + "'"); } } DavProperty contentLanguage = getProperty(DavPropertyName.GETCONTENTLANGUAGE); if (contentLanguage != null) { outputContext.setContentLanguage(contentLanguage.getValue().toString()); } } /** * Returns the resource representing the parent item of the repository item * represented by this resource. If this resoure represents the root item * a {@link RootCollection} is returned. * * @return the collection this resource is internal member of. Except for the * repository root, the returned collection always represent the parent * repository node. * @see org.apache.jackrabbit.webdav.DavResource#getCollection() */ public DavResource getCollection() { DavResource collection = null; String parentPath = Text.getRelativeParent(getResourcePath(), 1); DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), getLocator().getWorkspacePath(), parentPath); try { collection = createResourceFromLocator(parentLoc); } catch (DavException e) { log.error("Unexpected error while retrieving collection: " + e.getMessage()); } return collection; } /** * Moves the underlying repository item to the indicated destination. * * @param destination * @throws DavException * @see DavResource#move(DavResource) * @see javax.jcr.Session#move(String, String) */ public void move(DavResource destination) throws DavException { if (!exists()) { throw new DavException(DavServletResponse.SC_NOT_FOUND); } DavResourceLocator destLocator = destination.getLocator(); if (!getLocator().isSameWorkspace(destLocator)) { throw new DavException(DavServletResponse.SC_FORBIDDEN); } try { String itemPath = getLocator().getRepositoryPath(); String destItemPath = destination.getLocator().getRepositoryPath(); if (getTransactionId() == null) { // if not part of a transaction directely import on workspace getRepositorySession().getWorkspace().move(itemPath, destItemPath); } else { // changes will not be persisted unless the tx is completed. getRepositorySession().move(itemPath, destItemPath); } // no use in calling 'complete' that would fail for a moved item anyway. } catch (PathNotFoundException e) { // according to rfc 2518 throw new DavException(DavServletResponse.SC_CONFLICT, e.getMessage()); } catch (RepositoryException e) { throw new JcrDavException(e);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -