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 org.apache.commons.vfs2.FileSystem;
020import org.apache.commons.vfs2.FileSystemOptions;
021import org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder;
022
023/**
024 * Configuration options for WebDav.
025 *
026 * @since 2.0
027 */
028public final class WebdavFileSystemConfigBuilder extends HttpFileSystemConfigBuilder
029{
030    private static final WebdavFileSystemConfigBuilder BUILDER = new WebdavFileSystemConfigBuilder();
031
032    private static final boolean DEFAULT_FOLLOW_REDIRECT = false;
033
034    private WebdavFileSystemConfigBuilder()
035    {
036        super("webdav.");
037    }
038
039    /**
040     * Gets the singleton builder.
041     *
042     * @return the singleton builder.
043     */
044    public static HttpFileSystemConfigBuilder getInstance()
045    {
046        return BUILDER;
047    }
048
049    /**
050     * The user name to be associated with changes to the file.
051     * @param opts The FileSystem options
052     * @param creatorName The creator name to be associated with the file.
053     */
054    public void setCreatorName(final FileSystemOptions opts, final String creatorName)
055    {
056        setParam(opts, "creatorName", creatorName);
057    }
058
059    /**
060     * Return the user name to be associated with changes to the file.
061     * @param opts The FileSystem options
062     * @return The creatorName.
063     */
064    public String getCreatorName(final FileSystemOptions opts)
065    {
066        return getString(opts, "creatorName");
067    }
068
069    /**
070     * Gets whether to follow redirects for the connection.
071     *
072     * @param opts
073     *            The FileSystem options.
074     * @return {@code true} to follow redirects, {@code false} not to.
075     * @see #setFollowRedirect
076     * @since 2.1
077     */
078    @Override
079    public boolean getFollowRedirect(final FileSystemOptions opts)
080    {
081        return getBoolean(opts, KEY_FOLLOW_REDIRECT, DEFAULT_FOLLOW_REDIRECT);
082    }
083
084    /**
085     * Whether to use versioning.
086     * @param opts The FileSystem options.
087     * @param versioning true if versioning should be enabled.
088     */
089    public void setVersioning(final FileSystemOptions opts, final boolean versioning)
090    {
091        setParam(opts, "versioning", Boolean.valueOf(versioning));
092    }
093
094    /**
095     * The cookies to add to the request.
096     * @param opts The FileSystem options.
097     * @return true if versioning is enabled.
098     */
099    public boolean isVersioning(final FileSystemOptions opts)
100    {
101        return getBoolean(opts, "versioning", false);
102    }
103
104    /**
105     * @return The Webdav FileSystem Class object.
106     */
107    @Override
108    protected Class<? extends FileSystem> getConfigClass()
109    {
110        return WebdavFileSystem.class;
111    }
112}