dk.brics.xact.operations
Class XHTMLIndentation

java.lang.Object
  extended by dk.brics.xact.operations.XHTMLIndentation
All Implemented Interfaces:
XMLIndentation

public class XHTMLIndentation
extends Object
implements XMLIndentation

Indents XHTML output for the purpose of making it readible as possible, while attempting not to change its rendering (see note below) using the following rules:

The indentation uses four whitespaces per level and the system property line.separator as the linebreaker.

Please note that CSS can cause other XHTML elements to become whitespace-sensitive, so this is not generally a sound indentation for XHTML (ie. it can change the layout of the page). Therefore, this is mainly intended for debugging.


Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.brics.xact.operations.XMLIndentation
XMLIndentation.IndentType
 
Field Summary
 
Fields inherited from interface dk.brics.xact.operations.XMLIndentation
ALWAYS, NEVER, XHTML
 
Constructor Summary
XHTMLIndentation()
           
 
Method Summary
 String getIndentation()
          Returns the indentation string to prefix every line for each level of indentation.
 XMLIndentation.IndentType getIndentType(Element element)
          Decide whether indentation should be increased when printing the children of the specified element.
 String getLineBreak()
          Returns the string used to represent linebreaks.
 boolean isWhitespaceSensitive(Element element)
          Returns true if the specified element is sensitive to repeated whitespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XHTMLIndentation

public XHTMLIndentation()
Method Detail

getIndentation

public String getIndentation()
Description copied from interface: XMLIndentation
Returns the indentation string to prefix every line for each level of indentation.

Specified by:
getIndentation in interface XMLIndentation
Returns:
indentation string

getIndentType

public XMLIndentation.IndentType getIndentType(Element element)
Description copied from interface: XMLIndentation
Decide whether indentation should be increased when printing the children of the specified element.

In XHTML, elements such as <a> and <u> should not be indented because they are sensitive to leading and trailing whitespace.

Specified by:
getIndentType in interface XMLIndentation
Parameters:
element - an XML element about to be printed
Returns:
true if indentation should be enabled

getLineBreak

public String getLineBreak()
Description copied from interface: XMLIndentation
Returns the string used to represent linebreaks. Typically \r\n, \r or \n.

Specified by:
getLineBreak in interface XMLIndentation
Returns:
a string

isWhitespaceSensitive

public boolean isWhitespaceSensitive(Element element)
Description copied from interface: XMLIndentation
Returns true if the specified element is sensitive to repeated whitespace.

In XHTML, elements such as <pre> and <textarea> are sensitive to repeated whitespace, though any element can be made sensitive through CSS.

Specified by:
isWhitespaceSensitive in interface XMLIndentation
Parameters:
element - an XML element about to be printed
Returns:
true if element is whitespace-sensitive


Copyright © 2005-2011 Aarhus University.