View Javadoc

    1   package org.mortbay.jetty;
    2
    3   import java.io.UnsupportedEncodingException;
    4
    5   import org.mortbay.util.MultiMap;
    6   import org.mortbay.util.StringUtil;
    7   import org.mortbay.util.TypeUtil;
    8   import org.mortbay.util.URIUtil;
    9   import org.mortbay.util.UrlEncoded;
    10  import org.mortbay.util.Utf8StringBuffer;
    11
    12  public class EncodedHttpURI extends HttpURI
    13  {
    14      private String _encoding;
    15
    16      public EncodedHttpURI(String encoding)
    17      {
    18          super();
    19      }
    20
    21
    22      public String getScheme()
    23      {
    24          if (_scheme==_authority)
    25              return null;
    26          int l=_authority-_scheme;
    27          if (l==5 &&
    28              _raw[_scheme]=='h' &&
    29              _raw[_scheme+1]=='t' &&
    30              _raw[_scheme+2]=='t' &&
    31              _raw[_scheme+3]=='p' )
    32              return HttpSchemes.HTTP;
    33          if (l==6 &&
    34              _raw[_scheme]=='h' &&
    35              _raw[_scheme+1]=='t' &&
    36              _raw[_scheme+2]=='t' &&
    37              _raw[_scheme+3]=='p' &&
    38              _raw[_scheme+4]=='s' )
    39              return HttpSchemes.HTTPS;
    40
    41          return StringUtil.toString(_raw,_scheme,_authority-_scheme-1,_encoding);
    42      }
    43
    44      public String getAuthority()
    45      {
    46          if (_authority==_path)
    47              return null;
    48          return StringUtil.toString(_raw,_authority,_path-_authority,_encoding);
    49      }
    50
    51      public String getHost()
    52      {
    53          if (_host==_port)
    54              return null;
    55          return StringUtil.toString(_raw,_host,_port-_host,_encoding);
    56      }
    57
    58      public int getPort()
    59      {
    60          if (_port==_path)
    61              return -1;
    62          return TypeUtil.parseInt(_raw, _port+1, _path-_port-1,10);
    63      }
    64
    65      public String getPath()
    66      {
    67          if (_path==_param)
    68              return null;
    69          return StringUtil.toString(_raw,_path,_param-_path,_encoding);
    70      }
    71
    72      public String getDecodedPath()
    73      {
    74          if (_path==_param)
    75              return null;
    76          return URIUtil.decodePath(_raw,_path,_param-_path);
    77      }
    78
    79      public String getPathAndParam()
    80      {
    81          if (_path==_query)
    82              return null;
    83          return StringUtil.toString(_raw,_path,_query-_path,_encoding);
    84      }
    85
    86      public String getCompletePath()
    87      {
    88          if (_path==_end)
    89              return null;
    90          return StringUtil.toString(_raw,_path,_end-_path,_encoding);
    91      }
    92
    93      public String getParam()
    94      {
    95          if (_param==_query)
    96              return null;
    97          return StringUtil.toString(_raw,_param+1,_query-_param-1,_encoding);
    98      }
    99
    100     public String getQuery()
    101     {
    102         if (_query==_fragment)
    103             return null;
    104         return StringUtil.toString(_raw,_query+1,_fragment-_query-1,_encoding);
    105     }
    106
    107     public boolean hasQuery()
    108     {
    109         return (_fragment>_query);
    110     }
    111
    112     public String getFragment()
    113     {
    114         if (_fragment==_end)
    115             return null;
    116         return StringUtil.toString(_raw,_fragment+1,_end-_fragment-1,_encoding);
    117     }
    118
    119     public void decodeQueryTo(MultiMap parameters)
    120     {
    121         if (_query==_fragment)
    122             return;
    123         UrlEncoded.decodeTo(StringUtil.toString(_raw,_query+1,_fragment-_query-1,_encoding),parameters,_encoding);
    124     }
    125
    126     public void decodeQueryTo(MultiMap parameters, String encoding)
    127         throws UnsupportedEncodingException
    128     {
    129         if (_query==_fragment)
    130             return;
    131
    132         if (encoding==null)
    133             encoding=_encoding;
    134         UrlEncoded.decodeTo(StringUtil.toString(_raw,_query+1,_fragment-_query-1,encoding),parameters,encoding);
    135     }
    136
    137     public String toString()
    138     {
    139         if (_rawString==null)
    140             _rawString= StringUtil.toString(_raw,_scheme,_end-_scheme,_encoding);
    141         return _rawString;
    142     }
    143
    144     public void writeTo(Utf8StringBuffer buf)
    145     {
    146         buf.getStringBuffer().append(toString());
    147     }
    148
    149 }