You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jspwiki.apache.org by Terry Steichen <te...@net-frame.com> on 2007/11/28 20:39:43 UTC

Adding custom JSP modules to JSPWiki (was JSPWiki 'Special Pages')

Janne,

Creating a customized top-level JSP is indeed one approach to adding 
customized JSP.  However, my past research (done about 6 months ago or 
so) into this (namely, via the JSPWiki source code) led me to conclude 
that it would not be easy to extend JSPWiki to include other types of 
contexts (which ViewTemplates uses to determine what XXXContent.jsp to 
pass the request to. 

Thus, it seemed to me (maybe reflecting an incomplete understanding of 
the JSPWiki architecture?) that a new top-level command would also need 
its own equivalent for ViewTemplate and XXContent, along with other 
ancillary modules.  While, as you say, none of these are really rocket 
science, as JSPWiki versions changed (and templates along with them), 
these customized modules would also have to be changed to stay in sync.

After this research, I concluded (rightly or not) that it seemed to be 
simpler to modify a single JSP, ViewTemplate.jsp.  As I've implemented 
them, basically all the customization changes are additive and thus can 
be inserted into each new ViewTemplate pretty easily.

As to a plugin not being able to load a JSP, I'm surprised that this 
can't be done (though I certainly defer to your technical expertise on 
that).  After all, it's trivial for a JSP to load another JSP.  Is this 
due to the fact that the plugin is implemented as a Java, rather than 
JSP, module? 

Terry


Janne Jalkanen wrote:
>
> So, what you are asking is how to create your own Command, so you can 
> influence what the ContentTag outputs?
>
> I don't think that is supported directly, but the easy way would be to 
> extend from ContentTag to support your own top-level JSP files.  That 
> way you should be able to just to either use your own ContentTag or 
> just replace the class name in jspwiki.tld for <wiki:Content>.
>
> If you look at it, ViewTemplate.jsp is really, really simple.  It 
> includes a header, and then defines the basic layout, which is mostly 
> CSS-based anyway.  The idea is that you can very simply "skin" jspwiki 
> by creating a new ViewTemplate.jsp for your own purposes.
>
> Plugins can't load JSPs directly.  This is a known fault with JSP as a 
> technology, and one of the reasons why e.g. Velocity is superior.  If 
> we were using Velocity, we could be using it programmatically everywhere.
>
> /Janne
>
> On Nov 28, 2007, at 17:52 , Terry Steichen wrote:
>
>> Janne,
>>
>> Most client requests to a JSPWiki site pertain to the simple display 
>> of the contents of ordinary wikipages.  (Other types of requests are 
>> handled, not by Wiki.jsp, but by other 'first line' JSP modules, such 
>> as Install, Captcha, SisterSites, Comment, Login, Logout, Preview, 
>> PageModified, PageInfo, Rename, Delete, Search, Message, 
>> UserPreferences, Diff, Vote, EditGroup, LostPassword, Edit, 
>> NewBlogEntry, NewGroup, or Group).
>>
>> For these requests to display the contents of ordinary pages, handled 
>> initially by Wiki.jsp, ViewTemplate.jsp provides the 'look and feel' 
>> aspects that surround the unique content stored in a wikipage. It, in 
>> effect, wraps the unique wikipage content with the standard header, 
>> footer and menus.
>>
>> The challenge I (and others, I think) face is how (within JSPWiki) to 
>> display content from a custom JSP so it has the same look and feel as 
>> wikipages (and to make JSPWiki treat that custom JSP as just another 
>> wikipage).  I mentioned that my (admittedly distasteful) approach was 
>> to modify ViewTemplate.jsp to accomplish this.
>> However, you seem to suggest/imply that there is indeed a way to do 
>> this without having to modify ViewTemplate.jsp.  Could you explain 
>> this could/should be done?  (I ask because if I can accomplish this 
>> without changing ViewTemplate.jsp, I would be more than delighted.)
>>
>> I realize I may be overlooking something very obvious that deserves a 
>> 'duh' response, but I'll take the risk.
>> Terry
>>
>> PS: Maybe via a plugin that directly loads a JSP?
>>
>>
>> Janne Jalkanen wrote:
>>> Any JSP page or plugin can request custom scripts to be added to the
>>> <head> by calling TemplateManager.addResourceRequest().  No need to
>>> rewrite ViewTemplate.
>>>
>>> /Janne
>>>
>>> On Wed, Nov 28, 2007 at 09:48:13AM +0100, Matthias Käppler wrote:
>>>
>>>> Hi,
>>>>
>>>> 2007/11/27, Terry Steichen <te...@net-frame.com>:
>>>>
>>>>> ...  With that
>>>>> caveat, I'll give you a few thoughts on how I use custom JSP pages 
>>>>> with
>>>>> JSPWiki.
>>>>> ...
>>>>>
>>>> Thanks for your explanations.
>>>>
>>>> What was really making trouble was the linking of script files in 
>>>> the JSP
>>>> that will be included as a special page. These scripts would be 
>>>> included as
>>>> part of the "pageContent" DIV, which itself was part of a HTML 
>>>> table and
>>>> HTML does not allow script tags at this point.
>>>> I solved the problem by rewriting ViewTemplate so that in <head> it 
>>>> checks
>>>> for the current request context and if it matches my special page, 
>>>> it will
>>>> include a MyCoolPageHeader.jsp containing all script tags. However, 
>>>> this
>>>> means that for every special page I would have to modify 
>>>> ViewTemplate and
>>>> check for some specific request context. Not the most beautiful of
>>>> approaches, but it works.
>>>>
>>>> Having said all this, I invite Andrew to comment.  He's a very 
>>>> smart guy
>>>>
>>>>> who knows a LOT more about security than do I.  There may be some
>>>>> problems in this approach I'm not aware of.  (As I prepare to post 
>>>>> this,
>>>>> I notice that Andrew seems to have shifted his view a bit, but I'd 
>>>>> still
>>>>> like his comments about this approach.)
>>>>>
>>>> Sure. I was just somewhat surprised by his answer, but he already 
>>>> said it
>>>> was a misunderstanding so no problem here. My apologies if I didn't 
>>>> make
>>>> myself clear enough in the first place.
>>>>
>>>> Thanks,
>>>> Matthias
>>>>
>>>
>>>
>
>

