Changeset 67

Show
Ignore:
Timestamp:
05/05/05 23:47:33 (4 years ago)
Author:
pragma
Message:

Added *working* servlet server w/regeneration and file-caching capabilities.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dsp/DSPGrammar.d

    r64 r67  
    3434    public static char[] escapeStr = "#"; 
    3535    public static char[] escapeEscapeStr = "##"; 
     36    public static char[] fileExtension = "dsp"; 
    3637    public static char[] rawPreamble = "dsp"; 
    3738    public static char[] preamble = "dsp:"; 
     
    4041    public static char[] newline = "\n"; 
    4142 
    42     public static char[] standardInclude = "import dsp.servlet.ServletRegistry,dsp.servlet.IDSPResponse,dsp.servlet.IDSPRequest,std.string,mango.io.model.IWriter";    
     43    public static char[] standardInclude = "import dsp.servlet.IDSPResponse,dsp.servlet.IDSPRequest,std.string,mango.io.model.IWriter";    
    4344    public static char[] servletPrefix = "__servlet_"; 
    4445    public static char[] servletDecl = "(IDSPRequest request, IDSPResponse response)"; 
     
    9192            `alias void function` ~ servletDecl ~ ` ServletHandle; 
    9293             
    93             static this(){ 
    94                 dsp.servlet.ServletRegistry.registerServletHandle(&` ~ servletFunctionName(name) ~ `,` ~ "`default`" ~ `); 
     94            extern(C) export void service(IDSPRequest request,IDSPResponse response){ 
     95                try{ 
     96                    ` ~ servletFunctionName(name) ~`(request,response); 
     97                } 
     98                catch(Exception e){ 
     99                    response.setException(e.toString());     
     100                } 
     101                catch(Object o){ 
     102                    response.setException("general servlet exception: " ~ o.toString());     
     103                }            
    95104            }` ~ newline 
     105            ; 
     106    } 
     107     
     108    public static char[] dependenciesSection(char[] dependenciesList,char[] modulePath){ 
     109        return  
     110            "static char[][] __dependencies = [`" ~ modulePath ~ "`," ~ dependenciesList ~ "];" ~ newline ~ 
     111            "extern(C) export char[][] dependencies(){ return __dependencies; }" ~ newline 
    96112            ; 
    97113    } 
  • trunk/dsp/DSPProcessor.d

    r49 r67  
    3333 
    3434 
    35 private import xml.IXMLConsumer
     35private import xml.IXMLConsumerAdapter
    3636private import xml.XMLAttributes; 
    3737 
     
    3939private import std.string; 
    4040 
    41 class DSPProcessor : IXMLConsumer
     41class DSPProcessor : IXMLConsumerAdapter
    4242    ServletGenerator generator; 
    4343    TagLibrary tags; 
     
    4848    } 
    4949     
    50     public char[] getServletSource(char[] modulePath){ 
    51         return generator.getServletSource(modulePath); 
     50    public char[] getServletSource(char[] modulePath,char[] fileExtension){ 
     51        return generator.getServletSource(modulePath,fileExtension); 
    5252    } 
    5353 
    5454    void xmlProlog(XMLAttributes attribs){ 
    55         writefln("parsed prolog"); 
    5655    } 
    5756     
  • trunk/dsp/RequestConfig.d

    r53 r67  
    3838    char[] cacheDirectory; 
    3939    char[] runtimeDirectory; 
     40    char[] options; 
    4041     
    4142    public char[] toString(){ 
     
    5253            "cacheDirectory: " ~ cacheDirectory ~ "\n" 
    5354            "runtimeDirectory: " ~ runtimeDirectory ~ "\n" 
     55            "options: " ~ options ~ "\n" 
    5456            ; 
    5557    } 
  • trunk/dsp/ServletCompiler.d

    r53 r67  
    6161 
    6262        parser.parse(processor, provider, stream); 
    63         std.file.write(cfg.dSourceFilename,cast(char[])processor.getServletSource(cfg.requestModule)); 
     63        std.file.write(cfg.dSourceFilename,cast(char[])processor.getServletSource(cfg.requestModule,cfg.ext)); 
    6464    } 
    6565     
     
    6767        char[] commandline = 
    6868            "dmd " ~ cfg.dSourceFilename ~  
     69            " " ~ cfg.options ~ 
    6970            " -op" ~ 
    7071            " -od" ~ cfg.tempDirectory ~  
     
    7374            " " ~ cfg.runtimeDirectory ~ "DllStub.obj" ~ 
    7475            " " ~ cfg.runtimeDirectory ~ "IDSPRequest.obj" ~ 
    75             " " ~ cfg.runtimeDirectory ~ "IDSPResponse.obj" ~ 
    76             " " ~ cfg.runtimeDirectory ~ "ServletRegistry.obj" ~             
     76            " " ~ cfg.runtimeDirectory ~ "IDSPResponse.obj" ~            
    7777            " " ~ cfg.runtimeDirectory ~ "servlet.def" ~ 
    7878            " -version=dsp" ~ 
     
    8585            " -op" ~ 
    8686            " -od" ~ cfg.tempDirectory ~  
    87             " dspruntime.lib" ~ 
     87            " mango.lib" ~ 
    8888            " servlet.def" ~ 
    8989            " -version=dsp" ~ 
     
    9191            ;    
    9292    */ 
    93             writefln("command: %s",commandline); 
     93            debug writefln("command: %s",commandline); 
    9494         
    9595        if(std.process.system(commandline) != 0){ 
  • trunk/dsp/ServletGenerator.d

    r49 r67  
    3535    char[] servletBody; 
    3636    char[] servletName; 
     37    char[] servletDependencies; 
    3738     
    3839    int contentMode; 
     
    147148    } 
    148149     
    149     public char[] getServletSource(char[] modulePath){ 
     150    public void addDependency(char[] dependency){ 
     151        servletDependencies ~= "`/" ~ dependency ~ "`,"; 
     152    } 
     153     
     154    public char[] getServletSource(char[] modulePath,char[] fileExtension){ 
    150155        return  
    151156            DSPGrammar.servletHeader(servletName,modulePath) ~  
     157            DSPGrammar.dependenciesSection(servletDependencies,"/" ~ modulePath ~ "." ~ fileExtension) ~ 
    152158            DSPGrammar.servletFunction(servletName,servletCPIn,servletBody,servletCPOut) 
    153159            ; 
  • trunk/dsp/servlet/DSPServlet.d

    r65 r67  
    3838private import dsp.RequestConfig; 
    3939 
     40private import mango.cache.Payload; 
     41private import mango.cache.QueuedCache; 
     42 
    4043private import mango.servlet.Servlet; 
     44private import mango.servlet.ServletContext; 
     45 
     46private import mango.http.utils.Dictionary; 
     47 
    4148private import mango.io.FilePath; 
     49private import mango.io.FileProxy; 
    4250private import mango.io.Uri; 
    4351private import mango.log.Logger; 
    4452 
     53private import mango.format.Int; 
     54 
    4555private import std.string; 
    4656 
    4757extern(C) alias void function(IDSPRequest request,IDSPResponse response) ServiceHandle; 
     58extern(C) alias char[][] function() DependencyHandle; 
     59 
     60//TODO: use SystemFinalizer to catch libraries that are still loaded at shutdown 
     61 
     62class DSPLibrary : Payload{ 
     63    protected long timeModified; 
     64    protected Library lib; 
     65    public ServiceHandle service; 
     66    protected DependencyHandle dependencies; 
     67 
     68    protected void unload(){ 
     69        debug printf("unloading library\n"); 
     70        lib.unload(); 
     71        lib = null; 
     72        service = null; 
     73        dependencies = null; 
     74        timeModified = 0; 
     75    } 
     76 
     77    public this(char[] path){ 
     78        lib = new Library(path); 
     79        if(lib && lib.isLoaded){ 
     80            service = cast(ServiceHandle)lib.getSymbol("service"); 
     81         
     82            if(!service){ 
     83                unload(); 
     84                throw new DSPException("servlet library does not have a valid service handle"); 
     85            } 
     86             
     87            dependencies = cast(DependencyHandle)lib.getSymbol("dependencies"); 
     88         
     89            if(!dependencies){ 
     90                unload(); 
     91                throw new DSPException("servlet library does not have a valid dependencies handle"); 
     92            } 
     93        } 
     94        else{ 
     95            if(lib){ 
     96                unload(); 
     97            } 
     98            throw new DSPException("could not load library"); 
     99        } 
     100         
     101        timeModified = (new FileProxy(path)).getModifiedTime(); 
     102    } 
     103     
     104    bit isOutOfDate(char[] basePath,FilePath path){ 
     105        if(!lib || !lib.isLoaded) return true; 
     106         
     107        // verify the date/time of the dependencies 
     108        foreach(char[] dep; dependencies()){ 
     109            debug printf("[%.*s%.*s]\n",basePath,dep); 
     110            if((new FileProxy(basePath ~ dep)).getModifiedTime() > timeModified){ 
     111                debug printf("%.*s%.*s : servlet is out of date.\n",basePath,dep);               
     112                unload(); // force unload 
     113                return true; 
     114            } 
     115        } 
     116         
     117        debug printf("%.*s%.*s : servlet is up to date.\n",basePath,path.toString());        
     118         
     119        return false; 
     120    } 
     121     
     122    void destroy (){ 
     123        printf("library: %.*s destroyed\n",lib.getPath); 
     124        unload(); 
     125    } 
     126     
     127    public char[] toString(){ 
     128        if(lib){ 
     129            if(lib.isLoaded){ 
     130                return "loaded: " ~ lib.getPath; 
     131            } 
     132            else{ 
     133                return "unloaded: " ~ lib.getPath; 
     134            } 
     135        } 
     136        return "[empty library]"; 
     137    } 
     138} 
    48139 
    49140/*  
    50     <p
     141    <desc
    51142        DSPServlet: dll-per-file implementation  
    52     </p><p
     143    </desc><desc
    53144        The size of the dlls is directly related to the size of the libraries contributed to its  
    54145        compilation.  Presently, the libs are floating arount 100kb in size each, due to the inclusion 
    55146        of phobos and mango.  Possibly loading those libs as dlls could reduce the size, as would recompiling 
    56147        them for a release or reduced-capability set. 
    57     </p><p
     148    </desc><desc
    58149        dll-per-file is not just for a development time practice, as it is very tunable. The QueuedCache 
    59150        can be used to good effect to expire infrequently used libs that needn't be loaded all the time. 
    60     </p
     151    </desc
    61152*/ 
    62153 
    63154class DSPServlet : Servlet{ 
    64     Library[char[]] libs; 
    65      
    66155    private static Logger logger; 
     156    protected QueuedCache cache; 
    67157 
    68158    static this (){ 
    69159        logger = Logger.getLogger ("dsp.servlets"); 
    70160    }    
    71  
    72     public this(){ 
    73     } 
    74      
    75     public ~this(){ 
    76         foreach(Library lib; libs){ 
    77             if(lib.isLoaded) lib.unload(); 
    78         } 
    79     } 
    80      
    81     Library getLibrary(DSPServletContext context,FilePath path){ 
    82         //TODO: make concurrent 
    83          
    84         Library lib = libs[path.toString()]; 
    85          
    86         //TODO: add check for file existence 
    87         //TODO: add check for library date and its validity vs the source file 
    88         if(!lib){ 
    89             RequestConfig cfg; 
    90              
    91             // configuration 
    92              
    93             cfg.pwd = context.getBasePath() ~ "\\"; 
    94             cfg.pwd = cfg.pwd.replace("/","\\"); 
    95             cfg.ext = path.getExtension(); 
    96              
    97             //HACK: filepath leaves prefixed '/' character on 
    98             cfg.name = path.getName()[1..$]; 
    99              
    100             cfg.modulePath = path.getPath(); 
    101             cfg.requestModule = cfg.modulePath ~ cfg.name; 
    102             cfg.dspSourceFilename = cfg.pwd ~ cfg.name ~ "." ~ cfg.ext; 
    103  
    104             cfg.tempDirectory = cfg.pwd ~ context.getConfiguration.get("temp-directory"); 
    105             cfg.cacheDirectory = cfg.pwd ~ context.getConfiguration.get("cache-directory"); 
    106  
    107             cfg.dSourceFilename = cfg.tempDirectory ~ cfg.name ~ ".d"; 
    108             cfg.destServletFilename = cfg.cacheDirectory ~ cfg.name ~ ".dll"; 
    109  
    110             cfg.runtimeDirectory = context.getConfiguration.get("runtime-directory"); 
    111  
    112             // debug 
    113             printf("%.*s\n",cfg.toString()); 
    114  
    115             // build the servlet library 
    116             ServletCompiler compiler = new ServletCompiler(); 
    117             compiler.CompileServlet(cfg); 
    118  
    119             // keep the library for later 
    120             lib = new Library(cfg.destServletFilename); 
    121             libs[path.toString()] = lib; 
    122         } 
     161     
     162     
     163    /*  
     164        <desc> 
     165            Attempt to recover the servlet from the library cache  
     166        </desc> 
     167    */ 
     168    DSPLibrary recoverLibrary(DSPServletContext context,FilePath path){ 
     169        char[] libraryPath = context.getBasePath ~ "/" ~ context.getConfiguration.get("cache-directory"); 
     170        libraryPath ~= path.getName[1..$] ~ ".dll"; 
     171         
     172        debug printf("attempting to recover: %.*s\n",libraryPath); 
     173         
     174        //TODO: check for file existence here or not? 
     175        try{ 
     176            return new DSPLibrary(libraryPath); 
     177        } 
     178         
     179        // catch-all here as the library may not be in a usable condition 
     180        //TODO: eliminate the library from the cache if it exists? 
     181        catch(Exception e){ 
     182            return null; 
     183        } 
     184    } 
     185 
     186 
     187    /* 
     188        <desc> 
     189            Attempt to build the library from scratch. 
     190        </desc> 
     191    */ 
     192    DSPLibrary buildLibrary(DSPServletContext context,FilePath path){ 
     193        DSPLibrary lib; 
     194        RequestConfig cfg; 
     195        Dictionary contextConfig = context.getConfiguration(); 
     196         
     197        // configuration 
     198        cfg.pwd = context.getBasePath() ~ "\\"; 
     199        cfg.pwd = cfg.pwd.replace("/","\\"); 
     200        cfg.ext = path.getExtension(); 
     201 
     202        //HACK: filepath leaves prefixed '/' character on 
     203        cfg.name = path.getName()[1..$]; 
     204 
     205        cfg.modulePath = path.getPath(); 
     206        cfg.requestModule = cfg.modulePath ~ cfg.name; 
     207        cfg.dspSourceFilename = cfg.pwd ~ cfg.name ~ "." ~ cfg.ext; 
     208 
     209        cfg.tempDirectory = cfg.pwd ~ contextConfig.get("temp-directory"); 
     210        cfg.cacheDirectory = cfg.pwd ~ contextConfig.get("cache-directory"); 
     211 
     212        cfg.dSourceFilename = cfg.tempDirectory ~ cfg.name ~ ".d"; 
     213        cfg.destServletFilename = cfg.cacheDirectory ~ cfg.name ~ ".dll"; 
     214 
     215        cfg.runtimeDirectory = contextConfig.get("runtime-directory"); 
     216         
     217        cfg.options = contextConfig.get("build-options"); 
     218 
     219        // debug 
     220        debug printf("%.*s\n",cfg.toString()); 
     221 
     222        // build the servlet library 
     223        ServletCompiler compiler = new ServletCompiler(); 
     224        compiler.CompileServlet(cfg); 
     225 
     226        // load the library 
     227        lib = new DSPLibrary(cfg.destServletFilename); 
     228 
    123229        return lib; 
    124230    } 
     
    135241            assert(dspResponse); 
    136242            assert(context); 
     243             
     244            dspResponse.setContentType("text/html"); 
    137245 
    138246            // bind to the needed dll on the fly 
    139247             
    140             Library lib = getLibrary(context,path); 
     248            DSPLibrary lib = cast(DSPLibrary)cache.get(request.getPathInfo); 
     249             
    141250            if(lib){ 
    142                 ServiceHandle handle = cast(ServiceHandle)lib.getSymbol("service"); 
    143  
    144                 // run the service handle 
    145                 if(handle){ 
    146                     handle(dspRequest,dspResponse); 
     251                printf("cache lib: %.*s = %.*s\n",request.getPathInfo,lib.toString()); 
     252            } 
     253            else{ 
     254                printf("cache lib: %.*s = [not present]\n",request.getPathInfo); 
     255            } 
     256             
     257            // attempt to recover the lib from the file cache 
     258            if(!lib){ 
     259                cache.extract(request.getPathInfo); // kill the cache entry 
     260                lib = recoverLibrary(context,path); 
     261                if(lib){ 
     262                    cache.put(request.getPathInfo,lib); 
    147263                } 
    148                 else{ 
    149                     throw new DSPException("servlet library does not have a valid service handle"); 
    150                 } 
    151  
    152                 dspResponse.getWriter.put("<h2>This is a test for DSP servlets</h2>"); 
    153  
    154                 if(dspResponse.isExceptionSet){ 
    155                     throw new DSPException("servlet: " ~ dspResponse.getException()); 
    156                 } 
    157             } 
    158             else{ 
    159                 throw new DSPException("could not load library"); 
    160             } 
     264            } 
     265             
     266            // rebuild the library if recovery fails or is out of date 
     267            if(!lib || lib.isOutOfDate(context.getBasePath,path)){ 
     268                lib = buildLibrary(context,path); 
     269                cache.put(request.getPathInfo,lib); 
     270            } 
     271             
     272            // run the servlet 
     273            lib.service(dspRequest,dspResponse); 
     274             
     275            //TODO: debug information 
    161276        } 
    162277        else{ 
     
    167282        } 
    168283    } 
     284     
     285    debug private import mango.http.utils.Dictionary; 
    169286 
    170287    void init (ServletConfig config) 
    171288    { 
    172         //TODO: is this needed? 
     289        //grab the cache size and concurrency from the config (somehow) 
     290        ServletContext context = config.getServletContext(); 
     291         
     292        debug{       
     293            foreach(DElement elem; context.getConfiguration()){ 
     294                printf("(servlet) config test: %.*s = %.*s\n",elem.name,elem.value); 
     295            } 
     296        } 
     297         
     298        uint threads = 0; 
     299        char[] serverThreads = context.getConfiguration.get("server-threads"); 
     300        if(serverThreads) threads = Int.parse(serverThreads); 
     301        if(threads == 0) threads = 16; 
     302         
     303        uint size = 0; 
     304        char[] dspCacheSize = context.getConfiguration.get("cache-size"); 
     305        if(dspCacheSize) size = Int.parse(dspCacheSize); 
     306        if(size == 0) size = 20; 
     307         
     308        debug printf("(cache config) size: %d threads: %d\n",size,threads); 
     309         
     310        cache = new QueuedCache(size,threads);       
    173311    }    
    174312} 
    175  
    176 /+ 
    177 /*  
    178     <p> 
    179         all-in-one implementation  
    180     </p><p> 
    181         The tradeoff for one dll per application is a smaller total runtime footprint at the cost of  
    182         more ram up-front and the inability to cache or unload pieces of the application.  There may 
    183         be situations where this mode is preferred, as it side-steps the limitations imposed by  
    184         wielding so many libs at once. 
    185     </p><p> 
    186         Developers may find that all-in-one works best for deployment only, and that it may be too 
    187         slow to recompile changes within even modestly sized applications. 
    188     </p> 
    189      
    190     TODO: needs compiler/generator support to work 
    191     TODO: may best rely on 'build' to get the job done 
    192 */ 
    193 class DSPAllInOneServlet : Servlet{ 
    194     Library lib; 
    195     ServletHandle handle; 
    196      
    197     private static Logger logger; 
    198  
    199     static this (){ 
    200         logger = Logger.getLogger ("dsp.servlets"); 
    201     }    
    202  
    203     public this(){ 
    204     } 
    205      
    206     public ~this(){ 
    207         if(lib && lib.isLoaded) lib.unload(); 
    208     } 
    209      
    210     Library getLibrary(DSPServletContext context,FilePath path){ 
    211         //TODO: make concurrent 
    212         //TODO: add check for file existence 
    213         //TODO: add check for library date and its validity vs the source file 
    214         if(!lib){ 
    215             RequestConfig cfg; 
    216              
    217             // configuration 
    218              
    219             cfg.pwd = context.getBasePath() ~ "\\"; 
    220             cfg.pwd = cfg.pwd.replace("/","\\"); 
    221             cfg.ext = path.getExtension(); 
    222              
    223             //HACK: filepath leaves prefixed '/' character on 
    224             cfg.name = path.getName()[1..$]; 
    225              
    226             cfg.modulePath = path.getPath(); 
    227             cfg.requestModule = cfg.modulePath ~ cfg.name; 
    228             cfg.dspSourceFilename = cfg.pwd ~ cfg.name ~ "." ~ cfg.ext; 
    229  
    230             cfg.tempDirectory = cfg.pwd ~ context.getConfiguration.get("temp-directory"); 
    231             cfg.cacheDirectory = cfg.pwd ~ context.getConfiguration.get("cache-directory"); 
    232  
    233             cfg.dSourceFilename = cfg.tempDirectory ~ cfg.name ~ ".d"; 
    234             cfg.destServletFilename = cfg.cacheDirectory ~ cfg.name ~ ".dll"; 
    235  
    236             cfg.runtimeDirectory = context.getConfiguration.get("runtime-directory"); 
    237  
    238             // debug 
    239             printf("%.*s\n",cfg.toString()); 
    240  
    241             // build the servlet library 
    242             ServletCompiler compiler = new ServletCompiler(); 
    243             compiler.CompileServlet(cfg); 
    244  
    245             // keep the library for later 
    246             lib = new Library(cfg.destServletFilename); 
    247             libs[path.toString()] = lib; 
    248         } 
    249         return lib; 
    250     } 
    251      
    252     void service (IServletRequest request, IServletResponse response){ 
    253         FilePath path = new FilePath(request.getPathInfo); 
    254          
    255         if(path.getExtension == "dsp"){ 
    256             IDSPRequest dspRequest = cast(IDSPRequest)request; 
    257             IDSPResponse dspResponse = cast(IDSPResponse)response; 
    258             DSPServletContext context = cast(DSPServletContext)request.getContext(); 
    259  
    260             assert(dspRequest); 
    261             assert(dspResponse); 
    262             assert(context); 
    263  
    264             // bind to the needed dll on the fly 
    265              
    266             Library lib = getLibrary(context,path); 
    267             if(lib){ 
    268                 ServiceHandle handle = cast(ServiceHandle)lib.getSymbol("service"); 
    269  
    270                 // run the service handle 
    271                 if(handle){ 
    272                     handle(dspRequest,dspResponse); 
    273                 } 
    274                 else{ 
    275                     throw new DSPException("servlet library does not have a valid service handle"); 
    276                 } 
    277  
    278                 dspResponse.getWriter.put("<h2>This is a test for DSP servlets</h2>"); 
    279  
    280                 if(dspResponse.isExceptionSet){ 
    281                     throw new DSPException("servlet: " ~ dspResponse.getException()); 
    282                 } 
    283             } 
    284             else{ 
    285                 throw new DSPException("could not load library"); 
    286             } 
    287         } 
    288         else{ 
    289             //TODO: use configuration and handling rules  
    290             //TODO: provide a directory listing if the file doesn't exist 
    291             logger.info ("request for file: " ~ request.getUri.getPath ~ " (" ~ request.getPathInfo ~ ")"); 
    292             response.copyFile (request.getContext, request.getPathInfo);         
    293         } 
    294     } 
    295  
    296     void init (ServletConfig config) 
    297     { 
    298         //TODO: is this needed? 
    299     }    
    300 } 
    301 +/ 
  • trunk/dsp/servlet/DSPServletProvider.d

    r57 r67  
    2626module dsp.servlet.DSPServletProvider; 
    2727 
     28private import xml.ConduitStream; 
     29 
     30private import dsp.ConfigParser; 
     31 
    2832private import dsp.servlet.DSPServlet; 
     33private import dsp.servlet.DSPServletContext; 
    2934private import dsp.servlet.DSPRequest; 
    3035private import dsp.servlet.DSPResponse; 
    3136 
    3237private import mango.servlet.ServletProvider; 
     38private import mango.servlet.ServletContext; 
    3339 
    3440private import mango.http.server.HttpRequest; 
     
    3743private import mango.http.server.model.IProviderBridge; 
    3844 
     45private import mango.http.utils.Dictionary; 
     46 
     47private import mango.io.FileConduit; 
     48 
    3949class DSPServletProvider : ServletProvider{ 
     50    protected MutableDictionary configuration; 
     51 
     52    public this (char[] configPath,uint urls = 2048){ 
     53        super(urls); 
     54         
     55        FileConduit fc = new FileConduit(configPath); 
     56         
     57        // load configuration 
     58        if(fc){ 
     59            ConduitStream cs = new ConduitStream(fc.getPath.getName,fc); 
     60            ConfigParser configParser = new ConfigParser(); 
     61            configuration = configParser.parse(cs); 
     62        } 
     63    } 
     64     
     65    public Dictionary getConfiguration(){ 
     66        return configuration; 
     67    } 
    4068 
    4169    override HttpRequest createRequest(IProviderBridge bridge){ 
    42         printf("create request\n"); 
     70        debug printf("DSPServletProvider: create request\n"); 
    4371        return new DSPRequest(bridge); 
    4472    } 
    4573 
    46     override HttpResponse createResponse(IProviderBridge bridge) 
    47     { 
    48         printf("create response\n"); 
     74    override HttpResponse createResponse(IProviderBridge bridge){ 
     75        debug printf("DSPServletProvider: create response\n"); 
    4976        return new DSPResponse(bridge); 
    5077    } 
     
    5380    { 
    5481        return "DSPServlet"; 
    55     }    
     82    } 
     83     
    5684} 
  • trunk/dspconf/config.xml

    r64 r67  
    11<?xml version="1.0"?> 
    22<config> 
    3     <temp-directory value="_temp\"/> 
    43    <cache-directory value="_cache\"/> 
     4    <cache-size value="2"/> 
    55    <runtime-directory value="c:\dev\dsp\trunk\runtime/"/> 
    6     <dmdopts></dmdopts
     6    <build-options value=""/
    77</config> 
  • trunk/dspconf/dsp01.dsp

    r55 r67  
    22<?dsp:in assert(response); ?> 
    33<?dsp:out assert(response); ?> 
    4 <?dsp:xml version="1.0" ?> 
    54<?dsp 
    65    char[] expr(){ 
     
    2019        else response.getWriter.put("hello world"); 
    2120    </dsp:code> 
     21    <p> 
     22        Changed Again IIIIIIII 
     23    </p> 
    2224</body> 
    2325</html> 
  • trunk/dspconf/dsp02.dsp

    r64 r67  
    11<?xml version="1.0" ?> 
    22<?dsp 
    3  
     3    response.getWriter.put("This is Servlet #2"); 
    44?> 
    55<html/> 
  • trunk/dspruntime.bat

    r51 r67  
    1 dmd -c dsp\servlet\ServletRegistry.d   -odruntime 
    21dmd -c dsp\servlet\IDSPRequest.d   -odruntime 
    32dmd -c dsp\servlet\IDSPResponse.d  -odruntime 
  • trunk/servertest.d

    r64 r67  
    9595 
    9696        // construct a servlet-provider 
    97         DSPServletProvider sp = new DSPServletProvider(); 
     97        DSPServletProvider sp = new DSPServletProvider("server.xml"); 
    9898 
    9999        // create a context for admin servlets 
  • trunk/xml/dom/std/CAttr.d

    r66 r67  
    2424    protected DOMTypeInfo _DOMTypeInfo; 
    2525 
    26     public this(in DOMString name){ 
     26    public this(CDocument document,DOMString name,DOMString value){ 
     27        super(document); 
    2728        _name = name; 
     29        _value = value; 
    2830    } 
    2931 
    30     public this(in DOMString namespaceURI, in DOMString qualifiedName){ 
     32    public this(CDocument document,in DOMString namespaceURI, in DOMString qualifiedName,DOMString value){ 
    3133        _name = qualifiedName; 
    3234        super.setQName(namespaceURI,qualifiedName); 
     35        _value = value; 
    3336    } 
     37     
     38    public void ownerElement(Element value){ _ownerElement = value; } 
    3439 
    3540 
  • trunk/xml/dom/std/CCharacterData.d

    r66 r67  
    1313abstract class CCharacterData : CNode, CharacterData{ 
    1414    protected DOMString _data; 
     15     
     16    protected this(CDocument document,DOMString data){ 
     17        super(document); 
     18        _data = data; 
     19    } 
    1520 
    1621    /+ CharacterData Overloads +/ 
     
    1924    void            data(DOMString value){ _data = value; } 
    2025 
    21     uint   length(){ return _data.length; } 
     26    uint               length(){ return _data.length; } 
    2227 
    23     DOMString          substringData(in uint offset,in uint count); 
    24     void               appendData(in DOMString arg); 
    25     void               insertData(in uint offset, in DOMString arg); 
    26     void               deleteData(in uint offset,  in uint count); 
    27     void               replaceData(in uint offset,in uint count,in DOMString arg); 
     28    DOMString       substringData(in uint offset,in uint count){ 
     29        if(offset+count >= _data.length){ 
     30            throw new DOMException(INDEX_SIZE_ERR); 
     31        }        
     32        return _data[offset..offset+count]; 
     33    } 
    2834     
    29 }; 
     35    void            appendData(in DOMString arg){ 
     36        _data ~= arg; 
     37    } 
     38     
     39    void            insertData(in uint offset, in DOMString arg){ 
     40        _data = _data[0..offset] ~ arg ~ _data[offset.._data.length]; 
     41    } 
     42     
     43    void            deleteData(in uint offset,  in uint count){ 
     44        if(offset+count >= _data.length){ 
     45            throw new DOMException(INDEX_SIZE_ERR); 
     46        } 
     47        _data = _data[0..offset] ~ _data[offset+count.._data.length]; 
     48    } 
     49     
     50    void            replaceData(in uint offset,in uint count,in DOMString arg){ 
     51        if(offset+count >= _data.length){ 
     52            throw new DOMException(INDEX_SIZE_ERR); 
     53        }    
     54        _data = _data[0..offset] ~ arg ~ _data[offset+count.._data.length]; 
     55    } 
     56
  • trunk/xml/dom/std/CDocument.d

    r66 r67  
    7272         
    7373    DocumentFragment        createDocumentFragment(){ 
    74         return new CDocumentFragment(); 
     74        return new CDocumentFragment(this); 
    7575    } 
    7676     
    7777    Text                    createTextNode(in DOMString data){ 
    78         return new CText(); 
     78        return new CText(this,data); 
    7979    } 
    8080     
    8181    Comment                 createComment(in DOMString data){ 
    82         return new CComment(data); 
     82        return new CComment(this,data); 
    8383    } 
    8484     
    8585    CDATASection            createCDATASection(in DOMString data){ 
    86         return new CCDATASection(data);    
     86        return new CCDATASection(this,data);   
    8787    }  
    8888     
     
    9191        //according to the XML version in use specified in the Document.xmlVersion attribute.  
    9292     
    93         return new CProcessingInstruction(target,data): 
     93        return new CProcessingInstruction(this,target,data): 
    9494    } 
    9595     
     
    9797        //TODO: NVALID_CHARACTER_ERR: Raised if the specified name is not an XML name  
    9898        //according to the XML version in use specified in the 
    99         return new CAttr(name); 
     99        return new CAttr(this,name); 
    100100    } 
    101101     
     
    105105        //according to the XML version in use specified in the 
    106106     
    107         CEntityReference value = new CEntityReference(name); 
     107        CEntityReference value = new CEntityReference(this,name); 
    108108        //TODO: find corresponding Entity and copy child list to 'value'. 
    109109        return value; 
     
    111111         
    112112    NodeList                getElementsByTagName(in DOMString tagname){ 
    113         CNodeList list = new CNodeList(); 
    114          
    115         //TODO: add matching tags in document order ("*" means all) 
     113        if(tagname == "*") return super._children.dup(); 
     114         
     115        NodeList list = new CNodeList(); 
     116         
     117        foreach(Node node; super._children){ 
     118            if(node.name == name) list.append(node); 
     119        } 
     120         
    116121        return list; 
    117122    } 
     
    127132        // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS 
    128133         
    129         return new CElement(namespaceURI,qualifiedName); 
     134        return new CElement(this,namespaceURI,qualifiedName); 
    130135    } 
    131136 
     
    134139        // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS 
    135140         
    136         return new CAttr(namespaceURI,qualifiedName);     
     141        return new CAttr(this,namespaceURI,qualifiedName);     
    137142    } 
    138143 
  • trunk/xml/dom/std/CNamedNodeMap.d

    r66 r67  
    1515    Node[DOMString] map; 
    1616 
     17    /+ NamedNodeMap Overrides +/ 
    1718    public Node getNamedItem(in DOMString name){ 
    1819        return map[name]; 
     
    5859}; 
    5960 
    60 //TODO: implement a read-only map 
     61 
     62 
     63class CReadOnlyNamedNodeMap : CNamedNodeMap{ 
     64    Node[DOMString] map; 
     65 
     66    public Node setNamedI