1 5 package xdoclet; 6 7 import java.net.URL ; 8 import java.util.ArrayList ; 9 import java.util.Collection ; 10 import java.util.Iterator ; 11 12 import org.apache.commons.logging.Log; 13 14 import xdoclet.tagshandler.IdTagsHandler; 15 import xdoclet.util.LogUtil; 16 import xdoclet.util.XmlValidator; 17 18 26 public class XmlSubTask extends TemplateSubTask 27 { 28 private boolean useIds = false; 29 30 private String xmlEncoding = "UTF-8"; 31 32 35 private boolean validateXML = false; 36 37 private String publicId = null; 38 39 private String systemId = null; 40 41 private URL dtdURL = null; 42 43 private String schema = null; 44 45 private URL schemaURL = null; 46 47 52 public boolean getUseIds() 53 { 54 return useIds; 55 } 56 57 62 public String getXmlencoding() 63 { 64 return xmlEncoding; 65 } 66 67 72 public URL getDtdURL() 73 { 74 return dtdURL; 75 } 76 77 82 public String getPublicId() 83 { 84 return publicId; 85 } 86 87 92 public String getSystemId() 93 { 94 return systemId; 95 } 96 97 102 public String getSchema() 103 { 104 return schema; 105 } 106 107 112 public boolean isValidateXML() 113 { 114 return validateXML; 115 } 116 117 122 public URL getSchemaURL() 123 { 124 return schemaURL; 125 } 126 127 134 public void setUseIds(boolean useIds) 135 { 136 this.useIds = useIds; 137 } 138 139 146 public void setXmlencoding(String xmlEncoding) 147 { 148 this.xmlEncoding = xmlEncoding; 149 } 150 151 156 public void setSchema(String schema) 157 { 158 this.schema = schema; 159 } 160 161 167 public void setValidateXML(boolean flag) 168 { 169 validateXML = flag; 170 } 171 172 177 public void copyAttributesFrom(TemplateSubTask templateSrc) 178 { 179 super.copyAttributesFrom(templateSrc); 180 181 XmlSubTask src = (XmlSubTask) templateSrc; 182 183 setValidateXML(src.isValidateXML()); 184 setPublicId(src.getPublicId()); 185 setSystemId(src.getSystemId()); 186 setDtdURL(src.getDtdURL()); 187 setSchema(src.getSchema()); 188 setSchemaURL(src.getSchemaURL()); 189 } 190 191 196 public void startProcess() throws XDocletException 197 { 198 Log log = LogUtil.getLog(XmlSubTask.class, "startProcess"); 199 200 super.getXJavaDoc().setDocEncoding(xmlEncoding); 201 202 if (log.isDebugEnabled()) { 203 log.debug("isValidateXML()=" + isValidateXML()); 204 log.debug("getPublicId()=" + getPublicId()); 205 log.debug("getSystemId()=" + getSystemId()); 206 log.debug("getDtdURL()=" + getDtdURL()); 207 log.debug("getSchema()=" + getSchema()); 208 log.debug("getSchemaURL()=" + getSchemaURL()); 209 } 210 211 if (shouldValidate()) { 212 XmlValidator validator = XmlValidator.getInstance(); 213 214 validator.reset(); 215 216 if (getPublicId() != null) { 217 validator.registerDTD(getPublicId(), getDtdURL()); 218 } 219 if (getSchemaURL() != null) { 220 validator.registerSchema(getSchemaURL()); 221 } 222 } 223 224 IdTagsHandler.reset(); 226 227 super.startProcess(); 228 } 229 230 235 protected void setSchemaURL(URL url) 236 { 237 this.schemaURL = url; 238 } 239 240 245 protected void setDtdURL(URL dtdURL) 246 { 247 this.dtdURL = dtdURL; 248 } 249 250 255 protected void setPublicId(String publicId) 256 { 257 this.publicId = publicId; 258 } 259 260 265 protected void setSystemId(String systemId) 266 { 267 this.systemId = systemId; 268 } 269 270 275 protected void engineFinished() throws XDocletException 276 { 277 Log log = LogUtil.getLog(XmlSubTask.class, "engineFinished"); 278 279 log.debug("isValidateXML()=" + isValidateXML()); 280 if (shouldValidate()) { 281 XmlValidator.getInstance().validate(getEngine().getOutput()); 282 } 283 } 284 285 290 private boolean shouldValidate() 291 { 292 return isValidateXML() && ((getPublicId() != null && getDtdURL() != null) || getSchemaURL() != null); 293 } 294 } 295 | Popular Tags |