1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.vfs2.provider.webdav4;
18
19 import org.apache.commons.vfs2.FileSystem;
20 import org.apache.commons.vfs2.FileSystemOptions;
21 import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder;
22
23 /**
24 * Configuration options for WebDav based on HTTP4.
25 *
26 * @since 2.5.0
27 */
28 public final class Webdav4FileSystemConfigBuilder extends Http4FileSystemConfigBuilder {
29
30 /**
31 * Defines whether a trailing slash ( / ) should be appended to the path.
32 * <p>
33 * This parameter expects a value of type {@link Boolean}.
34 * </p>
35 *
36 * @since 2.10.0
37 */
38 protected static final String KEY_APPEND_TRAILING_SLASH = "appendTrailingSlash";
39
40 private static final Webdav4FileSystemConfigBuilder BUILDER = new Webdav4FileSystemConfigBuilder();
41
42 private static final boolean DEFAULT_APPEND_TRAILING_SLASH = false;
43
44 private static final boolean DEFAULT_FOLLOW_REDIRECT = false;
45
46 /**
47 * Gets the singleton builder.
48 *
49 * @return the singleton builder.
50 */
51 public static Webdav4FileSystemConfigBuilder getInstance() {
52 return BUILDER;
53 }
54
55 private Webdav4FileSystemConfigBuilder() {
56 super("webdav4.");
57 }
58
59 /**
60 * Gets whether a trailing slash ( / ) should be appended to the path.
61 *
62 * @param opts The FileSystem options.
63 * @return {@code true} to follow redirects, {@code false} not to.
64 * @see #setAppendTrailingSlash
65 * @since 2.10.0
66 */
67 public boolean getAppendTrailingSlash(final FileSystemOptions opts) {
68 return getBoolean(opts, KEY_APPEND_TRAILING_SLASH, DEFAULT_APPEND_TRAILING_SLASH);
69 }
70
71 /**
72 * @return The Webdav FileSystem Class object.
73 */
74 @Override
75 protected Class<? extends FileSystem> getConfigClass() {
76 return Webdav4FileSystem.class;
77 }
78
79 /**
80 * Gets the user name to be associated with changes to the file.
81 *
82 * @param opts The FileSystem options
83 * @return The creatorName.
84 */
85 public String getCreatorName(final FileSystemOptions opts) {
86 return getString(opts, "creatorName");
87 }
88
89 /**
90 * Gets whether to follow redirects for the connection.
91 *
92 * @param opts The FileSystem options.
93 * @return {@code true} to follow redirects, {@code false} not to.
94 * @see #setFollowRedirect
95 */
96 @Override
97 public boolean getFollowRedirect(final FileSystemOptions opts) {
98 return getBoolean(opts, KEY_FOLLOW_REDIRECT, DEFAULT_FOLLOW_REDIRECT);
99 }
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 * Sets 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 }