1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 {
30 private Document document;
31 private String portletApplication;
32 public JetspeedContextRewriter(Document doc, String portletApplication)
33 {
34 this.document = doc;
35 this.portletApplication = portletApplication;
36 }
37
38 public void processContextXML()
39 throws Exception
40 {
41 if (document != null)
42 {
43 try
44 {
45
46 Element root = null;
47 if (!document.hasRootElement())
48 {
49 root = new Element("Context");
50 document.setRootElement(root);
51 }
52 else
53 {
54 root = document.getRootElement();
55 }
56
57
58 String pathAttribute = root.getAttributeValue("path");
59 if ((pathAttribute == null) || !pathAttribute.equals("/" + portletApplication))
60 {
61 root.setAttribute("path", "/" + portletApplication);
62 }
63
64
65 String docBaseAttribute = root.getAttributeValue("docBase");
66 if ((docBaseAttribute == null) || !docBaseAttribute.equals(portletApplication))
67 {
68 root.setAttribute("docBase", portletApplication);
69 }
70 }
71 catch (Exception e)
72 {
73 throw new Exception("Unable to process context.xml for infusion " + e.toString(), e);
74 }
75 }
76 }
77 }