org.apache.xalan.client
Class XSLTProcessorApplet

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byjava.applet.Applet
                  extended byorg.apache.xalan.client.XSLTProcessorApplet
All Implemented Interfaces:
javax.accessibility.Accessible, ImageObserver, MenuContainer, Serializable

public class XSLTProcessorApplet
extends java.applet.Applet

Provides applet host for the XSLT processor. To perform transformations on an HTML client:

  1. Use an <applet> tag to embed this applet in the HTML client.
  2. Use the DocumentURL and StyleURL PARAM tags or the setDocumentURL(java.lang.String) and setStyleURL(java.lang.String) methods to specify the XML source document and XSL stylesheet.
  3. Call the getHtmlText() method (or one of the transformToHtml() methods) to perform the transformation and return the result as a String.

See Also:
Serialized Form

Nested Class Summary
(package private)  class XSLTProcessorApplet.TrustedAgent
          This class maintains a worker thread that that is trusted and can do things like access data.
 
Nested classes inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  String m_attrNameToSet
           
private  String m_attrValueToSet
           
private  Thread m_callThread
          Thread stuff for the trusted worker thread.
private  URL m_codeBase
          Save this for use on the worker thread; may not be necessary.
private  URL m_documentBase
          DocumentBase URL
private  String m_documentURL
           
private  String m_documentURLOfCached
           
private  String m_elemIdToModify
           
(package private)  String m_expression
          Stylesheet parameter value
private  String m_htmlText
          Where the worker thread puts the HTML text.
(package private)  String m_key
          Stylesheet parameter key
private  String m_nameOfIDAttrOfElemToModify
          Stylesheet attribute name and value that the caller can set.
private  String m_sourceText
          Where the worker thread puts the document/stylesheet text.
private  String m_styleURL
           
private  String m_styleURLOfCached
           
(package private)  javax.xml.transform.TransformerFactory m_tfactory
          The stylesheet processor.
private  String m_treeURL
           
private  XSLTProcessorApplet.TrustedAgent m_trustedAgent
           
private  Thread m_trustedWorker
          Thread for running TrustedAgent.
private  String PARAM_documentURL
           
private  String PARAM_styleURL
           
 
Fields inherited from class java.applet.Applet
 
Fields inherited from class java.awt.Panel
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
XSLTProcessorApplet()
          The XSLTProcessorApplet constructor takes no arguments.
 
Method Summary
 void destroy()
          Cleanup; called when applet is terminated and unloaded.
 String escapeString(String s)
          Given a String containing markup, escape the markup so it can be displayed in the browser.
 void freeCache()
          The processor keeps a cache of the source and style trees, so call this method if they have changed or you want to do garbage collection.
 String getAppletInfo()
          Get basic information about the applet
 String getHtmlText()
          Assuming the stylesheet URL and the input XML URL have been set, perform the transformation and return the result as a String.
 String[][] getParameterInfo()
          Get descriptions of the applet parameters.
 String getResultTreeAsText()
          Get the HTML result Tree as a text string suitable for display in a browser.
private  String getSource()
          Use a Transformer to copy the source document to a StreamResult.
 String getSourceTreeAsText()
          Get the XML source Tree as a text string suitable for display in a browser.
 String getStyleTreeAsText()
          Get the XSL style Tree as a text string suitable for display in a browser.
 String getTreeAsText(String treeURL)
          Get an XML document (or stylesheet)
 void init()
          Standard applet initialization.
 void paint(Graphics g)
          Do not call; this applet contains no UI or visual components.
private  String processTransformation()
          Process the transformation.
 void setDocumentURL(String urlString)
          Set the URL to the XML document that will be transformed with the XSL stylesheet.
 void setStyleSheetAttribute(String nameOfIDAttrOfElemToModify, String elemId, String attrName, String value)
          Set an attribute in the stylesheet, which gives the ability to have some dynamic selection control.
 void setStylesheetParam(String key, String expr)
          Submit a stylesheet parameter.
 void setStyleURL(String urlString)
          Set the URL to the XSL stylesheet that will be used to transform the input XML.
 void start()
          Automatically called when the HTML client containing the applet loads.
 void stop()
          Automatically called when the HTML page containing the applet is no longer on the screen.
 String transformToHtml(String doc)
          Process a document and a stylesheet and return the transformation result.
 String transformToHtml(String doc, String style)
          Process a document and a stylesheet and return the transformation result.
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_tfactory

javax.xml.transform.TransformerFactory m_tfactory
The stylesheet processor.


m_styleURL

private String m_styleURL

m_documentURL

private String m_documentURL

PARAM_styleURL

private final String PARAM_styleURL
See Also:
Constant Field Values

PARAM_documentURL

private final String PARAM_documentURL
See Also:
Constant Field Values

m_styleURLOfCached

private String m_styleURLOfCached

m_documentURLOfCached

private String m_documentURLOfCached

m_codeBase

private URL m_codeBase
Save this for use on the worker thread; may not be necessary.


m_treeURL

private String m_treeURL

m_documentBase

private URL m_documentBase
DocumentBase URL


m_callThread

private transient Thread m_callThread
Thread stuff for the trusted worker thread.


m_trustedAgent

private transient XSLTProcessorApplet.TrustedAgent m_trustedAgent

m_trustedWorker

private transient Thread m_trustedWorker
Thread for running TrustedAgent.


