org.apache.cocoon.generation
Class CSVGeneratorBean

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.generation.FileGeneratorBean
          extended byorg.apache.cocoon.generation.CSVGeneratorBean
All Implemented Interfaces:
org.apache.cocoon.caching.CacheableProcessingComponent, org.apache.cocoon.sitemap.DisposableSitemapComponent, org.apache.cocoon.generation.Generator, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.xml.XMLProducer

public class CSVGeneratorBean
extends FileGeneratorBean

A simple parser converting a Comma Separated Values (CSV) file into XML.

This parser is controlled by the following sitemap parameters:

The generated output will look something like the following:

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <csv:document xmlns:csv="http://apache.org/cocoon/csv/1.0">
   <csv:header>
     <csv:column number="1">Column A</csv:column>
     <csv:column number="2">Column B</csv:column>
     <csv:column number="3">Column C</csv:column>
   </csv:header>
   <csv:record number="1">
     <csv:field number="1" column="Column A">Field A1</csv:field>
     <csv:field number="2" column="Column B">Field B1</csv:field>
     <csv:field number="3" column="Column C">Field C1</csv:field>
   </csv:record>
   <csv:record number="2">
     <csv:field number="1" column="Column A">Field A2</csv:field>
     <csv:field number="2" column="Column B">Field B2</csv:field>
     <csv:field number="3" column="Column C">Field C2</csv:field>
   </csv:record>
 </csv:document>
 

Note that this generator has been thoroughly tested with CSV files generated by Microsoft Excel. Unfortunately no official CSV specification has ever been published by any standard body, so the interpretation of the format might be slightly different in cases.

Version:
$Id: CSVGeneratorBean.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
static String NAMESPACE_PREFIX
          The namespace prefix of XML generated by this instance.
static String NAMESPACE_URI
          The namespace URI of XML generated by this instance.
 
Fields inherited from class org.apache.cocoon.generation.FileGeneratorBean
consumer, inputSource, parser, resolver
 
Fields inherited from interface org.apache.cocoon.generation.Generator
ROLE
 
Constructor Summary
CSVGeneratorBean()
          Create a new CSVGeneratorBean instance.
 
Method Summary
 void dispose()
           
 void generate()
          Generate XML data from a Comma Separated Value resource.
 Serializable getKey()
          Generate the unique key.
 void setup(org.apache.cocoon.environment.SourceResolver resolver, Map object_model, String source, Parameters parameters)
          Setup this CSVGeneratorBean instance.
 
Methods inherited from class org.apache.cocoon.generation.FileGeneratorBean
getValidity, setConsumer, setParser
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE_URI

public static final String NAMESPACE_URI

The namespace URI of XML generated by this instance.

See Also:
Constant Field Values

NAMESPACE_PREFIX

public static final String NAMESPACE_PREFIX

The namespace prefix of XML generated by this instance.

See Also:
Constant Field Values
Constructor Detail

CSVGeneratorBean

public CSVGeneratorBean()

Create a new CSVGeneratorBean instance.

Method Detail

dispose

public void dispose()
Specified by:
dispose in interface org.apache.cocoon.sitemap.DisposableSitemapComponent
Overrides:
dispose in class FileGeneratorBean
See Also:
ServiceableGenerator.dispose()

setup

public void setup(org.apache.cocoon.environment.SourceResolver resolver,
                  Map object_model,
                  String source,
                  Parameters parameters)
           throws org.apache.cocoon.ProcessingException,
                  SAXException,
                  IOException

Setup this CSVGeneratorBean instance.

Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Overrides:
setup in class FileGeneratorBean
Throws:
org.apache.cocoon.ProcessingException
SAXException
IOException
See Also:
SitemapModelComponent.setup(SourceResolver, Map, String, Parameters)

getKey

public Serializable getKey()

Generate the unique key.

Specified by:
getKey in interface org.apache.cocoon.caching.CacheableProcessingComponent
Overrides:
getKey in class FileGeneratorBean
Returns:
The generated key hashes the src

generate

public void generate()
              throws IOException,
                     SAXException,
                     org.apache.cocoon.ProcessingException

Generate XML data from a Comma Separated Value resource.

.

Specified by:
generate in interface org.apache.cocoon.generation.Generator
Overrides:
generate in class FileGeneratorBean
Throws:
IOException
SAXException
org.apache.cocoon.ProcessingException


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.