View Javadoc

1   /*
2    * $Id: URIRouteFilter.java 20007 2010-10-26 19:58:54Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.module.atom.routing;
11  
12  import org.mule.api.MuleMessage;
13  import org.mule.api.routing.filter.Filter;
14  import org.mule.transport.http.HttpConnector;
15  import org.mule.util.StringUtils;
16  
17  import java.util.HashSet;
18  import java.util.Set;
19  
20  import org.apache.abdera.i18n.templates.Route;
21  
22  public class URIRouteFilter implements Filter
23  {
24  
25      private Set<String> verbs;
26      private Route route;
27  
28      public URIRouteFilter()
29      {
30          super();
31      }
32  
33      public void setRoute(String routePattern)
34      {
35          route = new Route("", routePattern);
36      }
37  
38      public void setVerbs(String verbString)
39      {
40          if (verbString.equals("*"))
41          {
42              return;
43          }
44  
45          String[] split = verbString.split(",");
46          verbs = new HashSet<String>();
47          for (String s : split)
48          {
49              verbs.add(s.toUpperCase());
50          }
51      }
52  
53      public boolean accept(MuleMessage message)
54      {
55          String method = message.getInboundProperty(HttpConnector.HTTP_METHOD_PROPERTY, StringUtils.EMPTY);
56          if (verbs != null && !verbs.contains(method.toUpperCase()))
57          {
58              return false;
59          }
60  
61          String path = message.getInboundProperty(HttpConnector.HTTP_REQUEST_PROPERTY, StringUtils.EMPTY);
62  
63          return route.match(path);
64      }
65  
66  }