Revision: 5506 http://sourceforge.net/p/jump-pilot/code/5506 Author: michaudm Date: 2017-10-06 21:38:23 +0000 (Fri, 06 Oct 2017) Log Message: ----------- Improve string normalisation for database identifiers
Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/datastore/SQLUtil.java core/trunk/src/com/vividsolutions/jump/datastore/spatialdatabases/SpatialDatabasesDSMetadata.java Modified: core/trunk/src/com/vividsolutions/jump/datastore/SQLUtil.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/datastore/SQLUtil.java 2017-09-23 09:05:36 UTC (rev 5505) +++ core/trunk/src/com/vividsolutions/jump/datastore/SQLUtil.java 2017-10-06 21:38:23 UTC (rev 5506) @@ -5,6 +5,7 @@ import com.vividsolutions.jump.feature.AttributeType; import java.sql.Types; +import java.text.Normalizer; /** * Utililty class containing methods to manipulate SQL Strings @@ -120,14 +121,19 @@ */ public static String normalize(String name) { if (name == null) return null; + // NFKD is stronger than NFD, for example decompose single charater + // \u0308 (ffi_ligature into ffi (three letters) + name = Normalizer.normalize(name, Normalizer.Form.NFKD); + name = name.replaceAll("[\\p{InCombiningDiacriticalMarks}]", ""); StringBuilder sb = new StringBuilder(name.length()); for (int i = 0 ; i < name.length() ; i++) { char c = name.charAt(i); if(i==0) { - if (Character.isLetter(c) || c == '_') sb.append(Character.toLowerCase(c)); + if (Character.isDigit(c)) sb.append("_").append(Character.toLowerCase(c)); + else if (c < 128 && (Character.isLetter(c) || c == '_')) sb.append(Character.toLowerCase(c)); else sb.append('_'); } else { - if (Character.isLetterOrDigit(c) || c == '_') sb.append(Character.toLowerCase(c)); + if (c < 128 && (Character.isLetterOrDigit(c)) || c == '_') sb.append(Character.toLowerCase(c)); else sb.append('_'); } } Modified: core/trunk/src/com/vividsolutions/jump/datastore/spatialdatabases/SpatialDatabasesDSMetadata.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/datastore/spatialdatabases/SpatialDatabasesDSMetadata.java 2017-09-23 09:05:36 UTC (rev 5505) +++ core/trunk/src/com/vividsolutions/jump/datastore/spatialdatabases/SpatialDatabasesDSMetadata.java 2017-10-06 21:38:23 UTC (rev 5506) @@ -49,7 +49,7 @@ /** * The map of SRIDs found for these MD */ - protected Map sridMap = new HashMap(); + protected Map<String,SpatialReferenceSystemID> sridMap = new HashMap(); /** * query to get list of spatial tables from the connection. Must return @@ -498,9 +498,9 @@ * Returns the CREATE TABLE statement corresponding to this feature schema. * The statement includes column names and data types, but neither geometry * column nor primary key. - * @fSchema client feature schema - * @schemaName unquoted schema name or null to use default schema - * @tableName unquoted table name + * @param fSchema client feature schema + * @param schemaName unquoted schema name or null to use default schema + * @param tableName unquoted table name * @param normalizeColumnNames whether column names must be normalized (lowercased * and without special characters) or not */ @@ -565,8 +565,8 @@ * <p>Note 1 : In PostGIS 2.x, srid=-1 is automatically converted to srid=0 by * AddGeometryColumn function.</p> * <p>Note 2 : To stay compatible with PostGIS 1.x, last argument of - * AddGeometryColumn is omitted. As a consequence, geometry type is inserted - * a the column type rather than a constraint (new default behaviour in 2.x)</p> + * AddGeometryColumn is omitted. As a consequence, geometry type uses type modifier + * rather than constraints (new default behaviour in 2.x)</p> * <p>The geometry column name must have its final form. Attribute name normalization * is the responsability of the calling method.</p> */ @@ -592,7 +592,7 @@ * Return standard SQL data type for OpenJUMP AttributeType. * This method must be overloaded by specific database oj2dbType * @param type OpenJUMP attribute type - * @return + * @return the database datatype */ protected String getDbTypeName(AttributeType type) { if (type == AttributeType.GEOMETRY) return "varbinary"; @@ -607,13 +607,13 @@ else return "varchar"; } - /** - * Return the JDBC datatype from the native datatype. - * This method is implemented for PostgreSQL datatypes. It must be overloaded - * by specific database mapping. - * @param sqlType - * @return - */ + ///** + // * Return the JDBC datatype from the native datatype. + // * This method is implemented for PostgreSQL datatypes. It must be overloaded + // * by specific database mapping. + // * @param sqlType + // * @return + // */ //protected int getJdbcTypeFromSQL(String sqlType) { // if (sqlType.equals("character")) return Types.VARCHAR; // else if (sqlType.equals("character varying")) return Types.VARCHAR; ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel