SimpleServlets v5.5.0

com.simpleservlets.htmlobjects
Class HTMLUtil

java.lang.Object
  extended by com.simpleservlets.htmlobjects.HTMLUtil

public class HTMLUtil
extends Object

Miscellaneous utilities and tools for use with HTMLObjects.

Author:
Paul Hyde

Method Summary
static void addWarning(String msg, HTMLElement con)
          Adds a highlighted warning message to the passed container.
static String processMarkupEntities(String src)
          Processes the string passed in substituting the any of the special markup language characters with their markup entities.
static int send(HTMLPage page, HttpServletResponse res)
          Sends the content on the specified page as text/html.
static int send(HTMLPage page, PageContext pc)
          Sends the content on the specified page as text/html.
static String toStringParsed(Object value)
          Returns a string representation of the passed value which has been processed for entities.
static String toStringUnparsed(Object value)
          Returns a string representation of the passed value which has NOT been processed for entities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

send

public static int send(HTMLPage page,
                       HttpServletResponse res)
                throws IOException
Sends the content on the specified page as text/html. For the response, it specifies the ContentType (as text/html) and the ContentLength (determined from climbing the page tree.

Parameters:
page - the page tree to traverse to produce the content
res - the place to send the content
Returns:
the number of bytes sent.
Throws:
IOException - if there is a problem writing the content.

send

public static int send(HTMLPage page,
                       PageContext pc)
                throws PageProcessorException
Sends the content on the specified page as text/html. For the response, it specifies the ContentType (as text/html) and the ContentLength (determined from climbing the page tree.

Parameters:
page - the page tree to traverse to produce the content
pc - the place to send the content (uses pc.response).
Returns:
the number of bytes sent.
Throws:
PageProcessorException - if there is a problem writing the content.

addWarning

public static void addWarning(String msg,
                              HTMLElement con)
Adds a highlighted warning message to the passed container.

Parameters:
msg - warning message to display
con - container to add the formatted message to

processMarkupEntities

public static String processMarkupEntities(String src)
Processes the string passed in substituting the any of the special markup language characters with their markup entities. Specifically, the following replacements occur:
 <    &lt;
 >    &gt;
 &    &amp;
 "    &quot;
 '    &#39;
 
Note that &apos; is an entity in XML but not an entity in HTML.

If src does not contain any of these special characters, then src itself is returned unmodified (a new String is not constructed). If src is null, then null is returned. Otherwise, a new String is returned with the substitutions made.

Note that passing the returned String back into this method will produce yet another new String with the ampersands substituted. For example:

BeforeAfter
Small < Medium Small &lt; Medium
Small &lt; Medium Small &amp;lt; Medium


toStringParsed

public static String toStringParsed(Object value)
Returns a string representation of the passed value which has been processed for entities. Null is never returned—a zero-len string is returned instead.


toStringUnparsed

public static String toStringUnparsed(Object value)
Returns a string representation of the passed value which has NOT been processed for entities. Null is never returned—a zero-len string is returned instead.


SimpleServlets v5.5.0

Copyright © 2001-2007 Programix Incorporated. All rights reserved. SimpleServlets is free and is OSI Certified Open Source Software under the BSD license.