Changeset 99
- Timestamp:
- 05/26/05 00:06:16 (4 years ago)
- Files:
-
- trunk/dsp/DSPGrammar.d (modified) (1 diff)
- trunk/dsp/ServletCompilationContext.d (modified) (1 diff)
- trunk/dsp/ServletCompiler.d (modified) (1 diff)
- trunk/dsp/Util.d (modified) (1 diff)
- trunk/dsp/servlet/DSPLibrary.d (modified) (1 diff)
- trunk/dsp/servlet/DSPResponse.d (modified) (10 diffs)
- trunk/dsp/servlet/DSPServlet.d (modified) (9 diffs)
- trunk/dsp/servlet/DSPServletContext.d (modified) (1 diff)
- trunk/dsp/servlet/IDSPResponse.d (modified) (3 diffs)
- trunk/dsp/servlet/RuntimeTag.d (modified) (1 diff)
- trunk/dsp/servlet/ServiceHandle.d (modified) (1 diff)
- trunk/dsp/tags/Include.d (modified) (3 diffs)
- trunk/dspconf/dsp_include.dsp (added)
- trunk/dspconf/index.dsp (added)
- trunk/dspconf/test1.inc (added)
- trunk/xml/XMLParser.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dsp/DSPGrammar.d
r67 r99 52 52 53 53 public static char[] pathToNamespace(char[] path){ 54 return path.replace("\\",".").replace("/","."); 54 //TODO: improve this to be more intellegent in handling non-namespace chars 55 return path.replace(".","_").replace("\\",".").replace("/","."); 55 56 } 56 57 trunk/dsp/ServletCompilationContext.d
r98 r99 30 30 private import dsp.RequestConfig; 31 31 private import dsp.servlet.DSPServletContext; 32 private import dsp.servlet.DSPServlet; 33 34 private import xml.utf8all; 32 35 33 36 struct ServletCompilationContext{ 34 37 RequestConfig requestConfig; 35 38 DSPServletContext servletContext; 39 DSPServlet servlet; 40 XMLParser parser; 36 41 ServletGenerator generator; 37 42 TagLibrary tags; trunk/dsp/ServletCompiler.d
r97 r99 60 60 context.generator = new ServletGenerator(); 61 61 context.tags = new StandardTagLibrary(); 62 context.parser = parser; 62 63 63 64 parser.parse(new DSPProcessor(context), provider, source); trunk/dsp/Util.d
r97 r99 92 92 CompleteBufferReader reader = new CompleteBufferReader(buf); 93 93 return reader.read(); 94 conduit.close(); 94 95 } trunk/dsp/servlet/DSPLibrary.d
r98 r99 42 42 protected Library lib; 43 43 public ServiceHandle service; 44 public bit inUse; 44 45 protected DependencyHandle dependencies; 45 46 trunk/dsp/servlet/DSPResponse.d
r97 r99 30 30 private import dsp.servlet.DSPAttributes; 31 31 private import dsp.servlet.RuntimeTag; 32 private import dsp.servlet.DSPServlet; 32 33 33 34 private import mango.servlet.ServletResponse; … … 42 43 char[] exception; 43 44 HttpWriter[] writerStack; 44 HttpWriter writer;45 HttpWriter dspWriter; 45 46 RuntimeTag[char[]][] customTagScopeStack; 46 47 RuntimeTag[] tagStack; 47 48 DSPServlet servlet; 49 48 50 public this(IProviderBridge bridge){ 49 51 super(bridge); … … 51 53 } 52 54 55 void setServlet(DSPServlet servlet){ 56 this.servlet = servlet; 57 } 58 53 59 HttpWriter getWriter(){ 54 //return writer; 55 if(!writer) writer = super.getWriter(); 56 return writer; 60 if(!dspWriter) dspWriter = super.getWriter(); 61 return dspWriter; 57 62 } 58 63 … … 73 78 HttpWriter newWriter = new HttpWriter(new Buffer()); 74 79 writerStack ~= newWriter; 75 writer = newWriter;80 dspWriter = newWriter; 76 81 } 77 82 … … 84 89 writerStack.length = len-1; 85 90 86 char[] data = cast(char[]) writer.getBuffer().getContent();87 writer = oldWriter;91 char[] data = cast(char[])dspWriter.getBuffer().getContent(); 92 dspWriter = oldWriter; 88 93 89 94 return data; … … 120 125 } 121 126 122 RuntimeTag addTag( char[] tagname,char[] filename){127 RuntimeTag addTag(IDSPRequest request,char[] tagname,char[] filename){ 123 128 RuntimeTag tag; 124 // TODO: get the tag handle from the context somehow125 //tag.handle = context.getServletHandle(filename);129 // get the appropriate servlet handle from the servlet 130 tag.handle = servlet.getServletHandleForFile(request,filename); 126 131 127 132 customTagScopeStack[$-1][tagname] = tag; 128 133 } 129 134 130 void startTag(char[] name){131 RuntimeTag tag = findTag( name);135 void startTag(char[] tagname){ 136 RuntimeTag tag = findTag(tagname); 132 137 pushCurrentTag(tag.clone()); 133 138 … … 136 141 } 137 142 else{ 138 writer.put("<" ~name);143 dspWriter.put("<" ~ tagname); 139 144 } 140 145 } … … 146 151 } 147 152 else{ 148 writer.put(" " ~ name ~ "= '" ~ value.toString() ~ "'");153 dspWriter.put(" " ~ name ~ "= '" ~ value.toString() ~ "'"); 149 154 } 150 155 } … … 152 157 void endTagAttributes(){ 153 158 if(!getCurrentTag().isNull){ 154 writer.put(">");159 dspWriter.put(">"); 155 160 } 156 161 } 157 162 158 void endTag(IDSPRequest request,char[] name){163 void endTag(IDSPRequest request,char[] tagname){ 159 164 RuntimeTag tag = getCurrentTag(); 160 165 if(!tag.isNull){ … … 170 175 } 171 176 else{ 172 writer.put("</" ~name ~ ">");177 dspWriter.put("</" ~ tagname ~ ">"); 173 178 } 174 179 popCurrentTag(); trunk/dsp/servlet/DSPServlet.d
r97 r99 35 35 private import dsp.servlet.DSPLibrary; 36 36 private import dsp.servlet.DSPLibraryCache; 37 private import dsp.servlet.ServiceHandle; 37 38 38 39 private import dsp.DSPException; … … 72 73 private static Logger logger; 73 74 protected DSPLibraryCache cache; 75 DSPServletContext context; 74 76 75 77 static this (){ 76 78 logger = Logger.getLogger ("dsp.servlets"); 79 } 80 81 public this(DSPServletContext context){ 82 this.context = context; 77 83 } 78 84 … … 82 88 </desc> 83 89 */ 84 DSPLibrary recoverLibrary( DSPServletContext context,FilePath path){90 DSPLibrary recoverLibrary(FilePath path){ 85 91 char[] libraryPath = context.getBasePath ~ "/" ~ context.getConfiguration.get("cache-directory"); 86 92 libraryPath ~= path.getName[1..$] ~ ".dll"; … … 105 111 </desc> 106 112 */ 107 DSPLibrary buildLibrary( DSPServletContext context,FilePath path){113 DSPLibrary buildLibrary(FilePath path){ 108 114 DSPLibrary lib; 109 115 RequestConfig cfg; … … 136 142 137 143 ServletCompilationContext scc; 144 scc.servlet = this; 138 145 scc.requestConfig = cfg; 139 146 scc.servletContext = context; … … 146 153 lib = new DSPLibrary(cfg.destServletFilename); 147 154 155 return lib; 156 } 157 158 protected DSPLibrary getServletServiceHandle(char[] pathInfo,FilePath path){ 159 // find the needed dll on the fly 160 DSPLibrary lib = cast(DSPLibrary)cache.get(pathInfo); 161 162 debug{ 163 if(lib){ 164 printf("cache lib: %.*s = %.*s\n",pathInfo,lib.toString()); 165 } 166 else{ 167 printf("cache lib: %.*s = [not present]\n",request.getPathInfo); 168 } 169 } 170 171 // attempt to recover the lib from the file cache 172 if(!lib){ 173 lib = recoverLibrary(path); 174 cache.put(pathInfo,lib); // update the cache with new or empty lib 175 } 176 177 // rebuild the library if recovery fails or is out of date 178 if(!lib){ 179 lib = buildLibrary(path); 180 cache.put(pathInfo,lib); // update the cache 181 } 182 else{ 183 if(lib.isOutOfDate(context.getBasePath,path)){ 184 lib.unload(); 185 cache.put(pathInfo,null); // remove the old entry 186 lib = buildLibrary(path); 187 cache.put(pathInfo,lib); // update the cache 188 } 189 } 190 148 191 return lib; 149 192 } … … 155 198 IDSPRequest dspRequest = cast(IDSPRequest)request; 156 199 IDSPResponse dspResponse = cast(IDSPResponse)response; 157 DSPServletContext context = cast(DSPServletContext)request.getContext();158 200 159 201 assert(dspRequest); … … 161 203 assert(context); 162 204 205 dspResponse.setServlet(this); 163 206 dspResponse.setContentType("text/html"); 164 207 165 208 // bind to the needed dll on the fly 166 209 167 DSPLibrary lib = cast(DSPLibrary)cache.get(request.getPathInfo); 168 169 debug{ 170 if(lib){ 171 printf("cache lib: %.*s = %.*s\n",request.getPathInfo,lib.toString()); 172 } 173 else{ 174 printf("cache lib: %.*s = [not present]\n",request.getPathInfo); 175 } 176 } 177 178 // attempt to recover the lib from the file cache 179 if(!lib){ 180 lib = recoverLibrary(context,path); 181 cache.put(request.getPathInfo,lib); // update the cache with new or empty lib 182 } 183 184 // rebuild the library if recovery fails or is out of date 185 if(!lib){ 186 lib = buildLibrary(context,path); 187 cache.put(request.getPathInfo,lib); // update the cache 188 } 189 else{ 190 if(lib.isOutOfDate(context.getBasePath,path)){ 191 lib.unload(); 192 cache.put(request.getPathInfo,null); // remove the old entry 193 lib = buildLibrary(context,path); 194 cache.put(request.getPathInfo,lib); // update the cache 195 } 196 } 210 DSPLibrary lib = getServletServiceHandle(request.getPathInfo,path); 197 211 198 212 // run the servlet … … 215 229 } 216 230 } 217 231 232 //* delegate class that allows for binding of additional servlets 233 class LibraryDynamicHandle{ 234 DSPServlet servlet; 235 FilePath path; 236 char[] requestPathInfo; 237 238 public this(DSPServlet servlet,FilePath path,char[] requestPathInfo){ 239 this.servlet = servlet; 240 this.path = path; 241 this.requestPathInfo = requestPathInfo; 242 } 243 244 void handle(IDSPRequest request,IDSPResponse response){ 245 DSPLibrary lib = servlet.getServletServiceHandle(requestPathInfo,path); 246 lib.service(request,response); 247 } 248 } 249 250 //* delegate class that allows for binding of files as 'servlets' 251 class FileDynamicHandle{ 252 char[] filename; 253 public this(char[] filename){ this.filename = filename; } 254 void handle(IDSPRequest request,IDSPResponse response){ 255 response.copyFile(request.getContext, filename); 256 } 257 } 258 259 //TODO: http:// delegate class 260 class HttpDynamicHandle{ 261 char[] url; 262 public this(char[] url){ this.url = url; } 263 void handle(IDSPRequest request,IDSPResponse response){ 264 //TODO: generate http request based on passed data 265 } 266 } 267 268 //* returns a delegate for the requested binding 269 public ServiceHandleDelegate getServletHandleForFile(IDSPRequest request,char[] filename){ 270 FilePath requestPath = new FilePath(request.getPathInfo); 271 FilePath path = new FilePath(requestPath.getPath() ~ filename); 272 273 //TODO: include support for http://, https:// and file:// protocols. 274 275 if(path.getExtension() == "dsp"){ 276 return &((new LibraryDynamicHandle(this,path,request.getPathInfo)).handle); 277 } 278 279 return &((new FileDynamicHandle(path.toString())).handle); 280 } 281 218 282 debug private import mango.http.utils.Dictionary; 219 283 trunk/dsp/servlet/DSPServletContext.d
r97 r99 84 84 85 85 // set servlet 86 provider.addMapping("/*", provider.addServlet(new DSPServlet( ),"dsp",this));86 provider.addMapping("/*", provider.addServlet(new DSPServlet(this),"dsp",this)); 87 87 } 88 88 trunk/dsp/servlet/IDSPResponse.d
r97 r99 28 28 private import dsp.servlet.RuntimeTag; 29 29 private import dsp.servlet.IDSPRequest; 30 private import dsp.servlet.DSPServlet; 30 31 31 32 private import mango.servlet.model.IServletResponse; … … 38 39 39 40 void setException(char[] e); 41 42 void setServlet(DSPServlet servlet); 43 40 44 bit isExceptionSet(); 41 45 char[] getException(); … … 47 51 void endTagScope(); 48 52 49 RuntimeTag addTag( char[] tagname,char[] filename);50 void startTag(char[] name);53 RuntimeTag addTag(IDSPRequest request,char[] tagname,char[] filename); 54 void startTag(char[] tagname); 51 55 void setTagAttribute(char[] name,Box value); 52 56 void endTagAttributes(); 53 void endTag(IDSPRequest request,char[] name);57 void endTag(IDSPRequest request,char[] tagname); 54 58 } trunk/dsp/servlet/RuntimeTag.d
r98 r99 31 31 struct RuntimeTag{ 32 32 DSPAttributes attributes; 33 ServiceHandle handle;33 ServiceHandleDelegate handle; 34 34 35 35 RuntimeTag clone(){ trunk/dsp/servlet/ServiceHandle.d
r98 r99 30 30 31 31 extern(C) alias void function(IDSPRequest request,IDSPResponse response) ServiceHandle; 32 alias void delegate(IDSPRequest request,IDSPResponse response) ServiceHandleDelegate; 32 33 trunk/dsp/tags/Include.d
r98 r99 28 28 private import xml.utf8all; 29 29 30 private import dsp.Util; 30 31 private import dsp.ServletGenerator; 31 32 private import dsp.TagLibrary; … … 46 47 char[] filename = attribs["file"]; 47 48 48 // TODO:find a way to read in a file49 char[] filedata ;49 //find a way to read in a file 50 char[] filedata = getEntireConduit(context.servletContext.getResourceAsFile(filename)); 50 51 51 52 // process the data according to 'as' … … 68 69 69 70 case "dsp": 70 //TODO: find a way to insert the text back into the input stream71 context.parser.insertText(filedata); 71 72 break; 72 73 trunk/xml/XMLParser.d
r97 r99 173 173 } 174 174 return null; // dummy 175 } 176 177 public void insertText(CharT[] text){ 178 source = source[0..cursor] ~ text ~ source[cursor..source.length]; 175 179 } 176 180
