001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.tools.deploy;
018:
019: import org.jdom.Document;
020: import org.jdom.Element;
021: import org.jdom.Namespace;
022:
023: /**
024: * Utilities for manipulating the web.xml deployment descriptor version 2.3
025: *
026: * @author <a href="mailto:sweaver@einnovation.com">Scott T. Weaver </a>
027: * @author <a href="mailto:mavery@einnovation.com">Matt Avery </a>
028: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
029: * @version $Id: WebDescriptorUtilities.java,v 1.2 2004/05/12 22:25:04 taylor
030: * Exp $
031: */
032: class JetspeedWebApplicationRewriter2_3 extends
033: JetspeedWebApplicationRewriter {
034: public static final String JETSPEED_SERVLET_XPATH = "/js:web-app/js:servlet/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
035: public static final String JETSPEED_SERVLET_MAPPING_XPATH = "/js:web-app/js:servlet-mapping/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
036: public static final String PORTLET_TAGLIB_XPATH = "/js:web-app/js:taglib/js:taglib-uri[contains(child::text(), \"http://java.sun.com/portlet\")]";
037:
038: protected static final String[] ELEMENTS_BEFORE_SERVLET = new String[] {
039: "icon", "display-name", "description", "distributable",
040: "context-param", "filter", "filter-mapping", "listener",
041: "servlet" };
042: protected static final String[] ELEMENTS_BEFORE_SERVLET_MAPPING = new String[] {
043: "icon", "display-name", "description", "distributable",
044: "context-param", "filter", "filter-mapping", "listener",
045: "servlet", "servlet-mapping" };
046:
047: protected static final String[] ELEMENTS_BEFORE_TAGLIB_MAPPING = new String[] {
048: "icon", "display-name", "description", "distributable",
049: "context-param", "filter", "filter-mapping", "listener",
050: "servlet", "servlet-mapping", "session-config",
051: "mime-mapping", "welcome-file-list", "error-page", "taglib" };
052:
053: public JetspeedWebApplicationRewriter2_3(Document doc,
054: String portletApplication) {
055: super (doc, portletApplication);
056: }
057:
058: public JetspeedWebApplicationRewriter2_3(Document doc) {
059: super (doc);
060: }
061:
062: /**
063: * Returns the jetspeed servlet xpath.
064: *
065: * @return jetspeed servlet xpath
066: */
067: protected String getJetspeedServletXPath() {
068: return JETSPEED_SERVLET_XPATH;
069: }
070:
071: /**
072: * Returns the jetspeed servlet mapping xpath.
073: *
074: * @return jetspeed servlet mapping xpath
075: */
076: protected String getJetspeedServletMappingXPath() {
077: return JETSPEED_SERVLET_MAPPING_XPATH;
078: }
079:
080: /**
081: * Returns the portlet taglib xpath.
082: *
083: * @return portlet taglib xpath
084: */
085: protected String getPortletTagLibXPath() {
086: return PORTLET_TAGLIB_XPATH;
087: }
088:
089: /**
090: * Inserts the jetspeed servlet into web.xml
091: *
092: * @param root
093: * @throws Exception
094: */
095: protected void insertJetspeedServlet(Element root) throws Exception {
096: Namespace namespace = root.getNamespace();
097: Element jetspeedServletElement = new Element("servlet",
098: namespace);
099: Element servletName = new Element("servlet-name", namespace)
100: .addContent(JETSPEED_CONTAINER);
101: Element servletDspName = new Element("display-name", namespace)
102: .addContent(JETSPEED_SERVLET_DISPLAY_NAME);
103: Element servletDesc = new Element("description", namespace)
104: .addContent(JETSPEED_SERVLET_DESCRIPTION);
105: Element servletClass = new Element("servlet-class", namespace)
106: .addContent(JETSPEED_SERVLET_CLASS);
107: jetspeedServletElement.addContent(servletName);
108: jetspeedServletElement.addContent(servletDspName);
109: jetspeedServletElement.addContent(servletDesc);
110: jetspeedServletElement.addContent(servletClass);
111: insertContextNameParam(jetspeedServletElement);
112: insertLoadOnStartup(jetspeedServletElement);
113: insertElementCorrectly(root, jetspeedServletElement,
114: ELEMENTS_BEFORE_SERVLET);
115: }
116:
117: /**
118: * Inserts the jetspeed servlet mapping into web.xml
119: *
120: * @param root
121: * @throws Exception
122: */
123: protected void insertJetspeedServletMapping(Element root)
124: throws Exception {
125: Namespace namespace = root.getNamespace();
126: Element jetspeedServletMappingElement = new Element(
127: "servlet-mapping", namespace);
128:
129: Element servletMapName = new Element("servlet-name", namespace)
130: .addContent(JETSPEED_CONTAINER);
131: Element servletUrlPattern = new Element("url-pattern",
132: namespace).addContent("/container/*");
133:
134: jetspeedServletMappingElement.addContent(servletMapName);
135: jetspeedServletMappingElement.addContent(servletUrlPattern);
136:
137: insertElementCorrectly(root, jetspeedServletMappingElement,
138: ELEMENTS_BEFORE_SERVLET_MAPPING);
139: }
140:
141: /**
142: * Inserts the portlet taglib into web.xml
143: *
144: * @param root
145: * @throws Exception
146: */
147: protected void insertPortletTagLib(Element root) throws Exception {
148: Namespace namespace = root.getNamespace();
149: Element taglib = new Element("taglib", namespace);
150: Element taguri = new Element("taglib-uri", namespace)
151: .addContent("http://java.sun.com/portlet");
152: Element taglocation = new Element("taglib-location", namespace)
153: .addContent("/WEB-INF/tld/portlet.tld");
154:
155: taglib.addContent(taguri);
156: taglib.addContent(taglocation);
157:
158: insertElementCorrectly(root, taglib,
159: ELEMENTS_BEFORE_TAGLIB_MAPPING);
160: }
161: }
|