net.sf.fikin.xml
Class Stx

java.lang.Object
  extended by net.sf.fikin.xml.Stx

public class Stx
extends java.lang.Object

Makes STX operations easier.

This class provides absolutely the same same services as Xslt but it is operating with STX instead of XSLT

The only difference is that it does not support JAXP factory settings as this is not needed for STX

Please refer to Xslt documentation for full list of features and services provided by this class

STX is "Streaming Trasnformation for XML", which is pretty much XSLT but tailored for SAX processing (thus accepting unlimited input data). STX spec

STX processor in use is Joost and it is available at Joost

Usage:

      Stx stx = new Stx( Stx.newSAXSource( "my.stx" ) );
      stx.transform( Stx.newSAXSource("my.xml") );
      stx.transform( Stx.newSAXSource("my.xml"), new StreamResult( "my.txt" ) );
      ...
 
created on Oct 1, 2006

Since:
Version:
$Revision: 1.11 $
Author:
fiykov

Constructor Summary
Stx(javax.xml.transform.sax.SAXSource stx)
          instantiate an template with xsl source
 
Method Summary
 java.lang.String exportJavaObject(java.lang.Object obj)
          if you want to thread-safe export a callback java object called from the xstl (via one or another java extension api): call this method with the object to be exported the return is a an unique key value with which you can look it up via lookupObject(String) pass the key as a normal parameter to the xslt in the xslt you have to use the java extension api available and lookup the object via lookupObject(String)
 javax.xml.transform.ErrorListener getErrorListener()
          get error listener, by default it is System.stderr based
static java.lang.Object lookupObject(java.lang.String key)
          lookup a previously exported java object via exportJavaObject(Object) this method is called by xslt (via xslt vendor specific java extension api)
static javax.xml.transform.sax.SAXSource newSAXSource(java.io.File in)
          instantiate a new source out of a file it uses buffered input stream
static javax.xml.transform.sax.SAXSource newSAXSource(java.io.InputStream in)
          instantiate a new source out of an input stream
static javax.xml.transform.sax.SAXSource newSAXSource(java.io.Reader in)
          instantiate a new source out of a reader
static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String file)
          instantiate a new source out of a file name
static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String file, java.lang.Class callingCls)
          instantiate a new source out of a resource available in the classpath
static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String fqnFile, java.lang.ClassLoader cl)
          instantiate a new source out of a resource available in the classpath when a classloader is provided, it will be used to resolve the resource.
static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String file, java.lang.Package pkg)
          instantiate a new source out of a resource available in the classpath
static javax.xml.transform.sax.SAXSource newSAXSource(java.net.URL in)
          instantiate a new source out of an url location it uses buffered input stream
 void setErrorListener(javax.xml.transform.ErrorListener errorListener)
          set error listener to one the user has defined
 void transform(javax.xml.transform.sax.SAXSource in)
          transform in into output output is a dummy byte array stream
 void transform(javax.xml.transform.sax.SAXSource in, java.util.Hashtable params)
          transform in into output output is a dummy byte array stream
 void transform(javax.xml.transform.sax.SAXSource in, javax.xml.transform.Result out)
          transform in into output
 void transform(javax.xml.transform.sax.SAXSource in, javax.xml.transform.Result out, java.util.Hashtable params)
          transform in into output
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stx

public Stx(javax.xml.transform.sax.SAXSource stx)
    throws javax.xml.transform.TransformerConfigurationException
instantiate an template with xsl source

Parameters:
stx -
Throws:
javax.xml.transform.TransformerConfigurationException
Method Detail

setErrorListener

public void setErrorListener(javax.xml.transform.ErrorListener errorListener)
set error listener to one the user has defined

Parameters:
errorListener -

getErrorListener

public javax.xml.transform.ErrorListener getErrorListener()
get error listener, by default it is System.stderr based

Returns:
errorListener

transform

public void transform(javax.xml.transform.sax.SAXSource in,
                      javax.xml.transform.Result out,
                      java.util.Hashtable params)
               throws javax.xml.transform.TransformerException
transform in into output

Parameters:
in -
out -
params -
Throws:
javax.xml.transform.TransformerException

transform

public void transform(javax.xml.transform.sax.SAXSource in,
                      javax.xml.transform.Result out)
               throws javax.xml.transform.TransformerException
transform in into output

Parameters:
in -
out -
Throws:
javax.xml.transform.TransformerException

transform

public void transform(javax.xml.transform.sax.SAXSource in,
                      java.util.Hashtable params)
               throws javax.xml.transform.TransformerException
transform in into output output is a dummy byte array stream

Parameters:
in -
params -
Throws:
javax.xml.transform.TransformerException

transform

public void transform(javax.xml.transform.sax.SAXSource in)
               throws javax.xml.transform.TransformerException
transform in into output output is a dummy byte array stream

Parameters:
in -
Throws:
javax.xml.transform.TransformerException

exportJavaObject

public java.lang.String exportJavaObject(java.lang.Object obj)
if you want to thread-safe export a callback java object called from the xstl (via one or another java extension api):
  • call this method with the object to be exported
  • the return is a an unique key value with which you can look it up via lookupObject(String)
  • pass the key as a normal parameter to the xslt
  • in the xslt you have to use the java extension api available and lookup the object via lookupObject(String)
  • Parameters:
    obj -
    Returns:
    an unique key identifying this lookup object

    lookupObject

    public static java.lang.Object lookupObject(java.lang.String key)
    lookup a previously exported java object via exportJavaObject(Object) this method is called by xslt (via xslt vendor specific java extension api)

    Parameters:
    key - is the key obtained by exportJavaObject(Object)
    Returns:
    found object or null

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.io.Reader in)
    instantiate a new source out of a reader

    Parameters:
    in - is a reader object
    Returns:
    a new source object

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.io.InputStream in)
    instantiate a new source out of an input stream

    Parameters:
    in - is an input stream
    Returns:
    a new source object

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.io.File in)
                                                          throws java.io.FileNotFoundException
    instantiate a new source out of a file it uses buffered input stream

    Parameters:
    in - the file object
    Returns:
    a new source object
    Throws:
    java.io.FileNotFoundException

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.net.URL in)
                                                          throws java.io.IOException
    instantiate a new source out of an url location it uses buffered input stream

    Parameters:
    in - the url of the source
    Returns:
    a new source object
    Throws:
    java.io.IOException

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String file)
                                                          throws java.io.FileNotFoundException
    instantiate a new source out of a file name

    Parameters:
    file - is the fully qualified file name
    Returns:
    a new source object
    Throws:
    java.io.FileNotFoundException

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String fqnFile,
                                                                 java.lang.ClassLoader cl)
                                                          throws java.lang.NullPointerException
    instantiate a new source out of a resource available in the classpath when a classloader is provided, it will be used to resolve the resource. when classloader is null, the resource is seached via system classloader first, then via current's class classloader and finally via thread's context classloader. first time the resource is located it is returned.

    Parameters:
    fqnFile - is the fully qualified name of the resource
    cl - is the classloader to be used, if null it tries with Stx.class.getClassLoader() and if still is null tries Thread.currentThread().getContextClassLoader(). when null is passed it means the bootstraploader is meant.
    Returns:
    a new source object
    Throws:
    NullPoinerException - when no resource is found
    java.lang.NullPointerException

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String file,
                                                                 java.lang.Package pkg)
    instantiate a new source out of a resource available in the classpath

    Parameters:
    file - is the resource name (only file name)
    pkg - is the package (i.e. java package) where the file is
    Returns:
    a new source object

    newSAXSource

    public static javax.xml.transform.sax.SAXSource newSAXSource(java.lang.String file,
                                                                 java.lang.Class callingCls)
    instantiate a new source out of a resource available in the classpath

    Parameters:
    file - is the resource name (only file name)
    callingCls - is the class whose package the file is
    Returns:
    a new source object


    Copyright © 2003-2007 Nikolay Fiykov. All Rights Reserved.