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