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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package Torello.Languages;

import java.util.*;
import java.io.*;

/**
 * HTMLWordTables for Mandarin Chinese Translations.
 * 
 * <BR /><BR /><EMBED CLASS="external-html" DATA-FILE-ID="HTMLWT">
 */
@Torello.HTML.Tools.JavaDoc.StaticFunctional
public class HTMLWordTables
{
    private HTMLWordTables() { }

    /**
     * Builds a simple, short HTML version of the Chinese-Simplified / English / Spanish sentence
     * DIV
     * 
     * @param 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.
     * 
     * @param 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
     * <I><B>one less / fewer row</B></I> included.
     * 
     * @param 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
     * <I><B>one less / fewer row</B></I> included.
     * 
     * @param tableClass If this table needs a CSS-Class selector, pass it here.
     * 
     * @param tableID If this table requires a CSS-ID selector, pass it here.
     * 
     * @param onClickListener This is a string of the form "callbackFuntion(params);" It is
     * inserted
     *		into the &lt;TABLE on_click="INSERTED-STRING-HERE"&gt; tag
     * 
     * @return An Table-HTML string.  Note: The Vocabulary tables *ARE NOT* included.
     * 		This only includes the English, Spanish &amp; Chinese sentences.
     * 
     * @throws NullPointerException If simpSentence is null.
     */
    public static String toHTML(
            String simpSentence, String englSentence, String espaSentence,
            String tableClass, String tableID, String onClickListener
        )
    {
        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";
    }

    /**
     * The purpose of this method is to generate the "Pop Up" vocabulary table as HTML
     * 
     * @param tableClass This contains the HTML-tag "class" String.  It is included in the
     *		HTML &lt;TABLE CLASS="INSERT-TEXT-HERE&gt; String
     * 
     * @param tableID This contains the HTML-tag "id" String.  It is included in the
     *		HTML &lt;TABLE ID="INSERT-TEXT-HERE"&gt; String
     * 
     * @param setNoDisplay When this variable is <B>TRUE</B>, a CSS tag is added to the opening
     * &lt;TABLE&gt; tag, indicating: <BR /><CODE>STYLE="display: none;"</CODE> - which ensures
     * that this vocabulary table remains hidden.
     * 
     * @param simpWords A Vector of simplified chinese character-words.  This parameter may not be
     * null.
     * 
     * @param pronWords A Parallel Vector of the pronunciation of this input Simplified Mandarin
     * words.  Can be left out / null.
     * 
     * @param tradWords Parallel Vector.  Traditional-Chinese Characters.  May be null.
     * 
     * @param englWords Parallel Vector.  English Words.  Can be null.
     * 
     * @param espaWords Parallel Vector.  Chinese in Spanish.  Also may be null.	  
     * 
     * @return returns the Vocabulary Table as an HTML String of
     * &lt;TABLE&gt;Vocab-Rows&lt;/TABLE&gt;
     * 
     * @throws NullPointerException If simpWords is null.
     */
    public static String getHTMLVocabTable(
            String tableClass, String tableID, boolean setNoDisplay,
            Vector<String>	simpWords,
            Vector<String>	pronWords,
            Vector<String>	tradWords,
            Vector<String>	englWords,
            Vector<String>	espaWords
        )
    {
        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();
    }
}