Startup/Shutdown Action can get access to 'site'

"Florin T.PATRASCU" <[email protected]> Mon, 7 May 2007 23:54:39 -0400
Newsgroups gmane.comp.java.jpublish.devel
Message-ID <[email protected]>
--===============1468892719==
Content-Type: multipart/alternative; boundary=Apple-Mail-1-573300814


--Apple-Mail-1-573300814
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=ISO-8859-1;
	delsp=yes;
	format=flowed

Hi Andres,

is done; a bit different than your proposal, but with the same or =20
better effect, I hope ;)

I believe you have to wait a bit for the sf.net to synchronize the =20
public CVS before you can grab the updated version of JP3.

For Java actions you will have now a minimum context available at =20
startup and shutdown. In this context you don't have only the 'site' =20
but you'll also 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 =20
configuration) {

         Log syslog =3D (Log) =
context.get(RequestContext.JPUBLISH_SYSLOG);
         SiteContext site =3D context.getSiteContext(); // or ...get=20
( RequestContext.JPUBLISH_SITE

         syslog.info("configuration path: "+site.getConfigurationPath=20
());

     }


And you have a space (the context received by the Action) where all =20
the startup actions can share Objects. This is happening because I am =20=

reusing the same context for all the Actions executed at startup; a =20
similar approach 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 =20=

> I'm having is in a Java class action, there es where I cannot =20
> access the site context.
> Precisely I'm now trying to use java classes for actions, I'm not =20
> trying to migrate all the application that previously used =20
> beanshell actions to this new approach but I want new things in =20
> pure java.
> What I don't understand is that asymmetry between java class based =20
> action and script based ones. I'm not saying Jpublish is a bad =20
> thing, i've been using it from years but nobody and nothing is =20
> perfect.
> In fact what I tried to say is that java class based actions have =20
> nothing to do at start up if they can not access the site context, =20
> because where could they put any object created?
> My intention was to mention a quick and backward compatible fix =20
> (StartupAction interface) that I have no problem to implement, the =20
> same problem may be occurring in Shutdown actions so there may be a =20=

> better name :).
> Certainly I can fix that in my own Application by calling a =20
> StartupAction from a generic BeanShell kind of adapter where the =20
> 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=20=

> () 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: =20
> "+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/=20
> 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 =20
> Context is
> > null, that doesn't occur in script actions where you have a =20
> 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() =20
> 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
> >
> > =20
> ----------------------------------------------------------------------
> > ---
> > 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
>
>
> ----------------------------------------------------------------------=20=

> ---
> 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
>
> ----------------------------------------------------------------------=20=

> ---
> 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/=20
> _______________________________________________
> Jpublish-developer mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jpublish-developer


--Apple-Mail-1-573300814
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=ISO-8859-1

<HTML><BODY style=3D"word-wrap: break-word; -khtml-nbsp-mode: space; =
-khtml-line-break: after-white-space; ">Hi Andres,<DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>is done; a bit different =
than your proposal, but with the same or better effect, I hope =
;)<DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV>I believe you =
have to wait a bit for the sf.net to=A0synchronize the public CVS before =
you can grab the updated version of JP3.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>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 also find few helpers =
to help you do ... stuff at startup :)=A0</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>These helpers =
are:</DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV =
style=3D"text-align: justify;"><SPAN class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</SPAN>RequestContext.JPUBLISH_DATE_UTILITIES</DIV><DIV =
style=3D"text-align: justify;"><SPAN class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</SPAN>RequestContext.JPUBLISH_NUMBER_UTILITIES</DIV><DIV =
style=3D"text-align: justify;"><SPAN class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</SPAN>"messageUtilities"</DIV><DIV =
style=3D"text-align: justify;"><SPAN class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</SPAN>RequestContext.JPUBLISH_SYSLOG</DIV><DIV style=3D"text-align: =
justify;"><BR class=3D"khtml-block-placeholder"></DIV><DIV =
style=3D"text-align: justify;">and the one that you requested:</DIV><DIV =
style=3D"text-align: justify;"><SPAN class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</SPAN>RequestContext.JPUBLISH_SITE</DIV><DIV style=3D"text-align: =
justify;"><BR class=3D"khtml-block-placeholder"></DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>I tested my changes with =
the followings:</DIV><DIV>- in jpublish.xml</DIV><DIV><SPAN =
class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</SPAN>&lt;action-manager&gt;</DIV><DIV><SPAN class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</SPAN>=A0 =A0 &lt;startup-action =
name=3D"org.jpublish.test.JavaStartUpAction"/&gt;</DIV><DIV>....</DIV><DIV=
><BR class=3D"khtml-block-placeholder"></DIV><DIV>- =
JavaStartUpAction.java (excerpt)</DIV><DIV>=A0=A0 =A0public void =
execute(RequestContext context, Configuration configuration) =
{</DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV>=A0 =A0 =A0 =
=A0 Log syslog =3D (Log) =
context.get(RequestContext.JPUBLISH_SYSLOG);</DIV><DIV>=A0 =A0 =A0 =A0 =
SiteContext site =3D context.getSiteContext(); // or =
...get(=A0RequestContext.JPUBLISH_SITE</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>=A0 =A0 =A0 =A0 =
syslog.info("configuration path: =
"+site.getConfigurationPath());</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>=A0 =A0 }</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV><BR =
class=3D"khtml-block-placeholder"></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=A0reusing the same context for =
all the Actions executed at startup; a similar approach being used for =
shutdown.</DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV>I =
hope it helps,=A0</DIV><DIV><DIV> <SPAN class=3D"Apple-style-span" =
style=3D"border-collapse: separate; border-spacing: 0px 0px; color: =
rgb(0, 0, 0); font-family: Monaco; font-size: 13px; font-style: normal; =
font-variant: normal; font-weight: normal; letter-spacing: normal; =
line-height: normal; text-align: auto; =
-khtml-text-decorations-in-effect: none; text-indent: 0px; =
-apple-text-size-adjust: auto; text-transform: none; orphans: 2; =
white-space: normal; widows: 2; word-spacing: 0px; =
"><DIV>-florin</DIV><BR class=3D"Apple-interchange-newline"></SPAN> =
</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>PS</DIV><DIV>Now I have =
to=A0back-port this functionality to JPublish 2.0 ;)</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><BR><DIV><DIV>On 07-May-07, at =
21:52 , Andres Alcarraz wrote:</DIV><BR =
class=3D"Apple-interchange-newline"><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 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. <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 could they put any object created?<BR>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 =
name :). <BR>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.<BR><BR>my proposal =
is to define a new interface: <BR style=3D"font-family: courier =
new,monospace;"><SPAN style=3D"font-family: 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;"> =A0=A0=A0 public void =
setSiteContext(SiteContext context);</SPAN><BR style=3D"font-family: =
courier new,monospace;"><SPAN style=3D"font-family: courier =
new,monospace;">}</SPAN><BR style=3D"font-family: courier =
new,monospace;"><BR>And in the part of the code where the action is =
found (in findAction() when handling start up actions) <BR><SPAN =
style=3D"font-family: courier new,monospace;">if (action instanceof =
StartupAction)</SPAN><BR style=3D"font-family: courier =
new,monospace;"><SPAN style=3D"font-family: courier new,monospace;">=A0=A0=
=A0 ((StartupAction)action).setSiteContext(siteContext); =
</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, Florin T.PATRASCU &lt;<A =
href=3D"mailto:[email protected]">[email protected] =
</A>&gt;:</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 <BR>(bsh, js, etc.) you can simply use the parameter 'site'. =
For example,<BR>a simple startup Action (StartUpTest.bsh)=A0=A0containing =
only one line<BR>of code:<BR><BR>=A0=A0=A0=A0=A0=A0=A0=A0syslog.info( =
"configuration path: "+site.getConfigurationPath()); <BR><BR>The file =
jpublish.xml:<BR>...<BR>=A0=A0=A0=A0=A0=A0=A0=A0&lt;action-manager&gt;<BR>=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0&lt;startup-action =
name=3D"StartUpTest.bsh"/&gt;<BR>=A0=A0=A0=A0=A0=A0=A0=A0&lt;/action-manag=
er&gt;<BR>...<BR><BR>And when you'll start your JPublish application =
you'll see in the <BR>logs something like this:<BR>...<BR>=A0=A0=A0=A0=A0=A0=
=A0=A02275 [main] INFO=A0=A0syslog=A0=A0- configuration path: =
WEB-INF/jpublish.xml<BR>...<BR><BR>Don't worry, JPublish is a fine =
application :)<BR>-florin<BR><BR><BR>On 07-May-07, at 16:16 , Andres =
Alcarraz wrote: <BR><BR>&gt; Hi all, I was trying to make a java startup =
action when I realized<BR>&gt; that I cannot access the site context =
from them because the Context is<BR>&gt; null, that doesn't occur in =
script actions where you have a reference <BR>&gt; to the site context, =
I wonder what is the sense of having a startup<BR>&gt; action that has =
no access to the site context.<BR>&gt; Looking at the code I've found =
that when an action script is found<BR>&gt; site context is passed =
through the constructor, but that doesn't <BR>&gt; happen in java =
actions, I think the execute method could have more<BR>&gt; parameters =
or Action interface could have a setSiteContext() method, I<BR>&gt; know =
this would not be backward compatible, but a new StartupAction <BR>&gt; =
could be defined.<BR>&gt; What others means do i have to access the site =
context from a java<BR>&gt; startup action?<BR>&gt;<BR>&gt; I'm using =
jpublish 3.0b2 thanks in advance<BR>&gt;<BR>&gt;<BR>&gt; Andr=E9s<BR> =
&gt;<BR>&gt; =
----------------------------------------------------------------------<BR>=
&gt; ---<BR>&gt; This SF.net email is sponsored by DB2 Express<BR>&gt; =
Download DB2 Express C - the FREE version of DB2 express and take =
<BR>&gt; control of your XML. No limits. Just data. Click to get it =
now.<BR>&gt; <A =
href=3D"http://sourceforge.net/powerbar/db2/">http://sourceforge.net/power=
bar/db2/</A><BR>&gt; _______________________________________________ =
<BR>&gt; Jpublish-developer mailing list<BR>&gt; <A =
href=3D"mailto:[email protected]">Jpublish-develope=
[email protected]</A><BR>&gt; <A =
href=3D"https://lists.sourceforge.net/lists/listinfo/jpublish-developer"> =
https://lists.sourceforge.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 your =
XML. No limits. Just data. Click to get it now.<BR><A =
href=3D"http://sourceforge.net/powerbar/db2/">http://sourceforge.net/power=
bar/db2/</A><BR>_______________________________________________<BR>Jpublis=
h-developer mailing list <BR><A =
href=3D"mailto:[email protected]">Jpublish-develope=
[email protected]</A><BR><A =
href=3D"https://lists.sourceforge.net/lists/listinfo/jpublish-developer">h=
ttps://lists.sourceforge.net/lists/listinfo/jpublish-developer =
</A><BR></BLOCKQUOTE></DIV><BR><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; =
">------------------------------------------------------------------------=
-</DIV><DIV style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: =
0px; margin-left: 0px; ">This SF.net email is sponsored by DB2 =
Express</DIV><DIV style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; ">Download DB2 Express C - the =
FREE version of DB2 express and take</DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">control of =
your XML. No limits. Just data. Click to get it now.</DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; "><A =
href=3D"http://sourceforge.net/powerbar/db2/______________________________=
_________________">http://sourceforge.net/powerbar/db2/___________________=
____________________________</A></DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; =
">Jpublish-developer mailing list</DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A =
href=3D"mailto:[email protected]">Jpublish-develope=
[email protected]</A></DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A =
href=3D"https://lists.sourceforge.net/lists/listinfo/jpublish-developer">h=
ttps://lists.sourceforge.net/lists/listinfo/jpublish-developer</A></DIV> =
</BLOCKQUOTE></DIV><BR></DIV></DIV></BODY></HTML>=

--Apple-Mail-1-573300814--


--===============1468892719==
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/
--===============1468892719==
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

--===============1468892719==--