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

For more information, please explore the Attic.

View Javadoc

1   package org.apache.cactus.integration.api.cactify;
2   
3   import java.io.File;
4   import java.io.FileInputStream;
5   import java.io.IOException;
6   import java.util.Iterator;
7   import java.util.List;
8   
9   import org.codehaus.cargo.container.internal.util.ResourceUtils;
10  import org.codehaus.cargo.module.webapp.DefaultWarArchive;
11  import org.codehaus.cargo.module.webapp.WarArchive;
12  import org.codehaus.cargo.module.webapp.WebXml;
13  import org.codehaus.cargo.util.internal.log.AbstractLogger;
14  import org.codehaus.cargo.util.log.Logger;
15  
16  /**
17   * Util class for cactifying purposes.
18   * @author tahchiev
19   */
20  public class CactifyUtils {
21  	
22      /**
23       * The cargo ResourceUtils.
24       */
25      private ResourceUtils utils = new ResourceUtils();
26      /**
27       * The abstract cargo logger used both by Ant and Maven2.
28       */
29      private Logger logger;
30  	
31  
32      /**
33       * Log debug the given message.
34       * @param msg
35       */
36      public void debug(String msg)
37      {
38      	getLogger().debug(msg, this.getClass().getName());
39      }
40      /**
41       * Log info the given message.
42       * @param msg
43       */
44      public void info(String msg)
45      {
46      	getLogger().info(msg, this.getClass().getName());
47      }
48      /**
49       * Log warn the given message.
50       * @param msg
51       */
52      public void warn(String msg)
53      {
54      	getLogger().warn(msg, this.getClass().getName());
55      }
56      
57      /**
58       * Adds the definitions corresponding to the nested redirector elements to
59       * the provided deployment descriptor. 
60       * 
61       * @param theWebXml The deployment descriptor
62       */
63      public void addRedirectorDefinitions(WebXml theWebXml, List redirectors)
64      {
65          boolean filterRedirectorDefined = false;
66          boolean jspRedirectorDefined = false;
67          boolean servletRedirectorDefined = false;
68          
69          // add the user defined redirectors
70          for (Iterator i = redirectors.iterator(); i.hasNext();)
71          {
72          
73              Redirector redirector = (Redirector) i.next();
74              if (redirector instanceof FilterRedirector)
75              {
76                  filterRedirectorDefined = true;
77              }
78              else if (redirector instanceof JspRedirector)
79              {
80                  jspRedirectorDefined = true;
81              }
82              else if (redirector instanceof ServletRedirector)
83              {
84                  servletRedirectorDefined = true;
85              }
86              redirector.mergeInto(theWebXml);
87          }
88  
89          // now add the default redirectors if they haven't been provided by
90          // the user
91          if (!filterRedirectorDefined)
92          {
93              new FilterRedirector(getLogger())
94                  .mergeInto(theWebXml);
95          }
96          if (!servletRedirectorDefined)
97          {
98              new ServletRedirector(getLogger())
99                  .mergeInto(theWebXml);
100         }
101         if (!jspRedirectorDefined)
102         {
103             new JspRedirector(getLogger()).mergeInto(theWebXml);
104         }
105     }
106     /**
107      * Getter method for the logger.
108      * @return AbstractLogger
109      */
110 	public Logger getLogger() {
111 		return logger;
112 	}
113 	
114 	/**
115 	 * Setter method for the logger.
116 	 * @param logger
117 	 */
118 	public void setLogger(Logger logger) {
119 		this.logger = logger;
120 	}
121 
122 }