1 28 29 package com.caucho.xsl; 30 31 import com.caucho.vfs.Path; 32 import com.caucho.vfs.PersistentDependency; 33 import com.caucho.vfs.Vfs; 34 import com.caucho.xml.XMLWriter; 35 36 import org.w3c.dom.Node ; 37 38 import javax.xml.transform.Templates ; 39 import javax.xml.transform.URIResolver ; 40 import java.util.ArrayList ; 41 import java.util.Properties ; 42 43 50 abstract public class AbstractStylesheet 51 implements CauchoStylesheet, Templates { 52 private Path _path; 54 private ArrayList <PersistentDependency> _depends = 55 new ArrayList <PersistentDependency>(); 56 private ArrayList <String > _cacheDepends = new ArrayList <String >(); 57 private ArrayList _globalParameters; 58 59 protected Properties _output = new Properties (); 60 protected AbstractStylesheet _stylesheet; 61 62 protected String _errorPage; 63 protected URIResolver _uriResolver; 64 boolean _escapeEntities = true; 65 66 71 public void init(Path path) throws Exception 72 { 73 79 80 _path = path; 81 } 82 83 public void setURIResolver(URIResolver resolver) 84 { 85 _uriResolver = resolver; 86 } 87 88 public URIResolver getURIResolver() 89 { 90 return _uriResolver; 91 } 92 93 99 protected void copy(AbstractStylesheet stylesheet) 100 { 101 stylesheet._stylesheet = this; 102 stylesheet._depends = (ArrayList ) _depends.clone(); 103 stylesheet._output = (Properties ) _output.clone(); 104 stylesheet._errorPage = _errorPage; 105 stylesheet._globalParameters = _globalParameters; 106 stylesheet._path = _path; 107 stylesheet._uriResolver = _uriResolver; 108 } 109 110 113 public Object clone() 114 { 115 try { 116 AbstractStylesheet instance; 117 instance = (AbstractStylesheet) getClass().newInstance(); 118 119 copy(instance); 120 121 if (_path != null) 122 instance.init(_path); 123 else 124 instance.init(Vfs.lookup("anonymous.xsl")); 125 126 return instance; 127 } catch (Exception e) { 128 return null; 129 } 130 } 131 132 135 public Properties getOutputProperties() 136 { 137 return _output; 138 } 139 140 public Path getPath() 141 { 142 return _path; 143 } 144 145 148 public Object getProperty(String name) 149 { 150 if (name.equals(DEPENDS)) 151 return _depends; 152 else if (name.equals(CACHE_DEPENDS)) 153 return _cacheDepends; 154 else if (name.equals("caucho.path")) 155 return _path; 156 else if (name.equals(GLOBAL_PARAM)) 157 return _globalParameters; 158 else 159 return null; 160 } 161 162 165 public void setProperty(String name, Object value) 166 { 167 if (name.equals(GLOBAL_PARAM)) 168 _globalParameters = (ArrayList ) value; 169 } 170 171 174 public javax.xml.transform.Transformer newTransformer() 175 { 176 return new TransformerImpl((StylesheetImpl) clone()); 177 } 178 179 183 public boolean isModified() 184 { 185 for (int i = 0; i < _depends.size(); i++) { 186 PersistentDependency depend = _depends.get(i); 187 188 if (depend.isModified()) 189 return true; 190 } 191 192 return false; 193 } 194 195 201 protected void addDepend(PersistentDependency depend) 202 { 203 if (! _depends.contains(depend)) 204 _depends.add(depend); 205 } 206 207 210 public ArrayList <PersistentDependency> getDepends() 211 { 212 return _depends; 213 } 214 215 218 protected void addCacheDepend(String path) 219 { 220 _cacheDepends.add(path); 221 } 222 223 public ArrayList <String > getCacheDepends() 224 { 225 return _cacheDepends; 226 } 227 228 238 abstract public void transform(Node xml, 239 XMLWriter out, 240 TransformerImpl transformer) 241 throws Exception ; 242 } 243 244 | Popular Tags |