1 23 24 package org.enhydra.xml.xmlc.metadata; 25 26 import java.io.File ; 27 28 import org.enhydra.xml.xmlc.codegen.JavaLang; 29 import org.w3c.dom.Document ; 30 import org.xml.sax.InputSource ; 31 32 35 public class InputDocument extends Include { 36 39 public static final String TAG_NAME = "inputDocument"; 40 41 44 private static final String PROCESS_SSI_ATTR = "processSSI"; 45 private static final String DOCUMENT_FORMAT_ATTR = "documentFormat"; 46 private static final String RECOMPILE_SOURCE_ATTR = "recompileSource"; 47 48 private static final String SSI_BASE_ATTR = "SSIBase"; 50 52 55 public InputDocument(Document ownerDoc) { 56 super(ownerDoc, TAG_NAME); 57 } 58 59 63 public InputSource getInputSource() { 64 String url = getUrl(); 65 if (url == null) { 66 return null; 67 } 68 InputSource inputSource = new InputSource (url); 69 HTMLSection htmlMetaData = getMetaData().getHTMLSection(); 70 if (htmlMetaData != null) { 71 String htmlEncoding = htmlMetaData.getEncoding(); 72 if (htmlEncoding != null) { 73 inputSource.setEncoding(htmlEncoding); 74 } 75 } 76 return inputSource; 77 } 78 79 82 private String normalizeToUnixFile(String name) { 83 return name.replace('\\', '/'); 84 } 85 86 89 public boolean getProcessSSI() { 90 return getBooleanAttribute(PROCESS_SSI_ATTR); 91 } 92 93 96 public void setProcessSSI(boolean value) { 97 setBooleanAttribute(PROCESS_SSI_ATTR, value); 98 } 99 100 104 public void setSSIBase(String value) { 105 setRemoveAttribute(SSI_BASE_ATTR, value); 106 } 107 108 111 public String getSSIBase() { 112 return getAttributeNull(SSI_BASE_ATTR); 113 } 114 116 119 public DocumentFormat getDocumentFormat() { 120 return DocumentFormat.getType(getAttributeNull(DOCUMENT_FORMAT_ATTR)); 121 } 122 123 126 public void setDocumentFormat(DocumentFormat docType) { 127 setRemoveAttribute(DOCUMENT_FORMAT_ATTR, docType.getName()); 128 } 129 130 133 private String getDefaultRecompileSource() { 134 String inputFile = getUrl(); 135 if (inputFile == null) { 136 return null; } 138 String name = new File (inputFile).getName(); 139 140 String packageName = getMetaData().getDocumentClass().getPackageName(); 142 if (packageName != null) { 143 name = JavaLang.packageNameToUnixFileName(packageName) 144 + "/" + name; 145 } 146 return name; 147 } 148 149 155 public String getRecompileSource() { 156 String name = getAttributeNull(RECOMPILE_SOURCE_ATTR); 157 if (name == null) { 158 name = getDefaultRecompileSource(); 159 } 160 if (name != null) { 161 return normalizeToUnixFile(name); 162 } else { 163 return null; 164 } 165 } 166 167 170 public void setRecompileSource(String value) { 171 if (value != null) { 172 value = normalizeToUnixFile(value); 173 } 174 setRemoveAttribute(RECOMPILE_SOURCE_ATTR, value); 175 } 176 177 180 public boolean isRecompileSourceSpecified() { 181 return isAttributeSpecified(RECOMPILE_SOURCE_ATTR); 182 } 183 } 184 | Popular Tags |