Class XSLTProcessorApplet

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    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.
    This class extends Applet which ultimately causes this class to implement Serializable. This is a serious restriction on this class. All fields that are not transient and not static are written-out/read-in during serialization. So even private fields essentially become part of the API. Developers need to take care when modifying fields.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.BaselineResizeBehavior
    • Field Summary

      • 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

      Constructors 
      Constructor Description
      XSLTProcessorApplet()
      The XSLTProcessorApplet constructor takes no arguments.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      Cleanup; called when applet is terminated and unloaded.
      java.lang.String escapeString​(java.lang.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.
      java.lang.String getAppletInfo()
      Get basic information about the applet
      java.lang.String getHtmlText()
      Assuming the stylesheet URL and the input XML URL have been set, perform the transformation and return the result as a String.
      java.lang.String[][] getParameterInfo()
      Get descriptions of the applet parameters.
      java.lang.String getResultTreeAsText()
      Get the HTML result Tree as a text string suitable for display in a browser.
      java.lang.String getSourceTreeAsText()
      Get the XML source Tree as a text string suitable for display in a browser.
      java.lang.String getStyleTreeAsText()
      Get the XSL style Tree as a text string suitable for display in a browser.
      java.lang.String getTreeAsText​(java.lang.String treeURL)
      Get an XML document (or stylesheet)
      void init()
      Standard applet initialization.
      void paint​(java.awt.Graphics g)
      Do not call; this applet contains no UI or visual components.
      void setDocumentURL​(java.lang.String urlString)
      Set the URL to the XML document that will be transformed with the XSL stylesheet.
      void setStyleSheetAttribute​(java.lang.String nameOfIDAttrOfElemToModify, java.lang.String elemId, java.lang.String attrName, java.lang.String value)
      Set an attribute in the stylesheet, which gives the ability to have some dynamic selection control.
      void setStylesheetParam​(java.lang.String key, java.lang.String expr)
      Submit a stylesheet parameter.
      void setStyleURL​(java.lang.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.
      java.lang.String transformToHtml​(java.lang.String doc)
      Process a document and a stylesheet and return the transformation result.
      java.lang.String transformToHtml​(java.lang.String doc, java.lang.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, isValidateRoot, 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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, 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, getMousePosition, getMouseWheelListeners, getName, getParent, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • XSLTProcessorApplet

        public XSLTProcessorApplet()
        The XSLTProcessorApplet constructor takes no arguments.
    • Method Detail

      • getAppletInfo

        public java.lang.String getAppletInfo()
        Get basic information about the applet
        Overrides:
        getAppletInfo in class java.applet.Applet
        Returns:
        A String with the applet name and author.
      • getParameterInfo

        public java.lang.String[][] getParameterInfo()
        Get descriptions of the applet parameters.
        Overrides:
        getParameterInfo in class java.applet.Applet
        Returns:
        A two-dimensional array of Strings with Name, Type, and Description for each parameter.
      • init

        public void init()
        Standard applet initialization.
        Overrides:
        init in class java.applet.Applet
      • start

        public void start()
        Automatically called when the HTML client containing the applet loads. This method starts execution of the applet thread.
        Overrides:
        start in class java.applet.Applet
      • paint

        public void paint​(java.awt.Graphics g)
        Do not call; this applet contains no UI or visual components.
        Overrides:
        paint in class java.awt.Container
      • 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.
        Overrides:
        stop in class java.applet.Applet
      • destroy

        public void destroy()
        Cleanup; called when applet is terminated and unloaded.
        Overrides:
        destroy in class java.applet.Applet
      • setStyleURL

        public void setStyleURL​(java.lang.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​(java.lang.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​(java.lang.String nameOfIDAttrOfElemToModify,
                                           java.lang.String elemId,
                                           java.lang.String attrName,
                                           java.lang.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​(java.lang.String key,
                                       java.lang.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 java.lang.String escapeString​(java.lang.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 java.lang.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 java.lang.String getTreeAsText​(java.lang.String treeURL)
                                       throws java.io.IOException
        Get an XML document (or stylesheet)
        Parameters:
        treeURL - valid URL string for the document.
        Returns:
        document
        Throws:
        java.io.IOException
      • getSourceTreeAsText

        public java.lang.String getSourceTreeAsText()
                                             throws java.lang.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:
        java.lang.Exception - thrown if tree can not be converted.
      • getStyleTreeAsText

        public java.lang.String getStyleTreeAsText()
                                            throws java.lang.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:
        java.lang.Exception - thrown if tree can not be converted.
      • getResultTreeAsText

        public java.lang.String getResultTreeAsText()
                                             throws java.lang.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:
        java.lang.Exception - thrown if tree can not be converted.
      • transformToHtml

        public java.lang.String transformToHtml​(java.lang.String doc,
                                                java.lang.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 java.lang.String transformToHtml​(java.lang.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