1 2 package org.enhydra.tool.archive.xml; 3 4 import org.w3c.dom.Element ; 6 7 public class WarDescriptorHandler extends AbstractDescriptorHandler { 9 private final String SESSION_CONFIG = "session-config"; 10 private final String TIMEOUT_NAME = "session-timeout"; 11 private final String TIMEOUT_VALUE = "30"; 12 private final String DESC_NAME = "description"; 13 private final String DESC_VALUE = "no description"; 14 private final String PUBLIC_ID = 15 "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"; 16 private final String SYSTEM_ID = 17 "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"; 18 19 public static void main(String [] 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 e) { 28 e.printStackTrace(); 29 } 30 } 31 32 protected String getPublicID() { 34 return PUBLIC_ID; 35 } 36 37 protected String getSystemID() { 38 return SYSTEM_ID; 39 } 40 41 protected void prepElements() { 42 prepDescription(); 43 prepTimeout(); 44 } 45 46 private void prepDescription() { 48 Element 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 config = null; 60 Element 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 |