View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.tools.deploy;
18  
19  import org.jdom.Document;
20  import org.jdom.Element;
21  import org.jdom.Namespace;
22  
23  /***
24   * Utilities for manipulating the web.xml deployment descriptor version 2.3
25   * 
26   * @author <a href="mailto:sweaver@einnovation.com">Scott T. Weaver </a>
27   * @author <a href="mailto:mavery@einnovation.com">Matt Avery </a>
28   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
29   * @version $Id: WebDescriptorUtilities.java,v 1.2 2004/05/12 22:25:04 taylor
30   *                Exp $
31   */
32  class JetspeedWebApplicationRewriter2_3 extends JetspeedWebApplicationRewriter
33  {
34      public static final String JETSPEED_SERVLET_XPATH = "/js:web-app/js:servlet/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
35      public static final String JETSPEED_SERVLET_MAPPING_XPATH = "/js:web-app/js:servlet-mapping/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
36      public static final String PORTLET_TAGLIB_XPATH = "/js:web-app/js:taglib/js:taglib-uri[contains(child::text(), \"http://java.sun.com/portlet\")]";
37      
38      protected static final String[] ELEMENTS_BEFORE_SERVLET = new String[]{"icon", "display-name", "description",
39              "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet"};
40      protected static final String[] ELEMENTS_BEFORE_SERVLET_MAPPING = new String[]{"icon", "display-name",
41              "description", "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet",
42              "servlet-mapping"};
43      
44      protected static final String[] ELEMENTS_BEFORE_TAGLIB_MAPPING = new String[]{"icon", "display-name",
45              "description", "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet",
46              "servlet-mapping", "session-config", "mime-mapping", "welcome-file-list", "error-page", "taglib"};
47  
48      
49      public JetspeedWebApplicationRewriter2_3(Document doc, String portletApplication)
50      {
51          super(doc, portletApplication);
52      }
53  
54      public JetspeedWebApplicationRewriter2_3(Document doc)
55      {
56          super(doc);
57      }
58      
59      /***
60       * Returns the jetspeed servlet xpath.
61       * 
62       * @return jetspeed servlet xpath
63       */
64      protected String getJetspeedServletXPath()
65      {
66          return JETSPEED_SERVLET_XPATH;
67      }
68      
69      /***
70       * Returns the jetspeed servlet mapping xpath.
71       * 
72       * @return jetspeed servlet mapping xpath
73       */
74      protected String getJetspeedServletMappingXPath()
75      {
76          return JETSPEED_SERVLET_MAPPING_XPATH;
77      }
78  
79      /***
80       * Returns the portlet taglib xpath.
81       * 
82       * @return portlet taglib xpath
83       */
84      protected String getPortletTagLibXPath()
85      {
86          return PORTLET_TAGLIB_XPATH;
87      }
88  
89      /***
90       * Inserts the jetspeed servlet into web.xml
91       * 
92       * @param root
93       * @throws Exception
94       */
95      protected void insertJetspeedServlet(Element root) throws Exception
96      {
97          Namespace namespace = root.getNamespace();
98          Element jetspeedServletElement = new Element("servlet", namespace);
99          Element servletName = new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
100         Element servletDspName = new Element("display-name", namespace).addContent(JETSPEED_SERVLET_DISPLAY_NAME);
101         Element servletDesc = new Element("description", namespace)
102                 .addContent(JETSPEED_SERVLET_DESCRIPTION);
103         Element servletClass = new Element("servlet-class", namespace)
104                 .addContent(JETSPEED_SERVLET_CLASS);
105         jetspeedServletElement.addContent(servletName);
106         jetspeedServletElement.addContent(servletDspName);
107         jetspeedServletElement.addContent(servletDesc);
108         jetspeedServletElement.addContent(servletClass);
109         insertContextNameParam(jetspeedServletElement);
110         insertLoadOnStartup(jetspeedServletElement);
111         insertElementCorrectly(root, jetspeedServletElement, ELEMENTS_BEFORE_SERVLET);
112     }
113 
114     /***
115      * Inserts the jetspeed servlet mapping into web.xml
116      * 
117      * @param root
118      * @throws Exception
119      */
120     protected void insertJetspeedServletMapping(Element root) throws Exception
121     {
122         Namespace namespace = root.getNamespace();
123         Element jetspeedServletMappingElement = new Element("servlet-mapping", namespace);
124         
125         Element servletMapName = new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
126         Element servletUrlPattern = new Element("url-pattern", namespace).addContent("/container/*");
127 
128         jetspeedServletMappingElement.addContent(servletMapName);
129         jetspeedServletMappingElement.addContent(servletUrlPattern);
130 
131         insertElementCorrectly(root, jetspeedServletMappingElement, ELEMENTS_BEFORE_SERVLET_MAPPING);
132     }
133 
134     /***
135      * Inserts the portlet taglib into web.xml
136      * 
137      * @param root
138      * @throws Exception
139      */
140     protected void insertPortletTagLib(Element root) throws Exception
141     {
142         Namespace namespace = root.getNamespace();
143         Element taglib = new Element ("taglib", namespace);
144         Element taguri = new Element("taglib-uri", namespace).addContent("http://java.sun.com/portlet");
145         Element taglocation = new Element("taglib-location", namespace).addContent("/WEB-INF/tld/portlet.tld");
146         
147         taglib.addContent(taguri);
148         taglib.addContent(taglocation);
149         
150         insertElementCorrectly(root, taglib, ELEMENTS_BEFORE_TAGLIB_MAPPING);
151     }
152 }