001package Torello.JavaDoc; 002 003import java.io.File; 004import java.io.IOException; 005import java.util.Objects; 006import java.util.Vector; 007 008import Torello.HTML.HTMLNode; 009import Torello.JavaDoc.SyntaxHiLite.HiLiteCache; 010import Torello.JavaDoc.SyntaxHiLite.Pygmentize; 011 012/** 013 * A simple Functional-Interface allowing a user to swap in any customized, alternate or 014 * proprietary Syntax HiLiter to replace the default HiLiter used by this Upgrader Tool. 015 * 016 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=HILITER> 017 */ 018@FunctionalInterface 019public interface HiLiter 020{ 021 /** 022 * This {@code Functional Interface} expects this method to be implemented. Any HiLiter that 023 * would be "plugged into" this Documentation Tool must be able to <B>Pretty-Print HiLite</B> 024 * input Source-Code (passed as a {@code java.lang.String}) <I>and return HTML</I>. 025 * 026 * <BR /><BR /><B>NOTE:</B> Any Code HiLiter that can operate with this input may be plugged 027 * in here. In order to "Vectorize" HTML, just use the 028 * {@code HTMLPage.getPageTokens(String, false)} method. 029 * 030 * @param code This is the Source-Code as a {@code java.lang.String} 031 * 032 * @param codeType This is a short descriptor of what kind of code is being passed. The most 033 * frequent values for this parameter are: {@code 'java', 'html', 'js'} etc... 034 * 035 * @param snippetOrComplete This is a {@code boolean} that when {@code TRUE}, indicates that 036 * a <B>code-snippet</B> has been passed, and when {@code FALSE} indicates that a <B>complete 037 * source code file</B> has been passed. 038 * 039 * @return The intention is to return a Vectorized-HTML page (or sub-page) that contains a 040 * <B>HiLited & Pretty-Printed</B> version of the source-code. 041 * 042 * @throws IOException This method is not defined, but it is permitted to throw 043 * {@code IOException} - if there have been I/O problems when attempting to transform the 044 * source-code. 045 * 046 * @throws HiLiteException This exception may be used if other problems occur during the 047 * transformation process. 048 */ 049 public Vector<HTMLNode> hiLite 050 (String code, String codeType, boolean snippetOrComplete) 051 throws IOException, HiLiteException; 052 053 /** 054 * The Default <B>Code HiLiter</B> uses the package {@code Torello.JavaDoc.SyntaxHiLite}. 055 * 056 * @param cache This is the HiLiter-Cache that <I>may or may not be used</I>. 057 * @return An instance of {@code HiLiter} that can be used by the {@code Upgrade} Tool 058 */ 059 public static HiLiter getDefault(final HiLiteCache cache) 060 { 061 Objects.requireNonNull(cache, "HiLiteCache 'cache' Parameter has been passed null."); 062 return new JDU_HL(cache); 063 } 064} 065 066class JDU_HL implements HiLiter 067{ 068 private final Pygmentize pygmentize = new Pygmentize(); 069 private final HiLiteCache cache; 070 071 JDU_HL(HiLiteCache cache) { this.cache = cache; } 072 073 public Vector<HTMLNode> hiLite 074 (String code, String codeType, boolean snippetOrComplete) 075 throws IOException 076 { 077 final byte cssPrefix = snippetOrComplete ? (byte) 1 : (byte) 2; 078 final boolean useLineNumbers = ! snippetOrComplete; 079 080 return pygmentize.hiLite(code, codeType, useLineNumbers, cssPrefix, cache); 081 } 082}