1 5 package xdoclet.modules.apache.struts; 6 7 import xdoclet.XDocletException; 8 9 import xdoclet.XmlSubTask; 10 import xdoclet.modules.apache.struts.ejb.XDocletModulesApacheStrutsEjbMessages; 11 import xdoclet.util.Translator; 12 13 42 public class StrutsConfigXmlSubTask extends XmlSubTask 43 { 44 private final static String STRUTS_PUBLICID_10 = "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"; 45 46 private final static String STRUTS_SYSTEMID_10 = "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd"; 47 48 private final static String DTD_FILE_NAME_10 = "resources/struts-config_1_0.dtd"; 49 50 private final static String STRUTS_PUBLICID_11 = "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"; 51 52 private final static String STRUTS_SYSTEMID_11 = "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"; 53 54 private final static String DTD_FILE_NAME_11 = "resources/struts-config_1_1.dtd"; 55 56 private final static String STRUTS_PUBLICID_12 = "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"; 57 58 private final static String STRUTS_SYSTEMID_12 = "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"; 59 60 private final static String DTD_FILE_NAME_12 = "resources/struts-config_1_2.dtd"; 61 62 private static String DEFAULT_TEMPLATE_FILE = "resources/struts_config_xml.xdt"; 63 64 private static String GENERATED_FILE_NAME = "struts-config.xml"; 65 66 69 private String strutsVersion = StrutsVersion.STRUTS_1_0; 70 71 74 private String controller = ""; 75 76 79 public StrutsConfigXmlSubTask() 80 { 81 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 82 setDestinationFile(GENERATED_FILE_NAME); 83 } 84 85 public String getController() 86 { 87 return controller; 88 } 89 90 95 public String getVersion() 96 { 97 return strutsVersion; 98 } 99 100 106 public void setVersion(StrutsVersion version) 107 { 108 strutsVersion = version.getValue(); 109 } 110 111 116 public void setController(String controller) 117 { 118 this.controller = controller; 119 } 120 121 126 public void execute() throws XDocletException 127 { 128 if (strutsVersion.equals(StrutsVersion.STRUTS_1_0) && (controller.equals("") == false)) { 129 throw new XDocletException(Translator.getString(XDocletModulesApacheStrutsEjbMessages.class, XDocletModulesApacheStrutsEjbMessages.BAD_STRUTS_VERSION, new String []{controller, "1.1", "controller"})); 130 } 131 132 if (strutsVersion.equals(StrutsVersion.STRUTS_1_0)) { 133 setPublicId(STRUTS_PUBLICID_10); 134 setSystemId(STRUTS_SYSTEMID_10); 135 setDtdURL(getClass().getResource(DTD_FILE_NAME_10)); 136 } 137 else if (strutsVersion.equals(StrutsVersion.STRUTS_1_1)) { 138 setPublicId(STRUTS_PUBLICID_11); 139 setSystemId(STRUTS_SYSTEMID_11); 140 setDtdURL(getClass().getResource(DTD_FILE_NAME_11)); 141 } 142 else { 143 setPublicId(STRUTS_PUBLICID_12); 144 setSystemId(STRUTS_SYSTEMID_12); 145 setDtdURL(getClass().getResource(DTD_FILE_NAME_12)); 146 } 147 startProcess(); 148 } 149 150 153 public static class StrutsVersion extends org.apache.tools.ant.types.EnumeratedAttribute 154 { 155 public final static String STRUTS_1_0 = "1.0"; 156 157 public final static String STRUTS_1_1 = "1.1"; 158 159 public final static String STRUTS_1_2 = "1.2"; 160 161 166 public java.lang.String [] getValues() 167 { 168 return (new java.lang.String []{ 169 STRUTS_1_0, STRUTS_1_1, STRUTS_1_2 170 }); 171 } 172 } 173 } 174 | Popular Tags |