[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT/Java does not identify an external Java class

Subject: XSLT/Java does not identify an external Java class
From: "Linc" <lincolnmitchell@xxxxxxxxxxxxxx>
Date: Sat, 3 Jan 2004 08:30:52 +0800
xslt java class
Hi,

I am having difficulty getting an example working from the book 'XSLT
cookbook' by Sal Mangano, recipe 12.3 (page 542).
I receive the following error for the SVG bounding box example on running
"c:\my path...\saxon textWidthTest.xml textWidthTest.xslt > output.svg" at
the CMD line:
Error at xsl:value-of on line 17 of file:/c:/my path/textwidthtest.xslt:
  The URI xalan://com.ora.xsltckbk.util.SVGFontMetrics does not identify an
external Java class
Transformation failed: Run-time errors were reported

Here is the XLST and java file used:

XSLT file
------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:font="xalan://com.ora.xsltckbk.util.SVGFontMetrics"
exclude-result-prefixes="font xalan">

<xsl:output method="xml"/>

<xsl:template match="/">
  <svg width="100%" height="100%">
    <xsl:apply-templates/>
   </svg>
</xsl:template>


<xsl:template match="text">
  <xsl:variable name="fontMetrics" select="font:new(@font, @size,
boolean(@weight), boolean(@stytle))"/>
  <xsl:variable name="text" select="."/>
  <xsl:variable name="width" select="font:stringWidth($fontMetrics,
$text)"/>
  <xsl:variable name="height" select="font:stringHeight($fontMetrics,
$text)"/>
  <xsl:variable name="style">
    <xsl:if test="@style">
      <xsl:value-of select="concat('font-style:',@style)"/>
    </xsl:if>
  </xsl:variable>
  <xsl:variable name="weight">
    <xsl:if test="@weight">
      <xsl:value-of select="concat('font-weight:',@weight)"/>
    </xsl:if>
  </xsl:variable>
  <g style="font-family:{@font};font-size:{@size};{$style};{$weight}">
    <!-- Use the SVGFontMetrics info render a rectangle that is -->
    <!-- slightly bigger than the expected size of the text -->
    <!-- Adjust the y position based on the previous text size. -->
    <rect x="10"
          y="{sum(preceding-sibling::text/@size) * 2}pt"
          width="{$width + 2}"
          height="{$height + 2}"
          style="fill:none;stroke: black;stroke-width:0.5;"/>
    <!-- Render the text so it is cenetered in the rectangle -->
    <text x="11" y="{sum(preceding-sibling::text/@size) * 2 + @size div 2 +
2}pt">
      <xsl:value-of select="."/>
    </text>
  </g>

</xsl:template>


</xsl:stylesheet>




Java class in package (xsltckbk.jar)
-----------------------------------------------

package com.ora.xsltckbk.util ;
import java.awt.* ;
import java.awt.geom.* ;
import java.awt.font.* ;
import java.awt.image.*;

public class SVGFontMetrics
{
  public SVGFontMetrics(String fontName, int size)
  {
    m_font = new Font(fontName, Font.PLAIN, size) ;
    BufferedImage bi
        = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    m_graphics2D = bi.createGraphics() ;
  }

  public SVGFontMetrics(String fontName, int size, boolean bold, boolean
italic)
  {
    m_font = new Font(fontName, style(bold,italic) , size) ;
    BufferedImage bi
        = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    m_graphics2D = bi.createGraphics() ;
  }

  public double stringWidth(String str)
  {
    FontRenderContext frc = m_graphics2D.getFontRenderContext();
    TextLayout layout = new TextLayout(str, m_font, frc);
    Rectangle2D rect = layout.getBounds() ;
    return rect.getWidth() ;
  }

  public double stringHeight(String str)
  {
    FontRenderContext frc = m_graphics2D.getFontRenderContext();
    TextLayout layout = new TextLayout(str, m_font, frc);
    Rectangle2D rect = layout.getBounds() ;
    return rect.getHeight() ;
  }

  static private int style(boolean bold, boolean italic)
  {
    int style = Font.PLAIN ;
    if (bold) { style |= Font.BOLD;}
    if (italic) { style |= Font.ITALIC;}
    return style ;
  }

  private Font m_font = null ;
  private Graphics2D m_graphics2D = null;
}




I have searched the http://www.mulberrytech.com/xsl/xsl-list archives, and
numerous other sites for the answer, edited the classpath to include
"xsltckbk.jar" but to no avail.

Any help appreciated.



Linc



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.