This project has retired. For details please refer to its Attic page.
HttpUtils xref
View Javadoc

1   package org.apache.archiva.redback.integration;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.lang.StringUtils;
23  
24  import java.util.Properties;
25  
26  /**
27   * Collection of Utility methods useful in an Http environment.
28   *
29   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
30   *
31   */
32  public class HttpUtils
33  {
34      /**
35       * Convert typical complex header into properties.
36       * <p/>
37       * <p/>
38       * Example:
39       * </p>
40       * <p/>
41       * <code>
42       * realm="Somewhere Over The Rainbow", domain="kansas.co.us", nonce="65743ABCF"
43       * </code>
44       * <p/>
45       * <p>becomes</p>
46       * <p/>
47       * <code>
48       * Map ( "realm",  "Somewhere Over The Rainbox" )
49       * Map ( "domain", "kansas.co.us" )
50       * Map ( "nonce",  "65743ABCF" )
51       * </code>
52       *
53       * @param rawheader
54       * @param majorDelim
55       * @param subDelim
56       * @return
57       */
58      public static Properties complexHeaderToProperties( String rawheader, String majorDelim, String subDelim )
59      {
60          Properties ret = new Properties();
61  
62          if ( StringUtils.isEmpty( rawheader ) )
63          {
64              return ret;
65          }
66  
67          String array[] = StringUtils.split( rawheader, majorDelim );
68          for ( int i = 0; i < array.length; i++ )
69          {
70              // String quotes.
71              String rawelem = StringUtils.replace( array[i], "\"", "" );
72              String parts[] = StringUtils.split( rawelem, subDelim, 2 );
73  
74              ret.setProperty( StringUtils.trim( parts[0] ), StringUtils.trim( parts[1] ) );
75          }
76  
77          return ret;
78      }
79  }