|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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).
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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 ![]() |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
bricker42 we have success
|
|
#7
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > binding java from xslt |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|