Barracuda: RE: One possible solution to URL parameters in event sequence (contribution acceptable?)

"Christian Cryder" <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Hi Jack!

Ok, I want to implement this solution, prefereably in the next day or two.
So...couple of questions:

1. Can you send me the actuall classes modified? That will make it easier
for me to review the code...

2. What about multiple param values?

> >     public void setParam(String key, String val) {
> >         if (params==null) params = new HashMap(10);
> >         params.put(key, val);
> >     }

As its implemented right now, it will overwrite them. I'm guessing this is
just oversight, but I thought I'd check with you.

3. Just to make sure I understand, the idea behind your changes to
DefaultEventDispatcher is that if the event being dispatched contains
params, it would add those into the req object, as if they were their all
along, right?

Let me know, and we'll make this happen el pronto...

Christian
----------------------------------------------
Christian Cryder [[email protected]]
Internet Architect, ATMReports.com
Barracuda - http://barracuda.enhydra.org
----------------------------------------------
"Coffee? I could quit anytime, just not today"


> -----Original Message-----
> From: Jack Hodges [mailto:[email protected]]
> Sent: Tuesday, December 03, 2002 3:31 PM
> To: Christian Cryder
> Cc: Jack Hodges
> Subject: RE: One possible solution to URL parameters in event sequence
> (contribution acceptable?)
>
>
> Christian,
>
> I just got back to work from vacation and hoped you would have
> looked at my contribution and made a response. Is this something
> you guys would consider putting into the code? It would help
> solve that other guy's (more recent) problem with CSREs, because
> he could use the event sequence directly.
>
> Jack Hodges
> EFI
>
> > -----Original Message-----
> > From: Jack Hodges [mailto:[email protected]]
> > Sent: Friday, November 22, 2002 1:46 AM
> > To: '[email protected]'
> > Cc: Jack Hodges
> > Subject: One possible way to solve my problem, is this feasible
> > (compiles at least, my ant is failing so I cannot test)
> >
> >
> > Christian,
> >
> > This is probably a very short-sighted hack, but would the
> > following work? It
> > augments two classes:
> >
> >  - DefaultBaseEvent
> >  - DefaultEventDispatcher
> >
> > The idea here is to be able to do the following:
> >
> >   BaseEvent newEvent = (LocalRequestEvent)cls.newInstance();
> >   newEvent.setParam("key1", key1Val1);
> >   newEvent.setParam("key2", key2Val2);
> >   newEvent.setSource(baseEvent);
> >   context.getQueue().addEvent(newEvent);
> >
> > The idea is that when the event is about to be dispatched, we find the
> > listeners, and this is the first/last place where the event and
> > the context
> > are brought together as unique entities, so we could marry the event
> > paramteres to the context request here. Since the parameters
> are following
> > the event around through its journey, but aren't appropriate
> > until the event
> > is about to be handled, this seemed like the appropriate spot to do the
> > dirty work.
> >
> > ==================================================================
> > ==========
> > ====
> > In DefaultBaseEvent: [create a params map with accessors,
> > although I didn't
> > have
> >                       a use for getEvent()]
> >
> > public abstract class DefaultBaseEvent implements BaseEvent {
> >     ...
> >     // jbh_112202.1_start
> >     protected Map params = null; // private parameter map
> >     // end_jbh_112202.1
> >
> >     ...
> >
> >     //jbh_112202.2 - this method (with additional parameter) added from
> > BAction
> >     //csc_101701.1 - this method (with additional parameter) added
> >     /**
> >      * Get the action to be fired by this component. The action
> >      * will either be the URL or the Event that backs this component
> >      *
> >      * @param vc the ViewContext that determines the context of
> the action
> >      * @param preventRewriting this should be set to true only
> if you want
> > to
> >      *      prevent URLRewriting from taking place. As a developer, you
> >      *      will probably never need to do this, unless to need
> to further
> >      *      modify the action prior to finally encoding it
> > (HTMLActionRenderer
> >      *      does this)
> >      * @return a string representing the action to be fired by this
> > component
> >      */
> >     public String getEvent() {
> >         StringBuffer sb  = new StringBuffer(200);
> >         String       sep = "?";
> >
> >         sb.append(getEventIDWithExtension());
> >
> >         if (params != null && params.size() > 0) {
> >             Iterator it  = params.keySet().iterator();
> >
> >             while (it.hasNext()) {
> >                 Object key = it.next();
> >                 Object val = params.get(key);
> >
> >                 if (key != null && val != null) {
> >                     if (val instanceof String[]) {
> >                         String [] vals = (String [])val;
> >
> >                         for (int i = 0; i < vals.length; i++) {
> >                             sb.append(sep);
> >
> sb.append(URLEncoder.encode(key.toString()));
> >                             sb.append("=");
> >
> > sb.append(URLEncoder.encode(vals[i].toString()));
> >                         }
> >                     } else {
> >                         sb.append(sep);
> >                         sb.append(URLEncoder.encode(key.toString()));
> >                         sb.append("=");
> >                         sb.append(URLEncoder.encode(val.toString()));
> >                     }
> >                 }
> >
> >                 sep = "&";
> >             }
> >         }
> >
> >         return sb.toString();
> >     }
> >     // end_jbh_112202.2
> >
> >     //jbh_112202.3_start
> >     //-------------------- Params ------------------------------
> >     /**
> >      * Set any associated params
> >      */
> >     public void setParam(String key, String val) {
> >         if (params==null) params = new HashMap(10);
> >         params.put(key, val);
> >     }
> >
> >     /**
> >      * Get any associated params
> >      */
> >     public Map getParams() {
> >         return params;
> >     }
> >     //end_jbh_112202.3
> >
> >
> > ==================================================================
> > ==========
> > IN DefaultEventDispatcher: [Get the request object from the
> > context, get the
> >                             params from the event, and map one to
> > the other]
> >
> >     protected void notifyListeners(BaseEvent event, List list,
> > EventContext
> > context) throws EventException {
> >         // jbh_112202.1_start
> >         HttpServletRequest req    =
> > ((ControlEventContext)context).getRequest();
> >         Map                params =
> ((DefaultBaseEvent)event).getParams();
> >
> >         if (req != null && params != null) {
> >             Iterator eventKeys = params.keySet().iterator();
> >
> >             while (eventKeys.hasNext()) {
> >                 String key = (String)eventKeys.next();
> >                 req.setAttribute(key, params.get(key));
> >             }
> >         }
> >         // end_jbh_112202.1
> >
> > I suppose the big question is, and you would know this, can I cast an
> > EventContext to a ControlEventContext, and can I cast a BaseEvent to a
> > DefaultBaseEvent? After all, the latter are extensions or
> > implementations of
> > the former.
> >
> > When you said you hadn't thought of an elegant way to do something like
> > this, I wondered if maybe you hadn't thought of even a hacky
> way to do it,
> > which perhaps this is.
> >
> > Jack Hodges
> > EFI
>

_______________________________________________
Barracuda mailing list
[email protected]
http://www.enhydra.org/mailman/listinfo.cgi/barracuda
FAQ - http://www.jguru.com/faq/Barracuda
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.