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 org.apache.commons.vfs2.FileSystem; 020import org.apache.commons.vfs2.FileSystemOptions; 021import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder; 022 023/** 024 * Configuration options for WebDav based on HTTP4. 025 * 026 * @since 2.5.0 027 */ 028public final class Webdav4FileSystemConfigBuilder extends Http4FileSystemConfigBuilder { 029 030 /** 031 * Defines whether a trailing slash ( / ) should be appended to the path. 032 * <p> 033 * This parameter expects a value of type {@link Boolean}. 034 * </p> 035 * 036 * @since 2.10.0 037 */ 038 protected static final String KEY_APPEND_TRAILING_SLASH = "appendTrailingSlash"; 039 040 private static final Webdav4FileSystemConfigBuilder BUILDER = new Webdav4FileSystemConfigBuilder(); 041 042 private static final boolean DEFAULT_APPEND_TRAILING_SLASH = false; 043 044 private static final boolean DEFAULT_FOLLOW_REDIRECT = false; 045 046 /** 047 * Gets the singleton builder. 048 * 049 * @return the singleton builder. 050 */ 051 public static Webdav4FileSystemConfigBuilder getInstance() { 052 return BUILDER; 053 } 054 055 private Webdav4FileSystemConfigBuilder() { 056 super("webdav4."); 057 } 058 059 /** 060 * Gets whether a trailing slash ( / ) should be appended to the path. 061 * 062 * @param opts The FileSystem options. 063 * @return {@code true} to follow redirects, {@code false} not to. 064 * @see #setAppendTrailingSlash 065 * @since 2.10.0 066 */ 067 public boolean getAppendTrailingSlash(final FileSystemOptions opts) { 068 return getBoolean(opts, KEY_APPEND_TRAILING_SLASH, DEFAULT_APPEND_TRAILING_SLASH); 069 } 070 071 /** 072 * @return The Webdav FileSystem Class object. 073 */ 074 @Override 075 protected Class<? extends FileSystem> getConfigClass() { 076 return Webdav4FileSystem.class; 077 } 078 079 /** 080 * Gets the user name to be associated with changes to the file. 081 * 082 * @param opts The FileSystem options 083 * @return The creatorName. 084 */ 085 public String getCreatorName(final FileSystemOptions opts) { 086 return getString(opts, "creatorName"); 087 } 088 089 /** 090 * Gets whether to follow redirects for the connection. 091 * 092 * @param opts The FileSystem options. 093 * @return {@code true} to follow redirects, {@code false} not to. 094 * @see #setFollowRedirect 095 */ 096 @Override 097 public boolean getFollowRedirect(final FileSystemOptions opts) { 098 return getBoolean(opts, KEY_FOLLOW_REDIRECT, DEFAULT_FOLLOW_REDIRECT); 099 } 100 101 /** 102 * The cookies to add to the request. 103 * 104 * @param opts The FileSystem options. 105 * @return true if versioning is enabled. 106 */ 107 public boolean isVersioning(final FileSystemOptions opts) { 108 return getBoolean(opts, "versioning", false); 109 } 110 111 /** 112 * Sets whether a trailing slash ( / ) should be appended to the path. 113 * 114 * @param opts The FileSystem options. 115 * @param appendTrailingSlash {@code true} to append slash, {@code false} not to. 116 * @since 2.10.0 117 */ 118 public void setAppendTrailingSlash(final FileSystemOptions opts, final boolean appendTrailingSlash) { 119 setParam(opts, KEY_APPEND_TRAILING_SLASH, appendTrailingSlash); 120 } 121 122 /** 123 * The user name to be associated with changes to the file. 124 * 125 * @param opts The FileSystem options 126 * @param creatorName The creator name to be associated with the file. 127 */ 128 public void setCreatorName(final FileSystemOptions opts, final String creatorName) { 129 setParam(opts, "creatorName", creatorName); 130 } 131 132 /** 133 * Whether to use versioning. 134 * 135 * @param opts The FileSystem options. 136 * @param versioning true if versioning should be enabled. 137 */ 138 public void setVersioning(final FileSystemOptions opts, final boolean versioning) { 139 setParam(opts, "versioning", Boolean.valueOf(versioning)); 140 } 141}