View Javadoc

1   package br.com.ibnetwork.guara.parameters.impl;
2   
3   import java.net.URLDecoder;
4   import java.util.StringTokenizer;
5   
6   import javax.servlet.http.HttpServletRequest;
7   
8   import org.apache.avalon.framework.configuration.Configurable;
9   import org.apache.avalon.framework.configuration.Configuration;
10  import org.apache.avalon.framework.configuration.ConfigurationException;
11  import org.apache.avalon.framework.service.ServiceException;
12  import org.apache.avalon.framework.service.ServiceManager;
13  import org.apache.avalon.framework.service.Serviceable;
14  
15  
16  import br.com.ibnetwork.guara.parameters.ParameterParser;
17  import br.com.ibnetwork.guara.parameters.ParameterParserBuilder;
18  
19  /***
20   * @author <a href="mailto:leandro@ibnetwork.com.br">leandro</a>
21   */
22  public class ParameterParserBuilderImpl
23  	extends ParameterParserBuilderSupport
24  	implements ParameterParserBuilder, Serviceable, Configurable
25  {
26  
27      public void service(ServiceManager manager)
28      	throws ServiceException
29      {
30          super.service(manager);
31      }
32  
33      public void configure(Configuration conf)
34      	throws ConfigurationException
35      {
36          super.configure(conf);
37      }
38  
39      protected void extractPathInfo(ParameterParser parser, HttpServletRequest request)
40      {
41          // Also cache any pathinfo variables that are passed around as
42          // if they are query string data.
43          try
44          {
45              StringTokenizer st = new StringTokenizer(request.getPathInfo(), "/");
46              boolean isNameTok = true;
47              String pathPart = null;
48              String parameterName = null;
49              while (st.hasMoreTokens())
50              {
51                  if (isNameTok)
52                  {
53                      parameterName = URLDecoder.decode(st.nextToken(),encoding);
54                      isNameTok = false;
55                  }
56                  else
57                  {
58                      pathPart = URLDecoder.decode(st.nextToken(),encoding);
59                      if(parameterName != null && parameterName.length() > 0)
60                      {
61                          add(parser,parameterName, pathPart);
62                      }
63                      isNameTok = true;
64                  }
65              }
66          }
67          catch (Exception e)
68          {
69              // If anything goes wrong above, don't worry about it.
70              // Chances are that the path info was wrong anyways and
71              // things that depend on it being right will fail later
72              // and should be caught later.
73          }
74      }
75  
76  }