Class HTMLWordTables


  • public class HTMLWordTables
    extends java.lang.Object
    HTMLWordTables - Documentation.

    This class generates the HTML CSS z-index-based tables that are used by java-script. Java-script utilizes the z-index axis to generate popup windows which contain Mandarin Chinese, English, and even Spanish Translations. Specifically, the tables generally contain:

    • 繁体字 (Traditional-Chinese, Hong Kong, Taiwan, Southern China - Optional)
    • 简体中文 (Standard-Chinese Simplified Characters
    • 拼音罗马 (Romanization)
    • English
    • Español


    Static (Functional) API: The methods in this class are all (100%) defined with the Java Key-Word / Key-Concept 'static'. Furthermore, there is no way to obtain an instance of this class, because there are no public (nor private) constructors. Java's Spring-Boot, MVC feature is *not* utilized because it flies directly in the face of the light-weight data-classes philosophy. This has many advantages over the rather ornate Component Annotations (@Component, @Service, @AutoWired, etc... 'Java Beans') syntax:

    • The methods here use the key-word 'static' which means (by implication) that there is no internal-state. Without any 'internal state' there is no need for constructors in the first place! (This is often the complaint by MVC Programmers).
    • A 'Static' (Functional-Programming) API expects to use fewer data-classes, and light-weight data-classes, making it easier to understand and to program.
    • The Vectorized HTML data-model allows more user-control over HTML parse, search, update & scrape. Also, memory management, memory leakage, and the Java Garbage Collector ought to be intelligible through the 'reuse' of the standard JDK class Vector for storing HTML Web-Page data.

    The power that object-oriented programming extends to a user is (mostly) limited to data-representation. Thinking of "Services" as "Objects" (Spring-MVC, 'Java Beans') is somewhat 'over-applying' the Object Oriented Programming Model. Like most classes in the Java-HTML JAR Library, this class backtracks to a more C-Styled Functional Programming Model (no Objects) - by re-using (quite profusely) the key-word static with all of its methods, and by sticking to Java's well-understood class Vector

    Internal-State: A user may click on this class' source code (see link below) to view any and all internally defined fields class. A cursory inspection of the code would prove that this class has precisely zero internally defined global fields (Spaghetti). All variables used by the methods in this class are local fields only, and therefore this class ought to be though of as 'state-less'.



    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method
      static String getHTMLVocabTable​(String tableClass, String tableID, boolean setNoDisplay, Vector<String> simpWords, Vector<String> pronWords, Vector<String> tradWords, Vector<String> englWords, Vector<String> espaWords)
      static String toHTML​(String simpSentence, String englSentence, String espaSentence, String tableClass, String tableID, String onClickListener)
      • Methods inherited from class java.lang.Object

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

      • toHTML

        public static java.lang.String toHTML​(java.lang.String simpSentence,
                                              java.lang.String englSentence,
                                              java.lang.String espaSentence,
                                              java.lang.String tableClass,
                                              java.lang.String tableID,
                                              java.lang.String onClickListener)
        Builds a simple, short HTML version of the Chinese-Simplified / English / Spanish sentence DIV
        Parameters:
        simpSentence - This may be a single word, a complete phrase, sentence, or even a paragraph of simplified Mandarin Chinese scraped from a web-site like Gov.CN. If this parameter is null, an exception will be thrown.
        englSentence - This is intended to be the English-Translated version of the Simplified-Chinese sentence. If this parameter is null, the output HTML-table will have one less / fewer row included.
        espaSentence - This is supposed to be the Spanish-translated version of the Simplified-Chinese sentence. If this parameter is null, the output HTML-table will have one less / fewer row included.
        tableClass - If this table needs a CSS-Class selector, pass it here.
        tableID - If this table requires a CSS-ID selector, pass it here.
        onClickListener - This is a string of the form "callbackFuntion(params);" It is inserted into the <TABLE on_click="INSERTED-STRING-HERE"> tag
        Returns:
        An Table-HTML string. Note: The Vocabulary tables *ARE NOT* included. This only includes the English, Spanish & Chinese sentences.
        Throws:
        java.lang.NullPointerException - If simpSentence is null.
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
         if (simpSentence == null) throw new NullPointerException
             ("simpSentence MAY NOT be NULL, engl and espa can be.");
        
         String tableIncludeStr = "";
        
         tableIncludeStr += (tableClass != null)
             ? (" CLASS=\"" + tableClass + "\"")
             : "";
        
         tableIncludeStr += (tableID != null)
             ? (" ID=\"" + tableID + "\"")
             : "";
        
         tableIncludeStr += (onClickListener != null)
             ? (" onclick=\"" + onClickListener + "\"")
             : "";
        
         return	"<TABLE " + tableIncludeStr + "><TBODY>\n" +
                 ((simpSentence != null)
                     ? ("<TR CLASS=\"ZHROW\" ><TD>" + simpSentence + "</TD></TR>\n") 
                     : "") +
                 ((englSentence != null) 
                     ? ("<TR CLASS=\"ENROW\" ><TD>" + englSentence + "</TD></TR>\n") 
                     : "") +
                 ((espaSentence != null) 
                     ? ("<TR CLASS=\"ESROW\" ><TD>" + espaSentence + "</TD></TR>\n") 
                     : "") +
                 "</TBODY></TABLE>\n";
        
      • getHTMLVocabTable

        public static java.lang.String getHTMLVocabTable​
                    (java.lang.String tableClass,
                     java.lang.String tableID,
                     boolean setNoDisplay,
                     java.util.Vector<java.lang.String> simpWords,
                     java.util.Vector<java.lang.String> pronWords,
                     java.util.Vector<java.lang.String> tradWords,
                     java.util.Vector<java.lang.String> englWords,
                     java.util.Vector<java.lang.String> espaWords)
        
        The purpose of this method is to generate the "Pop Up" vocabulary table as HTML
        Parameters:
        tableClass - This contains the HTML-tag "class" String. It is included in the HTML <TABLE CLASS="INSERT-TEXT-HERE> String
        tableID - This contains the HTML-tag "id" String. It is included in the HTML <TABLE ID="INSERT-TEXT-HERE"> String
        setNoDisplay - When this variable is TRUE, a CSS tag is added to the opening <TABLE> tag, indicating:
        STYLE="display: none;" - which ensures that this vocabulary table remains hidden.
        simpWords - A Vector of simplified chinese character-words. This parameter may not be null.
        pronWords - A Parallel Vector of the pronunciation of this input Simplified Mandarin words. Can be left out / null.
        tradWords - Parallel Vector. Traditional-Chinese Characters. May be null.
        englWords - Parallel Vector. English Words. Can be null.
        espaWords - Parallel Vector. Chinese in Spanish. Also may be null.
        Returns:
        returns the Vocabulary Table as an HTML String of <TABLE>Vocab-Rows</TABLE>
        Throws:
        java.lang.NullPointerException - If simpWords is null.
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
         if (simpWords== null) throw new NullPointerException
             ("simpWords MAY NOT be NULL, engl and espa can be.");
        
         StringBuilder sb = new StringBuilder();
        
         // Build the <TABLE> tag.  It may require a CSS "CLASS=...", possibly a "ID=...", 
         // or a CSS-styled "display: none;"
        
         sb.append("<TABLE");
         if (tableClass	!= null)    sb.append(" CLASS=\""	+ tableClass	+ "\"");
         if (tableID		!= null)    sb.append(" ID=\""		+ tableID		+ "\"");
         if (setNoDisplay)           sb.append(" STYLE=\"display: none;\"");
         sb.append(">\n<TBODY>\n");
        
         int len = simpWords.size();
        
         for (int i = 0; i < len; i++)
         {
             sb.append(
                 "<TR>\n" +
                 ((simpWords != null) ? ("<TD>" + simpWords.elementAt(i) + "</TD>\n") : "")	+
                 ((pronWords != null) ? ("<TD>" + pronWords.elementAt(i) + "</TD>\n") : "")	+
                 ((tradWords != null) ? ("<TD>" + tradWords.elementAt(i) + "</TD>\n") : "")	+
                 ((englWords != null) ? ("<TD>" + englWords.elementAt(i) + "</TD>\n") : "")	+
                 ((espaWords != null) ? ("<TD>" + espaWords.elementAt(i) + "</TD>\n") : "")	+
                 "</TR>\n"	);
         }
        
         sb.append("</TBODY>\n</TABLE>\n");
         return sb.toString();