Re: Adding custom JSP modules to JSPWiki

Posted by Andrew Jaquith <an...@mac.com>.
Yeah. I was just going to pipe in about Stripes -- but stifled the  
thought because it was too philosophical.

Put simply, the Command pattern does exactly what Janne describes. In  
retrospect I think it was a mistake to put them in (you can blame me  
for that). Partly because it welds together top-level JSPs, URL  
patterns and request contexts -- but mostly because it makes it  
JSPWiki harder to extend.

The JSPWiki 3.0 local branch that I've been working on, which uses  
Stripes, makes things much cleaner, simpler AND flexible. Each "wiki  
context" becomes its own ActionBean class. 'Beans can be used in all  
sorts of combinations. It breaks the one-context-for-one-page rule.

Anyway, I think we're going to declare 2.6.0 soon; 2.8 follows  
immediately after, and then we can get to work on the good stuff 3.0.   
Terry, that doesn't help you much in the short term, I know. But know  
that extensibility is going to be a much bigger theme in 3.0.

Andrew

On Nov 28, 2007, at 3:50 PM, Janne Jalkanen wrote:

>> Forgive me if I'm missing something, but when I originally did my  
>> research I did look into extending ContentTag.  However, it seemed  
>> to me that this would in turn also require a modification/extension  
>> of WikiContext, which would in turn require modification/extension  
>> of PageCommand/WikiCommand.  By the time I got to this point, I  
>> decided to give up on this approach.  Was I making it more  
>> complicated than it really is?
>
> Yup.  The Command represents a built-in JSPWiki command, or a  
> RequestContext, or a top-level JSP (or one of the *Content.jsp) - 
> files, which are all more or less different names for the same thing.
>
> The trick would not be to add a new Command, but to simply use some  
> custom logic in your ContentTag subclass, and if it does not match  
> against your own parameters, call the superclass method.
>
>> Regarding the issue of launching a JSP from a plugin (which, if it  
>> could be done, would be, I think, a truly elegant way to do this):  
>> If all that it needs is a request, response and pageContext, could  
>> those be captured and stored as session attributes by (one of) the  
>> original request-handling JSPs (and then accessed and used by the  
>> plugin to launch the JSP)?  Maybe using some of the logic employed  
>> by Velocity, if necessary?
>
> I don't think that is a good idea.  For example, unit testing that  
> without a servlet container would be impossible (or at least very  
> difficult), and it would make that particular plugin non-usable for  
> non-JSP cases.  Also, I would be very hesitant to make the  
> assumption that mucking about with the pagecontext in such a way  
> would be okay.
>
> Velocity bypasses JSP completely, and requires only Servlet  
> support.  It would be a far cleaner and nicer solution, and I know  
> some people are succesfully using Velocity templates with JSPWiki to  
> generate HTML.
>
> Anyway, with Stripes we can get rid of most of this stuff, which is  
> getting too arcane anyway. :-)
>
> /Janne


Re: Adding custom JSP modules to JSPWiki

Posted by Janne Jalkanen <Ja...@ecyrd.com>.
> I've done quite a bit of work with Velocity myself.  Could you put  
> me in touch with someone who's using Velocity within JSPWiki?

I know they're lurking on this list.  Maybe they will contact you...

/Janne

Re: Adding custom JSP modules to JSPWiki

Posted by Terry Steichen <te...@net-frame.com>.
Janne Jalkanen wrote:
> The trick would not be to add a new Command, but to simply use some 
> custom logic in your ContentTag subclass, and if it does not match 
> against your own parameters, call the superclass method.
I tried to follow this idea, because it sounds so simple and clean.  But 
when I examined it more closely it seems to get involved in some of the 
deeper aspects of JSPWiki processing that I've never really understood.  
So, this approach is not really an option for me.
> Velocity bypasses JSP completely, and requires only Servlet support.  
> It would be a far cleaner and nicer solution, and I know some people 
> are succesfully using Velocity templates with JSPWiki to generate HTML.
I've done quite a bit of work with Velocity myself.  Could you put me in 
touch with someone who's using Velocity within JSPWiki?

In the meanwhile, I think I'll stick with making additive changes to 
ViewTemplate.jsp to handle customized JSPs.

Terry


Re: Adding custom JSP modules to JSPWiki

Posted by Janne Jalkanen <Ja...@ecyrd.com>.
> Forgive me if I'm missing something, but when I originally did my  
> research I did look into extending ContentTag.  However, it seemed  
> to me that this would in turn also require a modification/extension  
> of WikiContext, which would in turn require modification/extension  
> of PageCommand/WikiCommand.  By the time I got to this point, I  
> decided to give up on this approach.  Was I making it more  
> complicated than it really is?

Yup.  The Command represents a built-in JSPWiki command, or a  
RequestContext, or a top-level JSP (or one of the *Content.jsp) - 
files, which are all more or less different names for the same thing.

The trick would not be to add a new Command, but to simply use some  
custom logic in your ContentTag subclass, and if it does not match  
against your own parameters, call the superclass method.

> Regarding the issue of launching a JSP from a plugin (which, if it  
> could be done, would be, I think, a truly elegant way to do this):  
> If all that it needs is a request, response and pageContext, could  
> those be captured and stored as session attributes by (one of) the  
> original request-handling JSPs (and then accessed and used by the  
> plugin to launch the JSP)?  Maybe using some of the logic employed  
> by Velocity, if necessary?

I don't think that is a good idea.  For example, unit testing that  
without a servlet container would be impossible (or at least very  
difficult), and it would make that particular plugin non-usable for  
non-JSP cases.  Also, I would be very hesitant to make the assumption  
that mucking about with the pagecontext in such a way would be okay.

Velocity bypasses JSP completely, and requires only Servlet support.   
It would be a far cleaner and nicer solution, and I know some people  
are succesfully using Velocity templates with JSPWiki to generate HTML.

Anyway, with Stripes we can get rid of most of this stuff, which is  
getting too arcane anyway. :-)

/Janne

Re: Adding custom JSP modules to JSPWiki

Posted by Terry Steichen <te...@net-frame.com>.
Janne,

/*Note: I've shifted this from the user to the dev list.*/

Forgive me if I'm missing something, but when I originally did my 
research I did look into extending ContentTag.  However, it seemed to me 
that this would in turn also require a modification/extension of 
WikiContext, which would in turn require modification/extension of 
PageCommand/WikiCommand.  By the time I got to this point, I decided to 
give up on this approach.  Was I making it more complicated than it 
really is?

Regarding the issue of launching a JSP from a plugin (which, if it could 
be done, would be, I think, a truly elegant way to do this): If all that 
it needs is a request, response and pageContext, could those be captured 
and stored as session attributes by (one of) the original 
request-handling JSPs (and then accessed and used by the plugin to 
launch the JSP)?  Maybe using some of the logic employed by Velocity, if 
necessary?

Terry


