View Javadoc

    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.vfs.provider.http;
    18
    19  import org.apache.commons.vfs.FileSystemConfigBuilder;
    20  import org.apache.commons.vfs.FileSystemOptions;
    21  import org.apache.commons.vfs.UserAuthenticator;
    22  import org.apache.commons.httpclient.Cookie;
    23
    24  /***
    25   * Configuration options for HTTP
    26   *
    27   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
    28   * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
    29   */
    30  public class HttpFileSystemConfigBuilder extends FileSystemConfigBuilder
    31  {
    32      private final static HttpFileSystemConfigBuilder builder = new HttpFileSystemConfigBuilder();
    33
    34      public static HttpFileSystemConfigBuilder getInstance()
    35      {
    36          return builder;
    37      }
    38
    39      private HttpFileSystemConfigBuilder()
    40      {
    41      }
    42
    43      /***
    44       * Set the charset used for url encoding<br>
    45       *
    46       * @param chaset the chaset
    47       */
    48      public void setUrlCharset(FileSystemOptions opts, String chaset)
    49      {
    50          setParam(opts, "urlCharset", chaset);
    51      }
    52
    53      /***
    54       * Set the charset used for url encoding<br>
    55       *
    56       * @return the chaset
    57       */
    58      public String getUrlCharset(FileSystemOptions opts)
    59      {
    60          return (String) getParam(opts, "urlCharset");
    61      }
    62
    63      /***
    64       * Set the proxy to use for http connection.<br>
    65       * You have to set the ProxyPort too if you would like to have the proxy relly used.
    66       *
    67       * @param proxyHost the host
    68       * @see #setProxyPort
    69       */
    70      public void setProxyHost(FileSystemOptions opts, String proxyHost)
    71      {
    72          setParam(opts, "proxyHost", proxyHost);
    73      }
    74
    75      /***
    76       * Set the proxy-port to use for http connection
    77       * You have to set the ProxyHost too if you would like to have the proxy relly used.
    78       *
    79       * @param proxyPort the port
    80       * @see #setProxyHost
    81       */
    82      public void setProxyPort(FileSystemOptions opts, int proxyPort)
    83      {
    84          setParam(opts, "proxyPort", new Integer(proxyPort));
    85      }
    86
    87      /***
    88       * Get the proxy to use for http connection
    89       * You have to set the ProxyPort too if you would like to have the proxy relly used.
    90       *
    91       * @return proxyHost
    92       * @see #setProxyPort
    93       */
    94      public String getProxyHost(FileSystemOptions opts)
    95      {
    96          return (String) getParam(opts, "proxyHost");
    97      }
    98
    99      /***
    100      * Get the proxy-port to use for http the connection
    101      * You have to set the ProxyHost too if you would like to have the proxy relly used.
    102      *
    103      * @return proxyPort: the port number or 0 if it is not set
    104      * @see #setProxyHost
    105      */
    106     public int getProxyPort(FileSystemOptions opts)
    107     {
    108         if (!hasParam(opts, "proxyPort"))
    109         {
    110             return 0;
    111         }
    112
    113         return ((Number) getParam(opts, "proxyPort")).intValue();
    114     }
    115
    116     /***
    117      * Set the proxy authenticator where the system should get the credentials from
    118      */
    119     public void setProxyAuthenticator(FileSystemOptions opts, UserAuthenticator authenticator)
    120     {
    121         setParam(opts, "proxyAuthenticator", authenticator);
    122     }
    123
    124     /***
    125      * Get the proxy authenticator where the system should get the credentials from
    126      */
    127     public UserAuthenticator getProxyAuthenticator(FileSystemOptions opts)
    128     {
    129         return (UserAuthenticator) getParam(opts, "proxyAuthenticator");
    130     }
    131
    132     /***
    133      * The cookies to add to the reqest
    134      */
    135     public void setCookies(FileSystemOptions opts, Cookie[] cookies)
    136     {
    137         setParam(opts, "cookies", cookies);
    138     }
    139
    140     /***
    141      * The cookies to add to the reqest
    142      */
    143     public Cookie[] getCookies(FileSystemOptions opts)
    144     {
    145         return (Cookie[]) getParam(opts, "cookies");
    146     }
    147
    148     protected Class getConfigClass()
    149     {
    150         return HttpFileSystem.class;
    151     }
    152 }