Class ImpExExportWriter
- java.lang.Object
-
- de.hybris.platform.impex.jalo.exp.ImpExExportWriter
-
- Direct Known Subclasses:
ImpExCSVExportWriter,ImpExXMLExportWriter
public abstract class ImpExExportWriter extends java.lang.ObjectWith 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 descriptorfor defining the output format of the following items. Afterwards you can export items belonging to the specified header.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedImpExExportWriter()Constructs a ImpExExportWriter with the default SessionContext.protectedImpExExportWriter(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 voidclose()Closes the underlying writer.abstract voidcomment(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.ObjectgetAttributeValue(StandardColumnDescriptor cd, Item item)Queries an items Attribute given by the column descriptor.intgetColumnOffset()Returns the current column offset.HeaderDescriptorgetCurrentHeader()Returns the currently active header.abstract java.lang.ObjectgetExportWriter()Returns the general writer which is used for this export.protected LanguagegetLanguage(StandardColumnDescriptor cd)Extracts the Language from the given column descriptor or returns the default one.abstract voidnewLine()Write a newline.voidsetColumnOffset(int offset)Sets the column offset to be used when exporting data.voidsetCurrentHeader(HeaderDescriptor header)Sets the current Header.voidsetCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode)Sets the current Header.voidsetCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry)Sets the current Header which uses given document id registry for id resolving.voidsetCurrentHeader(java.lang.String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry, boolean outputHeader)Sets the current Header which uses given document id registry for id resolving.abstract voidwriteComment(java.lang.String comment)Writes the Stringcommentto the writer as a line comment.abstract voidwriteCurrentHeader(boolean asComment)Writes the the current header either as a comment, ifasCommentis set totrue, or as a normal row ifasCommentis false.abstract voidwriteLine(Item item)Exports the Item into the underlying Writer using current header.abstract voidwriteSrcLine(java.lang.String scrLine)Writes the StringsrcLineto 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 ImpExExceptionSets the current Header. This header defines the used columns when exporting an item withwriteLine(Item).- Parameters:
headerLine- the header line from which theheaderobject will be parsedheaderValidationMode- the following modes are supported:ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_STRICTImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXEDImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLYImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXEDImpExConstants.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 ImpExExceptionSets 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_STRICTImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXEDImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLYImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXEDImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICTdocIDRegistry- 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 ImpExExceptionSets 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_STRICTImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXEDImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLYImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXEDImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICTdocIDRegistry- 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 ImpExExceptionWrites the the current header either as a comment, ifasCommentis set totrue, or as a normal row ifasCommentis 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-nmeans that thenleft-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.IOExceptionWrites the StringsrcLineto 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.IOExceptionWrites the Stringcommentto 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
-
-