KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > xml > WarDescriptorHandler


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