Revision: 6371 http://sourceforge.net/p/jump-pilot/code/6371 Author: michaudm Date: 2020-08-09 17:49:20 +0000 (Sun, 09 Aug 2020) Log Message: ----------- #494 : hu i18n file + wkt loader accepts csv extension (v 1.1.0)
Modified Paths: -------------- plug-ins/CsvDriver/trunk/build.xml plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/AutoCSVFile.java plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDataSource.java plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDriverConfiguration.java plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVFile.java plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/FieldSeparator.java plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/SaveCSVFileDataSourceQueryChooser.java Modified: plug-ins/CsvDriver/trunk/build.xml =================================================================== --- plug-ins/CsvDriver/trunk/build.xml 2020-08-05 13:45:55 UTC (rev 6370) +++ plug-ins/CsvDriver/trunk/build.xml 2020-08-09 17:49:20 UTC (rev 6371) @@ -16,7 +16,7 @@ <property name="resources" value="resources" /> <!-- plugins --> - <property name="csv-driver-version" value="1.0.3" /> + <property name="csv-driver-version" value="1.1.0" /> <!--property name="openjump-ext" value="C:/Users/Michaël/DEVELOPPEMENTS/OpenJUMP-2012/dist/openjump-1.6.2beta/lib/ext" /--> <!--property name="openjump-ext" value="C:\Program Files\OpenJUMP-1.6.3-r3576-CORE\lib\ext" /--> Modified: plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/AutoCSVFile.java =================================================================== --- plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/AutoCSVFile.java 2020-08-05 13:45:55 UTC (rev 6370) +++ plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/AutoCSVFile.java 2020-08-09 17:49:20 UTC (rev 6371) @@ -43,15 +43,15 @@ // Pattern to differenciate a comment line Pattern starting with # // from a header line Pattern starting with #FID or #X (old xyz format) - private final static Pattern SHARP_PATTERN = Pattern.compile("^#(?!(FID|X)[\t,;\\| ])"); + private final static Pattern SHARP_PATTERN = Pattern.compile("^#(?!(FID|X)[\t,;| ])"); // Pattern matching a unquoted, integer, decimal or scientic number // A non-comment line containing such a pattern is considered as a data line - private final static Pattern NUMBER_PATTERN = Pattern.compile("[\\s\\|,;]-?\\d+(\\.\\d+([eE][-\\+]\\d+)?)?[\\s\\|,;]"); + private final static Pattern NUMBER_PATTERN = Pattern.compile("[\\s|,;]-?\\d+(\\.\\d+([eE][-+]\\d+)?)?[\\s|,;]"); // Pattern matching a WKT string // A non-comment line containing such a pattern is considered as a data line - private final static Pattern WKT_PATTERN = Pattern.compile("(((MULTI)?(POINT|LINESTRING|POLYGON))|GEOMETRYCOLLECTION) ?( EMPTY|\\([\\(\\)\\d,\\. ]*\\))"); + private final static Pattern WKT_PATTERN = Pattern.compile("(((MULTI)?(POINT|LINESTRING|POLYGON))|GEOMETRYCOLLECTION) ?( EMPTY|\\([()\\d,. ]*\\))"); /** No parameter constructor for persitence in a project file.*/ @@ -87,9 +87,10 @@ /** * Test to guess the encoding of a file (taken from * neoedmund'editor at http://code.google.com/p/neoeedit/) - * @Deprecated too dangerous, just use the system default, it can be forced + * @deprecated too dangerous, just use the system default, it can be forced * in the command line */ + @Deprecated private String guessEncoding() throws IOException { // Main multi-bytes encodings String local_charset = Charset.defaultCharset().name(); @@ -181,7 +182,7 @@ nonComment++; } br.close(); - guessFieldSeparator(lines.toArray(new String[lines.size()])); + guessFieldSeparator(lines.toArray(new String[0])); setColumns(line1); setHeaderLine(hasHeaderLine() && !pirol); setAttributeTypes(line2); @@ -200,7 +201,7 @@ // if no lines are provided, return the current fieldSeparator if (lines.length == 0) return false; FieldSeparator[] separators = new FieldSeparator[]{TABULATION, COMMA, SEMI_COLUMN, PIPE, WHITESPACE}; - List<Set<Integer>> counts = new ArrayList<Set<Integer>>(); + List<Set<Integer>> counts = new ArrayList<>(); for (int i = 0 ; i < separators.length ; i++) { Pattern _fieldPattern = separators[i].getFieldPattern(); counts.add(new HashSet<Integer>()); @@ -246,7 +247,7 @@ protected void setColumns(String line) throws IOException, CSVFileException { - if (line != null /*&& getFeatureSchema() == null*/) { + if (line != null) { boolean header = !NUMBER_PATTERN.matcher(line).find() && !WKT_PATTERN.matcher(line).find(); setHeaderLine(header); @@ -258,7 +259,7 @@ * Try to guess geometry columns from the column names and create the * FeatureSchema */ - protected void guessGeometryColumns(String line) throws CSVFileException, IOException { + protected void guessGeometryColumns(String line) { String[] columns = getColumns(); if (columns != null && columns.length>0) { int wkt = -1; Modified: plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDataSource.java =================================================================== --- plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDataSource.java 2020-08-05 13:45:55 UTC (rev 6370) +++ plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDataSource.java 2020-08-09 17:49:20 UTC (rev 6371) @@ -211,7 +211,7 @@ writer.close(); // [mmichaud 2013-11-06] resolve a problem of persistence in the project file - if (getProperties().get(SAVED_AS) != null && ((Boolean)getProperties().get(SAVED_AS)).booleanValue()) { + if (getProperties().get(SAVED_AS) != null && (Boolean) getProperties().get(SAVED_AS)) { AutoCSVFile csvFile = new AutoCSVFile(csv.getFilePath(), csv.getEntryName()); csv.setEncoding(csv.getCharset().name()); csv.setFieldSeparator(csv.getFieldSeparator()); Modified: plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDriverConfiguration.java =================================================================== --- plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDriverConfiguration.java 2020-08-05 13:45:55 UTC (rev 6370) +++ plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVDriverConfiguration.java 2020-08-09 17:49:20 UTC (rev 6371) @@ -43,8 +43,9 @@ /** * Extension loading a driver for csv and other character delimited text files * @author Michaël MICHAUD - * @version 1.0.3 (2020-07-31) + * @version 1.0.4 (2020-08-09) */ +// 1.1.0 (2020-08-09) add hu i18n file, wkt loader now accept files with csv extension, cleanup // 1.0.3 (2020-07-31) fix serialization of fieldSeparator in jmp file (need OJ r6363) // 1.0.2 (2018-01-27) add I18N for finnish language // 1.0.1 (2017-05-07) fix parser to parse correctly non quoted fields including double quotes @@ -81,7 +82,7 @@ return "1.0.3 (2020-07-31)"; } - public void configure(PlugInContext context) throws Exception { + public void configure(PlugInContext context) { final WorkbenchContext wcontext = context.getWorkbenchContext(); @@ -100,7 +101,7 @@ Pattern.compile("^//"), Pattern.compile("^--"), Pattern.compile("^\\$"), - Pattern.compile("^#(?!(FID|X)[\t,;\\| ])")})); + Pattern.compile("^#(?!(FID|X)[\t,;| ])")})); FieldComponentFactoryRegistry.setFactory( wcontext, @@ -146,7 +147,7 @@ //////////////////////////////////////////////////////////////////////// // Create configurable csv File Loader for XYZ puntal data //////////////////////////////////////////////////////////////////////// - List<String> csvExtensions = new ArrayList<String>(); + List<String> csvExtensions = new ArrayList<>(); csvExtensions.add("txt"); csvExtensions.add("xyz"); csvExtensions.add("csv"); @@ -161,7 +162,7 @@ // [mmichaud 2013-11-07] change internationalized options to fixed keys properties // This is necessary to use persist CSVDataSource in the project file private Map<String,Object> toProperties(Map <String,Object> options) { - Map<String,Object> properties = new HashMap<String,Object>(); + Map<String,Object> properties = new HashMap<>(); properties.put(CSVDataSource.CHARSET, options.get(I18NPlug.getI18N("drivers.csv.encoding"))); properties.put(CSVDataSource.COMMENT_LINE_PATTERN, options.get(I18NPlug.getI18N("drivers.csv.comment-line-pattern"))); properties.put(CSVDataSource.FIELD_SEPARATOR, options.get(I18NPlug.getI18N("drivers.csv.field-separator"))); @@ -197,8 +198,9 @@ //////////////////////////////////////////////////////////////////////// // Create configurable csv File Loader for WKT data //////////////////////////////////////////////////////////////////////// - List<String> wktExtensions = new ArrayList<String>(); + List<String> wktExtensions = new ArrayList<>(); wktExtensions.add("wkt"); + wktExtensions.add("csv"); DataSourceFileLayerLoader wktOptionsFileLoader = new DataSourceFileLayerLoader( wcontext, CSVDataSource.class, "wkt (set options)", wktExtensions) { @@ -210,7 +212,7 @@ // [mmichaud 2013-11-07] change internationalized options to fixed keys properties // This is necessary to use persist CSVDataSource in the project file private Map<String,Object> toProperties(Map <String,Object> options) { - Map<String,Object> properties = new HashMap<String,Object>(); + Map<String,Object> properties = new HashMap<>(); properties.put(CSVDataSource.CHARSET, options.get(I18NPlug.getI18N("drivers.csv.encoding"))); properties.put(CSVDataSource.COMMENT_LINE_PATTERN, options.get(I18NPlug.getI18N("drivers.csv.comment-line-pattern"))); properties.put(CSVDataSource.FIELD_SEPARATOR, options.get(I18NPlug.getI18N("drivers.csv.field-separator"))); @@ -250,14 +252,12 @@ protected Map<String,Object> toProperties(URI uri, Map<String,Object> options) { - Map<String,Object> properties = super.toProperties(uri, new HashMap<String, Object>()); + Map<String,Object> properties = super.toProperties(uri, new HashMap<String,Object>()); try { final CSVFile csvFile = new AutoCSVFile((String)properties.get(DataSource.FILE_KEY), (String)properties.get("CompressedFile")); properties.put("CSV_FILE", csvFile); - } catch(IOException e) { + } catch(IOException | CSVFileException e) { e.printStackTrace(); - } catch(CSVFileException e) { - e.printStackTrace(); } return properties; } @@ -285,7 +285,7 @@ // http://stackoverflow.com/questions/8509339/what-is-the-most-common-encoding-of-each-language // http://www.w3.org/International/O-charset-lang.html SortedMap<String,Charset> availableCharsets = Charset.availableCharsets(); - List<Charset> charsets = new ArrayList<Charset>(); + List<Charset> charsets = new ArrayList<>(); String[] charsetNames = new String[]{ "windows-1252", "UTF-8", @@ -308,7 +308,7 @@ charsets.add(availableCharsets.get(name)); } } - return charsets.toArray(new Charset[charsets.size()]); + return charsets.toArray(new Charset[0]); } } \ No newline at end of file Modified: plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVFile.java =================================================================== --- plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVFile.java 2020-08-05 13:45:55 UTC (rev 6370) +++ plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/CSVFile.java 2020-08-09 17:49:20 UTC (rev 6371) @@ -81,7 +81,7 @@ boolean initialized = false; - private final List<Exception> exceptions = new ArrayList<Exception>(); + private final List<Exception> exceptions = new ArrayList<>(); /** @@ -271,7 +271,7 @@ * Tokenize the line using this CSVFile fieldSeparator. */ public String[] tokenize(String line) { - List<String> tokens = new ArrayList<String>(); + List<String> tokens = new ArrayList<>(); Matcher matcher = fieldSeparator.getFieldPattern().matcher(line); while (!matcher.hitEnd() && matcher.find()) { String token = matcher.group(1)!=null ? matcher.group(1) : @@ -278,7 +278,7 @@ matcher.group(2).replaceAll("\"\"","\""); tokens.add(token); } - return tokens.toArray(new String[tokens.size()]); + return tokens.toArray(new String[0]); } @@ -401,18 +401,18 @@ protected void setAttributeTypes(String line) { if (line != null && schema == null) { - List<AttributeType> typeList = new ArrayList<AttributeType>(); + List<AttributeType> typeList = new ArrayList<>(); Matcher matcher = getFieldSeparator().getFieldPattern().matcher(line); boolean typed = true; while (!matcher.hitEnd() && matcher.find()) { String type = matcher.group(1)!=null ? matcher.group(1) : matcher.group(2); - if (type.matches("(?i)(STRING|CHAR|VARCHAR)(\\([\\d\\.]+\\))?")) { + if (type.matches("(?i)(STRING|CHAR|VARCHAR)(\\([\\d.]+\\))?")) { typeList.add(AttributeType.STRING); } - else if (type.matches("(?i)(DOUBLE|DECIMAL|NUMERIC|FLOAT|REAL)(\\([\\d\\.]+\\))?")) { + else if (type.matches("(?i)(DOUBLE|DECIMAL|NUMERIC|FLOAT|REAL)(\\([\\d.]+\\))?")) { typeList.add(AttributeType.DOUBLE); } - else if (type.matches("(?i)(INT(EGER)?|LONG)(\\([\\d\\.]+\\))?")) { + else if (type.matches("(?i)(INT(EGER)?|LONG)(\\([\\d.]+\\))?")) { typeList.add(AttributeType.INTEGER); } else if (type.matches("(?i)(DATE|TIME)")) { @@ -456,8 +456,8 @@ return new Iterator<Feature>() { String line; - InputStream in; - BufferedReader br; + final InputStream in; + final BufferedReader br; { // Skip comment and header lines int headerSize = headerLine ? 1 : 0; @@ -644,7 +644,7 @@ writer.write("" + feature.getGeometry().getCoordinate().z); } else { - String value = null; + String value; if (feature.getSchema().getAttributeType(columns[i]) == AttributeType.GEOMETRY) { value = wktw.write(feature.getGeometry()); } else { Modified: plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/FieldSeparator.java =================================================================== --- plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/FieldSeparator.java 2020-08-05 13:45:55 UTC (rev 6370) +++ plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/FieldSeparator.java 2020-08-09 17:49:20 UTC (rev 6371) @@ -52,9 +52,10 @@ } public FieldSeparator(String sep) { - if (sep.equals("{tab}")) this.separator = '\t'; + if (sep == null) this.separator = '\t'; + else if (sep.equals("{tab}")) this.separator = '\t'; else if (sep.equals("{whitespace}")) this.separator = ' '; - else if (sep != null & sep.length() > 0) this.separator = sep.charAt(0); + else if (sep.length() > 0) this.separator = sep.charAt(0); else this.separator = '\t'; } @@ -67,9 +68,10 @@ } public void setSeparator(String sep) { - if (sep.equals("{tab}")) this.separator = '\t'; + if (sep == null) this.separator = '\t'; + else if (sep.equals("{tab}")) this.separator = '\t'; else if (sep.equals("{whitespace}")) this.separator = ' '; - else if (sep != null & sep.length() > 0) this.separator = sep.charAt(0); + else if (sep.length() > 0) this.separator = sep.charAt(0); else this.separator = '\t'; } @@ -94,7 +96,7 @@ } public String[] getFields(String line) { - List<String> tokens = new ArrayList<String>(); + List<String> tokens = new ArrayList<>(); Matcher matcher = getFieldPattern().matcher(line); while (!matcher.hitEnd() && matcher.find()) { String token = matcher.group(1)!=null ? @@ -102,7 +104,7 @@ matcher.group(2); tokens.add(token); } - return tokens.toArray(new String[tokens.size()]); + return tokens.toArray(new String[0]); } public String toString() { Modified: plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/SaveCSVFileDataSourceQueryChooser.java =================================================================== --- plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/SaveCSVFileDataSourceQueryChooser.java 2020-08-05 13:45:55 UTC (rev 6370) +++ plug-ins/CsvDriver/trunk/src/fr/michaelm/jump/drivers/csv/SaveCSVFileDataSourceQueryChooser.java 2020-08-09 17:49:20 UTC (rev 6371) @@ -53,8 +53,8 @@ } - private final JComboBox fieldSeparator = new JComboBox( - new Object[]{TABULATION,COMMA,SEMI_COLUMN,PIPE,WHITESPACE}); + private final JComboBox<FieldSeparator> fieldSeparator = new JComboBox<>( + new FieldSeparator[]{TABULATION,COMMA,SEMI_COLUMN,PIPE,WHITESPACE}); private final JComboBox<Charset> charsetChooser = new JComboBox<>(CSVDriverConfiguration.createCommonCharsetArray()); _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel