Re: [Simpleweb-Support] Content Based Resolving
Brought to you by:
niallg
From: Niall G. <gal...@ya...> - 2005-12-08 21:37:16
|
Hi Brian, This looks like it will work. However, how are you implementing your model? It is often good to have an empty shell service that can interact with your applications data, and then push this data into the template. If you are implementing a FreemarkerService, how is this achieved? For example: public Document execute(Request a, Response b, Document c) { MyData d = MyModel.someOperation(); c.put("data", d); return c; } Niall --- Brian Davis <wic...@gm...> wrote: > Hi Niall > > Actually.. I am looking to implement the following.. > Basically.. the > idea is that instead of using the resolver to > resolve to the correct > service.. the engine would instead ask each > registered service to > handle the request, in succession.. > > for each service > { > int status = service.handle(req, res); > > if (status == HANDLED) > { > break; > } > } > > Any thoughts? > > public class Server throws Exception > { > public Server(Host host) > { > _host = host; > > _loader = new SerialLoader(); > > Iterator it = host.roots(); > > while (it.hasNext()) > { > _loader.addContext(new FileContext(root)); > } > > > _loader.register("com.wickedfastsolutions.server.app.KillService"); > > _loader.register("com.wickedfastsolutions.server.app.ProtocolHandlerService"); > > _loader.register("com.wickedfastsolutions.server.app.DiretoryListingService"); > > _loader.register("com.wickedfastsolutions.server.app.FreeMarkerService"); > > _loader.register("com.wickedfastsolutions.server.app.FileService"); > > ProtocolHandler handler = > ProtocolHandlerFactory.getInstance(_loader); > > Connection connection = > ConnectionFactory.getConnection(handler); > > connection.connect(new > ServerSocket(_host.getPort(), 50, > InetAddress.getByName(_host.getAddress()))); > > System.err.println("Current Time is " + new > Date()); > System.err.println("Server is running at " + > _host.getAddress() + " port " + _host.getPort()); > } > > public static void main(String[] args) throws > Exception > { > Host host = new Host(); > > host.addRoot(new File("test/carol")); > host.addRoot(new File("test/templates1")); > host.addRoot(new File("test/templates2")); > > host.addRoot(new File("test")); > host.setAddress("127.0.0.1"); > host.setPort(2000); > > _server = new Server(host); > } > > public static Server getServer() > { > return _server; > } > > public Host getHost() > { > return _host; > } > > public SerialLoader getLoader() > { > return _loader; > } > > private Host _host; > private SerialLoader _loader; > private static Server _server; > } > > > On 12/2/05, Niall Gallagher > <gal...@ya...> wrote: > > Hi Brian, > > > > With regard to directory references that do not > end > > with "/", this is handled in the FileEngine > > implementation. You can delegate to this when you > have > > to download static content such as images. > > > > Regarding content based resolving, it would > certainly > > be an attractive feature. However, how does a > template > > engine know which files are templates? A template > with > > no template markup is still a template. In any > event > > the templating system may have to parse the > template > > to figure out if it is a template, which could be > > slow. I cannot comment too much on Freemarker, is > it > > able to peek into files and determine whether it > is a > > template or not? > > > > Finally, why not resolve in reverse. For instance > let > > everything be a template, and match images and > other > > non-text content to a specific service. For > instance > > > > resolve match="*" name="template" > > type="example.TemplateService" > > resolve match="/*.zip" name="file" > > type="example.FileService" > > resolve match="/images/*" name="file" > > type="example.FileService" > > > > Something that may interest you is the tiles > > implementation in simple.template. It does not use > a > > file extension, instead it caches mismatches. So > it > > assumes everything is a template, if after a peek > it > > turns out not to be this information is cached, so > a > > second peek is not performed. This somewhat > reduces > > the overhead of peeking into the file. > > > > Niall > > > > --- Brian Davis <wic...@gm...> wrote: > > > > > Hmm.. > > > > > > The URL resolver is useful under certain > contexts... > > > However.. I can > > > envision at least 2 scenerios in which I would > have > > > better luck with a > > > content based resolver. Let me illustrate.. > > > > > > Let's say for example that I want to have a url > > > resolve to my > > > directorylistingservice... how would i write a > regex > > > to support that.. > > > while link */ is easy.. what about urls that > don't > > > end in /.. > > > > > > a more appropriate check might be .... if (new > > > File(requestPath).isDirectory() && canRead()) > > > > > > Scenerio two.. > > > > > > Basically I want to use a template engine such > as > > > FreeMarker on files. > > > However, I want to use the simple framework to > > > return everything > > > else.. (those things that are not FreeMarker > > > templates)... Now you > > > might say that link("*.ftl", FreeMarkerService) > is > > > the way to do it.. > > > > > > However, it would be better if I could forget > the > > > file extension and > > > use FreeMarker syntax in .txt, .html, .csv, > .xml.. > > > in this way the web > === message truncated === Niall Gallagher __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |