org.apache.jackrabbit.webdav.jcr.RootCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackrabbit-jcr-server
Show all versions of jackrabbit-jcr-server
WebDAV server implementations for JCR
/*
* 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.webdav.DavException;
import org.apache.jackrabbit.webdav.DavResource;
import org.apache.jackrabbit.webdav.DavResourceFactory;
import org.apache.jackrabbit.webdav.DavResourceIterator;
import org.apache.jackrabbit.webdav.DavResourceIteratorImpl;
import org.apache.jackrabbit.webdav.DavResourceLocator;
import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.search.SearchResource;
import org.apache.jackrabbit.webdav.io.InputContext;
import org.apache.jackrabbit.webdav.io.OutputContext;
import org.apache.jackrabbit.webdav.version.DeltaVResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.RepositoryException;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.io.IOException;
/**
* RootCollection
represent the WebDAV root resource that does not
* represent any repository item. A call to getMembers() returns a
* DavResourceIterator
containing only workspace resources
* resources, thus revealing the names of the accessable JCR workspaces.
*/
public class RootCollection extends AbstractResource {
private static Logger log = LoggerFactory.getLogger(RootCollection.class);
/**
* Create a new RootCollection
.
*
* @param locator
* @param session
*/
protected RootCollection(DavResourceLocator locator, JcrDavSession session,
DavResourceFactory factory) {
super(locator, session, factory);
// initialize the supported locks and reports
initLockSupport();
initSupportedReports();
}
/**
* Returns a string listing the METHODS for this resource as it
* is required for the "Allow" response header.
*
* @return string listing the METHODS allowed
* @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
*/
public String getSupportedMethods() {
StringBuffer sb = new StringBuffer(DavResource.METHODS);
sb.append(", ");
sb.append(DeltaVResource.METHODS_INCL_MKWORKSPACE);
sb.append(", ");
sb.append(SearchResource.METHODS);
return sb.toString();
}
/**
* Returns true
*
* @return true
* @see org.apache.jackrabbit.webdav.DavResource#exists()
*/
public boolean exists() {
return true;
}
/**
* Returns true
*
* @return true
* @see org.apache.jackrabbit.webdav.DavResource#isCollection()
*/
public boolean isCollection() {
return true;
}
/**
* Returns an empty string.
*
* @return empty string
* @see org.apache.jackrabbit.webdav.DavResource#getDisplayName()
*/
public String getDisplayName() {
return "";
}
/**
* Always returns 'now'
*
* @return
*/
public long getModificationTime() {
return new Date().getTime();
}
/**
* Sets content lengths to '0' and retrieves the modification time.
*
* @param outputContext
* @throws IOException
*/
public void spool(OutputContext outputContext) throws IOException {
outputContext.setContentLength(0);
outputContext.setModificationTime(getModificationTime());
}
/**
* Always returns null
*
* @return null
for the root resource is not internal member
* of any resource.
* @see org.apache.jackrabbit.webdav.DavResource#getCollection()
*/
public DavResource getCollection() {
return null;
}
/**
* Throws exception: 403 Forbidden.
* @see DavResource#addMember(DavResource, InputContext)
*/
public void addMember(DavResource resource, InputContext inputContext) throws DavException {
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
/**
* Returns an iterator over the member resources, which are all
* workspace resources available.
*
* @return members of this collection
* @see org.apache.jackrabbit.webdav.DavResource#getMembers()
*/
public DavResourceIterator getMembers() {
List memberList = new ArrayList();
try {
String[] wsNames = getRepositorySession().getWorkspace().getAccessibleWorkspaceNames();
for (int i = 0; i < wsNames.length; i++) {
String wspPath = "/"+wsNames[i];
DavResourceLocator childLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), wspPath, wspPath);
memberList.add(createResourceFromLocator(childLoc));
}
} catch (RepositoryException e) {
log.error(e.getMessage());
} catch (DavException e) {
// should never occur
log.error(e.getMessage());
}
return new DavResourceIteratorImpl(memberList);
}
/**
* Throws exception: 403 Forbidden.
* @see DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource)
*/
public void removeMember(DavResource member) throws DavException {
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
//--------------------------------------------------------------------------
/**
* @see AbstractResource#initLockSupport()
*/
protected void initLockSupport() {
// no locking supported
}
/**
* Since the root resource does not represent a repository item and therefore
* is not member of a workspace resource, this method always returns
* null
.
*
* @return null
* @see AbstractResource#getWorkspaceHref()
*/
protected String getWorkspaceHref() {
return null;
}
}