public class XMLTemplate extends Object implements ExportTemplate
Modifier and Type | Field and Description |
---|---|
private Writer |
exportStream |
private Element |
itemElement |
private String |
itemIdPrefix |
private Item |
itemType |
private static Pattern |
NEWLINE |
private List<ExportedProperty> |
properties |
private XMLOutputter |
xmlOut |
Constructor and Description |
---|
XMLTemplate(Writer exportStream,
List<ExportedProperty> properties,
Item itemType)
Create a new template.
|
Modifier and Type | Method and Description |
---|---|
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 |
getDefaultFileExtension()
Get the default file extension to give to files generated by this template.
|
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.
|
private final XMLOutputter xmlOut
private final Writer exportStream
private final List<ExportedProperty> properties
private final Item itemType
private final String itemIdPrefix
private Element itemElement
private static final Pattern NEWLINE
public XMLTemplate(Writer exportStream, List<ExportedProperty> properties, Item itemType)
exportStream
- The stream to write toproperties
- All exported propertiesitemType
- The type of items we are exportingpublic String getMimeType()
ExportTemplate
getMimeType
in interface ExportTemplate
public String getDefaultFileExtension()
ExportTemplate
getDefaultFileExtension
in interface ExportTemplate
public void beginDocument() throws IOException
beginDocument
in interface ExportTemplate
IOException
- If there is an errorpublic void writeHeaders() throws IOException
writeHeaders
in interface ExportTemplate
IOException
- If there is an errorpublic void beginItem(int id) throws IOException
beginItem
in interface ExportTemplate
id
- Id of the new item.IOException
- If there is an errorpublic void writeAnnotations(ExportedProperty ep, List<?> values, String unit) throws IOException
writeAnnotations
in interface ExportTemplate
ep
- Exported property the annotations belongs tovalues
- Annotation values to be written.unit
- The unit of the annotation values, or null
to not display write a unitIOException
- If there is an errorpublic void writeProperty(ExportedProperty ep, Object data)
writeProperty
in interface ExportTemplate
ep
- The exported property the data
belongs to.data
- Data to be written.public void writeCollection(ExportedProperty ep, Collection<?> values) throws IOException
writeCollection
in interface ExportTemplate
ep
- Exported property the values belong tovalues
- The values to be writtenIOException
public void endItem() throws IOException
endItem
in interface ExportTemplate
IOException
- If there is an errorpublic void endDocument() throws IOException
endDocument
in interface ExportTemplate
IOException
- If there is an error