Class XhtmlRenderer

    • Constructor Summary

      Constructors 
      Constructor Description
      XhtmlRenderer()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract java.lang.String getCssClass​(int style)
      Looks up the CSS class identifier that corresponds to the syntax style.
      protected java.lang.String getCssClassDefinitions()
      Returns all the CSS class definitions that should appear within the style XHTML tag.
      protected abstract java.util.Map getDefaultCssStyles()
      Returns a map of all the CSS styles that the renderer requires, together with default definitions for them.
      protected abstract ExplicitStateHighlighter getHighlighter()
      Returns the language-specific highlighting lexer that should be used
      protected java.lang.String getXhtmlFooter()
      Returns the XHTML footer that nicely finishes the file after the highlighted source code.
      protected java.lang.String getXhtmlHeader​(java.lang.String name)
      Returns the XHTML header that preceedes the highlighted source code.
      protected java.lang.String getXhtmlHeaderFragment​(java.lang.String name)
      Returns the XHTML header that preceedes the highlighted source code for a fragment.
      void highlight​(java.lang.String name, java.io.InputStream in, java.io.OutputStream out, java.lang.String encoding, boolean fragment)
      Transforms source code that's provided through an InputStream to highlighted syntax in XHTML and writes it back to an OutputStream.
      java.lang.String highlight​(java.lang.String name, java.lang.String in, java.lang.String encoding, boolean fragment)
      Transforms source code that's provided through a String to highlighted syntax in XHTML and returns it as a String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XhtmlRenderer

        public XhtmlRenderer()
    • Method Detail

      • highlight

        public void highlight​(java.lang.String name,
                              java.io.InputStream in,
                              java.io.OutputStream out,
                              java.lang.String encoding,
                              boolean fragment)
                       throws java.io.IOException
        Transforms source code that's provided through an InputStream to highlighted syntax in XHTML and writes it back to an OutputStream.

        If the highlighting has to become a fragment, no CSS styles will be generated.

        For complete documents, there's a collection of default styles that will be included. It's possible to override these by changing the provided jhighlight.properties file. It's best to look at this file in the JHighlight archive and modify the styles that are there already.

        Specified by:
        highlight in interface Renderer
        Parameters:
        name - The name of the source file.
        in - The input stream that provides the source code that needs to be transformed.
        out - The output stream to which to resulting XHTML should be written.
        encoding - The encoding that will be used to read and write the text.
        fragment - true if the generated XHTML should be a fragment; or false if it should be a complete page
        Throws:
        java.io.IOException
        Since:
        1.0
        See Also:
        highlight(String, String, String, boolean)
      • highlight

        public java.lang.String highlight​(java.lang.String name,
                                          java.lang.String in,
                                          java.lang.String encoding,
                                          boolean fragment)
                                   throws java.io.IOException
        Transforms source code that's provided through a String to highlighted syntax in XHTML and returns it as a String.

        If the highlighting has to become a fragment, no CSS styles will be generated.

        Specified by:
        highlight in interface Renderer
        Parameters:
        name - The name of the source file.
        in - The input string that provides the source code that needs to be transformed.
        encoding - The encoding that will be used to read and write the text.
        fragment - true if the generated XHTML should be a fragment; or false if it should be a complete page or false if it should be a complete document
        Returns:
        the highlighted source code as XHTML in a string
        Throws:
        java.io.IOException
        Since:
        1.0
        See Also:
        highlight(String, InputStream, OutputStream, String, boolean)
      • getDefaultCssStyles

        protected abstract java.util.Map getDefaultCssStyles()
        Returns a map of all the CSS styles that the renderer requires, together with default definitions for them.
        Returns:
        The map of CSS styles.
        Since:
        1.0
      • getCssClass

        protected abstract java.lang.String getCssClass​(int style)
        Looks up the CSS class identifier that corresponds to the syntax style.
        Parameters:
        style - The syntax style.
        Returns:
        The requested CSS class identifier; or

        null if the syntax style isn't supported.

        Since:
        1.0
      • getHighlighter

        protected abstract ExplicitStateHighlighter getHighlighter()
        Returns the language-specific highlighting lexer that should be used
        Returns:
        The requested highlighting lexer.
        Since:
        1.0
      • getCssClassDefinitions

        protected java.lang.String getCssClassDefinitions()
        Returns all the CSS class definitions that should appear within the style XHTML tag.

        This should support all the classes that the getCssClass(int) method returns.

        Returns:
        The CSS class definitions
        Since:
        1.0
        See Also:
        getCssClass(int)
      • getXhtmlHeader

        protected java.lang.String getXhtmlHeader​(java.lang.String name)
        Returns the XHTML header that preceedes the highlighted source code.

        It will integrate the CSS class definitions and use the source's name to indicate in XHTML which file has been highlighted.

        Parameters:
        name - The name of the source file.
        Returns:
        The constructed XHTML header.
        Since:
        1.0
      • getXhtmlHeaderFragment

        protected java.lang.String getXhtmlHeaderFragment​(java.lang.String name)
        Returns the XHTML header that preceedes the highlighted source code for a fragment.
        Parameters:
        name - The name of the source file.
        Returns:
        The constructed XHTML header.
        Since:
        1.0
      • getXhtmlFooter

        protected java.lang.String getXhtmlFooter()
        Returns the XHTML footer that nicely finishes the file after the highlighted source code.
        Returns:
        The requested XHTML footer.
        Since:
        1.0