Class ImpExExportWriter
java.lang.Object
de.hybris.platform.impex.jalo.exp.ImpExExportWriter
- Direct Known Subclasses:
ImpExCSVExportWriter,ImpExXMLExportWriter
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 an
After instantiating you have to set an
header descriptor for defining the output format of
the following items. Afterwards you can export items belonging to the specified header.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a ImpExExportWriter with the default SessionContext.protectedConstruct a ImpExExportWriter with the given SessionContext. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Closes the underlying writer.abstract voidWrites a comment.getAllAttributeValues(Set<StandardColumnDescriptor> columns, Item item) Queries all items Attribute given by the set of column descriptors.protected ObjectgetAttributeValue(StandardColumnDescriptor cd, Item item) Queries an items Attribute given by the column descriptor.intReturns the current column offset.Returns the currently active header.abstract ObjectReturns the general writer which is used for this export.protected LanguageExtracts 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(String headerLine, EnumerationValue headerValidationMode) Sets the current Header.voidsetCurrentHeader(String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry) Sets the current Header which uses given document id registry for id resolving.voidsetCurrentHeader(String headerLine, EnumerationValue headerValidationMode, DocumentIDRegistry docIDRegistry, boolean outputHeader) Sets the current Header which uses given document id registry for id resolving.abstract voidwriteComment(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 voidExports the Item into the underlying Writer using current header.abstract voidwriteSrcLine(String scrLine) Writes the StringsrcLineto the writer as a normal line.
-
Constructor Details
-
ImpExExportWriter
protected ImpExExportWriter()Constructs a ImpExExportWriter with the default SessionContext. -
ImpExExportWriter
Construct a ImpExExportWriter with the given SessionContext.- Parameters:
ctx- SessionContext
-
-
Method Details
-
newLine
public abstract void newLine()Write a newline. -
comment
Writes a comment.- Parameters:
comment- comment to write
-
close
public abstract void close()Closes the underlying writer. -
setCurrentHeader
public void setCurrentHeader(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 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(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_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(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_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
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
Writes 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:
-
writeLine
Exports the Item into the underlying Writer using current header.- Parameters:
item- Item to export.- Throws:
ImpExException- error while translating item to text
-
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
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 Map<String,Object> getAllAttributeValues(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 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:
-
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
Writes the StringsrcLineto the writer as a normal line.- Parameters:
scrLine- the line to be written to the writer- Throws:
IOException- if an error occurs while writing
-
writeComment
Writes the Stringcommentto the writer as a line comment.- Parameters:
comment- the line to be written to the writer- Throws:
IOException- if an error occurs while writing
-