XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 25th, 2004, 11:49 AM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
binding java from xslt

In short, I am trying to get the pixel width of an image. I have located the java class ImageInfo. Its API is http://www.geocities.com/marcoschmi...ImageInfo.html. I am losing all my hair (and the entire weekend) trying to use its getWidth() method from my XSLT. I am using Xalan-J with the namespace xmlns:java="http://xml.apache.org/xalan/java". I am getting errors no matter what I try to do. I would be so thankful for some help.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:java="http://xml.apache.org/xalan/java"
  version="1.1">

  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <body bgcolor="#FFFFFF">
        <h2>Test</h2>
        <xsl:variable name="img" select="'c:\WORLD.gif'"/>
        <xsl:variable name="imgObject" select="java:ImageInfo.setInput($img)"/>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>


file:javatest.xsl; Line #13; Column #88; XSLT Error (javax.xml.transform.TransformerException): java.lang
.NoSuchMethodException: For extension function, could not find method static ImageInfo.setInput([ExpressionContext,] #STRING).

Reply With Quote
  #2  
Old January 26th, 2004, 12:01 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
At a guess ImageInfo is probably in a package, so this line is wrong:
Code:
<xsl:variable name="imgObject" select="java:ImageInfo.setInput($img)"/>


It should be something like
Code:
<xsl:variable name="imgObject" select="java:the.package.name.ImageInfo.setInput($img)"/>


The URL you posted doesn't work for me so I can't confirm it, but based on the error message that's my guess.

Reply With Quote
  #3  
Old January 26th, 2004, 01:25 AM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
Thank you. On the URL, a "period" got appended to it. Try this

http://www.geocities.com/marcoschmi.../ImageInfo.html

The source of the class doesn't seem to list a package--but I am a Java novice.

Reply With Quote
  #4  
Old January 26th, 2004, 02:47 AM
tank80's Avatar
tank80 tank80 is offline
php-oriented object
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 0x9832053
Posts: 173 tank80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation Power: 8
Send a message via ICQ to tank80
are you using java 1.4? in this case, this version doesn't allow to use a class that doesn't have a package (like some.package.name.ImageInfo)
try using an older version of java or modifing the class source including a package name on the top.

Hope this helps

Reply With Quote
  #5  
Old January 26th, 2004, 11:25 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Also, looking at the usage example, setInput isn't a static method. You need to do something like this:
Code:
select="java:package.name.ImageInfo.new()"/>
<xsl:variable name="imgObject" select="java:setInput( $imageInfo, 'c:\WORLD.gif' )" />


**edit**
Ok, rereading the javadoc it's worse than that. You can't just pass an image path to setInput, you have to pass an InputStream.

My recommendation to you would be to write your own java class with a single static method that takes a path name as a parameter and returns a width. You can use ImageInfo inside your class to get the information, but you'll have a much easier time with the xsl if you write your own wrapper class.

If you need help writing the java class ask for some help in the java forums here.

Last edited by bricker42 : January 26th, 2004 at 11:29 AM.

Reply With Quote
  #6  
Old January 28th, 2004, 01:37 PM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
bricker42 we have success

Reply With Quote
  #7  
Old January 28th, 2004, 01:42 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Glad to hear it . Do you have time to describe what you did? It could be useful for anyone else that has a similar problem.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > binding java from xslt


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT