com.arsdigita.templating.html
Interface HTMLParser

All Known Implementing Classes:
XHTMLParser

public interface HTMLParser

This interface is intended to provide limited support for templating in the context of CMS and similar applications, where users are expected to submit HTML that may have custom tags that have to be processed programmaticaly.

For example, suppose you allow a content item body to have the <footnote> tag. Suppose the user submits the following HTML fragment,

  <h2>What is Truth?</h2>

  <p>We've bandied about the term truth,<footnote>Strictly speaking,
  this is not true.</footnote> and we've mentioned that certain operators
  return a true or false value. Before we go any further, we really ought to
  explain exactly what we mean by that.  </p>
 

To render this content correctly, we have to transform this fragment to look like so:

  <h2>What is Truth?</h2>

  <p>We've bandied about the term truth<sup><a
  href="#fn1">1</a></sup>, and we've mentioned that certain operators
  return a true or false value. Before we go any further, we really ought to
  explain exactly what we mean by that. </p>

  <hr>
  <p id="fn1"><sup>1</sup>Strictly speaking, this is not true.</p>
 

So that the rendered output looks like so:

What is Truth?

We've bandied about the term truth1, and we've mentioned that certain operators return a true or false value. Before we go any further, we really ought to explain exactly what we mean by that.


1Strictly speaking, this is not true.

This interface is similar to the SAXParser interface. One major difference is that this parser normally treats most of the markup as text whose structure is of no interest to the designated ContentHandler. See parse(String, ContentHandler) for more details.

Since:
2002-08-21
Version:
$Id: //core-platform/dev/src/com/arsdigita/templating/html/HTMLParser.java#4 $
Author:
Vadim Nasardinov (vadimn@redhat.com)

Method Summary
 boolean isRegistered(String qName)
          Checks if the tag is registered with this parser.
 void parse(String html, ContentHandler handler)
          The interface is designed around the following assumptions.
 void registerTag(String qName)
          Registers the tag qName.
 

Method Detail

registerTag

public void registerTag(String qName)
Registers the tag qName.


parse

public void parse(String html,
                  ContentHandler handler)
           throws HTMLParserException

The interface is designed around the following assumptions.

  1. Clients of the interface are only interested in special tags registered via registerTag(String). All other markup is treated as text.
  2. The HTML fragment html is well-formed with regards to the special tags. It does not have to be well-formed with regards to the "normal" markup that has not been registered with the parser via registerTag(String). (Implementations of this interface may, of course, impose this additional restriction. )

Throws:
HTMLParserException

isRegistered

public boolean isRegistered(String qName)
Checks if the tag is registered with this parser.



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC