2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.integration.api.cactify;
22  
23  import org.codehaus.cargo.module.webapp.WebXml;
24  import org.codehaus.cargo.module.webapp.WebXmlTag;
25  import org.codehaus.cargo.module.webapp.WebXmlUtils;
26  import org.codehaus.cargo.module.webapp.WebXmlVersion;
27  import org.codehaus.cargo.module.webapp.elements.FilterMapping;
28  import org.codehaus.cargo.util.log.Logger;
29  
30  /**
31   * Implementation of <code>Redirector</code> for filter test redirectors. 
32   */
33  public class FilterRedirector extends Redirector
34  {
35  
36      /**
37       * The name of the Cactus filter redirector class.
38       */
39      private static final String FILTER_REDIRECTOR_CLASS =
40          "org.apache.cactus.server.FilterTestRedirector";
41      
42      /**
43       * The default mapping of the Cactus filter redirector.
44       */
45      private static final String DEFAULT_FILTER_REDIRECTOR_MAPPING =
46          "/FilterRedirector";
47      
48      /**
49       * Default constructor.
50       */
51      public FilterRedirector()
52      {
53          this.name = "FilterRedirector";
54          this.mapping = DEFAULT_FILTER_REDIRECTOR_MAPPING;
55      }
56      /**
57       * Constructor with owner task to set.
58       * @param theOwnerTask object
59       */
60      public FilterRedirector(Logger logger)
61      {
62          this();
63          this.logger = logger;
64      }
65  
66      /**
67       * {@inheritDoc}
68       * @see CactifyWarTask.Redirector#mergeInto
69       */
70      public void mergeInto(WebXml theWebXml)
71      {
72      	//If no version is specified then we accept the version is 2.2
73      	//and we don't add the filter redirector.
74      	if(theWebXml.getVersion() == null)
75      		return;
76          if (WebXmlVersion.V2_3.compareTo(theWebXml.getVersion()) <= 0)
77          {
78              if (WebXmlUtils.getFilterNamesForClass
79                  (theWebXml,FILTER_REDIRECTOR_CLASS).hasNext() && logger != null) 
80              {
81                  logger.warn("WARNING: Your web.xml already includes " 
82                  + this.name + " mapping. Cactus is adding another one " 
83                  + "which may prevent your container from starting.", "WARNING");
84              }
85              
86              WebXmlUtils.addFilter(theWebXml, this.name, FILTER_REDIRECTOR_CLASS);
87              
88              
89  //        	WebXmlTag s = new WebXmlTag(theWebXml.getDescriptorType(), "");
90              
91  //            Iterator iter = WebXmlUtils.getFilterMappingElements(theWebXml, name);
92              
93              
94              //Element filterMappingElement =
95              //    theWebXml.getDocument().createElement(WebXmlType.FILTER_MAPPING);
96              //filterMappingElement.appendChild(createNestedText(WebXmlTag.FILTER_NAME, filterName));
97              //filterMappingElement.appendChild(createNestedText(WebXmlTag.URL_PATTERN, urlPattern));
98              //addElement(WebXmlTag.FILTER_MAPPING, filterMappingElement, getRootElement());
99              
100             
101             WebXmlTag tag = (WebXmlTag)theWebXml.getDescriptorType().getTagByName("filter-mapping");
102             FilterMapping filterMapping = new FilterMapping(tag);
103             filterMapping.setName(this.name);
104             filterMapping.setUrlPattern(this.mapping);
105             filterMapping.setFilterName(this.name);
106             
107             
108             //theWebXml.addTag(filterMapping);
109 //            
110 //            theWebXml.addTag(filterM);
111 //            
112 //            FilterMapping filterMapping = new FilterMapping();
113 
114 
115             
116             WebXmlUtils.addFilterMapping(theWebXml, filterMapping);
117             if (this.roles != null)
118             {
119                 addSecurity(theWebXml);
120             }
121         }
122     }
123     
124 }