From: Keats K. <ke...@xa...> - 2004-12-03 15:12:04
|
You can just cast the Context to a WebContext. Here's an example from the CGITool: public Object init (Context context) throws PropertyException { try { WebContext wc = (WebContext) context; CGI_Impersonator cgi = new CGI_Impersonator(wc); return cgi; } catch (ClassCastException ce) { throw new PropertyException( "CGITool only works with WebContext", ce); } } This is a good concept. In fact we talked about creating a BrowserTool years ago, but nobody ever got around to it. Keats marcel.huijkman wrote: > Thanks for the advise. > This is the stuff in my log-file: > > 03-12-2004 00:21:08.734 broker NOTICE starting > org.webmacro.Broker: WebMacro.properties > 03-12-2004 00:21:08.734 broker NOTICE Loaded settings from > WebMacro.defaults, WebMacro.properties, (System Properties) > 03-12-2004 00:21:08.734 broker WARNING Context object Info is > not of type ContextObjectFactory > > So I changes a little bit but now I found out that Context isn't quite > the same as WebContext. > > What do I want it for? > > In WebContext you could do getRequest() > which eventually could give you stuff like "USER_AGENT" > > So I could make a $BrowserInfo or something which would tell you the > browser's name or stuff like that. > Based on this, you could make some clever markup things. > > I've got loads of utils, but it would be nice if I could share them > with others. > > So please kick me some more :-) > > > > > > > Keats Kirsch wrote: > >> Turn on debugging and check the log. It should show whether or not >> the Info tool got loaded and why it might have failed. >> >> Keats >> >> marcel.huijkman wrote: >> >>> I'm playing with this 'trick' but can't get it to work. >>> >>> in my webmacro.defaults I've got this: >>> ContextTools.Info: org.webmacro.util.Info >>> >>> But when I do this in my template: >>> $Info >>> >>> It says: >>> Exception:org.webmacro.PropertyException$UndefinedVariableException: >>> Attempted to write an undefined variable: $Info at >>> c:\mydir\wsf\templates\index.wmt:15.1 >>> >>> So I think I must be doing something wrong. >>> >>> If somebody could kick me in the right direction, I'll sent some >>> virtual flowers from Holland :-) >>> >>> >>> >>> >>> Keats Kirsch wrote: >>> >>>> I had developed a way to use "context-aware" functions, but I think >>>> the concept was rejected in favor of the new AutoContextVariable >>>> concept. >>>> I believe it works something like: >>>> >>>> public class ContextManipulator implements ContextAutoLoader { >>>> public Object get(String name, Context context) throws >>>> PropertyException { >>>> return doSomethingWithTheContext(context); >>>> } >>>> } >>>> >>>> I think you configure this as a ContextTool, like: >>>> >>>> ContextTools.Manipulate: com.acme.wm.ContextManipulator >>>> >>>> And then access it in the template like: >>>> >>>> $Manipulate >>>> >>>> Hope this helps. >>>> >>>> Keats >>>> >>>> marcel.huijkman wrote: >>>> >>>>> How to get the context into a ContextTool? >>>>> >>>>> I am playing with a ContextTool, which does a lot for me, but I >>>>> want to be able to manipulate the context from within my too. >>>>> >>>>> I can do it in a dirty kind of way, by putting the context in >>>>> a var "WM_CONTEXT" into the context. >>>>> >>>>> And if I have to get of set something, I'll do it like this in my >>>>> template: >>>>> $util.manipulate($WM_CONTEXT); >>>>> >>>>> But I was wandering if there isn't any better, cleaner way to do >>>>> this? >>>>> Can a ContextTool (that is loaded once) manipulate the exact context >>>>> the end-user is playing with? >>>>> >>>>> - Marcel - >>>>> >>>>> PS. I start working for a java-company next year, so I hope to do >>>>> more WM. >>>>> |