01: package org.enhydra.tool.archive.xml;
02:
03: //
04: import org.w3c.dom.Element;
05:
06: //
07: public class WarDescriptorHandler extends AbstractDescriptorHandler {
08: private final String SESSION_CONFIG = "session-config";
09: private final String TIMEOUT_NAME = "session-timeout";
10: private final String TIMEOUT_VALUE = "30";
11: private final String DESC_NAME = "description";
12: private final String DESC_VALUE = "no description";
13: private final String PUBLIC_ID = "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";
14: private final String SYSTEM_ID = "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd";
15:
16: //
17: public static void main(String[] args) {
18: WarDescriptorHandler prep = new WarDescriptorHandler();
19:
20: prep.setSource("d:/test/simple/test2.xml");
21: prep.setOutStream(System.out);
22: try {
23: prep.prep();
24: } catch (Exception e) {
25: e.printStackTrace();
26: }
27: }
28:
29: //
30: protected String getPublicID() {
31: return PUBLIC_ID;
32: }
33:
34: protected String getSystemID() {
35: return SYSTEM_ID;
36: }
37:
38: protected void prepElements() {
39: prepDescription();
40: prepTimeout();
41: }
42:
43: //
44: private void prepDescription() {
45: Element desc = null;
46:
47: desc = lookup(getDoc().getDocumentElement(), DESC_NAME);
48: if (desc == null) {
49: desc = getDoc().createElement(DESC_NAME);
50: desc.appendChild(getDoc().createTextNode(DESC_VALUE));
51: getDoc().getDocumentElement().appendChild(desc);
52: }
53: }
54:
55: private void prepTimeout() {
56: Element config = null;
57: Element timeout = null;
58:
59: config = lookup(getDoc().getDocumentElement(), SESSION_CONFIG);
60: if (config == null) {
61: config = getDoc().createElement(SESSION_CONFIG);
62: getDoc().getDocumentElement().appendChild(config);
63: }
64: timeout = lookup(config, TIMEOUT_NAME);
65: if (timeout == null) {
66: timeout = getDoc().createElement(TIMEOUT_NAME);
67: timeout.appendChild(getDoc().createTextNode(TIMEOUT_VALUE));
68: config.appendChild(timeout);
69: }
70: }
71:
72: }
|