public class HtmlRenderer extends TunedDTDParser
Principle: There is a complete parsed DTD (given to the constructor by param "dtd") and there is the source text. The source is parsed a second time and copied to the output, after being wrapped into HTML elements according to the parameters and the cross-reference info in the Dtd object.
ATTENTION this class inherits from "TunedDTDParser", but is used for incomplete functionality, so that many field values are under-defined and can be irritating, esp when in "PARSED-dtd" they have the same name (e.g. "this.entityUsage" is totally undefined, and "parsedDtd.entityUsage" is meant!)
After the object has been created,
#printHtml(Writer,String,ToolOptions,String)
must be called.
The current implementation renders a primitive html document which
(modulo color) CAN LOOK EXACTLY like the dtd source.
Indeed, color, links and tool-tips are added for easy orientation:
All colors are defined by css classes for <span>
, <a>
,
<p>
elements, etc.
Anchors are given to (the start of)
Links are put accordingly,
TOOLTIPS are given
--expandTooltips
for switching
all tooltips between definition text and expanded(=effective) text.
Attlists stand a little bit aside and are reachable by links in a cyclic way:
When the NAME in a definiton (content model or attlist) is given by a parameter entity, than the switch --expandDefNames decides what to show. The cyclic links through elements and attlists are the same as above, but additionally the tooltip is prepended with the other variant, and, iff shown, the character "%" is a link to the definition place.
Preparing all this syntactic information requires expansion, but the goal for
verbatim visual presentation forbids. Therefore the method of choice
is a two(2)-phase approach:
The successfully parsed dtd model and the unparsed text are both
parameters to this process.
The original layout shall be kept verbatim.
The parsing process from TunedDTDParser
is partly overridden,
most analysis is skipped and reduced to mere verbatim character copying.
The required syntax information is taken from the dtd model.
Nearly all generated output is contained in one top-level
"<pre>
" element, which is the most-light-weight way of
making browsers respect whitespace and line-breaks.
Switching visibility goes by java-script. It operates on PAIRS OF SIBLINGS:
<span>
" element carries the "onclick" code
for expanding its successor and collapsing itself.
It is additionally marked by the dedicated class "dtd_meta_switch".
<span>
"
carries the "onclick" code
for expanding the predecessor of its parent and collapsing its parent.
pre | | (<=== ON/OFF PAIR ====>) ( +-----------------------------+------------------------(------- | | ( span span style="display:none;" style="display:block;" class=dtd_meta_switch | ( onclick=switchon() +------------------+-------------(-+---- | | | ( | | span(/div/?) span (span div(/i/?) onclick=switchoff() | ( | class="dtd_attlist_decl" | --> arbitrary nesting (=indicator class!) | #PCDATA "switchOnText"Seen from the standpoint of the following code, there is the additional level of "content" packing:
pre | +-----------------------------+------------------------------- | | pre.Content pre.Content span class=meta_switch span class=PI/Comment/Eldef etc switchOnText | onclick=switchon() +----------------+-------------(-+---- | | ( | span.Content span.Content (span.Content span span (span onclick=switchoff()
TunedDTDParser.ParsingFailed
TunableParser.CharSet, TunableParser.ExtensionalCharSet
currentElementName, entityUsage, errorOnExpand, generalEntities, ignoreErrors, LAZY_ENTITY_ERROR, nicePE, parameterEntities, UNPARSED_CONTENTS
asciiLetterSet, decDigitSet, encNameSet, hexDigitSet, initialSet, nameSet, prefix_GE, prefix_PE, pubidCharSet, sNoPESet, sSet, stringconstant_IGNORE, stringconstant_INCLUDE, versionNumSet
base, in, messageGenerator, topleveldocumentid
Constructor and Description |
---|
HtmlRenderer(DTD.Dtd dtd,
MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
Statistics statistics,
Reader text)
Only constructor, returns a use-once instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_close(String switchOnText,
ToolOptions.visibility visible,
String switch_on_class)
Take the currently top-level (currently growing) list "Ln" of span elements.
|
protected Element_a |
anchorCH(String contents,
String href) |
static String |
anchorEntityName(String name,
boolean parameter)
For anchors in generated html.
|
static String |
anchorName(DTD.Attlist a,
int count) |
static String |
anchorName(DTD.Element e) |
protected void |
append_list_all_references(Set<String> c,
int maxColumn,
Function<String,String> getClass) |
protected void |
append(Element_a a)
Append to top-level list (either in spanLists or the lsit preItems).
|
protected void |
append(Element_span a)
Append to top-level list (either in spanLists or the lsit preItems).
|
protected DTD.Attlist |
attlistDecl()
Parsing AND rendering function, DEEPLY CHANGED COPY of super():
Entities can appear anywhere and cover more than one "column".
|
protected void |
checkCssClass(String cssClass) |
protected void |
checkMassSwitch(ToolOptions.visibility visible,
boolean present,
String text,
String cssClass,
List<Element_span.Content> ons,
List<Element_span.Content> offs) |
protected void |
close_region_and_prepend_switch_external_entity_content(String switchtext,
ToolOptions.visibility visible)
Special values for text and css class, but operation as in
_close(String, ToolOptions.visibility,String) }. |
protected void |
close_region_and_prepend_switch(String switchtext,
ToolOptions.visibility visible)
Special values for text and css class, but operation as in
_close(String, ToolOptions.visibility,String) }. |
static String |
codekey2anchorname(String s) |
protected void |
collectAttlistSource(String name) |
protected DTD.Comment |
comment()
Parsing function.
|
protected void |
conditionalSection(DTD.Dtd dtd)
Parsing function.
|
protected void |
consume()
CALL-BACK function, influencing the parsing functionality of the
super-class to store all character data in the buffer
#consumed() . |
protected boolean |
containsPERefs(String s)
ATTENTION GERefs will also be signalled !?!?!
ATTENTION external PERefs will also be signalled !?!?!
With "conventional" usage both facts should not be confusing.
|
protected void |
content_match(String keyword) |
protected DTD.Element |
elementDecl()
Parsing AND rendering function, EXTENDED COPY of super():
|
static String |
elementGraphFileName(String resultFileName) |
protected DTD.Entity |
entityDecl()
Parsing AND rendering function, EXTENDED COPY of super():
|
static String |
entityGraphFileName(String resultFileName) |
protected String |
expandedText(DTD.Attlist a) |
protected String |
expandedText(DTD.Element e)
ATTENION "mode=1" ??? FIXME WAS SOLL DAS BEDEUTEN ??
append the content model behind each "DTD.Abbrev"
|
protected String |
expandedText(DTD.Entity e)
ATTENTION intended only for INTERNAL PARAMETER entities!
|
protected ToolOptions.visibility |
firstPart(ToolOptions.visibility m) |
protected void |
includeTrailingWs()
Consume whitespace before the "close span region()" is called, so that
the whitespace will be part of collapsing/exploding/skipping.
|
protected void |
initModes(ToolOptions options)
Sets the global boolean flags etc.
|
protected void |
insert_switchOff(String text,
String cssClass,
ToolOptions.visibility currentmode)
Do the same as
reduce_switchOff(String, ToolOptions.visibility) , but not with
accumulated source text, but with synthetic, explicit text
(probably in a Dtd "comment" syntax !-) Is required for insertion of external parameter entities and additional print-outs like graphics and analyses! |
protected void |
insertAlphaindex(ToolOptions options) |
protected void |
insertAnalyses(ToolOptions options) |
protected ToolOptions.visibility |
intern(ToolOptions options,
ToolOptions.visibility optionMode)
Option still does not use enumerations.
|
protected boolean |
isDynamic(ToolOptions.visibility m) |
protected Element_p |
makeFooter(String basicFileName,
String url_htmlRenderer_docu) |
protected void |
makeHeadline_dtd_coords(String alternative,
boolean dynamic,
String cmdline,
String date,
String userText) |
protected void |
makeMassSwitches(boolean withInstructions)
assume only called if "htmlIsDynamic==true"
|
protected void |
makeSvg(File outputfile,
String title,
Multimap<String,String> relation,
String altText,
String switchText,
String mapIdentifier,
ToolOptions.visibility visibility)
DOCME
|
protected void |
open_span_region()
push a new (intially empty) list of span.content, for later reducing it to
a single content element.
|
protected String |
peRef2deftext(String entname)
A pe REF can be dangling! ONLY in this case null is returned.
|
protected DTD.PI |
pi()
Parsing function.
|
void |
prepareTooltips(boolean expand)
Collect tool-tip text for element references.
|
void |
printHtml(Writer output,
String dtdFileName,
String outfilename,
@Opt File outputdir,
ToolOptions options,
String cmdLineText)
Main (currently: the only) entry method after constructor call.
|
protected ToolOptions.visibility |
readMode(boolean present,
boolean isFileInsert,
boolean isAdditional,
String name,
ToolOptions.visibility code,
ToolOptions options)
Processes on/off/onOff/offOn-switches.
|
protected Element_a |
reduce_a(String cssClass,
String ownAnchor,
String foreignAnchor,
String tooltip)
Append an xhtml "anchor" object to the currently growing list.
|
protected void |
reduce_element_reference()
Output either a link to the definition, as calculated by the global
"object to anchor" mechanisms, or a span, iff the reference is
void/dangling!
INCLUDES PARSING, ie. |
protected DTD.Entity |
reduce_entity_reference(boolean parameter)
Output either a link to the definition, as calculated by the global
"object to anchor" mechanisms, or a span, iff the reference is
void/dangling!
INCLUDES PARSING, ie. |
protected Element_span |
reduce_span()
Substitute the "css class for the rest, which has no own class"
|
protected Element_span |
reduce_span(String cssClass)
Append an xhtml "span" object containing ALL characters
accumulated in the buffer
#consumed() , with the given
(non-null, non-empty!) css class. |
protected void |
reduce_switchOff(String cssClass,
ToolOptions.visibility currentmode)
Do the same as
reduce_span(String) , but additionally
set the onclick-action, iff ToolOptions.visibility is dynamic. |
protected void |
s()
Parsing function for non-optional whitespace, at those places where
expansion pf PEs is allowed.
|
protected void |
scanForReferences_attOrEnt(boolean inSingleQuotes,
boolean inDoubleQuotes,
boolean possiblyElementRefs)
Parses the definition string of a entity defintion, or a whole
sequence of attribute definition entries.
|
protected void |
scanForReferences_contentModel()
Parses an element definition's content model and outputs all
sub-segments correctly wrapped to the html element list.
|
protected void |
skip_entityDef() |
protected Element_span |
spanC(String contents) |
protected Element_span |
spanCC(String contents,
String cssClass) |
protected DTD.TextDecl |
textDecl()
Parsing function.
|
protected void |
throwAwayConsumed() |
protected void |
throwAwaySpanRegion() |
attDef, attType, attValue, AUX_convert, children, constructReplacementText, content, cp, declareGeneralEntity, declareParameterEntity, defaultDecl, dtd, encName, encodingDecl, entityValue, enumerated, eq, eRef, externalId, extSubset, fatalError, ignore, markupDecl, mixed, modifierOpt, name, niceEntityValue, nmtoken, notationDecl, parse, parse, parseId, parselocal, peRef, pubidLiteral, resolve, retrieveGeneralEntity, retrieveParameterEntity, retrieveReplacementText, sNoPE, sOpt, sOptNoPE, storeEntityUsage, sWsOpt, systemLiteral, versionInfo, versionNum
lookahead_pe, prefixedEntityName
eof, error, failure, getMessageReceiver, lookahead_eof, lookahead, lookahead, lookahead, lookahead, lookahead, match, match, match, match, matchahead, matchahead, matchahead, matchUpto, matchUpto, readExternal, setBase, setMessageReceiver, skipUpto, warning, word
public static final String path_to_stylesheet
public static final String path_to_javascript
public static final String href_bandm_online_docu
public static final String infotext_bandm_online_docu
public static final String class_noclass
public static final String class_meta_switch
public static final String class_meta_generated
public static final String class_alert
public static final String class_textdecl
public static final String class_comment
public static final String class_copyright_comment
public static final String class_pi
public static final String class_ent_include
public static final String class_ent_ignore
public static final String class_ent_p_def
public static final String class_ent_p_ref
public static final String class_ent_p_ref_UNDEF
public static final String class_ent_p_ext_ref
public static final String class_ent_p_ext_content_frame
public static final String class_ent_p_ext_content
public static final String class_ent_p_ext_nonshow
public static final String class_ent_g_def
public static final String class_ent_g_ref
public static final String class_ent_g_ref_UNDEF
public static final String class_el_def
public static final String class_el_ref
public static final String class_el_ref_UNDEF
public static final String class_att_def
public static final String class_att_def_DANGLING
public static final String class_att_ref
public static final String class_att_ref_UNDEF
protected ToolOptions.visibility mode_pi
protected ToolOptions.visibility mode_comment
protected ToolOptions.visibility mode_insert
protected ToolOptions.visibility mode_element
protected ToolOptions.visibility mode_attlist
protected ToolOptions.visibility mode_pe
protected ToolOptions.visibility mode_ge
protected ToolOptions.visibility mode_elementGraph
protected ToolOptions.visibility mode_entityGraph
protected ToolOptions.visibility mode_analyses
protected ToolOptions.visibility mode_alphaindex
protected boolean expandTooltips
protected boolean expandEntities
protected boolean expandContents
protected boolean expandAttlists
protected boolean expandDefNames
protected String separator_content_attlist
protected boolean eatWs
protected int output_linewidth
protected int content_linewidth
protected int max_tooltip_width
public static final int DISTANCE_TOOLTIP_OVERALL_WIDTH
public static final int DISTANCE_CONTENTS_OVERALL_WIDTH
protected static final Element_span.Content nbsp2
protected boolean htmlIsDynamic
protected boolean outputFormatIsDynamic
protected boolean hasPEs
protected String outputDifferences
protected final Map<DTD.Element,String> el2tooltip
protected final Map<DTD.Entity,String> ent2tooltip
protected final DTD.Dtd parsedDtd
protected final Statistics statistics
protected List<Element_pre.Content> preItems
protected Stack<List<Element_span.Content>> spanLists
protected Element_span last_appended_span
protected StringBuilder consumed
protected final Element_span spanLF
protected final Element_span spanSP
protected int fileInsertionNumber
protected final DTD.PI dummy_PI
protected static final DTD.Comment dummy_comment
protected static final DTD.Element dummy_element
public static Function<String,String> shortname2graphanchor
public static final String ref_list_spacer
public static final Element_span span_ref_list_spacer
public static final int ref_list_right_margin
public HtmlRenderer(DTD.Dtd dtd, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Statistics statistics, Reader text)
printHtml(java.io.Writer, java.lang.String, java.lang.String, java.io.File, eu.bandm.tools.dtm.ToolOptions, java.lang.String)
.dtd
- already successfully parsed dtd with all digested informationmsg
- for all error messagestext
- the same text as in "dtd", but unparsedprotected boolean isDynamic(ToolOptions.visibility m)
protected ToolOptions.visibility firstPart(ToolOptions.visibility m)
public static final String anchorEntityName(String name, boolean parameter)
public static final String anchorName(DTD.Element e)
public static final String anchorName(DTD.Attlist a, int count)
public void prepareTooltips(boolean expand)
protected String peRef2deftext(String entname)
protected boolean containsPERefs(String s)
protected String expandedText(DTD.Element e)
protected String expandedText(DTD.Attlist a)
protected String expandedText(DTD.Entity e)
protected void append(Element_a a)
protected void append(Element_span a)
protected void open_span_region()
protected void throwAwaySpanRegion()
protected void _close(String switchOnText, ToolOptions.visibility visible, String switch_on_class)
protected void close_region_and_prepend_switch(String switchtext, ToolOptions.visibility visible)
_close(String, ToolOptions.visibility,String)
}.protected void close_region_and_prepend_switch_external_entity_content(String switchtext, ToolOptions.visibility visible)
_close(String, ToolOptions.visibility,String)
}.protected void consume()
#consumed()
.consume
in class TunableParser<XMLDocumentIdentifier>
protected void throwAwayConsumed()
protected void checkCssClass(String cssClass)
protected Element_span spanC(String contents)
protected Element_span spanCC(String contents, String cssClass)
protected Element_a reduce_a(String cssClass, String ownAnchor, String foreignAnchor, String tooltip)
protected Element_span reduce_span(String cssClass)
#consumed()
, with the given
(non-null, non-empty!) css class. Flush that buffer.
(No further effects on the list stack!)protected Element_span reduce_span()
protected void reduce_switchOff(String cssClass, ToolOptions.visibility currentmode)
reduce_span(String)
, but additionally
set the onclick-action, iff ToolOptions.visibility is dynamic.protected void insert_switchOff(String text, String cssClass, ToolOptions.visibility currentmode)
reduce_switchOff(String, ToolOptions.visibility)
, but not with
accumulated source text, but with synthetic, explicit text
(probably in a Dtd "comment" syntax !-) protected void reduce_element_reference()
consumed
buffer, and no component of the name
has been parsed/consumed.protected DTD.Entity reduce_entity_reference(boolean parameter)
consumed
buffer,
and the lead-in character has just been recognized, but not consumed.protected void scanForReferences_contentModel()
protected void scanForReferences_attOrEnt(boolean inSingleQuotes, boolean inDoubleQuotes, boolean possiblyElementRefs)
protected void s()
s
in class TunedDTDParser
protected DTD.TextDecl textDecl()
TunedDTDParser
textDecl
in class TunedDTDParser
protected void includeTrailingWs()
protected DTD.PI pi()
TunedDTDParser
pi
in class TunedDTDParser
protected DTD.Comment comment()
TunedDTDParser
comment
in class TunedDTDParser
protected DTD.Element elementDecl()
elementDecl
in class TunedDTDParser
protected void content_match(String keyword)
protected void conditionalSection(DTD.Dtd dtd)
conditionalSection
in class TunedDTDParser
protected DTD.Entity entityDecl()
entityDecl
in class TunedDTDParser
protected void skip_entityDef()
protected void collectAttlistSource(String name)
protected DTD.Attlist attlistDecl()
attlistDecl
in class TunedDTDParser
protected void initModes(ToolOptions options)
protected ToolOptions.visibility intern(ToolOptions options, ToolOptions.visibility optionMode)
protected ToolOptions.visibility readMode(boolean present, boolean isFileInsert, boolean isAdditional, String name, ToolOptions.visibility code, ToolOptions options)
protected void makeHeadline_dtd_coords(String alternative, boolean dynamic, String cmdline, String date, String userText)
protected void makeMassSwitches(boolean withInstructions)
protected void checkMassSwitch(ToolOptions.visibility visible, boolean present, String text, String cssClass, List<Element_span.Content> ons, List<Element_span.Content> offs)
protected void makeSvg(File outputfile, String title, Multimap<String,String> relation, String altText, String switchText, String mapIdentifier, ToolOptions.visibility visibility)
filename
- the relative or absolute path where to put the result file ?? FIXMEprotected void append_list_all_references(Set<String> c, int maxColumn, Function<String,String> getClass)
protected void insertAlphaindex(ToolOptions options)
protected void insertAnalyses(ToolOptions options)
public void printHtml(Writer output, String dtdFileName, String outfilename, @Opt @Opt File outputdir, ToolOptions options, String cmdLineText)
output
- the Writer
to create the html file.dtdFileName
- DOCMEoutfilename
- local name of the written html text, used only to derive the names
of the svg files, if any (and for one single warning, if it ends not with "html")outputdir
- directory of the written html text, there the svg files will be placed.
When null, svg generation is suppressed.options
- needed for all the fine-tuning switches. Can come from a command line,
or can be constructed explicitly when html rendering is initiated programmatically.
(Therefore the options already decoded into the other method parameters are ignored.)cmdLineText
- DOCMEdtdTitle
- ??????? FIXME used as the html title (to appear in browser head lines, etc)see also the complete user documentation .