I'm working on integrating the Java API of WURFL (
http://wurfl.sourceforge.net ) into an OPS application. Because the WURFL datafile is a fairly large XML document, I decided to write a servlet context listener pipeline to initialize the Java WURFL tools at server startup time. I now have running code, but in the process, I had to work around a lot of difficulty in writing a custom processor to go in that pipeline. I'm hoping someone here can tell me a better way. The WURFL Java tooling looks for its datafile (wurfl.xml) and an optional patch file (wurfl_patch.xml) in only a few places - by default, only /WEB-INF/ of a webapp, or /tmp/. I wanted to be able to put the datafiles anywhere I wanted, which means that I have to initialize WURFL by handing it InputStreams for those two files. (Unfortunately, the WURFL api won't accept a stream of SAX events.) I configured OPS to run the pipeline processor at servlet startup, and wrote a custom processor to be run inside that pipeline. I wanted to be able to read "oxf:/" URLs from the procesor's configuration, something like this: <p:processor name="my:wurfl-init-processor"> <p:input name="config"> <config> <wurfl-loc>oxf:/data/wurfl/wurfl.xml</wurfl-loc> <wurfl-patch-loc>oxf:/data/wurfl/wurfl_patch.xml</wurfl-patch-loc> </config> </p:input> </p:processor> I couldn't get this to work, though, because I couldn't find any way to get a ResourceManager within my custom processor, and thus, I had no way to resolve "oxf:/" URLs. I tried several different ways to initialize ResourceManagerWrapper, but I could never get it properly initialized. I finally had to do something like this (heavily abridged) in my processor: public void start(PipelineContext context) { Document config = readInputAsDOM4J(context, "config"); String wurflLoc = config.valueOf("/config/wurfl-loc"); String wurflPatchLoc = config.valueOf("/config/wurfl-patch-loc"); ExternalContext externalCtx = (ExternalContext) context.getAttribute(PipelineContext.EXTERNAL_CONTEXT); ServletContext srvCtx = (ServletContext) externalCtx.getNativeContext(); File wurflFile = new File(srvCtx.getRealPath(wurflLoc)); File wurflPatchFile = new File(srvCtx.getRealPath(wurflPatchLoc)); // and then open InputStreams and pass them to WURFL } This means that I have to use webapp-relative paths in my configuration: <wurfl-loc>/WEB-INF/resources/data/wurfl/wurfl.xml</wurfl-loc> <wurfl-patch-loc>/WEB-INF/resources/data/wurfl/wurfl_patch.xml</wurfl-patch-loc> That's not unworkable, but I'd rather be able to take advantage of the extra layer of indirection provided by the "oxf:/" protocol. Also, it means my processor has an explicit dependency on the Servlet API. So, finally, the question: Can anyone tell me how I can get access to my ResourceManager from within this processor? Thanks for reading through such a long email. Any suggestions would be greatly appreciated. Jeff Jones The Weather Channel Interactive -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Jeff,
Try: ResourceManager resourceManager = ResourceManagerWrapper.instance(); From there, you can call several methods, including getting an InputStream, a SAX stream, etc. -Erik Jeff Jones wrote: > I'm working on integrating the Java API of WURFL ( > http://wurfl.sourceforge.net ) into an OPS application. Because the > WURFL datafile is a fairly large XML document, I decided to write a > servlet context listener pipeline to initialize the Java WURFL tools at > server startup time. I now have running code, but in the process, I had > to work around a lot of difficulty in writing a custom processor to go > in that pipeline. I'm hoping someone here can tell me a better way. > > The WURFL Java tooling looks for its datafile (wurfl.xml) and an > optional patch file (wurfl_patch.xml) in only a few places - by default, > only /WEB-INF/ of a webapp, or /tmp/. I wanted to be able to put the > datafiles anywhere I wanted, which means that I have to initialize WURFL > by handing it InputStreams for those two files. (Unfortunately, the > WURFL api won't accept a stream of SAX events.) > > I configured OPS to run the pipeline processor at servlet startup, and > wrote a custom processor to be run inside that pipeline. I wanted to be > able to read "oxf:/" URLs from the procesor's configuration, something > like this: > > <p:processor name="my:wurfl-init-processor"> > <p:input name="config"> > <config> > <wurfl-loc>oxf:/data/wurfl/wurfl.xml</wurfl-loc> > <wurfl-patch-loc>oxf:/data/wurfl/wurfl_patch.xml</wurfl-patch-loc> > </config> > </p:input> > </p:processor> > > I couldn't get this to work, though, because I couldn't find any way to > get a ResourceManager within my custom processor, and thus, I had no way > to resolve "oxf:/" URLs. I tried several different ways to initialize > ResourceManagerWrapper, but I could never get it properly initialized. > > I finally had to do something like this (heavily abridged) in my processor: > > public void start(PipelineContext context) { > Document config = readInputAsDOM4J(context, "config"); > > String wurflLoc = config.valueOf("/config/wurfl-loc"); > String wurflPatchLoc = config.valueOf("/config/wurfl-patch-loc"); > > ExternalContext externalCtx = (ExternalContext) > context.getAttribute(PipelineContext.EXTERNAL_CONTEXT); > > ServletContext srvCtx = (ServletContext) > externalCtx.getNativeContext(); > > File wurflFile = new File(srvCtx.getRealPath(wurflLoc)); > File wurflPatchFile = new File(srvCtx.getRealPath(wurflPatchLoc)); > > // and then open InputStreams and pass them to WURFL > } > > This means that I have to use webapp-relative paths in my configuration: > > <wurfl-loc>/WEB-INF/resources/data/wurfl/wurfl.xml</wurfl-loc> > <wurfl-patch-loc>/WEB-INF/resources/data/wurfl/wurfl_patch.xml</wurfl-patch-loc> > > > That's not unworkable, but I'd rather be able to take advantage of the > extra layer of indirection provided by the "oxf:/" protocol. Also, it > means my processor has an explicit dependency on the Servlet API. > > So, finally, the question: Can anyone tell me how I can get access to my > ResourceManager from within this processor? > > Thanks for reading through such a long email. Any suggestions would be > greatly appreciated. > > Jeff Jones > The Weather Channel Interactive -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |