public class XMLTemplate extends java.lang.Object implements ExportTemplate
Modifier and Type | Field and Description |
---|---|
private java.io.Writer |
exportStream |
private Element |
itemElement |
private java.lang.String |
itemIdPrefix |
private Item |
itemType |
private static java.util.regex.Pattern |
NEWLINE |
private java.util.List<ExportedProperty> |
properties |
private XMLOutputter |
xmlOut |
Constructor and Description |
---|
XMLTemplate(java.io.Writer exportStream,
java.util.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 java.lang.String |
escape(java.lang.String data) |
java.lang.String |
getDefaultFileExtension()
Get the default file extension to give to files generated by this template.
|
java.lang.String |
getMimeType()
Get the MIME type to assign to files generated by this template.
|
void |
writeAnnotations(ExportedProperty ep,
java.util.List<?> values,
java.lang.String unit)
Add annotation values to the current item element.
|
void |
writeCollection(ExportedProperty ep,
java.util.Collection<?> values)
Add collection values to the current item element.
|
void |
writeHeaders()
Write property and annotation definitions.
|
void |
writeProperty(ExportedProperty ep,
java.lang.Object data)
Add the property value to the current item element.
|
private final XMLOutputter xmlOut
private final java.io.Writer exportStream
private final java.util.List<ExportedProperty> properties
private final Item itemType
private final java.lang.String itemIdPrefix
private Element itemElement
private static final java.util.regex.Pattern NEWLINE
public XMLTemplate(java.io.Writer exportStream, java.util.List<ExportedProperty> properties, Item itemType)
exportStream
- The stream to write toproperties
- All exported propertiesitemType
- The type of items we are exportingpublic java.lang.String getMimeType()
ExportTemplate
getMimeType
in interface ExportTemplate
public java.lang.String getDefaultFileExtension()
ExportTemplate
getDefaultFileExtension
in interface ExportTemplate
public void beginDocument() throws java.io.IOException
beginDocument
in interface ExportTemplate
java.io.IOException
- If there is an errorpublic void writeHeaders() throws java.io.IOException
writeHeaders
in interface ExportTemplate
java.io.IOException
- If there is an errorpublic void beginItem(int id) throws java.io.IOException
beginItem
in interface ExportTemplate
id
- Id of the new item.java.io.IOException
- If there is an errorpublic void writeAnnotations(ExportedProperty ep, java.util.List<?> values, java.lang.String unit) throws java.io.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 unitjava.io.IOException
- If there is an errorpublic void writeProperty(ExportedProperty ep, java.lang.Object data)
writeProperty
in interface ExportTemplate
ep
- The exported property the data
belongs to.data
- Data to be written.public void writeCollection(ExportedProperty ep, java.util.Collection<?> values) throws java.io.IOException
writeCollection
in interface ExportTemplate
ep
- Exported property the values belong tovalues
- The values to be writtenjava.io.IOException
public void endItem() throws java.io.IOException
endItem
in interface ExportTemplate
java.io.IOException
- If there is an errorpublic void endDocument() throws java.io.IOException
endDocument
in interface ExportTemplate
java.io.IOException
- If there is an errorprivate java.lang.String escape(java.lang.String data)