java.lang.Object
org.csveed.bean.BeanInstructionsImpl
- All Implemented Interfaces:
BeanInstructions
The Class BeanInstructionsImpl.
-
Constructor Summary
ConstructorsConstructorDescriptionBeanInstructionsImpl(Class beanClass) Instantiates a new bean instructions impl. -
Method Summary
Modifier and TypeMethodDescriptionReturns the class of the bean on which processing is taking place.Class<? extends AbstractMapper> The mapping strategy to use for processing the bean.Returns the properties of the bean on which processing is taking place.protected StringgetPropertyLogLine(BeanProperty property) Gets the property log line.Returns the instructions for processing rows.The first column that counts as a dynamic column.ignoreProperty(String propertyName) Sets a field to be ignored for purposes of mapping.voidLogs all the settings.mapColumnIndexToProperty(int columnIndex, String propertyName) Maps a column in the CSV to a specific property.mapColumnNameToProperty(String columnName, String propertyName) Maps a column name (which is found in the header) to a specific property.setComment(char symbol) Sets the character that will be interpreted as a comment field on the first position of a row.setConverter(String propertyName, Converter converter) Sets a customPropertyEditorfor the property.Determines what dateformat to apply to the cell value before storing it as a date.setEndOfLine(char[] symbols) Sets the characters (plural) that will be interpreted as end-of-line markers (unless within a quoted field).setEscape(char symbol) Sets the character that will be interpreted as an escape symbol while within a quoted field.setHeaderNameToProperty(String propertyName) Determines what property will receive the header name in the currently active dynamic column.setHeaderValueToProperty(String propertyName) Determines what property will receive the cell value in the currently active dynamic column.setLocalizedNumber(String propertyName, Locale locale) Determines what Locale to apply to the cell value before converting it to a number.setMapper(Class<? extends AbstractMapper> mapper) Determines which mapping strategy is to be employed for mapping cells to bean properties.setQuote(char symbol) Sets the character that will be interpreted as a quote symbol, signifying either the start or the end of a quoted field.setQuotingEnabled(boolean enabled) Sets whether or not quotes are written around the field values.setRequired(String propertyName, boolean required) Determines if the field is required.setSeparator(char symbol) Sets the character that will be interpreted as a separator between cells.setStartIndexDynamicColumns(int startIndex) A file can have a special layout with a dynamic number of columns.setStartRow(int startRow) Sets the start row of the CSV file.setUseHeader(boolean useHeader) Makes sure that the first readable line is interpreted as the header line.skipCommentLines(boolean skip) Determines whether comment lines must be skipped.skipEmptyLines(boolean skip) Determines whether empty lines must be skipped or treated as single-column rows.booleanStates whether a header is used.
-
Constructor Details
-
BeanInstructionsImpl
Instantiates a new bean instructions impl.- Parameters:
beanClass- the bean class
-
-
Method Details
-
logSettings
public void logSettings()Description copied from interface:BeanInstructionsLogs all the settings.- Specified by:
logSettingsin interfaceBeanInstructions
-
getPropertyLogLine
Gets the property log line.- Parameters:
property- the property- Returns:
- the property log line
-
getRowInstructions
Description copied from interface:BeanInstructionsReturns the instructions for processing rows.- Specified by:
getRowInstructionsin interfaceBeanInstructions- Returns:
- the row instructions
-
setUseHeader
Description copied from interface:BeanInstructionsMakes sure that the first readable line is interpreted as the header line. That line will not be read as content. This method is called wheneverCsvFile.useHeader()is used. The default value for this setting is true. This call is a facade forRowInstructions.setUseHeader(boolean).- Specified by:
setUseHeaderin interfaceBeanInstructions- Parameters:
useHeader- true if the header is interpreted and used- Returns:
- convenience for chaining
-
setStartRow
Description copied from interface:BeanInstructionsSets the start row of the CSV file. IfBeanInstructions.setUseHeader(boolean)== true, this will be the header row and the next ones are all content rows. This method is called wheneverCsvFile.startRow()is used. The default value for this setting is 1. This call is a facade forRowInstructions.setStartRow(int).- Specified by:
setStartRowin interfaceBeanInstructions- Parameters:
startRow- the first row to start reading, including the header row- Returns:
- convenience for chaining
-
setEscape
Description copied from interface:BeanInstructionsSets the character that will be interpreted as an escape symbol while within a quoted field. This method is called wheneverCsvFile.escape()is used. The default value for this setting is a double quote (") symbol. This call is a facade forRowInstructions.setEscape(char).- Specified by:
setEscapein interfaceBeanInstructions- Parameters:
symbol- the symbol to use for escaping characters within a quoted field- Returns:
- convenience for chaining
-
setQuote
Description copied from interface:BeanInstructionsSets the character that will be interpreted as a quote symbol, signifying either the start or the end of a quoted field. This method is called wheneverCsvFile.quote()is used. The default value for this setting is a double quote (") symbol. This call is a facade forRowInstructions.setQuote(char).- Specified by:
setQuotein interfaceBeanInstructions- Parameters:
symbol- the symbol to use for indicating start/end of a quoted field- Returns:
- convenience for chaining
-
setQuotingEnabled
Description copied from interface:BeanInstructionsSets whether or not quotes are written around the field values. If enabled, the character set as the escape symbol will be disabled. If disabled, no quotes are written around the field values and the escape symbol is not escaped. This setting has no effect when reading CSV files, only when writing them.- Specified by:
setQuotingEnabledin interfaceBeanInstructions- Parameters:
enabled- whether or not to put quotes around fields- Returns:
- convenience for chaining
-
setSeparator
Description copied from interface:BeanInstructionsSets the character that will be interpreted as a separator between cells. This method is called wheneverCsvFile.separator()is used. The default value for this setting is a semi-colon (;). This call is a facade forRowInstructions.setSeparator(char).- Specified by:
setSeparatorin interfaceBeanInstructions- Parameters:
symbol- the symbol to use as a separator between cells- Returns:
- convenience for chaining
-
setComment
Description copied from interface:BeanInstructionsSets the character that will be interpreted as a comment field on the first position of a row. This method is called wheneverCsvFile.comment()is used. The default value for this setting is a hashtag (#).- Specified by:
setCommentin interfaceBeanInstructions- Parameters:
symbol- the symbol to use as the 0-position comment marker- Returns:
- convenience for chaining
-
setEndOfLine
Description copied from interface:BeanInstructionsSets the characters (plural) that will be interpreted as end-of-line markers (unless within a quoted field). This method is called wheneverCsvFile.endOfLine()is used. The default values for this setting are \r and \n. This call is a facade forRowInstructions.setEndOfLine(char[]).- Specified by:
setEndOfLinein interfaceBeanInstructions- Parameters:
symbols- the symbol to interpret as end-of-line markers (unless within a quoted field)- Returns:
- convenience for chaining
-
skipEmptyLines
Description copied from interface:BeanInstructionsDetermines whether empty lines must be skipped or treated as single-column rows. This method is called wheneverCsvFile.skipEmptyLines()is used. The default value for this setting is to skip the empty lines.- Specified by:
skipEmptyLinesin interfaceBeanInstructions- Parameters:
skip- true to skip empty lines, false to treat as single-column rows- Returns:
- convenience for chaining
-
skipCommentLines
Description copied from interface:BeanInstructionsDetermines whether comment lines must be skipped. This method is called wheneverCsvFile.skipCommentLines()is used. The default value for this setting is to skip comment lines. This method exists to guarantee that lines are not accidentally treated as comment lines.- Specified by:
skipCommentLinesin interfaceBeanInstructions- Parameters:
skip- true to skip comment lines, identified as starting with a comment marker- Returns:
- convenience for chaining
-
setMapper
Description copied from interface:BeanInstructionsDetermines which mapping strategy is to be employed for mapping cells to bean properties. This method is called wheneverCsvFile.mappingStrategy()is used. The default mapping strategy isColumnIndexMapper, which looks at either the position of a property within the class or the custom index ifCsvCell.columnIndex()orBeanInstructions.mapColumnIndexToProperty(int, String)has been set.- Specified by:
setMapperin interfaceBeanInstructions- Parameters:
mapper- the mapping strategy to employ for mapping cells to bean properties- Returns:
- convenience for chaining
-
setDate
Description copied from interface:BeanInstructionsDetermines what dateformat to apply to the cell value before storing it as a date. This method is called wheneverCsvDateis used. The default for date format is dd-MM-yyyy.- Specified by:
setDatein interfaceBeanInstructions- Parameters:
propertyName- the name of the property to write the date todateFormat- the date format to apply for parsing the date value- Returns:
- convenience for chaining
-
setLocalizedNumber
Description copied from interface:BeanInstructionsDetermines what Locale to apply to the cell value before converting it to a number. This method is called wheneverCsvLocalizedNumberis used. The default for Locale is the Locale of the server.- Specified by:
setLocalizedNumberin interfaceBeanInstructions- Parameters:
propertyName- the name of the property to write the data tolocale- the Locale to apply for converting the number- Returns:
- convenience for chaining
-
setRequired
Description copied from interface:BeanInstructionsDetermines if the field is required. If so, the cell may not be empty and aCsvExceptionwill be thrown if this occurs. This method is called wheneverCsvCell.required()is used. The default for a property is false.- Specified by:
setRequiredin interfaceBeanInstructions- Parameters:
propertyName- property for which the requirement appliesrequired- whether the cell must be not-null- Returns:
- convenience for chaining
-
setConverter
Description copied from interface:BeanInstructionsSets a customPropertyEditorfor the property. This PropertyEditor is called to convert the text to the type of the property and set it on the bean. This method is called wheneverCsvConverter.converter()is used. The default for a property is based on the wonderful set of PropertyEditors that Spring offers, which is all basics and some extras as well.- Specified by:
setConverterin interfaceBeanInstructions- Parameters:
propertyName- property to which the converter must be appliedconverter- PropertyEditor to apply to the property- Returns:
- convenience for chaining
-
ignoreProperty
Description copied from interface:BeanInstructionsSets a field to be ignored for purposes of mapping. This method is called wheneverCsvIgnoreis used. By default none of the fields are ignored unless, custom instructions are used. In this case, all fields are ignored by default.- Specified by:
ignorePropertyin interfaceBeanInstructions- Parameters:
propertyName- property which must be ignored for mapping- Returns:
- convenience for chaining
-
mapColumnIndexToProperty
Description copied from interface:BeanInstructionsMaps a column in the CSV to a specific property. This method is called wheneverCsvCell.columnIndex()is used. By default there is NO mapping when custom instructions are used, so you should roll your own. Note that column indexes are 1-based, not 0-based- Specified by:
mapColumnIndexToPropertyin interfaceBeanInstructions- Parameters:
columnIndex- column index for which the property mapping must be appliedpropertyName- property to which the index-based mapping must be applied- Returns:
- convenience for chaining
-
mapColumnNameToProperty
Description copied from interface:BeanInstructionsMaps a column name (which is found in the header) to a specific property. Note that to use this, headers must be enabled. This method is called wheneverCsvCell.columnName()is used. By default there is NO mapping when custom instructions are used, so you should roll your own. Also, don't forget toBeanInstructions.setMapper(Class)toColumnNameMapperfor this to work.- Specified by:
mapColumnNameToPropertyin interfaceBeanInstructions- Parameters:
columnName- column name for which the property mapping must be appliedpropertyName- property to which the name-based mapping must be applied- Returns:
- convenience for chaining
-
setHeaderNameToProperty
Description copied from interface:BeanInstructionsDetermines what property will receive the header name in the currently active dynamic column.- Specified by:
setHeaderNameToPropertyin interfaceBeanInstructions- Parameters:
propertyName- property in which the active dynamic header name must be stored- Returns:
- convenience for chaining
-
setHeaderValueToProperty
Description copied from interface:BeanInstructionsDetermines what property will receive the cell value in the currently active dynamic column.- Specified by:
setHeaderValueToPropertyin interfaceBeanInstructions- Parameters:
propertyName- property in which the active dynamic column value must be stored- Returns:
- convenience for chaining
-
setStartIndexDynamicColumns
Description copied from interface:BeanInstructionsA file can have a special layout with a dynamic number of columns. If the intention is to duplicate rows for every separate column, this is the method you require. It will remember the start position of the dynamic columns and treat every column after that as dynamic. For every dynamic column a row will be created. If a bean has fields annotated with @CsvHeaderName or @CsvHeaderValue, it will store the values of the header or the cell for that index column in the fields.- Specified by:
setStartIndexDynamicColumnsin interfaceBeanInstructions- Parameters:
startIndex- start index of dynamic columns- Returns:
- convenience for chaining
-
getMappingStrategy
Description copied from interface:BeanInstructionsThe mapping strategy to use for processing the bean.- Specified by:
getMappingStrategyin interfaceBeanInstructions- Returns:
- applied mapping strategy
-
getProperties
Description copied from interface:BeanInstructionsReturns the properties of the bean on which processing is taking place.- Specified by:
getPropertiesin interfaceBeanInstructions- Returns:
- the properties of the processed bean
-
getStartIndexDynamicColumns
Description copied from interface:BeanInstructionsThe first column that counts as a dynamic column.- Specified by:
getStartIndexDynamicColumnsin interfaceBeanInstructions- Returns:
- the first of the dynamic columns
-
getBeanClass
Description copied from interface:BeanInstructionsReturns the class of the bean on which processing is taking place.- Specified by:
getBeanClassin interfaceBeanInstructions- Returns:
- class of the processed bean
-
useHeader
public boolean useHeader()Description copied from interface:BeanInstructionsStates whether a header is used.- Specified by:
useHeaderin interfaceBeanInstructions- Returns:
- true if a header is used
-