public class ImpExReader
extends java.lang.Object
Media, File, InputStream, CSVReader or from a database) is
possible via bean shell commands (java statements starting with #%). Attention! This reader only parses value lines.
For interpreting them you need to use an extension like ImpExImportReader.
For example:
ImpExReader reader = new ImpExReader( new CSVReader( "import.impex" ) );
Example file: "import.impex"
"#% impex.setRelaxedMode(false);"
"INSERT_UPDATE Language";"isocode[unique=true]";"name[lang=en]"
"#% impex.includeExternalData( new CSVReader(""Language.csv"",""windows-1252""));"
Example file: "Language.csv"
;"de";"German"
reader.enableCodeExecution( true );
reader.enableExternalImpExSyntaxParsing( true );
readLine() for parsing and getting the headers and value lines.
Object nextOutput = null;
do
{
nextOutput = reader.readLine();
if( nextOutput instanceof HeaderDescriptor )
{
//do something with header
}
if( nextOutput instanceof ValueLine )
{
//do something with line
}
}
while(nextOutput != null);
reader.close();
| Modifier and Type | Class and Description |
|---|---|
static class |
ImpExReader.ResultSetCSVReader
A
CSVReader extension for reading a SQL ResultSet as CSV. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.Integer |
FIRST
The position of current header mode and type within the current line
Map. |
| Constructor and Description |
|---|
ImpExReader(CSVReader reader,
boolean skipValueLines)
Instantiates a new reader using the given
CSVReader as input. |
ImpExReader(CSVReader reader,
boolean skipValueLines,
EnumerationValue headerValidationMode)
Instantiates a new reader using the given
CSVReader as input. |
ImpExReader(CSVReader reader,
boolean skipValueLines,
EnumerationValue headerValidationMode,
DocumentIDRegistry docIdRegistry)
Instantiates a new reader using the given
CSVReader as input. |
ImpExReader(CSVReader reader,
boolean skipValueLines,
EnumerationValue headerValidationMode,
DocumentIDRegistry docIdRegistry,
InvalidHeaderPolicy headerHandlingPolicy) |
ImpExReader(java.io.InputStream input,
java.lang.String encoding)
Instantiates a new reader using the given stream and encoding as input.
|
ImpExReader(java.io.InputStream input,
java.lang.String encoding,
boolean skipValueLines)
Instantiates a new reader using the given stream and encoding as input.
|
ImpExReader(java.lang.String fileName,
java.lang.String encoding,
boolean skipValueLines)
Instantiates a new reader using the file with given name and encoding as input.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addDefinition(java.lang.String cell)
Adds a definition to the reader context and is therefore available for parsing of headers.
|
void |
addExternalDataMedia(ImpExMedia ext)
Adds an external media to the reader context which is then accessible via
includeExternalDataMedia. |
void |
addExternalDataMedias(java.util.Collection<ImpExMedia> toAdd)
Adds an collection of external medias to the reader context which are then accessible via
includeExternalDataMedia each. |
protected void |
addHeaderExceptionInfoAsComment(java.util.Map<java.lang.Integer,java.lang.String> adjustedLine,
HeaderValidationException ex) |
void |
addHeaderReplacementRule(java.lang.String srcPattern,
java.lang.String tgtPattern,
int prio) |
protected void |
addToBeanShellContext(java.lang.String key,
java.lang.Object value)
Adds a variable referencing to the given object to the bean shell context.
|
protected java.util.Map<java.lang.Integer,java.lang.String> |
adjustLineIndexes(java.util.Map<java.lang.Integer,java.lang.String> line)
Adjusts the line indexes using the column offset set at reader manager.
|
protected java.util.List<java.lang.String> |
applyHeaderReplacements(java.util.List<java.lang.String> columns) |
protected void |
assureBeanShellLoaded()
Assures that the bean shell instance is loaded.
|
protected void |
checkDefinitonKey(java.lang.String newKey,
java.util.Map currentDefinitions)
Checks if a key of a definition is a prefix of an already present key.
|
void |
close()
Closes all used readers.
|
protected AbstractCodeLine |
createCodeLine(java.util.Map<java.lang.Integer,java.lang.String> line)
Interprets the given line as code line.
|
protected AbstractCodeLine |
createCodeLineLegacyWay(java.util.Map<java.lang.Integer,java.lang.String> line) |
protected AbstractCodeLine |
createCodeLineModernWay(java.util.Map<java.lang.Integer,java.lang.String> line) |
HeaderDescriptor |
createInvalidHeader(java.util.Map<java.lang.Integer,java.lang.String> line,
HeaderValidationException ex) |
protected HeaderDescriptor |
createNewHeader(java.util.Map<java.lang.Integer,java.lang.String> line)
Creates from a header line a header object.
|
protected ValueLine |
createValueLine(HeaderDescriptor header,
java.util.Map<java.lang.Integer,java.lang.String> line)
Creates from a line which represents a data row a value line.
|
void |
debug(java.lang.String msg)
Debugs a message with the current logger instance.
|
void |
debug(java.lang.String msg,
java.lang.Throwable throwable)
Debugs a message with the current logger instance.
|
void |
enableCodeExecution(boolean isOn)
Sets the code execution flag.
|
void |
enableExternalCodeExecution(boolean isOn)
Sets the external code execution flag.
|
void |
enableExternalDataCodeExecution(boolean isOn)
Deprecated.
since ages - use
enableExternalCodeExecution(boolean) instead |
void |
enableExternalImpExSyntaxParsing(boolean isOn)
Deprecated.
since ages - use
enableExternalSyntaxParsing(boolean) instead |
void |
enableExternalSyntaxParsing(boolean isOn)
Sets the external syntax parsing flag.
|
boolean |
enterIfBlock(AbstractCodeLine line)
Has to be called when an if-condition occurs.
|
void |
error(java.lang.String msg)
Prints an error message with the current logger instance.
|
void |
error(java.lang.String msg,
java.lang.Throwable throwable)
Prints an error message with the current logger instance.
|
protected void |
execute(AbstractCodeLine line,
java.util.Map csvLine)
Executes the code line at the bean shell.
|
protected void |
execute(AbstractCodeLine line,
java.util.Map csvLine,
boolean forEachMode)
Executes the code line at the bean shell.
|
void |
exitIfBlock()
Has to be called when an endif-marker occurs.
|
ImpExMedia |
findExternalDataMedia(java.lang.String code)
Searches the media with the given code in the context of the reader and returns it.
|
protected ImpExMedia |
findExternalDataMedia(java.lang.String prefix,
java.lang.String code) |
protected java.lang.String |
findMarker(java.lang.String expr)
Checks if the given expression starts with a marker (special construct, see
ImpExConstants.Syntax.CodeMarkers ) and returns the marker string.. |
protected java.util.Set<java.lang.String> |
getAllExternalDataMediaCodes()
Gets all medias added to reader context for external data inclusion.
|
HeaderDescriptor.AttributeConstraintFilter |
getAttributeConstraintFilter()
Get the current constraint filter used in
HeaderDescriptors created until yet. |
AbstractCodeLine |
getBeforeEachCode()
Gets the code line executed after parsing but before interpreting of each line.
|
protected java.util.Map<java.lang.Integer,CSVCellDecorator> |
getCellDecorators()
Gets all decorators set for current header.
|
CSVReader |
getCSVReader()
Gets the reader instance of the main script.
|
HeaderDescriptor |
getCurrentHeader()
Gets the current header which was set at each read value line.
|
java.lang.String |
getCurrentLocation()
Gets the current line number of the reader.
|
protected CSVReader |
getCurrentReader()
Returns the current activated reader used for reading data.
|
protected java.util.List<java.lang.Object[]> |
getDefaultReplacements() |
DocumentIDRegistry |
getDocumentIDRegistry()
Gets the used document ID registry which will be set to each created header.
|
java.lang.Object |
getFromBeanShellContext(java.lang.String key)
Gets the value of the given variable within bean shell context.
|
InvalidHeaderPolicy |
getInvalidHeaderPolicy() |
protected int |
getLineSize(java.util.Map<java.lang.Integer,java.lang.String> line)
Returns the actual length of a value line.
|
java.util.Locale |
getLocale()
Get the current locale setting used for parsing value lines.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
getScriptExecutionContext(java.util.Map<java.lang.Integer,java.lang.String> line) |
protected EnumerationValue |
getStrictMode() |
EnumerationValue |
getValidationMode() |
protected boolean |
gotInsertedLines()
Are lines available which have to be used before reading from reader?
|
protected boolean |
hasCellDecorators()
Checks if there are decorators set for current header.
|
void |
includeExternalData(CSVReader reader)
Redirects the main reader to the given temporary reader for including external data.
|
void |
includeExternalData(CSVReader reader,
int columnOffset)
Redirects the main reader to the given temporary reader for including external data.
|
void |
includeExternalData(CSVReader reader,
int linesToSkip,
int columnOffset)
Redirects the main reader to the given temporary reader for including external data.
|
void |
includeExternalData(CSVReader reader,
int columnOffset,
java.lang.String locationText)
Redirects the main reader to the given temporary reader for including external data.
|
void |
includeExternalData(java.io.File file,
java.lang.String encoding,
int linesToSkip)
Creates a new temporary reader with given file and encoding and redirects the main reader to that temporary reader
for including external data.
|
void |
includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
boolean setNewHeader)
Creates a new temporary reader with given input stream and encoding and redirects the main reader to that temporary
reader for including external data.
|
void |
includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
char[] delimiter,
int linesToSkip,
int columnOffset)
Creates a new temporary reader with given input stream and encoding and redirects the main reader to that temporary
reader for including external data.
|
void |
includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
int linesToSkip)
Creates a new temporary reader with given input stream and encoding and redirects the main reader to that temporary
reader for including external data.
|
void |
includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
int linesToSkip,
int columnOffset)
Creates a new temporary reader with given input stream and encoding and redirects the main reader to that temporary
reader for including external data.
|
void |
includeExternalData(java.lang.String fileName,
java.lang.String fileEncoding,
int linesToSkip)
Creates a new temporary reader with file of given filename and encoding and redirects the main reader to that
temporary reader for including external data.
|
void |
includeExternalDataMedia(ImpExMedia media)
Redirects the import reader to external data stored inside a media.
|
void |
includeExternalDataMedia(ImpExMedia media,
int columnOffset)
Redirects the import reader to external data stored inside a media.
|
void |
includeExternalDataMedia(ImpExMedia media,
java.lang.String encoding,
char delimiter,
int linesToSkip,
int columnOffset)
Redirects the import reader to external data stored inside a media.
ATTENTION: The given parameters will be used for configuring of media, not the attributes set at media. |
void |
includeExternalDataMedia(java.lang.String code)
Redirects the import reader to external data stored inside a media which was announced with
addExternalDataMedia before. |
void |
includeExternalDataMedia(java.lang.String code,
int columnOffset)
Redirects the import reader to external data stored inside a media which was announced with
addExternalDataMedia before. |
void |
includeExternalDataMedia(java.lang.String code,
int linesToSkip,
int columnOffset)
Deprecated.
since ages - use
includeExternalDataMedia(String, int) instead |
void |
includeExternalDataMedia(java.lang.String code,
java.lang.String encoding)
Deprecated.
since ages - use
includeExternalDataMedia(String) instead |
void |
includeExternalDataMedia(java.lang.String code,
java.lang.String encoding,
char delimiter,
int linesToSkip,
int columnOffset)
Deprecated.
since ages - use
includeExternalDataMedia(String, int) instead |
void |
includeExternalDataMedia(java.lang.String code,
java.lang.String encoding,
int columnOffset)
Deprecated.
since ages - use
includeExternalDataMedia(String, int) instead |
void |
includeExternalDataMedia(java.lang.String code,
java.lang.String encoding,
int linesToSkip,
int columnOffset)
Deprecated.
since ages - use
includeExternalDataMedia(String, int) instead |
void |
includeSQLData(java.lang.String sqlStatement)
Uses current settings to establish a database connection, to fire given statement and to parse the result set to
value lines.
|
void |
includeSQLData(java.lang.String sqlStatement,
int skip,
int offset)
Fires the given statement to the database connection established with current settings and parses the lines of the
resulting result set as value lines.
|
void |
includeSQLData(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String className,
java.lang.String sqlStatement)
Establishes a connection to a database with the given parameters, fires the given statement and includes the
resulting result set as external data.
|
void |
info(java.lang.String msg)
Prints an info message with the current logger instance.
|
void |
info(java.lang.String msg,
java.lang.Throwable throwable)
Prints an info message with the current logger instance.
|
void |
initDatabase(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String className)
Initializes the parameters for using a database connection using
includeSQLData. |
void |
insertLine(java.util.Map csvLine)
Inserts the line into reading process.
|
boolean |
isCodeExecutionEnabled()
Is parsing and interpreting of code lines in data enabled?
|
protected boolean |
isCodeLine(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks if the given line is a code line (introduced with #%).
|
boolean |
isCombinedSearchEnabled()
Tells whether or not to use combined search queries.
|
protected boolean |
isCommentLine(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks if the given line is a comment (introduced with #).
|
boolean |
isDebugEnabled() |
protected boolean |
isDefinition(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks if the given line declares a definition.
|
protected boolean |
isEmptyLine(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks if line has no columns.
|
protected boolean |
isEndUserRights(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks if the given ends a UserRight section (consists only of $END_USERRIGHTS).
|
boolean |
isExternalCodeExecutionEnabled()
Is parsing and interpreting of code lines in external data enabled?
|
boolean |
isExternalSyntaxParsingEnabled()
Will non value lines in external lines be interpreted or parsed as value lines.
|
protected boolean |
isHeaderLine(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks if the given line is a header line (introduced with header mode string).
|
boolean |
isIncludingExternalData()
Tells whether or not this reader fetches its data from a external source currently (see
includeExternalData(CSVReader) etc. |
boolean |
isInfoEnabled() |
protected boolean |
isNotInInactiveIfBlock(AbstractCodeLine curLine)
Tests if you are allowed to execute code, based on the current if-block situation.
|
protected boolean |
isStartUserRights(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks if the given introduces a UserRight section (consists only of $START_USERRIGHTS).
|
protected void |
legacyExecute(AbstractCodeLine line,
java.util.Map<java.lang.Integer,java.lang.String> csvLine) |
protected java.util.List<java.lang.String> |
lineToList(java.util.Map<java.lang.Integer,java.lang.String> line)
Rearranges a csv line map into a list object.
|
protected void |
modernExecute(AbstractScriptingEngineCodeLine line,
java.util.Map csvLine) |
static HeaderDescriptor |
parseHeader(java.lang.String headerLine)
Generates a header object from given line.
|
static HeaderDescriptor |
parseHeader(java.lang.String headerLine,
DocumentIDRegistry docIdRegistry)
Generates a header object from given line.
|
static HeaderDescriptor |
parseHeader(java.lang.String headerLine,
EnumerationValue mode)
Generates a header object from given line.
|
static HeaderDescriptor |
parseHeader(java.lang.String headerLine,
EnumerationValue mode,
DocumentIDRegistry docIdRegistry)
Generates a header object from given line.
|
protected void |
processCodeLine(AbstractCodeLine line)
Processes given code line.
|
protected boolean |
processMarkerCodeLine(AbstractCodeLine line)
Processes the special logic of the marker set to the given code line and returns true, if the code line should be
executed or the marker prohibits the execution.
|
java.lang.Object |
readLine()
Fetches the next line, parses it and returns it encapsulated in a
HeaderDescriptor if the line was a
header definition or a ValueLine if it was a data row. |
protected java.util.Map<java.lang.Integer,java.lang.String> |
readNextCSVLine()
Reads the next line.
|
void |
removeExternalDataMedia(Media ext)
Removes an media from the reader context and is therefore not includable as external data anymore.
|
void |
removeExternalDataMedias(java.util.Collection<Media> toRemove)
Removes an collection medias from the reader context and are therefore not integrable as external data anymore.
|
protected java.util.Map<java.lang.Integer,java.lang.String> |
replaceDefinitions(java.util.Map<java.lang.Integer,java.lang.String> line)
Checks the given line for definition usage and replace all definition keys with the correct definition values.
|
void |
setAttributeConstraintFilter(HeaderDescriptor.AttributeConstraintFilter filter)
Sets a new constraint filter (for defining methods like isMandatory for attributes) used in each created
HeaderDescriptor from now. |
protected void |
setBeanShellContext(Interpreter shell,
java.util.Map<java.lang.Integer,java.lang.String> line)
Declares default variables within the bean shell context which therefore are available within bean shell code
interpretation.
|
protected void |
setBeforeEachCode(AbstractCodeLine line)
Sets the code line executed after parsing but before interpreting of each line.
|
protected void |
setCellDecorators(HeaderDescriptor header)
Extracts all decorators from given header columns and stores them for line parsing.
|
void |
setCurrentHeader(HeaderDescriptor header)
Sets the given header instance as current header.
|
void |
setCurrentHeader(java.lang.String headerCSVDefinition)
Generates from given header line a
HeaderDescriptor and sets it as current header for further reading of
input. |
protected void |
setInvalidHeaderPolicy(InvalidHeaderPolicy invalidHeaderPolicy) |
void |
setLocale(java.util.Locale locale)
Sets the locale used while parsing value lines.
|
void |
setRelaxedMode(boolean enable)
Deprecated.
since 3.0, use
setValidationMode(EnumerationValue) instead |
void |
setRelaxedMode(java.lang.String enable)
Deprecated.
since 3.0, use
setValidationMode(EnumerationValue) instead |
void |
setValidationMode(EnumerationValue headerValidationMode)
Sets the header valdiation mode used for all created headers.
|
void |
setValidationMode(java.lang.String mode) |
protected void |
sortRulesList(java.util.List<java.lang.Object[]> rulesList) |
protected java.lang.String[] |
splitDefinitonCell(java.lang.String cell)
Splits the given definition in key and value pair.
|
protected void |
storeUserRightsLine(java.util.Map line)
Concatenates given line and adds it to the already read user rights lines for further special processing.
|
void |
warn(java.lang.String msg)
Prints an warn message with the current logger instance.
|
void |
warn(java.lang.String msg,
java.lang.Throwable throwable)
Prints an warn message with the current logger instance.
|
protected void |
writeUserRightsLines()
Writes all stored UserRights lines to an temporary buffer and imports this file with the
ImportExportUserRightsHelper. |
public static final java.lang.Integer FIRST
Map.public ImpExReader(java.lang.String fileName,
java.lang.String encoding,
boolean skipValueLines)
throws java.io.UnsupportedEncodingException,
java.io.FileNotFoundException
fileName - the name of the file used as input for the readerencoding - used encoding for reading the fileskipValueLines - if true, all value lines (lines within input containing data) will be not interpreted and therefore not
returned by call of readLine()java.io.UnsupportedEncodingException - the given encoding is unknownjava.io.FileNotFoundException - there is no file with the given file namepublic ImpExReader(java.io.InputStream input,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException
input - stream from which the script is readencoding - used encoding for reading from streamjava.io.UnsupportedEncodingException - encoding is unknownpublic ImpExReader(java.io.InputStream input,
java.lang.String encoding,
boolean skipValueLines)
throws java.io.UnsupportedEncodingException
input - stream from which the script is readencoding - used encoding for reading from streamskipValueLines - if true, readLine will not return a ValueLine, they will be skipped without
parsing themjava.io.UnsupportedEncodingException - encoding is unknownpublic ImpExReader(CSVReader reader, boolean skipValueLines)
CSVReader as input. Relaxed mode is disabled and a new
document ID registry will be instantiated.reader - the reader from which the script is readskipValueLines - if true, readLine will not return a ValueLine, they will be skipped without
parsing thempublic ImpExReader(CSVReader reader, boolean skipValueLines, EnumerationValue headerValidationMode)
CSVReader as input. A new document ID registry will be
instantiated.reader - the reader from which the script is readskipValueLines - if true, readLine will not return a ValueLine, they will be skipped without
parsing themheaderValidationMode - 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_STRICTpublic ImpExReader(CSVReader reader, boolean skipValueLines, EnumerationValue headerValidationMode, DocumentIDRegistry docIdRegistry)
CSVReader as input.reader - the reader from which the script is readskipValueLines - if true, readLine will not return a ValueLine, they will be skipped without
parsing themheaderValidationMode - 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_STRICTdocIdRegistry - the used document ID registry set to each created ImpExHeaderDesriptorpublic ImpExReader(CSVReader reader, boolean skipValueLines, EnumerationValue headerValidationMode, DocumentIDRegistry docIdRegistry, InvalidHeaderPolicy headerHandlingPolicy)
public InvalidHeaderPolicy getInvalidHeaderPolicy()
protected void setInvalidHeaderPolicy(InvalidHeaderPolicy invalidHeaderPolicy)
protected EnumerationValue getStrictMode()
protected java.util.List<java.lang.Object[]> getDefaultReplacements()
protected void sortRulesList(java.util.List<java.lang.Object[]> rulesList)
public void addHeaderReplacementRule(java.lang.String srcPattern,
java.lang.String tgtPattern,
int prio)
public void setAttributeConstraintFilter(HeaderDescriptor.AttributeConstraintFilter filter)
HeaderDescriptor from now.filter - the new filter used in headerspublic HeaderDescriptor.AttributeConstraintFilter getAttributeConstraintFilter()
HeaderDescriptors created until yet.public static HeaderDescriptor parseHeader(java.lang.String headerLine) throws ImpExException
headerLine - the line which will be parsed and a header object is created fromImpExException - the given line does not represent a header or is misspelledpublic static HeaderDescriptor parseHeader(java.lang.String headerLine, DocumentIDRegistry docIdRegistry) throws ImpExException
headerLine - the line which will be parsed and a header object is created fromdocIdRegistry - a document ID registry which will be attached to the header objectImpExException - the given line does not represent a header or is misspelledpublic static HeaderDescriptor parseHeader(java.lang.String headerLine, EnumerationValue mode) throws ImpExException
headerLine - the line which will be parsed and a header object is created frommode - should the relaxed mode be set in header objectImpExException - the given line does not represent a header or is misspelledpublic static HeaderDescriptor parseHeader(java.lang.String headerLine, EnumerationValue mode, DocumentIDRegistry docIdRegistry) throws ImpExException
headerLine - the line which will be parsed and a header object is created frommode - should the relaxed mode be set in header objectdocIdRegistry - a document ID registry which will be attached to the header objectImpExException - the given line does not represent a header or is misspelledpublic boolean isExternalSyntaxParsingEnabled()
@Deprecated public void enableExternalImpExSyntaxParsing(boolean isOn)
enableExternalSyntaxParsing(boolean) insteadisOn - set true if external parsing should be activatedpublic void enableExternalSyntaxParsing(boolean isOn)
isOn - set true if external parsing should be activatedpublic boolean isCombinedSearchEnabled()
public void setLocale(java.util.Locale locale)
locale - the new locale used from nowpublic java.util.Locale getLocale()
public void close()
throws java.io.IOException
java.io.IOException - error while closing streamspublic CSVReader getCSVReader()
getCurrentReader().public void addExternalDataMedia(ImpExMedia ext)
includeExternalDataMedia.ext - the new media which can be included as external data source nowpublic void addExternalDataMedias(java.util.Collection<ImpExMedia> toAdd)
includeExternalDataMedia each.toAdd - the new medias which can be included as external data source nowpublic void removeExternalDataMedia(Media ext)
ext - the media which will be removed from contextpublic void removeExternalDataMedias(java.util.Collection<Media> toRemove)
toRemove - the media collection which will be removed from contextprotected java.util.Set<java.lang.String> getAllExternalDataMediaCodes()
public ImpExMedia findExternalDataMedia(java.lang.String code) throws JaloBusinessException
code - code of the mediaJaloBusinessException - a media with the code was found but has had no data attachedprotected ImpExMedia findExternalDataMedia(java.lang.String prefix, java.lang.String code)
public boolean isIncludingExternalData()
includeExternalData(CSVReader) etc. ).public void setCurrentHeader(java.lang.String headerCSVDefinition)
throws ImpExException
HeaderDescriptor and sets it as current header for further reading of
input.headerCSVDefinition - line defining a headerImpExException - error while generation of the header objectpublic void setCurrentHeader(HeaderDescriptor header)
header - the header which will be used from now as header for read value linespublic HeaderDescriptor getCurrentHeader()
public final void initDatabase(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String className)
includeSQLData.url - url to the databaseuser - name of user / account in databasepassword - password of userclassName - name of database driver (JDBC)public void includeSQLData(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String className,
java.lang.String sqlStatement)
Example script:
#% impex.enableCodeExecution( true );
#% impex.setRelaxedMode( true );
INSERT_UPDATE Product; code[unique=true]
#%
impex.includeSQLData("jdbc:mysql://localhost/testdb?user=hendrik&password=hendrik"
,"com.mysql.jdbc.Driver","Select * from Products");
url - url to the databaseuser - name of the user / account at databasepassword - password of userclassName - name of the database driversqlStatement - error while establishing connection or reading result setpublic void includeSQLData(java.lang.String sqlStatement)
sqlStatement - error while accessing the result set of given statementpublic void includeSQLData(java.lang.String sqlStatement,
int skip,
int offset)
Example script:
#% impex.enableCodeExecution( true );
#% impex.setRelaxedMode( true );
#%
impex.initDatabase( "jdbc:mysql://localhost/testdb?user=hendrik&password=hendrik","com.mysql.jdbc.Driver" );
INSERT_UPDATE Product; code[unique=true]
#% impex.includeSQLData("Select * from Products");
sqlStatement - statement which will be executedskip - lines to skip within result setoffset - amount of columns to skip from leftpublic void includeExternalData(java.io.File file,
java.lang.String encoding,
int linesToSkip)
throws java.io.UnsupportedEncodingException,
java.io.FileNotFoundException
file - file which contains external data to be includedencoding - the encoding used in given filelinesToSkip - amount of lines the reader of the file will initial skipjava.io.UnsupportedEncodingException - given encoding is unknownjava.io.FileNotFoundException - given file is not foundpublic void includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
int linesToSkip)
throws java.io.UnsupportedEncodingException
inputStream - input stream from which external data to be included is accessableencoding - the used encodinglinesToSkip - amount of lines the reader of the stream will initial skipjava.io.UnsupportedEncodingException - given encoding is unknownpublic void includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
int linesToSkip,
int columnOffset)
throws java.io.UnsupportedEncodingException
inputStream - input stream from which external data to be included is accessibleencoding - the used encodinglinesToSkip - amount of lines the reader of the stream will initial skipcolumnOffset - position difference of header columns to data columns. Is data in hybris style, use 0 because data columns
positions are exactly the same as in header. In default style use -1, because the data columns do not have
a first column with type information. So the header columns have to be shifted one to the left =>-1.java.io.UnsupportedEncodingException - given encoding is unknownpublic void includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
char[] delimiter,
int linesToSkip,
int columnOffset)
throws java.io.UnsupportedEncodingException
inputStream - input stream from which external data to be included is accessibleencoding - the used encodingdelimiter - field separators used in external datalinesToSkip - amount of lines the reader of the stream will initial skipcolumnOffset - position difference of header columns to data columns. Is data in hybris style, use 0 because data columns
positions are exactly the same as in header. In default style use -1, because the data columns do not have
a first column with type information. So the header columns have to be shifted one to the left =>-1.java.io.UnsupportedEncodingException - given encoding is unknownpublic void includeExternalData(java.lang.String fileName,
java.lang.String fileEncoding,
int linesToSkip)
throws java.io.UnsupportedEncodingException,
java.io.FileNotFoundException
fileName - file which contains external data to be includedfileEncoding - the encoding used in given filelinesToSkip - amount of lines the reader of the file will initial skipjava.io.UnsupportedEncodingException - given encoding is unknownjava.io.FileNotFoundException - given file is not foundpublic void includeExternalData(CSVReader reader)
reader - the temporary reader which reads from external datapublic void includeExternalData(CSVReader reader, int linesToSkip, int columnOffset)
reader - the temporary reader which reads from external datalinesToSkip - amount of lines which will be skipped when start reading from external datacolumnOffset - position difference of header columns to data columns. Is data in hybris style, use 0 because data columns
positions are exactly the same as in header. In default style use -1, because then data columns do not have
a first column with type information as in hybris style. So the header columns have to be shifted one to
the left => -1.public void includeExternalData(CSVReader reader, int columnOffset)
reader - the temporary reader which reads from external datacolumnOffset - position difference of header columns to data columns. Is data in hybris style, use 0 because data columns
positions are exactly the same as in header. In default style use -1, because then data columns do not have
a first column with type information as in hybris style. So the header columns have to be shifted one to
the left => -1.public void includeExternalData(CSVReader reader, int columnOffset, java.lang.String locationText)
reader - the temporary reader which reads from external datacolumnOffset - position difference of header columns to data columns. Is data in hybris style, use 0 because data columns
positions are exactly the same as in header. In default style use -1, because then data columns do not have
a first column with type information as in hybris style. So the header columns have to be shifted one to
the left => -1.locationText - identifier of the external data for logging purposespublic void includeExternalData(java.io.InputStream inputStream,
java.lang.String encoding,
boolean setNewHeader)
throws java.io.UnsupportedEncodingException,
ImpExException
inputStream - input stream from which external data to be included is accessibleencoding - the used encodingsetNewHeader - if true, the first line of the external data will be tried to interpreted as headerjava.io.UnsupportedEncodingException - given encoding is unknownImpExException - error while parsing header from first line (only when setNewHeader==true)public void includeExternalDataMedia(java.lang.String code)
throws java.io.UnsupportedEncodingException
addExternalDataMedia before. No lines will be skipped and column offset is set to -1 (data is not in hybris
style).code - the media codejava.io.UnsupportedEncodingException - unknown encoding givenpublic void includeExternalDataMedia(java.lang.String code,
int columnOffset)
throws java.io.UnsupportedEncodingException
addExternalDataMedia before. No lines will be skipped.code - the media codecolumnOffset - the column offset compared to impex standard: if the first column already contains data use -1 since impex
normally starts in column 0java.io.UnsupportedEncodingException - unknown encoding given@Deprecated
public void includeExternalDataMedia(java.lang.String code,
int linesToSkip,
int columnOffset)
throws java.io.UnsupportedEncodingException
includeExternalDataMedia(String, int) instead
addExternalDataMedia before. linesToSkip value will be used instead of the equivalent attribute set at the media. It is
preferred to set the encoding and linesToSkip directly at the media and to use
includeExternalDataMedia(String, int ) instead.code - the media codelinesToSkip - amount of lines which will be skipped when start reading from external datacolumnOffset - the column offset compared to impex standard: if the first column already contains data use -1 since impex
normally starts in column 0java.io.UnsupportedEncodingException - unknown encoding given@Deprecated
public void includeExternalDataMedia(java.lang.String code,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException
includeExternalDataMedia(String) instead
addExternalDataMedia before. No lines will be skipped and column offset is set to -1 (data is not in hybris
style).includeExternalDataMedia(String) instead.code - the media codeencoding - the encoding of the csv data stored inside the mediajava.io.UnsupportedEncodingException - unknown encoding given@Deprecated
public void includeExternalDataMedia(java.lang.String code,
java.lang.String encoding,
int columnOffset)
throws java.io.UnsupportedEncodingException
includeExternalDataMedia(String, int) instead
addExternalDataMedia before. No lines will be skipped.includeExternalDataMedia(String ) instead.code - the media codeencoding - the encoding of the csv data stored inside the mediacolumnOffset - the column offset compared to impex standard: if the first column already contains data use -1 since impex
normally starts in column 0java.io.UnsupportedEncodingException - unknown encoding given@Deprecated
public void includeExternalDataMedia(java.lang.String code,
java.lang.String encoding,
int linesToSkip,
int columnOffset)
throws java.io.UnsupportedEncodingException
includeExternalDataMedia(String, int) instead
addExternalDataMedia before. linesToSkip value will be used instead of the equivalent attribute set at the
media. It is preferred to set the encoding and linesToSkip directly at the media and to use
includeExternalDataMedia(String ) instead.code - the media codeencoding - the encoding of the csv data stored inside the medialinesToSkip - amount of lines which will be skipped when start reading from external datacolumnOffset - the column offset compared to impex standard: if the first column already contains data use -1 since impex
normally starts in column 0java.io.UnsupportedEncodingException - unknown encoding given@Deprecated
public void includeExternalDataMedia(java.lang.String code,
java.lang.String encoding,
char delimiter,
int linesToSkip,
int columnOffset)
throws java.io.UnsupportedEncodingException
includeExternalDataMedia(String, int) instead
addExternalDataMedia before.encoding,delimiter and linesToSkip values will be used instead of
the equivalent attribute set at the media. It is preferred to set these values directly at the media and to use
includeExternalDataMedia(String) instead.code - the media codeencoding - the encoding of the csv data stored inside the mediadelimiter - field separator used in external datalinesToSkip - amount of lines which will be skipped when start reading from external datacolumnOffset - the column offset compared to impex standard: if the first column already contains data use -1 since impex
normally starts in column 0java.io.UnsupportedEncodingException - unknown encoding givenpublic void includeExternalDataMedia(ImpExMedia media) throws java.io.UnsupportedEncodingException
ColumnOffset will be set to -1media - the media containing the external datajava.io.UnsupportedEncodingException - unknown encoding givenpublic void includeExternalDataMedia(ImpExMedia media, int columnOffset) throws java.io.UnsupportedEncodingException
media - the media containing the external datacolumnOffset - the column offset compared to impex standard: if the first column already contains data use -1 since impex
normally starts in column 0java.io.UnsupportedEncodingException - unknown encoding givenpublic void includeExternalDataMedia(ImpExMedia media, java.lang.String encoding, char delimiter, int linesToSkip, int columnOffset) throws java.io.UnsupportedEncodingException
media - media instance holding the external dataencoding - the encoding of the csv data stored inside the mediadelimiter - field separator used in external datalinesToSkip - amount of lines which will be skipped when start reading from external datacolumnOffset - the column offset compared to impex standard: if the first column already contains data use -1 since impex
normally starts in column 0java.io.UnsupportedEncodingException - unknown encoding givenpublic java.lang.String getCurrentLocation()
protected CSVReader getCurrentReader()
public DocumentIDRegistry getDocumentIDRegistry()
protected boolean gotInsertedLines()
public void insertLine(java.util.Map csvLine)
csvLine - line which will be inserted in line processingprotected java.util.Map<java.lang.Integer,java.lang.String> readNextCSVLine()
protected java.util.Map<java.lang.Integer,java.lang.String> adjustLineIndexes(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to adjustpublic java.lang.Object readLine()
throws ImpExException
HeaderDescriptor if the line was a
header definition or a ValueLine if it was a data row.HeaderDescriptor or ValueLine instances or null if end of data is reached.ImpExException - if a header could not be parsed properlyprotected void addHeaderExceptionInfoAsComment(java.util.Map<java.lang.Integer,java.lang.String> adjustedLine,
HeaderValidationException ex)
public HeaderDescriptor createInvalidHeader(java.util.Map<java.lang.Integer,java.lang.String> line, HeaderValidationException ex) throws HeaderValidationException
HeaderValidationExceptionprotected boolean hasCellDecorators()
protected java.util.Map<java.lang.Integer,CSVCellDecorator> getCellDecorators()
protected void setCellDecorators(HeaderDescriptor header)
header - header from which the decorators will be extractedprotected void storeUserRightsLine(java.util.Map line)
line - line with a UserRight data rowprotected void writeUserRightsLines()
throws ImpExException
ImportExportUserRightsHelper.ImpExException - there were no user rights for import.protected void addDefinition(java.lang.String cell)
cell - string containing the definitionprotected java.lang.String[] splitDefinitonCell(java.lang.String cell)
cell - the definition to splitprotected void checkDefinitonKey(java.lang.String newKey,
java.util.Map currentDefinitions)
throws ImpExException
newKey - key to checkcurrentDefinitions - map with present definitionImpExException - the given key is a prefix of a present keyprotected java.util.Map<java.lang.Integer,java.lang.String> replaceDefinitions(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkprotected java.lang.String findMarker(java.lang.String expr)
ImpExConstants.Syntax.CodeMarkers ) and returns the marker string..expr - the expression to checkprotected AbstractCodeLine createCodeLine(java.util.Map<java.lang.Integer,java.lang.String> line)
isCodeLine(Map).line - line to interpretprotected AbstractCodeLine createCodeLineLegacyWay(java.util.Map<java.lang.Integer,java.lang.String> line)
protected AbstractCodeLine createCodeLineModernWay(java.util.Map<java.lang.Integer,java.lang.String> line)
protected HeaderDescriptor createNewHeader(java.util.Map<java.lang.Integer,java.lang.String> line) throws HeaderValidationException
line - line for which a header object is neededHeaderValidationException - header is not validprotected java.util.List<java.lang.String> applyHeaderReplacements(java.util.List<java.lang.String> columns)
protected int getLineSize(java.util.Map<java.lang.Integer,java.lang.String> line)
line.size() is not sufficient for that!line - line to checkprotected java.util.List<java.lang.String> lineToList(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to transformprotected boolean isEmptyLine(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkpublic void setValidationMode(java.lang.String mode)
public void setValidationMode(EnumerationValue headerValidationMode)
headerValidationMode - 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_STRICTpublic EnumerationValue getValidationMode()
@Deprecated public void setRelaxedMode(boolean enable)
setValidationMode(EnumerationValue) instead@Deprecated public void setRelaxedMode(java.lang.String enable)
setValidationMode(EnumerationValue) insteadprotected boolean isCommentLine(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkprotected boolean isCodeLine(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkprotected boolean isHeaderLine(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkprotected boolean isDefinition(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkprotected boolean isStartUserRights(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkprotected boolean isEndUserRights(java.util.Map<java.lang.Integer,java.lang.String> line)
line - line to checkprotected ValueLine createValueLine(HeaderDescriptor header, java.util.Map<java.lang.Integer,java.lang.String> line)
header - the header which corresponds to the given lineline - line for which a value line is neededpublic final boolean isCodeExecutionEnabled()
public void enableCodeExecution(boolean isOn)
isOn - Should code execution be enabled?public final boolean isExternalCodeExecutionEnabled()
@Deprecated public void enableExternalDataCodeExecution(boolean isOn)
enableExternalCodeExecution(boolean) insteadisOn - Should external code execution be enabled?public void enableExternalCodeExecution(boolean isOn)
isOn - Should external code execution be enabled?protected void setBeforeEachCode(AbstractCodeLine line)
line - code line to remember for before executionpublic AbstractCodeLine getBeforeEachCode()
public boolean enterIfBlock(AbstractCodeLine line)
line - the current code line containing the if-conditionpublic void exitIfBlock()
protected boolean isNotInInactiveIfBlock(AbstractCodeLine curLine)
protected boolean processMarkerCodeLine(AbstractCodeLine line) throws ImpExException
line - the code line with set markerImpExException - the marker set to the code line is unknownprotected void processCodeLine(AbstractCodeLine line) throws ImpExException
line - line to executeImpExException - error while execution of code lineprotected void setBeanShellContext(Interpreter shell,
java.util.Map<java.lang.Integer,java.lang.String> line)
throws EvalError
line - the given line objectcurrentLineNumber - the current line numbercurrentLocation - the current location of the active readershell - bean shell interpreter where the variables will be setline - line object which will be set to variable lineEvalError - error while setting variablesprotected java.util.Map<java.lang.String,java.lang.Object> getScriptExecutionContext(java.util.Map<java.lang.Integer,java.lang.String> line)
protected void addToBeanShellContext(java.lang.String key,
java.lang.Object value)
throws EvalError
key - name of variablevalue - object referenceEvalError - error with bean shellpublic java.lang.Object getFromBeanShellContext(java.lang.String key)
throws EvalError
key - name of variableEvalError - error with bean shellprotected void execute(AbstractCodeLine line, java.util.Map csvLine) throws ImpExException
line - the code linecsvLine - current line object for context variable 'line'ImpExException - error while code executionprotected void execute(AbstractCodeLine line, java.util.Map csvLine, boolean forEachMode) throws ImpExException
line - the code linecsvLine - current line object for context variable 'line'forEachMode - is the reason for execution not the normal script processing, instead it is a execution reasoned by a
forEach marker?ImpExException - error while code executionprotected void modernExecute(AbstractScriptingEngineCodeLine line, java.util.Map csvLine) throws ImpExException
ImpExExceptionprotected void legacyExecute(AbstractCodeLine line, java.util.Map<java.lang.Integer,java.lang.String> csvLine) throws ImpExException
ImpExExceptionprotected void assureBeanShellLoaded()
throws ImpExException
ImpExException - error while loading shellpublic boolean isDebugEnabled()
public void debug(java.lang.String msg,
java.lang.Throwable throwable)
msg - debug messagethrowable - cause of messagepublic void debug(java.lang.String msg)
msg - debug messagepublic boolean isInfoEnabled()
public void info(java.lang.String msg)
msg - info messagepublic void info(java.lang.String msg,
java.lang.Throwable throwable)
msg - info messagethrowable - cause of messagepublic void warn(java.lang.String msg)
msg - warn messagepublic void warn(java.lang.String msg,
java.lang.Throwable throwable)
msg - warn messagethrowable - cause of messagepublic void error(java.lang.String msg)
msg - error messagepublic void error(java.lang.String msg,
java.lang.Throwable throwable)
msg - error messagethrowable - cause of messageCopyright © 2018 SAP SE. All Rights Reserved.