com.mycompany.jsf.pl
Class XMLViewHandler.TemplateHandler

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bycom.mycompany.jsf.pl.XMLViewHandler.TemplateHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Enclosing class:
XMLViewHandler

private static class XMLViewHandler.TemplateHandler
extends org.xml.sax.helpers.DefaultHandler

This class is a SAX DefaultHandler for processing the template file.


Field Summary
private  javax.faces.context.FacesContext context
           
private  javax.faces.context.ResponseWriter out
           
private  javax.faces.component.UIViewRoot root
           
private  java.util.Stack stack
           
private  java.lang.Object suppressTemplate
           
private  java.lang.StringBuffer textBuff
           
 
Constructor Summary
XMLViewHandler.TemplateHandler(javax.faces.context.FacesContext context, javax.faces.component.UIViewRoot root)
          Creates an instance and pushes the root component onto a stack.
 
Method Summary
 void characters(char[] buf, int offset, int len)
          Buffer the characters until an end or start element is encountered.
 void endElement(java.lang.String namespaceURI, java.lang.String lName, java.lang.String qName)
          Writes buffered text, if any.
private  javax.faces.component.UIComponent findAndConfigure(java.lang.String id, org.xml.sax.Attributes attrs)
          Returns the component matching the ID, configured based on the attributes.
private  void handleTextIfNeeded()
          Creates a String containing the buffered characters and another String representing the element structure the characters belong to and lets the subclass handle it.
 void startElement(java.lang.String namespaceURI, java.lang.String lName, java.lang.String qName, org.xml.sax.Attributes attrs)
          Writes buffered text, if any, and tries to locate a component with the ID defined by the "id" attribute by calling the findComponent() method on the root component.
private  boolean suppressTemplate(javax.faces.component.UIComponent comp)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textBuff

private java.lang.StringBuffer textBuff

context

private javax.faces.context.FacesContext context

out

private javax.faces.context.ResponseWriter out

root

private javax.faces.component.UIViewRoot root

stack

private java.util.Stack stack

suppressTemplate

private java.lang.Object suppressTemplate
Constructor Detail

XMLViewHandler.TemplateHandler

public XMLViewHandler.TemplateHandler(javax.faces.context.FacesContext context,
                                      javax.faces.component.UIViewRoot root)
Creates an instance and pushes the root component onto a stack.

Method Detail

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String lName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Writes buffered text, if any, and tries to locate a component with the ID defined by the "id" attribute by calling the findComponent() method on the root component. This means that the "id" attribute value must contain all naming container parent IDs. If there's a matching component in the view, it's configured based on the template element attributes, and its encodeBegin() method is invoked, and it's pushed onto the stack. Template text suppression is enabled if the suppressTemplate() method returns "true". If no component matches the "id" attribute, the element name is pushed onto the stack and the start tag is written as-is.

Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String lName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Writes buffered text, if any. If the top object on the stack is a component, calls its encodeChildren() (if it's a type that renders its children) and its encodeEnd() methods, and disables suppressing template text if it was enabled by this component. If the top object is an element name and template text isn't suppressed, the end tag is written as-is.

Throws:
org.xml.sax.SAXException

findAndConfigure

private javax.faces.component.UIComponent findAndConfigure(java.lang.String id,
                                                           org.xml.sax.Attributes attrs)
Returns the component matching the ID, configured based on the attributes.


suppressTemplate

private boolean suppressTemplate(javax.faces.component.UIComponent comp)

characters

public void characters(char[] buf,
                       int offset,
                       int len)
                throws org.xml.sax.SAXException
Buffer the characters until an end or start element is encountered.

Throws:
org.xml.sax.SAXException

handleTextIfNeeded

private void handleTextIfNeeded()
Creates a String containing the buffered characters and another String representing the element structure the characters belong to and lets the subclass handle it. Note that this method must be be called in startElement() and endElement() before updating the element list, since the buffered characters belong to the previous element.