View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.shared.webapp.webxml;
20  
21  public class ServletMapping
22  {
23      private final String _servletName;
24      private final Class _servletClass;
25      private final String _urlPattern;
26      private final String _extension;
27      private final String _prefix;
28  
29      public ServletMapping(String servletName, Class servletClass, String urlPattern)
30      {
31          _servletName = servletName;
32          _servletClass = servletClass;
33          _urlPattern = urlPattern;
34          _extension = _urlPattern != null && _urlPattern.startsWith("*.") ? _urlPattern.substring(_urlPattern
35                  .indexOf('.')) : null;
36          if (_extension == null)
37          {
38              int index = _urlPattern.indexOf("/*");
39              if (index != -1)
40              {
41                  _prefix = _urlPattern.substring(0, _urlPattern.indexOf("/*"));
42              }
43              else
44              {
45                  _prefix = _urlPattern;
46              }
47          }
48          else
49          {
50              _prefix = null;
51          }
52      }
53  
54      public boolean isExtensionMapping()
55      {
56          return _extension != null;
57      }
58  
59      public String getExtension()
60      {
61          return _extension;
62      }
63  
64      public String getPrefix()
65      {
66          return _prefix;
67      }
68  
69      public String getServletName()
70      {
71          return _servletName;
72      }
73  
74      public Class getServletClass()
75      {
76          return _servletClass;
77      }
78  
79      public String getUrlPattern()
80      {
81          return _urlPattern;
82      }
83  }