Re: Startup/Shutdown Action can get access to 'site'
"Andres Alcarraz" <[email protected]> Tue, 8 May 2007 01:31:15 -0300
| Newsgroups | gmane.comp.java.jpublish.devel |
|---|---|
| Message-ID | <[email protected]> |
--===============0106023266== Content-Type: multipart/alternative; boundary="----=_Part_2210_16355779.1178598675246" ------=_Part_2210_16355779.1178598675246 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Wow that was quick, Thank you very much Florin I'll test this tomorrow ASAP= . Have a nice day Andr=E9s 2007/5/8, Florin T.PATRASCU <[email protected]>: > > Hi Andres, > is done; a bit different than your proposal, but with the same or better > effect, I hope ;) > I believe you have to wait a bit for the sf.net to synchronize the public > CVS before you can grab the updated version of JP3. > > For Java actions you will have now a minimum context available at startup > and shutdown. In this context you don't have only the 'site' but you'll a= lso > find few helpers to help you do ... stuff at startup :) > > These helpers are: > > RequestContext.JPUBLISH_DATE_UTILITIES > RequestContext.JPUBLISH_NUMBER_UTILITIES > "messageUtilities" > RequestContext.JPUBLISH_SYSLOG > > and the one that you requested: > RequestContext.JPUBLISH_SITE > > > I tested my changes with the followings: > - in jpublish.xml > <action-manager> > <startup-action name=3D"org.jpublish.test.JavaStartUpAction"/> > .... > > - JavaStartUpAction.java (excerpt) > public void execute(RequestContext context, Configuration > configuration) { > > Log syslog =3D (Log) context.get(RequestContext.JPUBLISH_SYSLOG); > SiteContext site =3D context.getSiteContext(); // or ...get( > RequestContext.JPUBLISH_SITE > > syslog.info("configuration path: "+site.getConfigurationPath()); > > } > > > And you have a space (the context received by the Action) where all the > startup actions can share Objects. This is happening because I am reusing > the same context for all the Actions executed at startup; a similar appro= ach > being used for shutdown. > > I hope it helps, > -florin > > > PS > Now I have to back-port this functionality to JPublish 2.0 ;) > > > On 07-May-07, at 21:52 , Andres Alcarraz wrote: > > Hello Florin thank you very much for answering so fast, but problem I'm > having is in a Java class action, there es where I cannot access the site > context. > Precisely I'm now trying to use java classes for actions, I'm not trying > to migrate all the application that previously used beanshell actions to > this new approach but I want new things in pure java. > What I don't understand is that asymmetry between java class based action > and script based ones. I'm not saying Jpublish is a bad thing, i've been > using it from years but nobody and nothing is perfect. > In fact what I tried to say is that java class based actions have nothing > to do at start up if they can not access the site context, because where > could they put any object created? > My intention was to mention a quick and backward compatible fix > (StartupAction interface) that I have no problem to implement, the same > problem may be occurring in Shutdown actions so there may be a better nam= e > :). > Certainly I can fix that in my own Application by calling a StartupAction > from a generic BeanShell kind of adapter where the action class is a > parameter of the beanshell adapter script. > > my proposal is to define a new interface: > public interface StartupAction extends Action{ > public void setSiteContext(SiteContext context); > } > > And in the part of the code where the action is found (in findAction() > when handling start up actions) > if (action instanceof StartupAction) > ((StartupAction)action).setSiteContext(siteContext); > > or something like this. > > Best regards and thanks again > > Andr=E9s > > > 2007/5/7, Florin T.PATRASCU <[email protected] >: > > > > Hi, > > > > If you need the SiteContext in startup actions, then in your Action > > (bsh, js, etc.) you can simply use the parameter 'site'. For example, > > a simple startup Action (StartUpTest.bsh) containing only one line > > of code: > > > > syslog.info( "configuration path: > > "+site.getConfigurationPath()); > > > > The file jpublish.xml: > > ... > > <action-manager> > > <startup-action name=3D"StartUpTest.bsh"/> > > </action-manager> > > ... > > > > And when you'll start your JPublish application you'll see in the > > logs something like this: > > ... > > 2275 [main] INFO syslog - configuration path: > > WEB-INF/jpublish.xml > > ... > > > > Don't worry, JPublish is a fine application :) > > -florin > > > > > > On 07-May-07, at 16:16 , Andres Alcarraz wrote: > > > > > Hi all, I was trying to make a java startup action when I realized > > > that I cannot access the site context from them because the Context i= s > > > null, that doesn't occur in script actions where you have a reference > > > to the site context, I wonder what is the sense of having a startup > > > action that has no access to the site context. > > > Looking at the code I've found that when an action script is found > > > site context is passed through the constructor, but that doesn't > > > happen in java actions, I think the execute method could have more > > > parameters or Action interface could have a setSiteContext() method, = I > > > know this would not be backward compatible, but a new StartupAction > > > could be defined. > > > What others means do i have to access the site context from a java > > > startup action? > > > > > > I'm using jpublish 3.0b2 thanks in advance > > > > > > > > > Andr=E9s > > > > > > ---------------------------------------------------------------------= - > > > --- > > > This SF.net email is sponsored by DB2 Express > > > Download DB2 Express C - the FREE version of DB2 express and take > > > control of your XML. No limits. Just data. Click to get it now. > > > http://sourceforge.net/powerbar/db2/ > > > _______________________________________________ > > > Jpublish-developer mailing list > > > [email protected] > > > https://lists.sourceforge.net/lists/listinfo/jpublish-developer > > > > > > > > -----------------------------------------------------------------------= -- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > Jpublish-developer mailing list > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/jpublish-developer > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/_____________________________________= __________ > Jpublish-developer mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jpublish-developer > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Jpublish-developer mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jpublish-developer > > ------=_Part_2210_16355779.1178598675246 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Wow that was quick, Thank you very much Florin I'll test this tomorrow = ASAP.<br><br>Have a nice day<br><br>Andr=E9s<br><br><div><span class=3D"gma= il_quote">2007/5/8, Florin T.PATRASCU <<a href=3D"mailto:[email protected]= ">[email protected] </a>>:</span><blockquote class=3D"gmail_quote" style=3D"border-left: 1px= solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><= div style=3D"">Hi Andres,<div><br></div><div>is done; a bit different than = your proposal, but with the same or better effect, I hope ;) <div><br></div><div>I believe you have to wait a bit for the <a href=3D"htt= p://sf.net" target=3D"_blank" onclick=3D"return top.js.OpenExtLink(window,e= vent,this)">sf.net</a> to synchronize the public CVS before you can gr= ab the updated version of JP3. </div><div><br></div><div>For Java actions you will have now a minimum cont= ext available at startup and shutdown. In this context you don't have o= nly the 'site' but you'll also find few helpers to help you do = ... stuff at startup :) </div><div><br></div><div>These helpers are:</div><div><br></div><div style= =3D"text-align: justify;"><span style=3D"white-space: pre;">=09</span>Reque= stContext.JPUBLISH_DATE_UTILITIES</div><div style=3D"text-align: justify;">= <span style=3D"white-space: pre;"> =09</span>RequestContext.JPUBLISH_NUMBER_UTILITIES</div><div style=3D"text-= align: justify;"><span style=3D"white-space: pre;">=09</span>"messageU= tilities"</div><div style=3D"text-align: justify;"><span style=3D"whit= e-space: pre;"> =09</span>RequestContext.JPUBLISH_SYSLOG</div><div style=3D"text-align: jus= tify;"><br></div><div style=3D"text-align: justify;">and the one that you r= equested:</div><div style=3D"text-align: justify;"><span style=3D"white-spa= ce: pre;"> =09</span>RequestContext.JPUBLISH_SITE</div><div style=3D"text-align: justi= fy;"><br></div><div><br></div><div>I tested my changes with the followings:= </div><div>- in jpublish.xml</div><div><span style=3D"white-space: pre;">= =09</span> <action-manager></div><div><span style=3D"white-space: pre;">=09</spa= n> <startup-action name=3D"org.jpublish.test.JavaStart= UpAction"/></div><div>....</div><div><br></div><div>- JavaStartUpAc= tion.java (excerpt) </div><div> public void execute(RequestContext context, C= onfiguration configuration) {</div><div><br></div><div> = Log syslog =3D (Log) context.get(RequestContext.JPUBLISH_SYSLOG);</= div><div> SiteContext site =3D=20 context.getSiteContext(); // or ...get( RequestContext.JPUBLISH_SITE</= div><div><br></div><div> syslog.info("confi= guration path: "+site.getConfigurationPath());</div><div><br></div><di= v> }</div><div><br> </div><div><br></div><div>And you have a space (the context received by the= Action) where all the startup actions can share Objects. This is happening= because I am reusing the same context for all the Actions executed at= startup; a similar approach being used for shutdown. </div><div><br></div><div>I hope it helps, </div><div><div> <span styl= e=3D"border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); f= ont-family: Monaco; font-size: 13px; font-style: normal; font-variant: norm= al; font-weight: normal; letter-spacing: normal; line-height: normal; text-= indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"= > <div>-florin</div><br></span> </div><div><br></div><div>PS</div><div>Now I = have to back-port this functionality to JPublish 2.0 ;)</div><div><br>= </div><br><div><div>On 07-May-07, at 21:52 , Andres Alcarraz wrote:</div><b= r> <blockquote type=3D"cite">Hello Florin thank you very much for answering so= fast, but problem I'm having is in a Java class action, there es where= I cannot access the site context.<br>Precisely I'm now trying to use j= ava classes for actions, I'm not trying to migrate all the application = that previously used beanshell actions to this new approach but I want new = things in pure java.=20 <br>What I don't understand is that asymmetry between java class based = action and script based ones. I'm not saying Jpublish is a bad thing, i= 've been using it from years but nobody and nothing is perfect.<br> In fact what I tried to say is that java class based actions have nothing = to do at start up if they can not access the site context, because where co= uld they put any object created?<br>My intention was to mention a quick and= backward compatible fix (StartupAction interface) that I have no problem t= o implement, the same problem may be occurring in Shutdown actions so there= may be a better name :).=20 <br>Certainly I can fix that in my own Application by calling a StartupActi= on from a generic BeanShell kind of adapter where the action class is a par= ameter of the beanshell adapter script.<br><br>my proposal is to define a n= ew interface:=20 <br style=3D"font-family: courier new,monospace;"><span style=3D"font-famil= y: courier new,monospace;">public interface StartupAction extends Action{</= span><br style=3D"font-family: courier new,monospace;"><span style=3D"font-= family: courier new,monospace;"> public void setSiteContext(SiteContext context);</span>= <br style=3D"font-family: courier new,monospace;"><span style=3D"font-famil= y: courier new,monospace;">}</span><br style=3D"font-family: courier new,mo= nospace;"><br>And in the part of the code where the action is found (in fin= dAction() when handling start up actions)=20 <br><span style=3D"font-family: courier new,monospace;">if (action instance= of StartupAction)</span><br style=3D"font-family: courier new,monospace;"><= span style=3D"font-family: courier new,monospace;"> ((Sta= rtupAction)action).setSiteContext(siteContext);=20 </span><br><br>or something like this.<br><br>Best regards and thanks again= <br><br>Andr=E9s<br><br><br><div><span class=3D"gmail_quote">2007/5/7, Flor= in T.PATRASCU <<a href=3D"mailto:[email protected]" target=3D"_b= lank" onclick=3D"return top.js.OpenExtLink(window,event,this)"> [email protected] </a>>:</span><blockquote class=3D"gmail_quote"= style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.= 8ex; padding-left: 1ex;">Hi,<br><br>If you need the SiteContext in startup = actions, then in your Action=20 <br>(bsh, js, etc.) you can simply use the parameter 'site'. For ex= ample,<br>a simple startup Action (StartUpTest.bsh) containing o= nly one line<br>of code:<br><br> &= nbsp;syslog.info( "configuration path: "+site.getConfigurationPat= h());=20 <br><br>The file jpublish.xml:<br>...<br> &nbs= p; <action-manager><br>  = ; <startup-ac= tion name=3D"StartUpTest.bsh"/><br> &nb= sp; </action-manager><br>...<br><br>And when you'= ;ll start your JPublish application you'll see in the=20 <br>logs something like this:<br>...<br>  = ; 2275 [main] INFO syslog - configuration = path: WEB-INF/jpublish.xml<br>...<br><br>Don't worry, JPublish is a fin= e application :)<br>-florin<br><br><br>On 07-May-07, at 16:16 , Andres Alca= rraz wrote:=20 <br><br>> Hi all, I was trying to make a java startup action when I real= ized<br>> that I cannot access the site context from them because the Co= ntext is<br>> null, that doesn't occur in script actions where you h= ave a reference=20 <br>> to the site context, I wonder what is the sense of having a startu= p<br>> action that has no access to the site context.<br>> Looking at= the code I've found that when an action script is found<br>> site c= ontext is passed through the constructor, but that doesn't=20 <br>> happen in java actions, I think the execute method could have more= <br>> parameters or Action interface could have a setSiteContext() metho= d, I<br>> know this would not be backward compatible, but a new StartupA= ction=20 <br>> could be defined.<br>> What others means do i have to access th= e site context from a java<br>> startup action?<br>><br>> I'm = using jpublish 3.0b2 thanks in advance<br>><br>><br>> Andr=E9s<br> ><br>> -------------------------------------------------------------= ---------<br>> ---<br>> This SF.net email is sponsored by DB2 Express= <br>> Download DB2 Express C - the FREE version of DB2 express and take= =20 <br>> control of your XML. No limits. Just data. Click to get it now.<br= >> <a href=3D"http://sourceforge.net/powerbar/db2/" target=3D"_blank" on= click=3D"return top.js.OpenExtLink(window,event,this)">http://sourceforge.n= et/powerbar/db2/ </a><br>> _______________________________________________ <br>> Jpubl= ish-developer mailing list<br>> <a href=3D"mailto:Jpublish-developer@lis= ts.sourceforge.net" target=3D"_blank" onclick=3D"return top.js.OpenExtLink(= window,event,this)"> [email protected]</a><br>> <a href=3D"https://lis= ts.sourceforge.net/lists/listinfo/jpublish-developer" target=3D"_blank" onc= lick=3D"return top.js.OpenExtLink(window,event,this)"> https://lists.source= forge.net/lists/listinfo/jpublish-developer </a><br><br><br>-----------------------------------------------------------= --------------<br>This SF.net email is sponsored by DB2 Express<br>Download= DB2 Express C - the FREE version of DB2 express and take <br>control of yo= ur XML. No limits. Just data. Click to get it now. <br><a href=3D"http://sourceforge.net/powerbar/db2/" target=3D"_blank" oncl= ick=3D"return top.js.OpenExtLink(window,event,this)">http://sourceforge.net= /powerbar/db2/</a><br>_______________________________________________<br>Jp= ublish-developer mailing list=20 <br><a href=3D"mailto:[email protected]" target=3D"_= blank" onclick=3D"return top.js.OpenExtLink(window,event,this)">Jpublish-de= [email protected]</a><br><a href=3D"https://lists.sourceforge.n= et/lists/listinfo/jpublish-developer" target=3D"_blank" onclick=3D"return t= op.js.OpenExtLink(window,event,this)"> https://lists.sourceforge.net/lists/listinfo/jpublish-developer </a><br></b= lockquote></div><br><div style=3D"margin: 0px;">---------------------------= ----------------------------------------------</div><div style=3D"margin: 0= px;"> This SF.net email is sponsored by DB2 Express</div><div style=3D"margin: 0p= x;">Download DB2 Express C - the FREE version of DB2 express and take</div>= <div style=3D"margin: 0px;">control of your XML. No limits. Just data. Clic= k to get it now. </div><div style=3D"margin: 0px;"><a href=3D"http://sourceforge.net/powerba= r/db2/_______________________________________________" target=3D"_blank" on= click=3D"return top.js.OpenExtLink(window,event,this)">http://sourceforge.n= et/powerbar/db2/_______________________________________________ </a></div><div style=3D"margin: 0px;">Jpublish-developer mailing list</div>= <div style=3D"margin: 0px;"><a href=3D"mailto:[email protected]= ceforge.net" target=3D"_blank" onclick=3D"return top.js.OpenExtLink(window,= event,this)"> [email protected]</a></div><div style=3D"margin: 0px= ;"><a href=3D"https://lists.sourceforge.net/lists/listinfo/jpublish-develop= er" target=3D"_blank" onclick=3D"return top.js.OpenExtLink(window,event,thi= s)"> https://lists.sourceforge.net/lists/listinfo/jpublish-developer</a></div> <= /blockquote></div><br></div></div></div><br>-------------------------------= ------------------------------------------<br>This SF.net email is sponsore= d by DB2 Express <br>Download DB2 Express C - the FREE version of DB2 express and take<br>co= ntrol of your XML. No limits. Just data. Click to get it now.<br><a onclick= =3D"return top.js.OpenExtLink(window,event,this)" href=3D"http://sourceforg= e.net/powerbar/db2/" target=3D"_blank"> http://sourceforge.net/powerbar/db2/</a><br>_______________________________= ________________<br>Jpublish-developer mailing list<br><a onclick=3D"return= top.js.OpenExtLink(window,event,this)" href=3D"mailto:Jpublish-developer@l= ists.sourceforge.net"> [email protected]</a><br><a onclick=3D"return top.js= .OpenExtLink(window,event,this)" href=3D"https://lists.sourceforge.net/list= s/listinfo/jpublish-developer" target=3D"_blank">https://lists.sourceforge.= net/lists/listinfo/jpublish-developer </a><br><br></blockquote></div><br> ------=_Part_2210_16355779.1178598675246-- --===============0106023266== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ --===============0106023266== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Jpublish-developer mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jpublish-developer --===============0106023266==--