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.webdav4;
018
019import java.net.URLStreamHandler;
020import java.util.Collection;
021
022import org.apache.commons.vfs2.Capability;
023import org.apache.commons.vfs2.FileName;
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.http4.Http4FileSystem;
029import org.apache.http.client.HttpClient;
030import org.apache.http.client.protocol.HttpClientContext;
031
032/**
033 * A WebDAV file system based on HTTP4.
034 *
035 * @since 2.5.0
036 */
037public class Webdav4FileSystem extends Http4FileSystem {
038
039    /**
040     * Constructs a new instance.
041     *
042     * @param rootName root base name
043     * @param fileSystemOptions file system options
044     * @param httpClient {@link HttpClient} instance
045     * @param httpClientContext {@link HttpClientContext} instance
046     */
047    protected Webdav4FileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions,
048            final HttpClient httpClient, final HttpClientContext httpClientContext) {
049        super(rootName, fileSystemOptions, httpClient, httpClientContext);
050    }
051
052    /**
053     * Returns the capabilities of this file system.
054     *
055     * @param caps The Capabilities to add.
056     */
057    @Override
058    protected void addCapabilities(final Collection<Capability> caps) {
059        caps.addAll(Webdav4FileProvider.capabilities);
060    }
061
062    /**
063     * Creates a file object. This method is called only if the requested file is not cached.
064     *
065     * @param name the FileName.
066     * @return The created FileObject.
067     */
068    @Override
069    protected FileObject createFile(final AbstractFileName name) throws Exception {
070        return new Webdav4FileObject(name, this);
071    }
072
073    /**
074     * Gets a URLStreamHandler.
075     *
076     * @return The URLStreamHandler.
077     */
078    public URLStreamHandler getURLStreamHandler() {
079        return new DefaultURLStreamHandler(getContext(), getFileSystemOptions());
080    }
081}