org.apache.cocoon.forms.util
Class XMLAdapter

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.xml.AbstractXMLConsumer
          extended by org.apache.cocoon.forms.util.XMLAdapter
All Implemented Interfaces:
LogEnabled, XMLConsumer, XMLizable, ContentHandler, LexicalHandler

public class XMLAdapter
extends AbstractXMLConsumer
implements XMLizable

Adapter class that wraps a Form object and makes it possible to populate a widget hierarchy from XML in form of SAX events and serialize the content of the widget hierarchy as XML.

The XML format is such that there is one XML element for each widget and the element get the widgets id as name. Exceptions from this is that the elements in a repeater gets the name item and a attribute position with the position of the repeater child, instead of just a number (which is not allowed as element name). Childs of a MultiValueField are also embeded within a item element. If the Form widget does not have an id it get the name uknown.

An AggregateField can both be interpreted as one value and as several widgets. This ambiguity is resolved by chosing to emit the single value rather than the fields as XML. For population of the form both forms are however allowed.

Version:
$Id: XMLAdapter.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Constructor Summary
XMLAdapter(Widget widget)
          Wrap a Form with an XMLAdapter
 
Method Summary
 void characters(char[] ch, int start, int len)
          Receive notification of character data.
 void endElement(String uri, String loc, String raw)
          Receive notification of the end of an element.
 Locale getLocale()
          Get the locale used for conversion between XML data and Java objects
 void setLocale(Locale locale)
          Set the locale used for conversion between XML data and Java objects
 void startElement(String uri, String loc, String raw, Attributes a)
          Receive notification of the beginning of an element.
 void toSAX(ContentHandler handler)
          Generates SAX events representing the object's state.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLConsumer
comment, endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLAdapter

public XMLAdapter(Widget widget)
Wrap a Form with an XMLAdapter

Method Detail

setLocale

public void setLocale(Locale locale)
Set the locale used for conversion between XML data and Java objects


getLocale

public Locale getLocale()
Get the locale used for conversion between XML data and Java objects


startElement

public void startElement(String uri,
                         String loc,
                         String raw,
                         Attributes a)
                  throws SAXException
Receive notification of the beginning of an element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class AbstractXMLConsumer
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
loc - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
a - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException

endElement

public void endElement(String uri,
                       String loc,
                       String raw)
                throws SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class AbstractXMLConsumer
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
loc - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int len)
                throws SAXException
Receive notification of character data.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class AbstractXMLConsumer
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
Throws:
SAXException

toSAX

public void toSAX(ContentHandler handler)
           throws SAXException
Generates SAX events representing the object's state.

Specified by:
toSAX in interface XMLizable
Throws:
SAXException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.