Class ImpExExportWriter
- java.lang.Object
-
- de.hybris.platform.impex.jalo.exp.ImpExExportWriter
-
- Direct Known Subclasses:
ImpExCSVExportWriter
,ImpExXMLExportWriter
public abstract class ImpExExportWriter extends java.lang.Object
With instantiating an implementation of this class you can export items of the platform to an output. The kind of output depends of implementation of this class (normal cases are CSV-files or XML-files).
After instantiating you have to set anheader descriptor
for defining the output format of the following items. Afterwards you can export items belonging to the specified header.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ImpExExportWriter()
Constructs a ImpExExportWriter with the default SessionContext.protected
ImpExExportWriter(SessionContext ctx)
Construct a ImpExExportWriter with the given SessionContext.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
close()
Closes the underlying writer.abstract void
comment(java.lang.String comment)
Writes a comment.protected java.util.Map<java.lang.String,java.lang.Object>
getAllAttributeValues(java.util.Set<StandardColumnDescriptor> columns, Item item)
Queries all items Attribute given by the set of column descriptors.protected java.lang.Object
getAttributeValue(StandardColumnDescriptor cd, Item item)
Queries an items Attribute given by the column descriptor.int
getColumnOffset()
Returns the current column offset.HeaderDescriptor
getCurrentHeader()
Returns the currently active header.abstract java.lang.Object
getExportWriter()
Returns the general writer which is used for this export.protected Language
getLanguage(StandardColumnDescriptor cd)
Extracts the Language from the given column descriptor or returns the default one.abstract void
newLine()
Write a newline.void
setColumnOffset(int offset)
Sets the column offset to be used when exporting data.void
setCurrentHeader(HeaderDescriptor header)
Sets the current Header.void
setCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode)
Sets the current Header.void
setCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry)
Sets the current Header which uses given document id registry for id resolving.void
setCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry, boolean outputHeader)
Sets the current Header which uses given document id registry for id resolving.abstract void
writeComment(java.lang.String comment)
Writes the Stringcomment
to the writer as a line comment.abstract void
writeCurrentHeader(boolean asComment)
Writes the the current header either as a comment, ifasComment
is set totrue
, or as a normal row ifasComment
is false.abstract void
writeLine(Item item)
Exports the Item into the underlying Writer using current header.abstract void
writeSrcLine(java.lang.String scrLine)
Writes the StringsrcLine
to the writer as a normal line.
-
-
-
Constructor Detail
-
ImpExExportWriter
protected ImpExExportWriter()
Constructs a ImpExExportWriter with the default SessionContext.
-
ImpExExportWriter
protected ImpExExportWriter(SessionContext ctx)
Construct a ImpExExportWriter with the given SessionContext.- Parameters:
ctx
- SessionContext
-
-
Method Detail
-
newLine
public abstract void newLine()
Write a newline.
-
comment
public abstract void comment(java.lang.String comment)
Writes a comment.- Parameters:
comment
- comment to write
-
close
public abstract void close()
Closes the underlying writer.
-
setCurrentHeader
public void setCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode) throws ImpExException
Sets the current Header. This header defines the used columns when exporting an item withwriteLine(Item)
.- Parameters:
headerLine
- the header line from which theheader
object will be parsedheaderValidationMode
- the following modes are supported:ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_STRICT
ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXED
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLY
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXED
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICT
- Throws:
ImpExException
- error while parsing the header from given string
-
setCurrentHeader
public void setCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry) throws ImpExException
Sets the current Header which uses given document id registry for id resolving. This header defines the used columns when exporting an item withwriteLine(Item)
.- Parameters:
headerLine
- the header lineheaderValidationMode
- the following modes are supported:ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_STRICT
ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXED
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLY
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXED
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICT
docIDRegistry
- the registry used by the new header for resolving document id's- Throws:
ImpExException
- error while parsing the header from given string
-
setCurrentHeader
public void setCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry, boolean outputHeader) throws ImpExException
Sets the current Header which uses given document id registry for id resolving. This header defines the used columns when exporting an item withwriteLine(Item)
. Outputs the Header into the underlying Writer and add a newline dependend on given output parameter.- Parameters:
headerLine
- the header lineheaderValidationMode
- the following modes are supported:ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_STRICT
ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXED
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLY
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXED
ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICT
docIDRegistry
- the registry used by the new header for resolving document id'soutputHeader
- write the header in specified style into the writer?- Throws:
ImpExException
- error while parsing the header from given string
-
setCurrentHeader
public void setCurrentHeader(HeaderDescriptor header)
Sets the current Header. This header defines the used columns when exporting an item withwriteLine(Item)
.- Parameters:
header
- the header object which defines the columns to export
-
writeCurrentHeader
public abstract void writeCurrentHeader(boolean asComment) throws ImpExException
Writes the the current header either as a comment, ifasComment
is set totrue
, or as a normal row ifasComment
is false. The columns are shifted according to the set column offset.- Throws:
ImpExException
- error while writing- See Also:
setColumnOffset(int)
,getColumnOffset()
-
writeLine
public abstract void writeLine(Item item) throws ImpExException
Exports the Item into the underlying Writer using current header.- Parameters:
item
- Item to export.- Throws:
ImpExException
- error while translating item to text
-
getCurrentHeader
public HeaderDescriptor getCurrentHeader()
Returns the currently active header. All subsequent calls towriteLine(Item)
will export these items as described by this header.- Returns:
- currently set header
-
getLanguage
protected Language getLanguage(StandardColumnDescriptor cd) throws HeaderValidationException
Extracts the Language from the given column descriptor or returns the default one.- Parameters:
cd
- column descriptor from which the language will be used- Returns:
- Language language of column descriptor or default language of session
- Throws:
HeaderValidationException
- if configured language of descriptor or of session is not valid
-
getAllAttributeValues
protected java.util.Map<java.lang.String,java.lang.Object> getAllAttributeValues(java.util.Set<StandardColumnDescriptor> columns, Item item) throws UnresolvedValueException
Queries all items Attribute given by the set of column descriptors.- Parameters:
columns
- set of column descriptors whose value are needed from given itemitem
- item whose attribute values are needed- Returns:
- values of item attribute specified by given set of column descriptors
- Throws:
UnresolvedValueException
- a attribute is not valid
-
getAttributeValue
protected java.lang.Object getAttributeValue(StandardColumnDescriptor cd, Item item) throws UnresolvedValueException
Queries an items Attribute given by the column descriptor.- Parameters:
cd
- column descriptor whose value is needed from given itemitem
- item whose attribute value is needed- Returns:
- value of item attribute specified by given column descriptor
- Throws:
UnresolvedValueException
- attribute is not valid
-
setColumnOffset
public void setColumnOffset(int offset)
Sets the column offset to be used when exporting data. An offset of 0 indicates that all fields (type field included) should be exported. A negative offset of-n
means that then
left-most items are shifted out, whereas a positive offset means that the columns are shifted to the right.- Parameters:
offset
- column offset
-
getColumnOffset
public int getColumnOffset()
Returns the current column offset.- Returns:
- current column offset
- See Also:
setColumnOffset(int)
-
getExportWriter
public abstract java.lang.Object getExportWriter()
Returns the general writer which is used for this export. e.g. a CSvWriter or a XMLWriter. The returnvalue must be casted.- Returns:
- uncasted Object
-
writeSrcLine
public abstract void writeSrcLine(java.lang.String scrLine) throws java.io.IOException
Writes the StringsrcLine
to the writer as a normal line.- Parameters:
scrLine
- the line to be written to the writer- Throws:
java.io.IOException
- if an error occurs while writing
-
writeComment
public abstract void writeComment(java.lang.String comment) throws java.io.IOException
Writes the Stringcomment
to the writer as a line comment.- Parameters:
comment
- the line to be written to the writer- Throws:
java.io.IOException
- if an error occurs while writing
-
-