Re: accessing java objects in xsl

5 messages Options
Embed this post
Permalink
Eric Dalquist

Re: accessing java objects in xsl

Reply Threaded More More options
Print post
Permalink
Take a look at http://xml.apache.org/xalan-j/extensions.html

If you're using Xalan for the XSLT engine you can call Java APIs from
within XSL.

-Eric

Leblanc Christophe wrote:

> hi,
>
> I wan't to rewrite url created in the portal. For this i wan't an
> access to encodeURL(String url) from  HttpServletResponse.
>
> Is there any way to do this in the xsl file ?
>
> Thanks
>
> Christophe Leblanc
>
> ---
> You are currently subscribed to [hidden email] as: [hidden email]
> To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/uportal-user
>
>  


smime.p7s (4K) Download Attachment
Gary Weaver

Re: accessing java objects in xsl

Reply Threaded More More options
Print post
Permalink
But he's not going to have access to the HttpServletResponse from within
the XSL, will he? While he could use java.net.URLEncoder, I think he is
saying that he wants to rewrite the URL, which is probably not something
possible to be done within the XSL unless somehow it is available during
the transformation? And it probably isn't a good place to be doing that
if at all possible anyway?

Gary


Eric Dalquist wrote:

> Take a look at http://xml.apache.org/xalan-j/extensions.html
>
> If you're using Xalan for the XSLT engine you can call Java APIs from
> within XSL.
>
> -Eric
>
> Leblanc Christophe wrote:
>> hi,
>>
>> I wan't to rewrite url created in the portal. For this i wan't an
>> access to encodeURL(String url) from  HttpServletResponse.
>>
>> Is there any way to do this in the xsl file ?
>>
>> Thanks
>>
>> Christophe Leblanc
>>
>> --- You are currently subscribed to [hidden email] as:
>> [hidden email]
>> To unsubscribe, change settings or access archives, see
>> http://www.ja-sig.org/wiki/display/JSG/uportal-user
>>
>>  


---
You are currently subscribed to [hidden email] as: [hidden email]
To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/uportal-user
Eric Dalquist

Re: accessing java objects in xsl

Reply Threaded More More options
Print post
Permalink
In reply to this post by Eric Dalquist
Some javascript/style in this post has been disabled (why?)
Sure, pass it in as a transformer attribute. Using Xalan elements is a great approach for things like this. Otherwise you end up having to do content rewriting which can be tricky and hard to maintain or front-load all URL generation in the code to pass into the XSLT which is also not very flexible. The upcoming consistent URL work for uPortal uses elements to great success for full on URL generation similar to how portlet URLs are generated.

Also you don't need the request to do URL encoding. You could more easily pass in the response encoding as a XSLT parameter

Here is an example that uses the default encoding:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";    
   version="1.0"
   xmlns:url="http://www.jclark.com/xt/java/java.net.URLEncoder";
   exclude-result-prefixes="url">

  <xsl:output method="html" indent="yes"/>
  
  <xsl:template match="/">
    <xsl:variable name="x" select="'encode me #1 superstar?'"/>
    <xsl:if test="function-available('url:encode')">
      <a href="http://www.skew.org/printenv?foo={url:encode($x)}">
        <xsl:value-of select="$x"/> 
      </a>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>



-Eric

Gary Weaver wrote:
But he's not going to have access to the HttpServletResponse from within the XSL, will he? While he could use java.net.URLEncoder, I think he is saying that he wants to rewrite the URL, which is probably not something possible to be done within the XSL unless somehow it is available during the transformation? And it probably isn't a good place to be doing that if at all possible anyway?

Gary


Eric Dalquist wrote:
Take a look at http://xml.apache.org/xalan-j/extensions.html

If you're using Xalan for the XSLT engine you can call Java APIs from within XSL.

-Eric

Leblanc Christophe wrote:
hi,

I wan't to rewrite url created in the portal. For this i wan't an
access to encodeURL(String url) from  HttpServletResponse.

Is there any way to do this in the xsl file ?

Thanks

Christophe Leblanc

--- You are currently subscribed to [hidden email] as: [hidden email]
To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/uportal-user

 


--- You are currently subscribed to [hidden email] as: [hidden email]
To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/uportal-user


smime.p7s (4K) Download Attachment
Leblanc Christophe

Re: accessing java objects in xsl

Reply Threaded More More options
Print post
Permalink
In reply to this post by Gary Weaver
Thanks for your responses.

I use urlrewritefilter and this tool can rewrite url when user access
the server, and when response is written.
For user access it is ok for me, but i wan't to dynamically rewrite
url in response. And not hardcoding urls in xsl.
I read urlrewritefilter rewrite url when response.encodeURL is called.
That's why I need access to this object in xsl file.

2009/10/9 Gary Weaver <[hidden email]>:

