You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ericsodt <de...@ll.mit.edu> on 2013/08/02 04:11:48 UTC

Dynamic xsl with custom uri resolver

I have a camel route working as follows:[code] from("subjectLine")                       
.to("xslt:transformSubject.xsl?uriResolver=#emailResolver")                       
.to("fop:application/pdf")                        .process(email)                       
.to("smtp://...");  [/code]Our customer has asked that we make the
stylesheet dynamic per each of the companies organizations.  I'm running the
problem when I try and make that stylesheet dynamic.  After reaching its
been said to try the following:[code]                        //
${header.CamelXsltResourceUri} =
http://localhost:8080/getStyleSheet/org123.xsl                       
.recipientList(simple("xslt:${header.CamelXsltResourceUri}?uriResolver=#resolver"))                       
.to("fop:application/pdf")                        .process(email)                       
.to("smtp://..."); [/code]However this does not work either.Any suggestions
on how I might overcome this issue?Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic xsl with custom uri resolver

Posted by ericsodt <de...@ll.mit.edu>.
>From what I am seeing, you can specify the custom resolver within the header 
{code}
.setHeader("CamelXsltResourceUri",simple("xslt:http://localhost:8080/<path>/<to>/<template>?*uriResolver=#myResolver*") 
{/code}

and it gets exercises at run time.  When I place break points within my
resolver and execute this route, it will step through the code.  



Claus Ibsen-2 wrote
> The CamelXsltResourceUri header is *only* for the location of the xls
> file. Any other options like a custom resolver must be set on the
> endpoint / component level.
> 
> On Tue, Aug 6, 2013 at 8:39 PM, ericsodt &lt;

> dean.ericson@.mit

> &gt; wrote:
>> Claus,
>>
>> The question I am asking is not one that can be resolved by the FAQ you
>> pointed to.  I notice this question gets posted a lot and no one seems to
>> be
>> fully answering it.  Here's my go at it:
>>
>> The Camel xslt docs mention "Dynamic Stylesheets" by saying the
>> following:
>> /*Available as of Camel 2.9*
>> Camel provides the CamelXsltResourceUri header which you can use to
>> define a
>> stylesheet to use instead of what is configured on the endpoint URI. This
>> allows you to provide a dynamic stylesheet at runtime./
>>
>> I wish they could have supported their documentation better and provided
>> an
>> example.  Hopefully the example below will help others.
>>
>> {code}
>>   // register myResolver bean
>>   SimpleRegistry sr = new SimpleRegistry();
>>   sr.put("myResolver", new MyResolver());
>>
>>   from("direct:location")
>>     .setHeader("CamelXsltResourceUri",
>> simple("xslt:http://localhost:8080/
> <path>
> /
> <to>
> /
> <template>
> ?uriResolver=#myResolver"))
>>     .to("xslt:placeHolderTemplate.xsl")
>> {/code}
>>
>> Then within the myResolver class, fetch a remote resource and pull down
>> the
>> xml you wish to use.
>>
>> NOTE:  placeHolderTemplate.xsl is a real file located on the classpath
>> for
>> compile-time validation.  Once we execute this route and Camel see's the
>> "CamelXsltResourceUri" property in the headers, it will use the
>> properties
>> value as an argument into myResolver.
>>
>> MyResolver looks like the following:
>> {code}
>> class MyResolver extends XsltUriResolver {
>>     public Source resolve(String href, String base) throws
>> TransformerException {
>>         if(href.contains("xslt:")){
>>          // do logic to get resource
>>         }
>>    }
>> }
>> {/code}
>>
>> I hope that helps
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736862.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: 

> cibsen@

> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen





--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736912.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic xsl with custom uri resolver

Posted by Claus Ibsen <cl...@gmail.com>.
The CamelXsltResourceUri header is *only* for the location of the xls
file. Any other options like a custom resolver must be set on the
endpoint / component level.

On Tue, Aug 6, 2013 at 8:39 PM, ericsodt <de...@ll.mit.edu> wrote:
> Claus,
>
> The question I am asking is not one that can be resolved by the FAQ you
> pointed to.  I notice this question gets posted a lot and no one seems to be
> fully answering it.  Here's my go at it:
>
> The Camel xslt docs mention "Dynamic Stylesheets" by saying the following:
> /*Available as of Camel 2.9*
> Camel provides the CamelXsltResourceUri header which you can use to define a
> stylesheet to use instead of what is configured on the endpoint URI. This
> allows you to provide a dynamic stylesheet at runtime./
>
> I wish they could have supported their documentation better and provided an
> example.  Hopefully the example below will help others.
>
> {code}
>   // register myResolver bean
>   SimpleRegistry sr = new SimpleRegistry();
>   sr.put("myResolver", new MyResolver());
>
>   from("direct:location")
>     .setHeader("CamelXsltResourceUri",
> simple("xslt:http://localhost:8080/<path>/<to>/<template>?uriResolver=#myResolver"))
>     .to("xslt:placeHolderTemplate.xsl")
> {/code}
>
> Then within the myResolver class, fetch a remote resource and pull down the
> xml you wish to use.
>
> NOTE:  placeHolderTemplate.xsl is a real file located on the classpath for
> compile-time validation.  Once we execute this route and Camel see's the
> "CamelXsltResourceUri" property in the headers, it will use the properties
> value as an argument into myResolver.
>
> MyResolver looks like the following:
> {code}
> class MyResolver extends XsltUriResolver {
>     public Source resolve(String href, String base) throws
> TransformerException {
>         if(href.contains("xslt:")){
>          // do logic to get resource
>         }
>    }
> }
> {/code}
>
> I hope that helps
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736862.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Dynamic xsl with custom uri resolver

Posted by ericsodt <de...@ll.mit.edu>.
Claus,

The question I am asking is not one that can be resolved by the FAQ you
pointed to.  I notice this question gets posted a lot and no one seems to be
fully answering it.  Here's my go at it:

The Camel xslt docs mention "Dynamic Stylesheets" by saying the following:
/*Available as of Camel 2.9*
Camel provides the CamelXsltResourceUri header which you can use to define a
stylesheet to use instead of what is configured on the endpoint URI. This
allows you to provide a dynamic stylesheet at runtime./

I wish they could have supported their documentation better and provided an
example.  Hopefully the example below will help others.

{code}
  // register myResolver bean
  SimpleRegistry sr = new SimpleRegistry();
  sr.put("myResolver", new MyResolver());

  from("direct:location")
    .setHeader("CamelXsltResourceUri",
simple("xslt:http://localhost:8080/<path>/<to>/<template>?uriResolver=#myResolver"))
    .to("xslt:placeHolderTemplate.xsl")
{/code}

Then within the myResolver class, fetch a remote resource and pull down the
xml you wish to use.

NOTE:  placeHolderTemplate.xsl is a real file located on the classpath for
compile-time validation.  Once we execute this route and Camel see's the
"CamelXsltResourceUri" property in the headers, it will use the properties
value as an argument into myResolver.

MyResolver looks like the following:
{code}
class MyResolver extends XsltUriResolver {
    public Source resolve(String href, String base) throws
TransformerException {
        if(href.contains("xslt:")){
         // do logic to get resource
        }
   }
}
{/code}

I hope that helps



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736862.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic xsl with custom uri resolver

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See this FAQ
http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html

On Fri, Aug 2, 2013 at 2:15 PM, ericsodt <de...@ll.mit.edu> wrote:
> mox,
>
> There is no CSS nor HTML involved.
>
> The call to '.to("xslt:transformSubject.xsl?uriResolver=#emailResolver") '
> does an xslt transformation.  I'm trying to figure out how to make
> 'transformSubject.xsl' dynamic while still being able to use my custom
> URIResolver.
>
> Thanks!
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736703.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Dynamic xsl with custom uri resolver

Posted by ericsodt <de...@ll.mit.edu>.
mox, 

There is no CSS nor HTML involved.

The call to '.to("xslt:transformSubject.xsl?uriResolver=#emailResolver") '
does an xslt transformation.  I'm trying to figure out how to make
'transformSubject.xsl' dynamic while still being able to use my custom
URIResolver.

Thanks!





--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736703.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic xsl with custom uri resolver

Posted by Mike Oxford <mo...@gmail.com>.
The CSS which is loaded is defined in your HTML.  If you're going to use a
parameter to fetch the HTML, you're going to have to dynamically rewrite
that HTML to point to the correct CSS.

Whether you use a handler to rewrite where to get the CSS file, or whether
it shoves all the CSS into the HTML and just delivers that ... either way
you're going to end up modifying the document delivered.

Or you'll have to create a lot of duplicates and de-normalize everything
... which works just fine until you make a change and have to update 50
documents.  =)

Or you write some javascript which looks at the document.URL, figures out
what CSS it needs, and then dynamically loads those files after the fact.
 Could be doable if you kept it sync so the JS blocks page render until
it's done with the CSS loading.

Pick yer poison...

-mox




On Thu, Aug 1, 2013 at 8:23 PM, ericsodt <de...@ll.mit.edu> wrote:

> Anyone have any ideas?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736670.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Dynamic xsl with custom uri resolver

Posted by ericsodt <de...@ll.mit.edu>.
Anyone have any ideas?



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-xsl-with-custom-uri-resolver-tp5736668p5736670.html
Sent from the Camel - Users mailing list archive at Nabble.com.