You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by "Gray, Cameron C." <cg...@ultraspeed.co.uk> on 2004/05/13 13:08:32 UTC

Two Problems

[ I am not subscribed please reply direct, not on list ]

Turbine-Dev,

For a client project I need to achieve two things for them to sign off
using Turbine in the application (saves me reinventing many wheels).

1) Changing of the /template/ uri pattern.
In Turbine 2.3 I found org.apache.turbine.util.URIConstants which
defines CGI_TEMPLATE_PARAM, however changing this on its own and
restarting does not modify the behaviour as expected.  I believe that
the DynamicURI tools still have the template string hardcoded, but after
changing that the generated links were in the correct form.

However, the AssemblyBroker still doesn't apply the correct Assembly and
Templating services to the template specified by the new parameter.  Am
I missing something?  Pointers would be appreciated...

2) Changing the use of , to designated folder hierarchies for templates
Is it possible to use lastIndexOf(".") to designate the extension,
rather than www,www,wwwtemplate.vm.  If so, where exactly is this
control handled searching the source is making my understanding of
Turbine tie itself in knots.  I can't follow the exact control flow from
doGet -> response.

Thank you for your time and help.

Best regards,

Cameron Gray
Operations Director, UltraSpeed UK Limited

Tel/Fax: 0870 141 7 143 (Option 5, Extension 101)
W: www.ultraspeed.co.uk

Nothing great was ever achieved without enthusiasm. - Ralph Waldo
Emerson

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Two Problems

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
"Gray, Cameron C." <cg...@ultraspeed.co.uk> writes:

>[ I am not subscribed please reply direct, not on list ]

sorry, I read this with a newsreader. So I hope that you check the
archives from time to time. ;-)

>Turbine-Dev,

>For a client project I need to achieve two things for them to sign off
>using Turbine in the application (saves me reinventing many wheels).

>1) Changing of the /template/ uri pattern.
>In Turbine 2.3 I found org.apache.turbine.util.URIConstants which
>defines CGI_TEMPLATE_PARAM, however changing this on its own and
>restarting does not modify the behaviour as expected.  I believe that
>the DynamicURI tools still have the template string hardcoded, but after
>changing that the generated links were in the correct form.

Uh, what? 

CGI_TEMPLATE_PARAM is the _NAME_ of a parameter. This means, that the
Turbine core expects the name of the template to display from a
parameter called (not really surprisingly) "template". Why would you
want to change this?!? If this is for corporate reasons; well you
_can_ redefine the constant but then you might have to recompile the
Turbine core. This is not a runtime settable parameter. At some point
we had to stop. ;-)

If what you really want to change the _loading_ directory for a
template (which defaults to /templates under your servlet container
webapplication root), you're looking at the wrong place:

The whole template _loading_ shebang happens in the
VelocityService. In its configuration you happen to find:

--- cut ---
services.VelocityService.resource.loader = file
services.VelocityService.file.resource.loader.description = Velocity File Resource Loader
services.VelocityService.file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
services.VelocityService.file.resource.loader.path = /templates/app
services.VelocityService.file.resource.loader.cache = false
services.VelocityService.file.resource.loader.modificationCheckInterval = 2
--- cut ---

which is responsible to actually load your template from the file
system (through the servlet container). Here you see the loader.path
which you can modify to load from any directory that you like.

I e.g. load most of the templates of an application from the class
path or with the jar-loader from velocity (which is really handy if
you have to exchange just all templates for an application in a single
go).


>2) Changing the use of , to designated folder hierarchies for templates
>Is it possible to use lastIndexOf(".") to designate the extension,
>rather than www,www,wwwtemplate.vm.  If so, where exactly is this
>control handled searching the source is making my understanding of
>Turbine tie itself in knots.  I can't follow the exact control flow from
>doGet -> response.

You want to change the ","? Well, welcome to one of the really tricky,
subtle and actually quite delicate points of the Turbine core. In a
very short message: 

You can't change the usage of "," and "." in Turbine and trust me, you
don't want to. Especially you can't use "/" instead of ",". Full Stop.

It took me ages to untie the mess from the 2.2 core into the state
that the 2.3 core is which is actually working quite reliably.

Again, think "foo,bar,baz.vm" not as a hierarchy but as an actual
template name. The fact that it is mapped into a folder hierarchy in
the filesystem happens in the
org.apache.turbine.services.template.mapper classes, and if you're
unhappy that

template/foo,bar,baz.vm gets mapped into

<your webapp root>/templates/foo/bar/baz.vm

then you can act in the velocity loader as described above (which
is responsible for the <your webapp root>/templates part

and the mapper classes (which _are_ exchangeable and there is even
documentation about this in the turbine site. ;-) are responsible for
mapping

foo,bar,baz.vm to  foo/bar/baz.vm

(think layout, where foo,bar,baz.vm can easily be mapped onto 
<your webapp root>/templates/layouts/Default.vm. This is the job of
the mapper).

BUT: One of the few practically unchangeable things is the fact that
one templating engine registers for one extension. That's what we use
the extensions for. However, noone forbids you to register the
VelocityEngine for .jsp ...

e.g. this registers the VelocityEngine for .vm ...

--- cut ---
services.VelocityService.template.extension=vm
services.VelocityService.default.page = VelocityPage
services.VelocityService.default.screen=VelocityScreen
services.VelocityService.default.layout = VelocityOnlyLayout
services.VelocityService.default.navigation=VelocityNavigation
services.VelocityService.default.error.screen = VelocityErrorScreen
services.VelocityService.default.layout.template = Default.vm
--- cut ---

	Regards
		Henning


-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

"Fighting for one's political stand is an honourable action, but re-
 fusing to acknowledge that there might be weaknesses in one's
 position - in order to identify them so that they can be remedied -
 is a large enough problem with the Open Source movement that it
 deserves to be on this list of the top five problems."
                       -- Michelle Levesque, "Fundamental Issues with
                                    Open Source Software Development"

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org