org.apache.cocoon.generation
Class CSVGenerator

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.generation.AbstractGenerator
              extended byorg.apache.cocoon.generation.ServiceableGenerator
                  extended byorg.apache.cocoon.generation.FileGenerator
                      extended byorg.apache.cocoon.generation.CSVGenerator
All Implemented Interfaces:
org.apache.cocoon.caching.CacheableProcessingComponent, Disposable, org.apache.cocoon.generation.Generator, Poolable, Recyclable, Serviceable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.xml.XMLProducer

public class CSVGenerator
extends FileGenerator

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: CSVGenerator.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.FileGenerator
inputSource, parser
 
Fields inherited from class org.apache.cocoon.generation.ServiceableGenerator
manager
 
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.generation.Generator
ROLE
 
Constructor Summary
CSVGenerator()
          Create a new CSVGenerator instance.
 
Method Summary
 void generate()
          Generate XML data from a Comma Separated Value resource.
 Serializable getKey()
          Generate the unique key.
 void recycle()
          Recycle this component.
 void setup(org.apache.cocoon.environment.SourceResolver resolver, Map object_model, String source, Parameters parameters)
          Setup this CSVGenerator instance.
 
Methods inherited from class org.apache.cocoon.generation.FileGenerator
getValidity, setParser
 
Methods inherited from class org.apache.cocoon.generation.ServiceableGenerator
dispose, service
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
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
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

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

CSVGenerator

public CSVGenerator()

Create a new CSVGenerator instance.

Method Detail

recycle

public void recycle()

Recycle this component.

.

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class FileGenerator

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 CSVGenerator instance.

Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Overrides:
setup in class FileGenerator
Throws:
org.apache.cocoon.ProcessingException
SAXException
IOException

getKey

public Serializable getKey()

Generate the unique key.

Specified by:
getKey in interface org.apache.cocoon.caching.CacheableProcessingComponent
Overrides:
getKey in class FileGenerator
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 FileGenerator
Throws:
IOException
SAXException
org.apache.cocoon.ProcessingException


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