jsutil
Class HtmlDispToActual

java.lang.Object
  |
  +--xbn.XBNObject
        |
        +--xbn.programs.XBNStatic
              |
              +--jsutil.HtmlDispToActual

public class HtmlDispToActual
extends XBNStatic

Takes the HTML (and presumably JavaScript) displayed within another HTML page, and translates it to its own HTML file.

Source code:  HtmlDispToActual.java

Start and end line delimiters denote the beginning and end of the HTML to be translated. The rest of the file is discarded.

Example

Assume that the base for all files in this example is C:\test_hdta\, and that a 'tryit' directory exists therein.

Given this html file: the_basics.html

And this code: TestHDTA.java

At a command prompt, navigate to C:\test_hdta\, and execute this
   java TestHDTA > hdta.log

Here is the output and log.


Fields inherited from class xbn.XBNObject
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP
 
Constructor Summary
HtmlDispToActual(String[] as_htmlLiterals, String[] as_replaceWith, String s_importRDirDisp, String s_importRDirNew)
          Create an HtmlDispToActual.
HtmlDispToActual(String s_importRDirDisp, String s_importRDirNew)
          Create an HtmlDispToActual with default character literal replacements.
 
Method Summary
 String getHtmlLiteral(int i_ndex, boolean b_ampSemiC)
          Get a literal character string, surrounded by '&' and ';'.
 int getHtmlLiteralCount()
          How many literal characters are there?.
 String getImportRDirDisp()
          Get the displayed JavaScript import directory part.
 String getImportRDirNew()
          Get the displayed JavaScript import directory part.
 String getLDEnd()
          Get the need-to-translate start-line delimiter.
 String getLDStart()
          Get the need-to-translate start-line delimiter.
 String getReplacement(int i_ndex)
          Get a replacement string.
 int getReplacementCount()
          How many literal characters are there?.
 void setDelimiterLines(String s_start, String s_end)
          Set the lines that denote the start and end of the example code.
 String toString()
          Get some information about this HtmlDispToActual.
 void translate(ForLineRetrieval flr_html, StringOrBuffer sob_output)
          Translate every line in the html that is between the delimiters.
 TranslateStats translate(ForLineRetrieval flr_html, StringOrBuffer sob_output, Outputter optr_dbg)
          Translate every line in the html that is between the delimiters.
 TranslateStats translate(StringOrBuffer sob_html)
          Translate some displayed HTML to actual HTML.
 
Methods inherited from class xbn.programs.XBNStatic
throwAXS
 
Methods inherited from class xbn.XBNObject
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HtmlDispToActual

public HtmlDispToActual(String s_importRDirDisp,
                        String s_importRDirNew)

Create an HtmlDispToActual with default character literal replacements.

Equal to
HtmlDispToActual(
   new String[]  {"nbsp", "lt", "gt", "quot", "amp"},
   new String[]  {" ", "<", ">", "\"", "&"},
   s_importRDirDisp, s_importRDirNew)


HtmlDispToActual

public HtmlDispToActual(String[] as_htmlLiterals,
                        String[] as_replaceWith,
                        String s_importRDirDisp,
                        String s_importRDirNew)

Create an HtmlDispToActual.

The last line in this constructor calls
   setDelimiterLines("<" + "!-- HTML TO TRANSLATE START --" + ">", "<" + "!-- HTML TO TRANSLATE END --" + ">")

Parameters:
as_htmlLiterals - The list of HTML character literals, minus the ampersand ('&') and semi-colon (';'), which need to be translated to actual HTML characters. The order of this array is the order in which replacemnts occur (so amp should pretty much always be the last item). Must be non-null, at least one item in length, and each item must be non-null, at least one character in length, unique, and may not contain anything but letters and digits. Altering this array after providing it here will cause unpredictable behavior. For example:
   new String[]  {"nbsp", "lt", "gt", "quot", "amp"}
as_replaceWith - The list of items to replace those in as_htmlLiterals. Must be non-null, have the same length as as_htmlLiterals length, and each item must be non-null, and at least one character in length, unique, and not fully contain any other. Element at index X in as_htmlLiterals is replaced with that same index in this ("&" + as_htmlLiterals[3] + ";" is translated to as_replaceWith[3]). Altering this array after providing it here will cause unpredictable behavior. For example:
   new String[]  {" ", "<", ">", "\"", "&"}
