org.apache.cocoon.transformation
public class: CastorTransformer [javadoc |
source]
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.xml.AbstractXMLProducer
org.apache.cocoon.xml.AbstractXMLPipe
org.apache.cocoon.transformation.AbstractTransformer
org.apache.cocoon.transformation.CastorTransformer
All Implemented Interfaces:
org.apache.avalon.framework.configuration.Configurable, Transformer, XMLPipe, org.apache.avalon.excalibur.pool.Recyclable, XMLProducer
Description: Marshals a object from the Sitemap, Session, Request or
the Conext into a series of SAX events
Configuation: The Castortransformer need to be configured with a
default mapping. This mapping is used as long as no other mapping
is spezfied as the element
<map:transformer name="CastorTransformer" src="org.apache.cocoon.transformation.CastorTransformer">
<mapping>castor/xmapping.xml</mapping>
</map:transformer>
A sample for the use:
<root xmlns:castor="http://castor.exolab.org/cocoontransfomer">
<castor:InsertBean name="invoice"/>
<castor:InsertBean name="product" scope="sitemap" mapping="castor/specicalmapping.xml"/>
</root>
The CastorTransfomer support only one Element
castor:InsertBean. This
element is replaced with the marshalled object. The Object given through the
attrbute
name will be searched in the
sitemap, request,
session and at least in
application
If the scope is explicitly given, e.g , the object will ge located only here
The Attribut
mapping specifys the mapping to be used. If not given
the default mapping is used
Author
Thorsten Mauch
| Field Summary |
|---|
| static final String | CMD_INSERT_BEAN | |
| static final String | ATTRIB_NAME | |
| static final String | ATTRIB_SCOPE | |
| static final String | VALUE_SITEMAP | |
| static final String | VALUE_SESSION | |
| static final String | VALUE_REQUEST | |
| static final String | VALUE_CONTEXT | |
| static final String | MAPPING_CONFIG | |
| Constructor: |
public CastorTransformer() {
/**
* Inner class eventhandler, forward the Castor SAX events
* to Cocoon 2 Events
*/
CastorEventAdapter = new HandlerBase(){
public void startElement(String name, AttributeList attributes) throws SAXException
{
AttributesImpl a= new AttributesImpl();
for(int i=0;i < attributes.getLength(); i++){
a.addAttribute("",attributes.getName(i),attributes.getName(i),
"",attributes.getValue(i));
}
CastorTransformer.super.contentHandler.startElement("",name,name,a);
}
public void characters(char[] chars, int offset, int length) throws SAXException
{
CastorTransformer.super.contentHandler.characters(chars, offset, length);
}
public void endElement(String name) throws SAXException
{
CastorTransformer.super.contentHandler.endElement("", name,name);
}
};
}
|
| Methods from org.apache.cocoon.xml.AbstractXMLPipe: |
|---|
|
characters, comment, endCDATA, endDTD, endDocument, endElement, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDTD, startDocument, startElement, startEntity, startPrefixMapping |
| Method from org.apache.cocoon.transformation.CastorTransformer Detail: |
public void characters(char[] ch,
int start,
int len) throws SAXException {
if(in_castor_element)
return;
super.characters(ch,start, len);
}
|
public void configure(Configuration conf) throws ConfigurationException {
try{
defaultmapping=conf.getChild(MAPPING_CONFIG).getValue();
}
catch(Exception e){
e.printStackTrace();
getLogger().error("can't load default mapping",e);
}
}
|
public void endElement(String uri,
String name,
String raw) throws SAXException {
if(CASTOR_URI.equals(uri)){
in_castor_element= false;
return;
}
super.endElement( uri, name, raw);
}
|
public String getFile(SourceResolver sr,
String FileName) {
try{
String path = sr.resolve(FileName).getSystemId();
if(path.startsWith(FILE_PREFIX)){
path = path.substring(FILE_PREFIX.length());
}
return path;
}
catch(Exception e){
getLogger().error("could not read mapping file",e);
return null;
}
}
|
public void setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters params) throws ProcessingException, IOException, SAXException {
this.objectModel=objectModel;
this.resolver=resolver;
}
|
public void startElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
if(CASTOR_URI.equals(uri)){
in_castor_element= true;
process(name,attr);
return;
}
super.startElement( uri, name, raw, attr);
}
|