Janne Jalkanen wrote:
>> Creating a customized top-level JSP is indeed one approach to adding 
>> customized JSP.  However, my past research (done about 6 months ago 
>> or so) into this (namely, via the JSPWiki source code) led me to 
>> conclude that it would not be easy to extend JSPWiki to include other 
>> types of contexts (which ViewTemplates uses to determine what 
>> XXXContent.jsp to pass the request to.
>
> No.  ViewTemplate does *not* determine it.  It's the ContentTag which 
> does it.  If you extend ContentTag, you get full control over what you 
> do.
>
>> Thus, it seemed to me (maybe reflecting an incomplete understanding 
>> of the JSPWiki architecture?) that a new top-level command would also 
>> need its own equivalent for ViewTemplate and XXContent, along with 
>> other ancillary modules.  While, as you say, none of these are really 
>> rocket science, as JSPWiki versions changed (and templates along with 
>> them), these customized modules would also have to be changed to stay 
>> in sync.
>
> No, it doesn't need its own equivalent.  You can use it by extending 
> ContentTag.
>
>> After this research, I concluded (rightly or not) that it seemed to 
>> be simpler to modify a single JSP, ViewTemplate.jsp.  As I've 
>> implemented them, basically all the customization changes are 
>> additive and thus can be inserted into each new ViewTemplate pretty 
>> easily.
>
> That works, too.  As long as you're willing to sacrifice a bit of 
> flexibility (but for a custom app and a custom template, this should 
> be an agreeable tradeoff).
>
>>
>> As to a plugin not being able to load a JSP, I'm surprised that this 
>> can't be done (though I certainly defer to your technical expertise 
>> on that).  After all, it's trivial for a JSP to load another JSP.  Is 
>> this due to the fact that the plugin is implemented as a Java, rather 
>> than JSP, module?
>>
>
> Yes.  A JSP needs the full request, response and pageContext - and 
> it's rather difficult to create all of them programmatically.  It 
> might be possible to create a framework which does that, but I haven't 
> seen anyone do it.  The servlet API is really the culprit here, as it 
> completely leaves the creation of such things as the burden of the 
> container.
>
> However, other templating systems like Velocity allow for 
> programmatical construction of the rendering context, which means that 
> you can just put in a template and some variables, and get back a String.
>
> /Janne
>

Re: Adding custom JSP modules to JSPWiki (was JSPWiki 'Special Pages')

Posted by Janne Jalkanen <Ja...@ecyrd.com>.
> Creating a customized top-level JSP is indeed one approach to  
> adding customized JSP.  However, my past research (done about 6  
> months ago or so) into this (namely, via the JSPWiki source code)  
> led me to conclude that it would not be easy to extend JSPWiki to  
> include other types of contexts (which ViewTemplates uses to  
> determine what XXXContent.jsp to pass the request to.

No.  ViewTemplate does *not* determine it.  It's the ContentTag which  
does it.  If you extend ContentTag, you get full control over what  
you do.

> Thus, it seemed to me (maybe reflecting an incomplete understanding  
> of the JSPWiki architecture?) that a new top-level command would  
> also need its own equivalent for ViewTemplate and XXContent, along  
> with other ancillary modules.  While, as you say, none of these are  
> really rocket science, as JSPWiki versions changed (and templates  
> along with them), these customized modules would also have to be  
> changed to stay in sync.

No, it doesn't need its own equivalent.  You can use it by extending  
ContentTag.

> After this research, I concluded (rightly or not) that it seemed to  
> be simpler to modify a single JSP, ViewTemplate.jsp.  As I've  
> implemented them, basically all the customization changes are  
> additive and thus can be inserted into each new ViewTemplate pretty  
> easily.

That works, too.  As long as you're willing to sacrifice a bit of  
flexibility (but for a custom app and a custom template, this should  
be an agreeable tradeoff).

>
> As to a plugin not being able to load a JSP, I'm surprised that  
> this can't be done (though I certainly defer to your technical  
> expertise on that).  After all, it's trivial for a JSP to load  
> another JSP.  Is this due to the fact that the plugin is  
> implemented as a Java, rather than JSP, module?
>

Yes.  A JSP needs the full request, response and pageContext - and  
it's rather difficult to create all of them programmatically.  It  
might be possible to create a framework which does that, but I  
haven't seen anyone do it.  The servlet API is really the culprit  
here, as it completely leaves the creation of such things as the  
burden of the container.

However, other templating systems like Velocity allow for  
programmatical construction of the rendering context, which means  
that you can just put in a template and some variables, and get back  
a String.

/Janne