s_importRDirDisp - The displayed JavaScript import, that needs to be replaced. Use this when outputting to a directory other than the one in which it is displayed. When null, output is written to the same directory (s_importRDirNew must also be null). When non-null, may not be null or zero characters in length, and must end with a url slash ('/'). When non-null, s_importRDirNew may not be null. Notes:
  • This does not have to be the entire import-directory, just the part that needs to change.
  • All instances of this string are replaced, even when it's not actually part of the JavaScript import directory.
  • When outputting to a super-directory (of the one in which it is displayed), then display the import directory as './', as empty-string cannot be replaced.
s_importRDirNew - What s_importRDirDisp should be replaced with. When s_importRDirDisp is non-null, this may not be null.
Method Detail

getHtmlLiteralCount

public final int getHtmlLiteralCount()

How many literal characters are there?.

Returns:
as_htmlLiterals.length where as_htmlLiterals is exactly as provided in the constructor.

getHtmlLiteral

public final String getHtmlLiteral(int i_ndex,
                                   boolean b_ampSemiC)

Get a literal character string, surrounded by '&' and ';'.

Parameters:
b_ampSemiC - Should the returned value be surrounded by '&' and ';'? If true, yes. If false, no.
Returns:
(b_ampSemiC)
   ?  "&" + as_htmlLiterals[i_ndex] + ";"
   :  as_htmlLiterals[i_ndex]

as_htmlLiterals is exactly as provided in the constructor.

getReplacementCount

public final int getReplacementCount()

How many literal characters are there?.

Returns:
as_replaceWith.length where as_replaceWith is exactly as provided in the constructor.

getReplacement

public final String getReplacement(int i_ndex)

Get a replacement string.

Returns:
"&" + as_htmlLiterals[i_ndex] + ";" where as_replaceWith is exactly as provided in the constructor.

getImportRDirDisp

public final String getImportRDirDisp()

Get the displayed JavaScript import directory part.

Returns:
s_importRDirDisp Exactly as provided in the constructor.

getImportRDirNew

public final String getImportRDirNew()

Get the displayed JavaScript import directory part.

Returns:
s_importRDirNew Exactly as provided in the constructor.

getLDStart

public final String getLDStart()

Get the need-to-translate start-line delimiter.

Set with setDelimiterLines.

Returns:
s_start Exactly as provided to setDelimiterLines.

getLDEnd

public final String getLDEnd()

Get the need-to-translate start-line delimiter.

Set with setDelimiterLines.

Returns:
s_end Exactly as provided to setDelimiterLines.

setDelimiterLines

public final void setDelimiterLines(String s_start,
                                    String s_end)

Set the lines that denote the start and end of the example code.

If you have multiple html code to translate, then each of those examples must have different line delimiters (and that html file must be fed into this class twice).

Parameters:
s_start - The line containing this delemiter, ignoring surrounding text, precedes the first line to be translated. In the html, this must exist exactly once, and must precede s_end. May not be null, must be surrounded with '<!--' and '-->', and must be different than s_end. Between '<!--' and '-->', may only exist letters, digits, underscores and spaces. See getLDStart.
s_end - The line containing this delemiter, ignoring surrounding text, follows the last line to be translated. In the html, this must exist exactly once, and must precede s_start. May not be null, must be surrounded with '<!--' and '-->', and must be different than s_start. Between '<!--' and '-->', may only exist letters, digits, underscores and spaces. See getLDEnd.

translate

public final void translate(ForLineRetrieval flr_html,
                            StringOrBuffer sob_output)

Translate every line in the html that is between the delimiters.

Equal to translate(flr_html, sob_output, (new Outputter))


translate

public final TranslateStats translate(ForLineRetrieval flr_html,
                                      StringOrBuffer sob_output,
                                      Outputter optr_dbg)

Translate every line in the html that is between the delimiters. Other lines, including the delimiters, are ignored.

See getLDStart and getLDEnd.

For every line after the start and before the end delimiter lines is translated.

Parameters:
flr_html - Represents the HTML source. May not be null.
sob_output - The StringOrBuffer to accumulate translated output. May not be null.
optr_dbg - The Outputter to use for debugging output. May not be null.

translate

public final TranslateStats translate(StringOrBuffer sob_html)

Translate some displayed HTML to actual HTML.

This function translates everything. It does not look for any line-delimiters. Use the flr-version of this function to change only those lines started and ended by these delimiters.

Specifically, this function does the following:


toString

public final String toString()

Get some information about this HtmlDispToActual.

Overrides:
toString in class Object



Copyright 2003-2005, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.

 

http://sourceforge.net/projects/jsutiljava

 

SourceForge.net Logo