01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
22: /**
23: * Utilities for manipulating the context.xml deployment descriptor
24: *
25: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
26: * @version $Id: JetspeedContextRewriter.java 517124 2007-03-12 08:10:25Z ate $
27: */
28: public class JetspeedContextRewriter {
29: private Document document;
30: private String portletApplication;
31:
32: public JetspeedContextRewriter(Document doc,
33: String portletApplication) {
34: this .document = doc;
35: this .portletApplication = portletApplication;
36: }
37:
38: public void processContextXML() throws Exception {
39: if (document != null) {
40: try {
41: // get root Context
42: Element root = null;
43: if (!document.hasRootElement()) {
44: root = new Element("Context");
45: document.setRootElement(root);
46: } else {
47: root = document.getRootElement();
48: }
49:
50: // set Context path
51: String pathAttribute = root.getAttributeValue("path");
52: if ((pathAttribute == null)
53: || !pathAttribute.equals("/"
54: + portletApplication)) {
55: root.setAttribute("path", "/" + portletApplication);
56: }
57:
58: // set Context docBase
59: String docBaseAttribute = root
60: .getAttributeValue("docBase");
61: if ((docBaseAttribute == null)
62: || !docBaseAttribute.equals(portletApplication)) {
63: root.setAttribute("docBase", portletApplication);
64: }
65: } catch (Exception e) {
66: throw new Exception(
67: "Unable to process context.xml for infusion "
68: + e.toString(), e);
69: }
70: }
71: }
72: }
|