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