001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.provider.webdav;
018
019import java.net.URLStreamHandler;
020import java.util.Collection;
021
022import org.apache.commons.httpclient.HttpClient;
023import org.apache.commons.vfs2.Capability;
024import org.apache.commons.vfs2.FileObject;
025import org.apache.commons.vfs2.FileSystemOptions;
026import org.apache.commons.vfs2.provider.AbstractFileName;
027import org.apache.commons.vfs2.provider.DefaultURLStreamHandler;
028import org.apache.commons.vfs2.provider.GenericFileName;
029import org.apache.commons.vfs2.provider.http.HttpFileSystem;
030
031/**
032 * A WebDAV file system.
033 *
034 * @since 2.0
035 */
036public class WebdavFileSystem extends HttpFileSystem {
037
038    /**
039     * Constructs a new instance.
040     *
041     * @param rootName root base name
042     * @param httpClient {@link HttpClient} instance
043     * @param fileSystemOptions Options to build this file system.
044     */
045    protected WebdavFileSystem(final GenericFileName rootName, final HttpClient httpClient,
046            final FileSystemOptions fileSystemOptions) {
047        super(rootName, httpClient, fileSystemOptions);
048    }
049
050    /**
051     * Returns the capabilities of this file system.
052     *
053     * @param caps The Capabilities to add.
054     */
055    @Override
056    protected void addCapabilities(final Collection<Capability> caps) {
057        caps.addAll(WebdavFileProvider.capabilities);
058    }
059
060    /**
061     * Creates a file object. This method is called only if the requested file is not cached.
062     *
063     * @param name the FileName.
064     * @return The created FileObject.
065     */
066    @Override
067    protected FileObject createFile(final AbstractFileName name) {
068
069        return new WebdavFileObject(name, this);
070    }
071
072    @Override
073    protected HttpClient getClient() {
074        // make accessible
075        return super.getClient();
076    }
077
078    /**
079     * Gets a URLStreamHandler.
080     *
081     * @return The URLStreamHandler.
082     */
083    public URLStreamHandler getURLStreamHandler() {
084        return new DefaultURLStreamHandler(getContext(), getFileSystemOptions());
085    }
086}