m_htmlText

private transient String m_htmlText
Where the worker thread puts the HTML text.


m_sourceText

private transient String m_sourceText
Where the worker thread puts the document/stylesheet text.


m_nameOfIDAttrOfElemToModify

private transient String m_nameOfIDAttrOfElemToModify
Stylesheet attribute name and value that the caller can set.


m_elemIdToModify

private transient String m_elemIdToModify

m_attrNameToSet

private transient String m_attrNameToSet

m_attrValueToSet

private transient String m_attrValueToSet

m_key

transient String m_key
Stylesheet parameter key


m_expression

transient String m_expression
Stylesheet parameter value

Constructor Detail

XSLTProcessorApplet

public XSLTProcessorApplet()
The XSLTProcessorApplet constructor takes no arguments.

Method Detail

getAppletInfo

public String getAppletInfo()
Get basic information about the applet

Returns:
A String with the applet name and author.

getParameterInfo

public String[][] getParameterInfo()
Get descriptions of the applet parameters.

Returns:
A two-dimensional array of Strings with Name, Type, and Description for each parameter.

init

public void init()
Standard applet initialization.


start

public void start()
Automatically called when the HTML client containing the applet loads. This method starts execution of the applet thread.


paint

public void paint(Graphics g)
Do not call; this applet contains no UI or visual components.

Overrides:
paint in class Container
Parameters:
g - the specified Graphics window
See Also:
Component.update(Graphics)

stop

public void stop()
Automatically called when the HTML page containing the applet is no longer on the screen. Stops execution of the applet thread.


destroy

public void destroy()
Cleanup; called when applet is terminated and unloaded.


setStyleURL

public void setStyleURL(String urlString)
Set the URL to the XSL stylesheet that will be used to transform the input XML. No processing is done yet.

Parameters:
urlString - valid URL string for XSL stylesheet.

setDocumentURL

public void setDocumentURL(String urlString)
Set the URL to the XML document that will be transformed with the XSL stylesheet. No processing is done yet.

Parameters:
urlString - valid URL string for XML document.

freeCache

public void freeCache()
The processor keeps a cache of the source and style trees, so call this method if they have changed or you want to do garbage collection.


setStyleSheetAttribute

public void setStyleSheetAttribute(String nameOfIDAttrOfElemToModify,
                                   String elemId,
                                   String attrName,
                                   String value)
Set an attribute in the stylesheet, which gives the ability to have some dynamic selection control.

Parameters:
nameOfIDAttrOfElemToModify - The name of an attribute to search for a unique id.
elemId - The unique ID to look for.
attrName - Once the element is found, the name of the attribute to set.
value - The value to set the attribute to.

setStylesheetParam

public void setStylesheetParam(String key,
                               String expr)
Submit a stylesheet parameter.

Parameters:
key - stylesheet parameter key
expr - the parameter expression to be submitted.
See Also:
Transformer.setParameter(String,Object)

escapeString

public String escapeString(String s)
Given a String containing markup, escape the markup so it can be displayed in the browser.

Parameters:
s - String to escape The escaped string.

getHtmlText

public String getHtmlText()
Assuming the stylesheet URL and the input XML URL have been set, perform the transformation and return the result as a String.

Returns:
A string that contains the contents pointed to by the URL.

getTreeAsText

public String getTreeAsText(String treeURL)
                     throws IOException
Get an XML document (or stylesheet)

Parameters:
treeURL - valid URL string for the document.
Returns:
document
Throws:
IOException

getSource

private String getSource()
                  throws javax.xml.transform.TransformerException
Use a Transformer to copy the source document to a StreamResult.

Returns:
the document as a string
Throws:
javax.xml.transform.TransformerException

getSourceTreeAsText

public String getSourceTreeAsText()
                           throws Exception
Get the XML source Tree as a text string suitable for display in a browser. Note that this is for display of the XML itself, not for rendering of HTML by the browser.

Returns:
XML source document as a string.
Throws:
Exception - thrown if tree can not be converted.

getStyleTreeAsText

public String getStyleTreeAsText()
                          throws Exception
Get the XSL style Tree as a text string suitable for display in a browser. Note that this is for display of the XML itself, not for rendering of HTML by the browser.

Returns:
The XSL stylesheet as a string.
Throws:
Exception - thrown if tree can not be converted.

getResultTreeAsText

public String getResultTreeAsText()
                           throws Exception
Get the HTML result Tree as a text string suitable for display in a browser. Note that this is for display of the XML itself, not for rendering of HTML by the browser.

Returns:
Transformation result as unmarked text.
Throws:
Exception - thrown if tree can not be converted.

transformToHtml

public String transformToHtml(String doc,
                              String style)
Process a document and a stylesheet and return the transformation result. If one of these is null, the existing value (of a previous transformation) is not affected.

Parameters:
doc - URL string to XML document
style - URL string to XSL stylesheet
Returns:
HTML transformation result

transformToHtml

public String transformToHtml(String doc)
Process a document and a stylesheet and return the transformation result. Use the xsl:stylesheet PI to find the document, if one exists.

Parameters:
doc - URL string to XML document containing an xsl:stylesheet PI.
Returns:
HTML transformation result

processTransformation

private String processTransformation()
                              throws javax.xml.transform.TransformerException
Process the transformation.

Returns:
The transformation result as a string.
Throws:
javax.xml.transform.TransformerException