2.17.2: 2011-06-17

net.sf.basedb.clients.web.plugins
Class XMLTemplate

java.lang.Object
  extended by net.sf.basedb.clients.web.plugins.XMLTemplate
All Implemented Interfaces:
ExportTemplate

public class XMLTemplate
extends Object
implements ExportTemplate

A XML template that exports data in a simple one-level XML format.

Version:
2.2
Author:
nicklas
Last modified
$Date: 2009-04-21 11:29:09 +0200 (Tue, 21 Apr 2009) $

Field Summary
private  Writer exportStream
           
private  Element itemElement
           
private  String itemIdPrefix
           
private  Item itemType
           
private static Pattern NEWLINE
           
private  List<ExportedProperty> properties
           
private  XMLOutputter xmlOut
           
 
Constructor Summary
XMLTemplate(Writer exportStream, List<ExportedProperty> properties, Item itemType)
          Create a new template.
 
Method Summary
 void beginDocument()
          Write XML start (<?
 void beginItem(int id)
          Begin a new item element.
 void endDocument()
          Close the document tags.
 void endItem()
          Write the current item element to the export stream.
private  String escape(String data)
           
 String getMimeType()
          Get the MIME type to assign to files generated by this template.
 void writeAnnotations(ExportedProperty ep, List<?> values, String unit)
          Add annotation values to the current item element.
 void writeCollection(ExportedProperty ep, Collection<?> values)
          Add collection values to the current item element.
 void writeHeaders()
          Write property and annotation definitions.
 void writeProperty(ExportedProperty ep, Object data)
          Add the property value to the current item element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlOut

private final XMLOutputter xmlOut

exportStream

private final Writer exportStream

properties

private final List<ExportedProperty> properties

itemType

private final Item itemType

itemIdPrefix

private final String itemIdPrefix

itemElement

private Element itemElement

NEWLINE

private static final Pattern NEWLINE
Constructor Detail

XMLTemplate

public XMLTemplate(Writer exportStream,
                   List<ExportedProperty> properties,
                   Item itemType)
Create a new template.

Parameters:
exportStream - The stream to write to
properties - All exported properties
itemType - The type of items we are exporting
Method Detail

getMimeType

public String getMimeType()
Description copied from interface: ExportTemplate
Get the MIME type to assign to files generated by this template.

Specified by:
getMimeType in interface ExportTemplate
Returns:
application/xml

beginDocument

public void beginDocument()
                   throws IOException
Write XML start (<?xml ...>) tag and DOCTYPE.

Specified by:
beginDocument in interface ExportTemplate
Throws:
IOException - If there is an error

writeHeaders

public void writeHeaders()
                  throws IOException
Write property and annotation definitions.

Specified by:
writeHeaders in interface ExportTemplate
Throws:
IOException - If there is an error

beginItem

public void beginItem(int id)
               throws IOException
Begin a new item element.

Specified by:
beginItem in interface ExportTemplate
Parameters:
id - Id of the new item.
Throws:
IOException - If there is an error

writeAnnotations

public void writeAnnotations(ExportedProperty ep,
                             List<?> values,
                             String unit)
                      throws IOException
Add annotation values to the current item element.

Specified by:
writeAnnotations in interface ExportTemplate
Parameters:
ep - Exported property the annotations belongs to
values - Annotation values to be written.
unit - The unit of the annotation values, or null to not display write a unit
Throws:
IOException - If there is an error

writeProperty

public void writeProperty(ExportedProperty ep,
                          Object data)
Add the property value to the current item element.

Specified by:
writeProperty in interface ExportTemplate
Parameters:
ep - The exported property the data belongs to.
data - Data to be written.
Since:
2.12

writeCollection

public void writeCollection(ExportedProperty ep,
                            Collection<?> values)
                     throws IOException
Add collection values to the current item element.

Specified by:
writeCollection in interface ExportTemplate
Parameters:
ep - Exported property the values belong to
values - The values to be written
Throws:
IOException

endItem

public void endItem()
             throws IOException
Write the current item element to the export stream.

Specified by:
endItem in interface ExportTemplate
Throws:
IOException - If there is an error

endDocument

public void endDocument()
                 throws IOException
Close the document tags.

Specified by:
endDocument in interface ExportTemplate
Throws:
IOException - If there is an error

escape

private String escape(String data)

2.17.2: 2011-06-17