> But he's not going to have access to the HttpServletResponse from within the
> XSL, will he? While he could use java.net.URLEncoder, I think he is saying
> that he wants to rewrite the URL, which is probably not something possible
> to be done within the XSL unless somehow it is available during the
> transformation? And it probably isn't a good place to be doing that if at
> all possible anyway?
>
> Gary
>
>
> Eric Dalquist wrote:
>>
>> Take a look at http://xml.apache.org/xalan-j/extensions.html
>>
>> If you're using Xalan for the XSLT engine you can call Java APIs from
>> within XSL.
>>
>> -Eric
>>
>> Leblanc Christophe wrote:
>>>
>>> hi,
>>>
>>> I wan't to rewrite url created in the portal. For this i wan't an
>>> access to encodeURL(String url) from  HttpServletResponse.
>>>
>>> Is there any way to do this in the xsl file ?
>>>
>>> Thanks
>>>
>>> Christophe Leblanc
>>>
>>> --- You are currently subscribed to [hidden email] as:
>>> [hidden email]
>>> To unsubscribe, change settings or access archives, see
>>> http://www.ja-sig.org/wiki/display/JSG/uportal-user
>>>
>>>
>
>
> --- You are currently subscribed to [hidden email] as:
> [hidden email]
> To unsubscribe, change settings or access archives, see
> http://www.ja-sig.org/wiki/display/JSG/uportal-user
>
>

---
You are currently subscribed to [hidden email] as: [hidden email]
To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/uportal-user

Eric Dalquist

Re: accessing java objects in xsl

Reply Threaded More More options
Print post
Permalink
In reply to this post by Eric Dalquist
Some javascript/style in this post has been disabled (why?)
Also for those interesting in a more complex example, here is the XSLT part of the code in-development in uPortal for generating URLs in XSL via a tag-library type system:

Unit test for Xalan Element that can generate a portlet URL in uPortals XSLT:
http://developer.jasig.org/source/browse/jasigsvn/uPortal/branches/working-3.2-urls/uportal-impl/src/test/java/org/jasig/portal/url/xml/PortletUrlXalanElementsTest.java?r=46648

XSL for test:
http://developer.jasig.org/source/browse/jasigsvn/uPortal/branches/working-3.2-urls/uportal-impl/src/test/resources/org/jasig/portal/url/xml/portletUrlTest.xsl?r=46634

Xalan Element code:
http://developer.jasig.org/source/browse/jasigsvn/uPortal/branches/working-3.2-urls/uportal-impl/src/main/java/org/jasig/portal/url/xml/PortletUrlXalanElements.java?r=46653
http://developer.jasig.org/source/browse/jasigsvn/uPortal/branches/working-3.2-urls/uportal-impl/src/main/java/org/jasig/portal/url/xml/BaseUrlXalanElements.java?r=46762


-Eric

Eric Dalquist wrote:
Sure, pass it in as a transformer attribute. Using Xalan elements is a great approach for things like this. Otherwise you end up having to do content rewriting which can be tricky and hard to maintain or front-load all URL generation in the code to pass into the XSLT which is also not very flexible. The upcoming consistent URL work for uPortal uses elements to great success for full on URL generation similar to how portlet URLs are generated.

Also you don't need the request to do URL encoding. You could more easily pass in the response encoding as a XSLT parameter

Here is an example that uses the default encoding:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";    
   version="1.0"
   xmlns:url="http://www.jclark.com/xt/java/java.net.URLEncoder";
   exclude-result-prefixes="url">

  <xsl:output method="html" indent="yes"/>
  
  <xsl:template match="/">
    <xsl:variable name="x" select="'encode me #1 superstar?'"/>
    <xsl:if test="function-available('url:encode')">
      <a href="http://www.skew.org/printenv?foo={url:encode($x)}">
        <xsl:value-of select="$x"/> 
      </a>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
  



-Eric

Gary Weaver wrote:
But he's not going to have access to the HttpServletResponse from within the XSL, will he? While he could use java.net.URLEncoder, I think he is saying that he wants to rewrite the URL, which is probably not something possible to be done within the XSL unless somehow it is available during the transformation? And it probably isn't a good place to be doing that if at all possible anyway?

Gary


Eric Dalquist wrote:
Take a look at http://xml.apache.org/xalan-j/extensions.html

If you're using Xalan for the XSLT engine you can call Java APIs from within XSL.

-Eric

Leblanc Christophe wrote:
hi,

I wan't to rewrite url created in the portal. For this i wan't an
access to encodeURL(String url) from  HttpServletResponse.

Is there any way to do this in the xsl file ?

Thanks

Christophe Leblanc

--- You are currently subscribed to [hidden email] as: [hidden email]
To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/uportal-user

 


--- You are currently subscribed to [hidden email] as: [hidden email]
To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/uportal-user


smime.p7s (4K) Download Attachment