[Schmitzm-commits] r1295 - in trunk: src/skrueger src/skrueger/geotools/io src_junit/skrueger/geotools/io
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Nov 22 16:10:01 CET 2010
Author: alfonx
Date: 2010-11-22 16:09:59 +0100 (Mon, 22 Nov 2010)
New Revision: 1295
Added:
trunk/src/skrueger/AbstractServerList.java
trunk/src/skrueger/geotools/io/AbstractGTServerSettings.java
trunk/src/skrueger/geotools/io/GsServerList.java
trunk/src/skrueger/geotools/io/GtDbServerSettings.java
trunk/src/skrueger/geotools/io/GtWfsServerSettings.java
trunk/src_junit/skrueger/geotools/io/GsServerListTest.java
trunk/src_junit/skrueger/geotools/io/GsServerSettingsTest.java
trunk/src_junit/skrueger/geotools/io/GtDbServerSettingsTest.java
trunk/src_junit/skrueger/geotools/io/GtWfsServerSettingsTest.java
Removed:
trunk/src/skrueger/AbstractSeverList.java
trunk/src/skrueger/geotools/io/DbServerSettings.java
trunk/src/skrueger/geotools/io/WfsServerSettings.java
trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java
trunk/src_junit/skrueger/geotools/io/WfsServerSettingsTest.java
Modified:
trunk/src/skrueger/ServerList.java
trunk/src/skrueger/geotools/io/DbServerList.java
trunk/src/skrueger/geotools/io/DbSettingsJComboBox.java
trunk/src/skrueger/geotools/io/GsServerSettings.java
trunk/src/skrueger/geotools/io/ServerSettings.java
trunk/src/skrueger/geotools/io/WfsServerList.java
trunk/src/skrueger/geotools/io/WfsSettingsJComboBox.java
trunk/src_junit/skrueger/geotools/io/DbServerListTest.java
trunk/src_junit/skrueger/geotools/io/DbSettingsJComboBoxTest.java
trunk/src_junit/skrueger/geotools/io/WfsServerListTest.java
trunk/src_junit/skrueger/geotools/io/WfsSettingsJComboBoxTest.java
Log:
Refactored ServerSettings and ServerList classes in schmitzm for more usablility ;-)
Copied: trunk/src/skrueger/AbstractServerList.java (from rev 1292, trunk/src/skrueger/AbstractSeverList.java)
===================================================================
--- trunk/src/skrueger/AbstractSeverList.java 2010-11-22 10:39:13 UTC (rev 1292)
+++ trunk/src/skrueger/AbstractServerList.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,88 @@
+package skrueger;
+
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+
+import org.jfree.util.Log;
+
+import skrueger.geotools.io.GtDbServerSettings;
+import skrueger.geotools.io.ServerSettings;
+
+abstract public class AbstractServerList<T extends ServerSettings> extends
+ ArrayList<T> implements ServerList<T> {
+ /**
+ * Character used to separate the parameters when serializing settings to a
+ * String
+ */
+ public static final String DELIMITER = "@";
+
+ public AbstractServerList(T... wfss) {
+ for (T wfs : wfss) {
+ add(wfs);
+ }
+ }
+
+ public AbstractServerList(String propertiesString) {
+ parsePropertiesString(propertiesString);
+ }
+
+ /**
+ * @return transforms the settings to a String that can be stored in a
+ * .properties line. @see #parsePropertiesString
+ * @throws MalformedURLException
+ */
+ @Override
+ public final boolean parsePropertiesString(String propString) {
+
+ if (propString == null)
+ return false;
+
+ String[] split = propString.split(Pattern.quote(DELIMITER));
+
+ for (String s : split) {
+ try {
+ T dbServer = newInstance();
+ dbServer.parsePropertiesString(s);
+
+ if (dbServer == null) {
+ Log.error("Could not import a "
+ + GtDbServerSettings.class.getSimpleName()
+ + ". Ignoring it.");
+ } else
+ add(dbServer);
+ } catch (Exception e) {
+ Log.error(
+ "Could not import a "
+ + GtDbServerSettings.class.getSimpleName()
+ + ". Ignoring it.", e);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ protected abstract T newInstance();
+
+ /**
+ * @return transforms the settings to a String that can be stored in a
+ * .properties line. @see #parsePropertiesString
+ */
+ public final String toPropertiesString() {
+
+ StringBuffer serialized = new StringBuffer(100);
+
+ for (T wfs : this) {
+ serialized.append(wfs.toPropertiesString());
+ serialized.append(DELIMITER);
+ }
+
+ return serialized.toString();
+ }
+
+ @Override
+ public boolean add(T e) {
+ return super.add(e);
+ }
+}
Property changes on: trunk/src/skrueger/AbstractServerList.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/skrueger/AbstractSeverList.java
===================================================================
--- trunk/src/skrueger/AbstractSeverList.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/AbstractSeverList.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,12 +0,0 @@
-package skrueger;
-
-import java.util.ArrayList;
-
-abstract public class AbstractSeverList<T> extends ArrayList<T> implements ServerList{
- /**
- * Character used to separate the parameters when serializing settings to a
- * String
- */
- public static final String DELIMITER = "@";
-
-}
Modified: trunk/src/skrueger/ServerList.java
===================================================================
--- trunk/src/skrueger/ServerList.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/ServerList.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,10 +1,14 @@
package skrueger;
+import skrueger.geotools.io.ServerSettings;
-public interface ServerList {
+public interface ServerList<T extends ServerSettings> {
+
String toPropertiesString();
boolean parsePropertiesString(String propString);
+
+ boolean add(T server);
}
Copied: trunk/src/skrueger/geotools/io/AbstractGTServerSettings.java (from rev 1292, trunk/src/skrueger/geotools/io/ServerSettings.java)
===================================================================
--- trunk/src/skrueger/geotools/io/ServerSettings.java 2010-11-22 10:39:13 UTC (rev 1292)
+++ trunk/src/skrueger/geotools/io/AbstractGTServerSettings.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,57 @@
+package skrueger.geotools.io;
+
+import java.util.HashMap;
+
+public abstract class AbstractGTServerSettings<T1, T2> extends HashMap<T1, T2>
+ implements ServerSettings {
+
+ public AbstractGTServerSettings(String propString) {
+ parsePropertiesString(propString);
+ }
+
+ public AbstractGTServerSettings() {
+ }
+
+ static Integer intOrNull(String string) {
+ if (string == null)
+ return null;
+ if (string.equals("null"))
+ return null;
+ return Integer.parseInt(string);
+ }
+
+ /**
+ * Character used to separate the parameters when serializing settings to a
+ * String
+ */
+ protected static final String DELIMITER = "|";
+
+ private String title;
+
+ static String stringOrNull(String string) {
+ if (string == null)
+ return null;
+ if (string.equals("null"))
+ return null;
+ return string;
+ }
+
+ public void setTitle(String title) {
+ if (title != null) {
+ if (title.contains(DELIMITER))
+ throw new IllegalArgumentException("Title may not contain "
+ + DELIMITER);
+ if (title.contains(WfsServerList.DELIMITER))
+ throw new IllegalArgumentException("Title may not contain "
+ + WfsServerList.DELIMITER);
+ }
+ this.title = title;
+ }
+
+ public String getTitle() {
+ if (title == null)
+ return toString();
+ return title;
+ }
+
+}
Property changes on: trunk/src/skrueger/geotools/io/AbstractGTServerSettings.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Modified: trunk/src/skrueger/geotools/io/DbServerList.java
===================================================================
--- trunk/src/skrueger/geotools/io/DbServerList.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/DbServerList.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,78 +1,23 @@
package skrueger.geotools.io;
-import java.net.MalformedURLException;
-import java.util.regex.Pattern;
+import skrueger.AbstractServerList;
-import org.jfree.util.Log;
-
-import skrueger.AbstractSeverList;
-
/**
- * A list of {@link DbServerSettings}.
+ * A list of {@link GtDbServerSettings}.
*/
-public class DbServerList extends AbstractSeverList<DbServerSettings> {
+public class DbServerList extends AbstractServerList<GtDbServerSettings> {
- public DbServerList(DbServerSettings... wfss) {
- for (DbServerSettings wfs : wfss) {
- add(wfs);
- }
+ public DbServerList(GtDbServerSettings... settings) {
+ super(settings);
}
public DbServerList(String propertiesString) {
parsePropertiesString(propertiesString);
}
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- */
@Override
- public String toPropertiesString() {
-
- StringBuffer serialized = new StringBuffer(100);
-
- for (DbServerSettings wfs : this) {
- serialized.append(wfs.toPropertiesString());
- serialized.append(DELIMITER);
- }
-
- return serialized.toString();
+ protected GtDbServerSettings newInstance() {
+ return new GtDbServerSettings();
}
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- * @throws MalformedURLException
- */
- @Override
- public boolean parsePropertiesString(String propString) {
- // DbServerList wfsServerList = new DbServerList();
-
- if (propString == null)
- return false;
-
- String[] split = propString.split(Pattern.quote(DELIMITER));
-
- for (String s : split) {
- try {
- DbServerSettings dbServer = new DbServerSettings(s);
- if (dbServer == null) {
- Log.error("Could not import a "
- + DbServerSettings.class.getSimpleName()
- + ". Ignoring it.");
- } else
- add(dbServer);
- } catch (Exception e) {
- Log.error(
- "Could not import a "
- + DbServerSettings.class.getSimpleName()
- + ". Ignoring it.", e);
- return false;
- }
- }
-
- return true;
-
- // return wfsServerList;
- }
}
Deleted: trunk/src/skrueger/geotools/io/DbServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/DbServerSettings.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/DbServerSettings.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,473 +0,0 @@
-package skrueger.geotools.io;
-
-import java.awt.Component;
-import java.net.MalformedURLException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-import org.geotools.data.postgis.PostgisNGDataStoreFactory;
-import org.geotools.jdbc.JDBCDataStore;
-import org.geotools.jdbc.JDBCDataStoreFactory;
-import org.jfree.util.Log;
-
-import schmitzm.swing.BooleanInputOption;
-import schmitzm.swing.ManualInputOption;
-import schmitzm.swing.ManualInputOption.Integer;
-import schmitzm.swing.ManualInputOption.PasswordViewable;
-import schmitzm.swing.ManualInputOption.Text;
-import schmitzm.swing.MultipleOptionPane;
-import schmitzm.swing.SelectionInputOption;
-import schmitzm.swing.SelectionInputOption.Combo;
-import skrueger.db.PGUtil;
-
-/**
- * This class describes all settings needed to connect to a WFS server. This
- * class extends a {@link HashMap} and contains two groups of keys:<br/>
- * The first group of keys, are all keys provided by Geotools to create a WFS
- * datastore, like: {@link JDBCDataStore#SCHEMA} .<br/>
- * The second group are additional keys defined in the enum
- * {@link DbServerSettings.Key}.<br/>
- * This class can serialize all important parameters needed to define the
- * connection into a {@link String} with {@link #toPropertiesString()} and
- * re-import the String with {@link #parsePropertiesString(String)}.
- */
-public class DbServerSettings extends ServerSettings<Object, Object> {
-
- Logger log = Logger.getLogger(DbServerSettings.class);
-
- public enum DbType {
- postgis("postgresql");
-
- private final String protocolString;
-
- DbType(String protocolString) {
- this.protocolString = protocolString;
- }
-
- public String getProtocolString() {
- return protocolString;
- };
- }
-
- /**
- * params.put(JDBCDataStoreFactory.DBTYPE.key, "postgis");
- * params.put(JDBCDataStoreFactory.HOST.key, host); // the name or ip
- * params.put(JDBCDataStoreFactory.PORT.key, port); // the port that
- *
- * params.put(JDBCDataStoreFactory.DATABASE.key, database); // the
- *
- * // name params.put(JDBCDataStoreFactory.USER.key, username); // the user
- * to params.put(JDBCDataStoreFactory.PASSWD.key, password); // the
- *
- * params.put(JDBCDataStoreFactory.SCHEMA, schema);
- *
- * params.put(JDBCDataStoreFactory.EXPOSE_PK.key, true); *
- */
-
- public enum Key {
- }
-
- private static Connection dbc;
-
- /**
- * Opens a GUI that asks the use define a DB connection.
- *
- * @param dbServer
- * <code>null</code> to create a new instance, or an instance to
- * edit.
- * @return <code>null</code> if the user cancelled the creation of a new
- * {@link DbServerSettings}, otherwise the edited instance.
- */
- public static DbServerSettings createOrEdit(Component owner,
- DbServerSettings dbServer) {
- boolean newCreated = false;
-
- if (dbServer == null) {
- newCreated = true;
- dbServer = new DbServerSettings(DbType.postgis);
- }
-
- Combo<DbType> dpTypeInput = new SelectionInputOption.Combo<DbType>(
- "Database type", true, DbType.values(), ArrayUtils.indexOf(
- DbType.values(), dbServer.getDbType()), DbType.values());
-
- Text hostInput = new ManualInputOption.Text("Hostname", true,
- dbServer.getHost());
-
- Integer portInput = new ManualInputOption.Integer("Port", true,
- dbServer.getPort());
-
- Text databaseInput = new ManualInputOption.Text("Database", true,
- dbServer.getDatabase());
-
- Text schemaInput = new ManualInputOption.Text("Schema", true,
- dbServer.getSchema());
-
- Text userInput = new ManualInputOption.Text("Username", true,
- dbServer.getUsername());
-
- PasswordViewable passwdInput = new ManualInputOption.PasswordViewable(
- "Password", true, dbServer.getPassword());
-
- BooleanInputOption exposePkInput = new BooleanInputOption(
- "Expose primary keys", dbServer.getExposePrimaryKey());
-
- Object[] input = MultipleOptionPane.showMultipleInputDialog(owner,
- "DB Connection paramters", dpTypeInput, hostInput, portInput,
- databaseInput, schemaInput, userInput, passwdInput,
- exposePkInput);
-
- if (input == null) {
- if (newCreated)
- return null;
- else
- return dbServer;
- } else {
- dbServer.setDbType((DbType) input[0]);
- dbServer.setHost((String) input[1]);
- dbServer.setPort((java.lang.Integer) input[2]);
- dbServer.setDatabase((String) input[3]);
- dbServer.setSchema((String) input[4]);
- dbServer.setUsername((String) input[5]);
- dbServer.setPassword(String.valueOf((char[]) input[6]));
- dbServer.setExposePrimaryKey((Boolean) input[7]);
- }
-
- return dbServer;
-
- }
-
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- * @throws MalformedURLException
- */
- @Override
- public boolean parsePropertiesString(String propString)
- throws MalformedURLException {
-
- if (propString == null || propString.isEmpty())
- throw new IllegalArgumentException("parameter to parse was empty");
- try {
-
- String[] split = propString.split(Pattern.quote(DELIMITER));
-
- int i = 0;
- setDbType( DbType.valueOf(split[i++]));
-// DbServerSettings dbServer = new DbServerSettings(
-// DbType.valueOf(split[i++])
-// );
-
- setTitle(split[i++]);
- setHost(split[i++]);
- setPort(java.lang.Integer.valueOf(split[i++]));
- setUsername(StringUtils.stripToNull(split[i++]));
- setPassword(split[i++]);
- setDatabase(split[i++]);
- setExposePrimaryKey(Boolean.valueOf(split[i++]));
- setSchema(stringOrNull(split[i++]));
-
- return true;
- } catch (Exception e) {
- Log.warn("couldn't parse " + propString, e);
- return false;
- }
- }
-
- private String[] cachedTypeNames = null;
- private String[] cachedGeometryTableNames;
-
- public DbServerSettings() {
- this(DbType.postgis);
-
- }
-
- public DbServerSettings(DbType dbType) {
- setDbType(dbType);
- setHost("localhost");
- setSchema("public");
- put(JDBCDataStoreFactory.PK_METADATA_TABLE.key, null);
- }
-
- public DbServerSettings(String propertiesString) {
- try {
- parsePropertiesString(propertiesString);
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- public String[] getCachedTypeNames() {
- return cachedTypeNames;
- }
-
- public String getDatabase() {
- return (String) get(JDBCDataStoreFactory.DATABASE.key);
- }
-
- public DbType getDbType() {
- String dbt = (String) get(PostgisNGDataStoreFactory.DBTYPE.key);
- if (dbt != null)
- return DbType.valueOf(dbt);
- return null;
- }
-
- public Boolean getExposePrimaryKey() {
- Boolean expk = (Boolean) get(JDBCDataStoreFactory.EXPOSE_PK.key);
- if (expk == null)
- return (Boolean) JDBCDataStoreFactory.EXPOSE_PK.sample;
- return expk;
- }
-
- public String getHost() {
- return (String) get(JDBCDataStoreFactory.HOST.key);
- }
-
- public String getPassword() {
- return (String) get(JDBCDataStoreFactory.PASSWD.key);
- }
-
- public java.lang.Integer getPort() {
- java.lang.Integer port = (java.lang.Integer) get(JDBCDataStoreFactory.PORT.key);
- if (port == null)
- return (java.lang.Integer) JDBCDataStoreFactory.PORT.sample;
- return port;
- }
-
- public String getSchema() {
- return (String) get(JDBCDataStoreFactory.SCHEMA.key);
- }
-
- public String getUsername() {
- return (String) get(JDBCDataStoreFactory.USER.key);
- }
-
- /**
- * @return <code>true</code>, if all parameters look OK, without actually
- * opening any connection.
- */
- public boolean isWellDefined() {
- if (getDbType() == null)
- return false;
-
- if (getHost() == null)
- return false;
-
- if (getUsername() == null)
- return false;
-
- if (getPassword() == null)
- return false;
-
- if (getPort() == null)
- return false;
-
- if (getSchema() == null)
- return false;
-
- return true;
- }
-
- public void setCachedTypeNames(String[] cachedTypeNames) {
- this.cachedTypeNames = cachedTypeNames;
- }
-
- public void setDatabase(String db) {
- put(JDBCDataStoreFactory.DATABASE.key, db);
- }
-
- public void setDbType(DbType dbType) {
- put(PostgisNGDataStoreFactory.DBTYPE.key, dbType.toString());
-
- if (dbType == DbType.postgis) {
- if (getPort() == null) {
- // For a PostGIS DBMS automatically set the port to 5432
- setPort(5432);
- }
- if (getUsername() == null) {
- // For a PostGIS DBMS automatically set the user to postgres
- setUsername("postgres");
- }
-
- }
-
- }
-
- public void setExposePrimaryKey(Boolean exportPk) {
- put(JDBCDataStoreFactory.EXPOSE_PK.key, exportPk);
- }
-
- public void setHost(String host) {
- put(JDBCDataStoreFactory.HOST.key, host);
- }
-
- public void setPassword(String password) {
- put(JDBCDataStoreFactory.PASSWD.key, password);
- }
-
- public void setPort(java.lang.Integer port) {
- put(JDBCDataStoreFactory.PORT.key, port);
- }
-
- public void setSchema(String schema) {
- put(JDBCDataStoreFactory.SCHEMA.key, schema);
- }
-
- public void setUsername(String username) {
- put(JDBCDataStoreFactory.USER.key, username);
- }
-
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- */
- public String toPropertiesString() {
-
- StringBuffer serialized = new StringBuffer(100);
-
- serialized.append(getDbType().toString());
- serialized.append(DELIMITER);
-
- serialized.append(getTitle());
- serialized.append(DELIMITER);
-
- serialized.append(getHost());
- serialized.append(DELIMITER);
-
- serialized.append(getPort().toString());
- serialized.append(DELIMITER);
-
- serialized.append(getUsername());
- serialized.append(DELIMITER);
-
- serialized.append(getPassword());
- serialized.append(DELIMITER);
-
- serialized.append(getDatabase());
- serialized.append(DELIMITER);
-
- serialized.append(getExposePrimaryKey().toString());
- serialized.append(DELIMITER);
-
- serialized.append(getSchema().toString());
- // serialized.append(DELIMITER);
-
- return serialized.toString();
- }
-
- @Override
- public String toString() {
-
- StringBuffer s = new StringBuffer();
-
- if (getDbType() != null) {
- s.append(getDbType().getProtocolString() + "://");
- }
-
- s.append(getHost());
-
- if (getPort() != null && getPort() != 5432) {
- s.append(":" + getPort());
- }
-
- s.append("/" + getDatabase());
-
- return s.toString();
- }
-
- /**
- * returns a valid Connection to our postgresql Database. Name of database,
- * username and password must be provided.
- *
- * @param database
- * name of the database
- * @param username
- * a valid username
- * @param password
- * valid password
- * @return database connection
- * @throws SQLException
- * @throws ClassNotFoundException
- */
- public Connection getDatabaseConnection() {
-
- try {
-
- if (dbc == null || dbc.isClosed()) {
- dbc = createNewDatabaseConnection();
- }
- return dbc;
- } catch (Exception e) {
- return null;
- }
- }
-
- private Connection createNewDatabaseConnection() throws SQLException {
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
- String url = "jdbc:postgresql://" + getHost()
- // + (":" + PropertyUtils.getDbPort())
- + ("/" + getDatabase());
-
- String password = getPassword();
- String username = getUsername();
-
- // log.debug("DB URL: " + url + " u=" + username + " p="
- // + password);
-
- return DriverManager.getConnection(url, username, password);
- }
-
- public String[] getDescribedTablesWithGeometry() {
-
- if (cachedGeometryTableNames == null) {
-
- Connection dc;
- try {
- dc = createNewDatabaseConnection();
- try {
-
- cachedGeometryTableNames = PGUtil
- .getColumnsDescribedInGeometryColumnsTable(dc
- .createStatement());
-
- } catch (SQLException e) {
- log.error(e, e);
- } finally {
- dc.close();
- }
- } catch (SQLException e1) {
- log.error(e1, e1);
- return new String[0];
- }
- }
- return cachedGeometryTableNames;
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- dispose();
- }
-
- public void dispose() {
- try {
- if (dbc != null && !dbc.isClosed()) {
- dbc.close();
- dbc = null;
- }
- } catch (SQLException e) {
- log.error("Error while disposing the database connection to "
- + toString(), e);
- }
- }
-}
\ No newline at end of file
Modified: trunk/src/skrueger/geotools/io/DbSettingsJComboBox.java
===================================================================
--- trunk/src/skrueger/geotools/io/DbSettingsJComboBox.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/DbSettingsJComboBox.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -8,7 +8,7 @@
private final DbServerList dbList;
public DbSettingsJComboBox(DbServerList wfsList) {
- super(wfsList.toArray(new DbServerSettings[0]));
+ super(wfsList.toArray(new GtDbServerSettings[0]));
this.dbList = wfsList;
}
@@ -17,7 +17,7 @@
}
public void listChanged() {
- setModel(new DefaultComboBoxModel(dbList.toArray(new DbServerSettings[0])));
+ setModel(new DefaultComboBoxModel(dbList.toArray(new GtDbServerSettings[0])));
}
}
Added: trunk/src/skrueger/geotools/io/GsServerList.java
===================================================================
--- trunk/src/skrueger/geotools/io/GsServerList.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/GsServerList.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,22 @@
+package skrueger.geotools.io;
+
+import skrueger.AbstractServerList;
+
+/**
+ * A list of {@link GtWfsServerSettings}.
+ */
+public class GsServerList extends AbstractServerList<GsServerSettings> {
+
+ public GsServerList(GsServerSettings... wfss) {
+ super(wfss);
+ }
+
+ public GsServerList(String propertiesString) {
+ super(propertiesString);
+ }
+
+ @Override
+ protected GsServerSettings newInstance() {
+ return new GsServerSettings();
+ }
+}
Property changes on: trunk/src/skrueger/geotools/io/GsServerList.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/skrueger/geotools/io/GsServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/GsServerSettings.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/GsServerSettings.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,34 +1,52 @@
package skrueger.geotools.io;
-import java.net.MalformedURLException;
import java.util.HashMap;
+import java.util.regex.Pattern;
+import org.apache.commons.lang.StringUtils;
+import org.jfree.util.Log;
+
/**
- * This class describes all settings needed to connect to a Geoserver server via REST configuration. This
- * class extends a {@link HashMap} and contains two groups of keys:<br/>
- * The first group of keys, are all keys provided by Geotools to create a WFS
- * <br/>
+ * This class describes all settings needed to connect to a Geoserver server via
+ * REST configuration. This class extends a {@link HashMap} and contains two
+ * groups of keys:<br/>
+ * The first group of keys, are all keys provided by Geotools to create a WFS <br/>
* This class can serialize all important parameters needed to define the
* connection into a {@link String} with {@link #toPropertiesString()} and
* re-import the String with {@link #parsePropertiesString(String)}.
*/
-public class GsServerSettings extends ServerSettings<Void, Void> {
+public class GsServerSettings extends AbstractGTServerSettings<Void, Void> {
- @Override
- public String toPropertiesString() {
- // TODO Auto-generated method stub
- return null;
+ public GsServerSettings() {
}
+ public GsServerSettings(String s) {
+ super(s);
+ }
+
@Override
- public boolean parsePropertiesString(String propString)
- throws MalformedURLException {
- // TODO Auto-generated method stub
- return false;
+ public boolean parsePropertiesString(String propString) {
+ if (propString == null || propString.isEmpty())
+ return false;
+ try {
+
+ String[] split = propString.split(Pattern.quote(DELIMITER));
+
+ int i = 0;
+ setUrl(split[i++]);
+ setTitle(split[i++]);
+ setUsername(StringUtils.stripToNull(split[i++]));
+ setPassword(split[i++]);
+
+ return true;
+ } catch (Exception e) {
+ Log.warn("couldn't parse " + propString, e);
+ return false;
+ }
}
-
String url;
+
public String getUrl() {
return url;
}
@@ -53,8 +71,25 @@
this.password = password;
}
-
String username;
String password;
+ @Override
+ public String toPropertiesString() {
+ StringBuffer serialized = new StringBuffer(100);
+
+ serialized.append(getUrl());
+ serialized.append(DELIMITER);
+
+ serialized.append(getTitle());
+ serialized.append(DELIMITER);
+
+ serialized.append(getUsername());
+ serialized.append(DELIMITER);
+
+ serialized.append(getPassword());
+ serialized.append(DELIMITER);
+
+ return serialized.toString();
+ }
}
Copied: trunk/src/skrueger/geotools/io/GtDbServerSettings.java (from rev 1292, trunk/src/skrueger/geotools/io/DbServerSettings.java)
===================================================================
--- trunk/src/skrueger/geotools/io/DbServerSettings.java 2010-11-22 10:39:13 UTC (rev 1292)
+++ trunk/src/skrueger/geotools/io/GtDbServerSettings.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,468 @@
+package skrueger.geotools.io;
+
+import java.awt.Component;
+import java.net.MalformedURLException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.geotools.data.postgis.PostgisNGDataStoreFactory;
+import org.geotools.jdbc.JDBCDataStore;
+import org.geotools.jdbc.JDBCDataStoreFactory;
+import org.jfree.util.Log;
+
+import schmitzm.swing.BooleanInputOption;
+import schmitzm.swing.ManualInputOption;
+import schmitzm.swing.ManualInputOption.Integer;
+import schmitzm.swing.ManualInputOption.PasswordViewable;
+import schmitzm.swing.ManualInputOption.Text;
+import schmitzm.swing.MultipleOptionPane;
+import schmitzm.swing.SelectionInputOption;
+import schmitzm.swing.SelectionInputOption.Combo;
+import skrueger.db.PGUtil;
+
+/**
+ * This class describes all settings needed to connect to a WFS server. This
+ * class extends a {@link HashMap} and contains two groups of keys:<br/>
+ * The first group of keys, are all keys provided by Geotools to create a WFS
+ * datastore, like: {@link JDBCDataStore#SCHEMA} .<br/>
+ * The second group are additional keys defined in the enum
+ * {@link GtDbServerSettings.Key}.<br/>
+ * This class can serialize all important parameters needed to define the
+ * connection into a {@link String} with {@link #toPropertiesString()} and
+ * re-import the String with {@link #parsePropertiesString(String)}.
+ */
+public class GtDbServerSettings extends AbstractGTServerSettings<Object, Object> {
+
+ Logger log = Logger.getLogger(GtDbServerSettings.class);
+
+ public enum DbType {
+ postgis("postgresql");
+
+ private final String protocolString;
+
+ DbType(String protocolString) {
+ this.protocolString = protocolString;
+ }
+
+ public String getProtocolString() {
+ return protocolString;
+ };
+ }
+
+ /**
+ * params.put(JDBCDataStoreFactory.DBTYPE.key, "postgis");
+ * params.put(JDBCDataStoreFactory.HOST.key, host); // the name or ip
+ * params.put(JDBCDataStoreFactory.PORT.key, port); // the port that
+ *
+ * params.put(JDBCDataStoreFactory.DATABASE.key, database); // the
+ *
+ * // name params.put(JDBCDataStoreFactory.USER.key, username); // the user
+ * to params.put(JDBCDataStoreFactory.PASSWD.key, password); // the
+ *
+ * params.put(JDBCDataStoreFactory.SCHEMA, schema);
+ *
+ * params.put(JDBCDataStoreFactory.EXPOSE_PK.key, true); *
+ */
+
+ public enum Key {
+ }
+
+ private static Connection dbc;
+
+ /**
+ * Opens a GUI that asks the use define a DB connection.
+ *
+ * @param dbServer
+ * <code>null</code> to create a new instance, or an instance to
+ * edit.
+ * @return <code>null</code> if the user cancelled the creation of a new
+ * {@link GtDbServerSettings}, otherwise the edited instance.
+ */
+ public static GtDbServerSettings createOrEdit(Component owner,
+ GtDbServerSettings dbServer) {
+ boolean newCreated = false;
+
+ if (dbServer == null) {
+ newCreated = true;
+ dbServer = new GtDbServerSettings(DbType.postgis);
+ }
+
+ Combo<DbType> dpTypeInput = new SelectionInputOption.Combo<DbType>(
+ "Database type", true, DbType.values(), ArrayUtils.indexOf(
+ DbType.values(), dbServer.getDbType()), DbType.values());
+
+ Text hostInput = new ManualInputOption.Text("Hostname", true,
+ dbServer.getHost());
+
+ Integer portInput = new ManualInputOption.Integer("Port", true,
+ dbServer.getPort());
+
+ Text databaseInput = new ManualInputOption.Text("Database", true,
+ dbServer.getDatabase());
+
+ Text schemaInput = new ManualInputOption.Text("Schema", true,
+ dbServer.getSchema());
+
+ Text userInput = new ManualInputOption.Text("Username", true,
+ dbServer.getUsername());
+
+ PasswordViewable passwdInput = new ManualInputOption.PasswordViewable(
+ "Password", true, dbServer.getPassword());
+
+ BooleanInputOption exposePkInput = new BooleanInputOption(
+ "Expose primary keys", dbServer.getExposePrimaryKey());
+
+ Object[] input = MultipleOptionPane.showMultipleInputDialog(owner,
+ "DB Connection paramters", dpTypeInput, hostInput, portInput,
+ databaseInput, schemaInput, userInput, passwdInput,
+ exposePkInput);
+
+ if (input == null) {
+ if (newCreated)
+ return null;
+ else
+ return dbServer;
+ } else {
+ dbServer.setDbType((DbType) input[0]);
+ dbServer.setHost((String) input[1]);
+ dbServer.setPort((java.lang.Integer) input[2]);
+ dbServer.setDatabase((String) input[3]);
+ dbServer.setSchema((String) input[4]);
+ dbServer.setUsername((String) input[5]);
+ dbServer.setPassword(String.valueOf((char[]) input[6]));
+ dbServer.setExposePrimaryKey((Boolean) input[7]);
+ }
+
+ return dbServer;
+
+ }
+
+ /**
+ * @return transforms the settings to a String that can be stored in a
+ * .properties line. @see #parsePropertiesString
+ * @throws MalformedURLException
+ */
+ @Override
+ public boolean parsePropertiesString(String propString) {
+
+ if (propString == null || propString.isEmpty())
+ return false;
+ try {
+
+ String[] split = propString.split(Pattern.quote(DELIMITER));
+
+ int i = 0;
+ setDbType(DbType.valueOf(split[i++]));
+ // DbServerSettings dbServer = new DbServerSettings(
+ // DbType.valueOf(split[i++])
+ // );
+
+ setTitle(split[i++]);
+ setHost(split[i++]);
+ setPort(java.lang.Integer.valueOf(split[i++]));
+ setUsername(StringUtils.stripToNull(split[i++]));
+ setPassword(split[i++]);
+ setDatabase(split[i++]);
+ setExposePrimaryKey(Boolean.valueOf(split[i++]));
+ setSchema(stringOrNull(split[i++]));
+
+ return true;
+ } catch (Exception e) {
+ Log.warn("couldn't parse " + propString, e);
+ return false;
+ }
+ }
+
+ private String[] cachedTypeNames = null;
+ private String[] cachedGeometryTableNames;
+
+ public GtDbServerSettings() {
+ this(DbType.postgis);
+
+ }
+
+ public GtDbServerSettings(DbType dbType) {
+ setDbType(dbType);
+ setHost("localhost");
+ setSchema("public");
+ put(JDBCDataStoreFactory.PK_METADATA_TABLE.key, null);
+ }
+
+ public GtDbServerSettings(String propertiesString) {
+ parsePropertiesString(propertiesString);
+ }
+
+ public String[] getCachedTypeNames() {
+ return cachedTypeNames;
+ }
+
+ public String getDatabase() {
+ return (String) get(JDBCDataStoreFactory.DATABASE.key);
+ }
+
+ public DbType getDbType() {
+ String dbt = (String) get(PostgisNGDataStoreFactory.DBTYPE.key);
+ if (dbt != null)
+ return DbType.valueOf(dbt);
+ return null;
+ }
+
+ public Boolean getExposePrimaryKey() {
+ Boolean expk = (Boolean) get(JDBCDataStoreFactory.EXPOSE_PK.key);
+ if (expk == null)
+ return (Boolean) JDBCDataStoreFactory.EXPOSE_PK.sample;
+ return expk;
+ }
+
+ public String getHost() {
+ return (String) get(JDBCDataStoreFactory.HOST.key);
+ }
+
+ public String getPassword() {
+ return (String) get(JDBCDataStoreFactory.PASSWD.key);
+ }
+
+ public java.lang.Integer getPort() {
+ java.lang.Integer port = (java.lang.Integer) get(JDBCDataStoreFactory.PORT.key);
+ if (port == null)
+ return (java.lang.Integer) JDBCDataStoreFactory.PORT.sample;
+ return port;
+ }
+
+ public String getSchema() {
+ return (String) get(JDBCDataStoreFactory.SCHEMA.key);
+ }
+
+ public String getUsername() {
+ return (String) get(JDBCDataStoreFactory.USER.key);
+ }
+
+ /**
+ * @return <code>true</code>, if all parameters look OK, without actually
+ * opening any connection.
+ */
+ public boolean isWellDefined() {
+ if (getDbType() == null)
+ return false;
+
+ if (getHost() == null)
+ return false;
+
+ if (getUsername() == null)
+ return false;
+
+ if (getPassword() == null)
+ return false;
+
+ if (getPort() == null)
+ return false;
+
+ if (getSchema() == null)
+ return false;
+
+ return true;
+ }
+
+ public void setCachedTypeNames(String[] cachedTypeNames) {
+ this.cachedTypeNames = cachedTypeNames;
+ }
+
+ public void setDatabase(String db) {
+ put(JDBCDataStoreFactory.DATABASE.key, db);
+ }
+
+ public void setDbType(DbType dbType) {
+ put(PostgisNGDataStoreFactory.DBTYPE.key, dbType.toString());
+
+ if (dbType == DbType.postgis) {
+ if (getPort() == null) {
+ // For a PostGIS DBMS automatically set the port to 5432
+ setPort(5432);
+ }
+ if (getUsername() == null) {
+ // For a PostGIS DBMS automatically set the user to postgres
+ setUsername("postgres");
+ }
+
+ }
+
+ }
+
+ public void setExposePrimaryKey(Boolean exportPk) {
+ put(JDBCDataStoreFactory.EXPOSE_PK.key, exportPk);
+ }
+
+ public void setHost(String host) {
+ put(JDBCDataStoreFactory.HOST.key, host);
+ }
+
+ public void setPassword(String password) {
+ put(JDBCDataStoreFactory.PASSWD.key, password);
+ }
+
+ public void setPort(java.lang.Integer port) {
+ put(JDBCDataStoreFactory.PORT.key, port);
+ }
+
+ public void setSchema(String schema) {
+ put(JDBCDataStoreFactory.SCHEMA.key, schema);
+ }
+
+ public void setUsername(String username) {
+ put(JDBCDataStoreFactory.USER.key, username);
+ }
+
+ /**
+ * @return transforms the settings to a String that can be stored in a
+ * .properties line. @see #parsePropertiesString
+ */
+ public String toPropertiesString() {
+
+ StringBuffer serialized = new StringBuffer(100);
+
+ serialized.append(getDbType().toString());
+ serialized.append(DELIMITER);
+
+ serialized.append(getTitle());
+ serialized.append(DELIMITER);
+
+ serialized.append(getHost());
+ serialized.append(DELIMITER);
+
+ serialized.append(getPort().toString());
+ serialized.append(DELIMITER);
+
+ serialized.append(getUsername());
+ serialized.append(DELIMITER);
+
+ serialized.append(getPassword());
+ serialized.append(DELIMITER);
+
+ serialized.append(getDatabase());
+ serialized.append(DELIMITER);
+
+ serialized.append(getExposePrimaryKey().toString());
+ serialized.append(DELIMITER);
+
+ serialized.append(getSchema().toString());
+ // serialized.append(DELIMITER);
+
+ return serialized.toString();
+ }
+
+ @Override
+ public String toString() {
+
+ StringBuffer s = new StringBuffer();
+
+ if (getDbType() != null) {
+ s.append(getDbType().getProtocolString() + "://");
+ }
+
+ s.append(getHost());
+
+ if (getPort() != null && getPort() != 5432) {
+ s.append(":" + getPort());
+ }
+
+ s.append("/" + getDatabase());
+
+ return s.toString();
+ }
+
+ /**
+ * returns a valid Connection to our postgresql Database. Name of database,
+ * username and password must be provided.
+ *
+ * @param database
+ * name of the database
+ * @param username
+ * a valid username
+ * @param password
+ * valid password
+ * @return database connection
+ * @throws SQLException
+ * @throws ClassNotFoundException
+ */
+ public Connection getDatabaseConnection() {
+
+ try {
+
+ if (dbc == null || dbc.isClosed()) {
+ dbc = createNewDatabaseConnection();
+ }
+ return dbc;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ private Connection createNewDatabaseConnection() throws SQLException {
+ try {
+ Class.forName("org.postgresql.Driver");
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ String url = "jdbc:postgresql://" + getHost()
+ // + (":" + PropertyUtils.getDbPort())
+ + ("/" + getDatabase());
+
+ String password = getPassword();
+ String username = getUsername();
+
+ // log.debug("DB URL: " + url + " u=" + username + " p="
+ // + password);
+
+ return DriverManager.getConnection(url, username, password);
+ }
+
+ public String[] getDescribedTablesWithGeometry() {
+
+ if (cachedGeometryTableNames == null) {
+
+ Connection dc;
+ try {
+ dc = createNewDatabaseConnection();
+ try {
+
+ cachedGeometryTableNames = PGUtil
+ .getColumnsDescribedInGeometryColumnsTable(dc
+ .createStatement());
+
+ } catch (SQLException e) {
+ log.error(e, e);
+ } finally {
+ dc.close();
+ }
+ } catch (SQLException e1) {
+ log.error(e1, e1);
+ return new String[0];
+ }
+ }
+ return cachedGeometryTableNames;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ dispose();
+ }
+
+ public void dispose() {
+ try {
+ if (dbc != null && !dbc.isClosed()) {
+ dbc.close();
+ dbc = null;
+ }
+ } catch (SQLException e) {
+ log.error("Error while disposing the database connection to "
+ + toString(), e);
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/skrueger/geotools/io/GtDbServerSettings.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Copied: trunk/src/skrueger/geotools/io/GtWfsServerSettings.java (from rev 1292, trunk/src/skrueger/geotools/io/WfsServerSettings.java)
===================================================================
--- trunk/src/skrueger/geotools/io/WfsServerSettings.java 2010-11-22 10:39:13 UTC (rev 1292)
+++ trunk/src/skrueger/geotools/io/GtWfsServerSettings.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,438 @@
+package skrueger.geotools.io;
+
+import java.awt.Component;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.geotools.data.wfs.WFSDataStoreFactory;
+import org.jfree.util.Log;
+
+import schmitzm.swing.BooleanInputOption;
+import schmitzm.swing.ManualInputOption;
+import schmitzm.swing.ManualInputOption.Integer;
+import schmitzm.swing.ManualInputOption.PasswordViewable;
+import schmitzm.swing.ManualInputOption.Text;
+import schmitzm.swing.MultipleOptionPane;
+import schmitzm.swing.SelectionInputOption;
+import schmitzm.swing.SelectionInputOption.Combo;
+
+/**
+ * This class describes all settings needed to connect to a WFS server. This
+ * class extends a {@link HashMap} and contains two groups of keys:<br/>
+ * The first group of keys, are all keys provided by Geotools to create a WFS
+ * datastore, like: {@link WFSDataStoreFactory#URL} or
+ * {@link WFSDataStoreFactory#USERNAME} .<br/>
+ * The second group are additional keys defined in the enum
+ * {@link GtWfsServerSettings.Key}.<br/>
+ * This class can serialize all important parameters needed to define the
+ * connection into a {@link String} with {@link #toPropertiesString()} and
+ * re-import the String with {@link #parsePropertiesString(String)}.
+ */
+public class GtWfsServerSettings extends AbstractGTServerSettings<Object, Object> {
+
+ public enum Key {
+ BASE_URL, VERSION
+ }
+
+ public enum HttpProtocol {
+ AUTO(null), POST(Boolean.TRUE), GET(Boolean.FALSE);
+
+ private final Boolean value;
+
+ private HttpProtocol(Boolean value) {
+ this.value = value;
+ }
+
+ public Boolean getValue() {
+ return value;
+ }
+
+ public static HttpProtocol parse(String object) {
+ if (object.equalsIgnoreCase("true"))
+ return POST;
+ if (object.equals("false"))
+ return GET;
+ return AUTO;
+ }
+
+ public static HttpProtocol parse(Boolean object) {
+ if (object == Boolean.TRUE)
+ return POST;
+ if (object == Boolean.FALSE)
+ return GET;
+ return AUTO;
+ }
+
+ }
+
+ public enum WfsProtocollVersion {
+ v1_0_0("1.0.0"), v1_1_0("1.1.0"), v1_1_1("1.1.1");
+
+ private final String versionString;
+
+ private WfsProtocollVersion(String versionString) {
+ this.versionString = versionString;
+ }
+
+ public String getVersionString() {
+ return versionString;
+ }
+ }
+
+ private static final URL defaultURl;
+ static {
+ try {
+ defaultURl = new URL("http://localhost:8080/geoserver/ows");
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Opens a GUI that asks the use define a DB connection.
+ *
+ * @param wfsServer
+ * <code>null</code> to create a new instance, or an instance to
+ * edit.
+ * @return <code>null</code> if the user cancelled the creation of a new
+ * {@link GtDbServerSettings}, otherwise the edited instance.
+ */
+ public static GtWfsServerSettings createOrEdit(Component owner,
+ GtWfsServerSettings wfsServer) {
+ boolean newCreated = false;
+
+ if (wfsServer == null) {
+ newCreated = true;
+ wfsServer = new GtWfsServerSettings();
+ }
+
+ Text hostInput = new ManualInputOption.Text(
+ "BaseURL (without any paramters)", true, wfsServer.getBaseUrl()
+ .toString());
+
+ Combo<WfsProtocollVersion> versionInput = new SelectionInputOption.Combo<WfsProtocollVersion>(
+ "WFS Version", true, WfsProtocollVersion.values(),
+ ArrayUtils.indexOf(WfsProtocollVersion.values(),
+ wfsServer.getVersion()), WfsProtocollVersion.values());
+ versionInput
+ .setToolTipText("If you have problems with Curves in GML3, try version 1.0.0.");
+
+ Integer maxFeaturesInput = new ManualInputOption.Integer(
+ "Max. features per request (0=no limit)", false,
+ wfsServer.getMaxFeatures());
+ maxFeaturesInput
+ .setToolTipText(WFSDataStoreFactory.MAXFEATURES.description
+ .toString());
+
+ Integer timeoutInput = new ManualInputOption.Integer("Timout in ms:",
+ false, wfsServer.getTimeout());
+ timeoutInput.setToolTipText(WFSDataStoreFactory.TIMEOUT.description
+ .toString());
+
+ BooleanInputOption lenientInput = new BooleanInputOption(
+ "lenient (=ignore errors)", wfsServer.getLenient());
+ lenientInput.setToolTipText(WFSDataStoreFactory.LENIENT.description
+ .toString());
+
+ SelectionInputOption.Combo<HttpProtocol> httpInput = new SelectionInputOption.Combo<HttpProtocol>(
+ "Ust HTTP GET or POST:", true, HttpProtocol.values(),
+ ArrayUtils.indexOf(HttpProtocol.values(),
+ wfsServer.getHttpProtocol()), HttpProtocol.values());
+ httpInput.setToolTipText(WFSDataStoreFactory.PROTOCOL.description
+ .toString());
+
+ Text userInput = new ManualInputOption.Text(
+ "Optional HTTPAuth Username", false, wfsServer.getUsername());
+
+ PasswordViewable passwdInput = new ManualInputOption.PasswordViewable(
+ "Optional HTTPAuth Password", false, wfsServer.getPassword());
+
+ // Show the options
+ Object[] input = MultipleOptionPane.showMultipleInputDialog(owner,
+ "WFS Connection parameters", hostInput, versionInput,
+ maxFeaturesInput, timeoutInput, lenientInput, httpInput,
+ userInput, passwdInput);
+
+ if (input == null) {
+ if (newCreated)
+ return null;
+ else
+ return wfsServer;
+ } else {
+ wfsServer.setBaseUrl((String) input[0]);
+ wfsServer.setVersion(((WfsProtocollVersion) input[1]));
+ wfsServer.setMaxFeatures((java.lang.Integer) input[2]);
+ wfsServer.setTimeout((java.lang.Integer) input[3]);
+ wfsServer.setLenient((java.lang.Boolean) input[4]);
+ wfsServer.setHttpProtocol((HttpProtocol) input[5]);
+ wfsServer.setUsername((String) input[6]);
+ wfsServer.setPassword(String.valueOf((char[]) input[7]));
+ }
+
+ return wfsServer;
+
+ }
+
+ public HttpProtocol getHttpProtocol() {
+ return HttpProtocol
+ .parse((Boolean) get(WFSDataStoreFactory.PROTOCOL.key));
+ }
+
+ public void setHttpProtocol(HttpProtocol protocol) {
+ put(WFSDataStoreFactory.PROTOCOL.key, protocol.getValue());
+ }
+
+ private Boolean getLenient() {
+ return (Boolean) get(WFSDataStoreFactory.LENIENT.key);
+ }
+
+ private void setLenient(Boolean lenient) {
+ put(WFSDataStoreFactory.LENIENT.key, lenient);
+ }
+
+ /**
+ * @return transforms the settings to a String that can be stored in a
+ * .properties line. @see #parsePropertiesString
+ * @throws MalformedURLException
+ */
+ @Override
+ public boolean parsePropertiesString(String propString) {
+
+ try {
+ String[] split = propString.split(Pattern.quote(DELIMITER));
+
+ // WfsServerSettings wfs = new WfsServerSettings();
+
+ int i = 0;
+ setTitle(split[i++]);
+ setBaseUrl(new URL(split[i++]));
+ setVersion(WfsProtocollVersion.valueOf(split[i++]));
+ setMaxFeatures(intOrNull(split[i++]));
+ setTimeout(intOrNull(split[i++]));
+ setLenient(java.lang.Boolean.valueOf(split[i++]));
+ setHttpProtocol(HttpProtocol.parse(split[i++]));
+
+ setUsername(stringOrNull(split[i++]));
+
+ setPassword(stringOrNull(split[i++]));
+
+ return true;
+ } catch (Exception e) {
+ Log.warn("couldn't parse " + propString, e);
+ return false;
+ }
+
+ }
+
+ private String[] cachedTypeNames = null;
+
+ public GtWfsServerSettings() {
+ this(defaultURl, WfsProtocollVersion.v1_0_0);
+ }
+
+ public GtWfsServerSettings(URL baseUrl, WfsProtocollVersion version) {
+ setVersion(version);
+ setBaseUrl(baseUrl);
+ setLenient(false);
+ }
+
+ public GtWfsServerSettings(String s) {
+ parsePropertiesString(s);
+ }
+
+ public URL getBaseUrl() {
+ return (URL) get(Key.BASE_URL);
+ }
+
+ public String[] getCachedTypeNames() {
+ return cachedTypeNames;
+ }
+
+ /**
+ * @return <code>null</code> if not correctly defined, otherwise the URL of
+ * the GetCapabilites request.
+ */
+ public URL getCapabilitiesUrl() {
+ return (URL) get(WFSDataStoreFactory.URL.key);
+ }
+
+ public java.lang.Integer getMaxFeatures() {
+ return (java.lang.Integer) get(WFSDataStoreFactory.MAXFEATURES.key);
+ }
+
+ public java.lang.Integer getTimeout() {
+ return (java.lang.Integer) get(WFSDataStoreFactory.TIMEOUT.key);
+ }
+
+ public WfsProtocollVersion getVersion() {
+ return (WfsProtocollVersion) get(Key.VERSION);
+ }
+
+ /**
+ * @return <code>true</code>, if all parameters look OK, without actually
+ * opening any connection.
+ */
+ public boolean isWellDefined() {
+ return updateCapabilitesUrl();
+ }
+
+ /**
+ * Set the BaseUrl as a String. Any pending parameters are automatically cut
+ * of.
+ */
+ public void setBaseUrl(String urlString) {
+ try {
+ // Cutoff any parameters
+ if (urlString.indexOf("?") > -1) {
+ urlString = urlString.substring(0, urlString.indexOf("?"));
+ }
+
+ setBaseUrl(new URL(urlString));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setBaseUrl(URL baseUrl) {
+
+ if (get(Key.BASE_URL) != baseUrl) {
+ setCachedTypeNames(null);
+ }
+
+ put(Key.BASE_URL, baseUrl);
+
+ updateCapabilitesUrl();
+ }
+
+ public void setCachedTypeNames(String[] cachedTypeNames) {
+ this.cachedTypeNames = cachedTypeNames;
+ }
+
+ public void setMaxFeatures(java.lang.Integer maxFeatures) {
+ put(WFSDataStoreFactory.MAXFEATURES.key, maxFeatures);
+ }
+
+ public void setTimeout(java.lang.Integer timeout) {
+ put(WFSDataStoreFactory.TIMEOUT.key, timeout);
+
+ }
+
+ public void setVersion(WfsProtocollVersion version) {
+
+ if (get(Key.VERSION) != version) {
+ setCachedTypeNames(null);
+ }
+
+ put(Key.VERSION, version);
+ updateCapabilitesUrl();
+ }
+
+ /**
+ * @return transforms the settings to a String that can be stored in a
+ * .properties line. @see #parsePropertiesString
+ */
+ public String toPropertiesString() {
+
+ StringBuffer serialized = new StringBuffer(100);
+
+ // Title
+ serialized.append(getTitle());
+ serialized.append(DELIMITER);
+
+ // BaseUrl
+ serialized.append(getBaseUrl().toString());
+ serialized.append(DELIMITER);
+
+ // Version
+ serialized.append(getVersion().toString());
+ serialized.append(DELIMITER);
+
+ serialized.append(getMaxFeatures());
+ serialized.append(DELIMITER);
+
+ serialized.append(getTimeout());
+ serialized.append(DELIMITER);
+
+ serialized.append(getLenient());
+ serialized.append(DELIMITER);
+
+ serialized.append(getHttpProtocol().getValue());
+ serialized.append(DELIMITER);
+
+ serialized.append(getUsername());
+ serialized.append(DELIMITER);
+
+ serialized.append(getPassword());
+ // serialized.append(DELIMITER);
+
+ return serialized.toString();
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer s = new StringBuffer();
+
+ URL baseUrl = getBaseUrl();
+ WfsProtocollVersion version = getVersion();
+
+ if (baseUrl != null)
+ s.append(baseUrl.toString() + " ");
+
+ if (version != null)
+ s.append(version.getVersionString());
+
+ return s.toString();
+ }
+
+ public boolean updateCapabilitesUrl() {
+ remove(WFSDataStoreFactory.URL.key);
+
+ if (getBaseUrl() == null)
+ return false;
+
+ if (getVersion() == null)
+ return false;
+
+ try {
+ URL base = getBaseUrl();
+
+ String a = base.toExternalForm();
+ if (a.endsWith("/"))
+ a = a.substring(0, a.length() - 1);
+
+ URL fullUrl = new URL(a + "?service=WFS&version="
+ + getVersion().getVersionString()
+ + "&request=GetCapabilities");
+
+ put(WFSDataStoreFactory.URL.key, fullUrl);
+
+ return true;
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ }
+
+ public void setPassword(String password) {
+ if (password != null && password.isEmpty())
+ password = null;
+ put(WFSDataStoreFactory.PASSWORD.key, password);
+ }
+
+ public String getPassword() {
+ return (String) get(WFSDataStoreFactory.PASSWORD.key);
+ }
+
+ public void setUsername(String username) {
+ if (username != null && username.isEmpty())
+ username = null;
+ put(WFSDataStoreFactory.USERNAME.key, username);
+ }
+
+ public String getUsername() {
+ return (String) get(WFSDataStoreFactory.USERNAME.key);
+ }
+
+}
Property changes on: trunk/src/skrueger/geotools/io/GtWfsServerSettings.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Modified: trunk/src/skrueger/geotools/io/ServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/ServerSettings.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/ServerSettings.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,55 +1,11 @@
package skrueger.geotools.io;
-import java.net.MalformedURLException;
-import java.util.HashMap;
-public abstract class ServerSettings<T1, T2> extends HashMap<T1, T2> {
+public interface ServerSettings {
- abstract public String toPropertiesString();
+ public String getTitle();
- static Integer intOrNull(String string) {
- if (string == null)
- return null;
- if (string.equals("null"))
- return null;
- return Integer.parseInt(string);
- }
+ public String toPropertiesString();
- /**
- * Character used to separate the parameters when serializing settings to a
- * String
- */
- protected static final String DELIMITER = "|";
-
- private String title;
-
- static String stringOrNull(String string) {
- if (string == null)
- return null;
- if (string.equals("null"))
- return null;
- return string;
- }
-
- public void setTitle(String title) {
- if (title != null) {
- if (title.contains(DELIMITER))
- throw new IllegalArgumentException("Title may not contain "
- + DELIMITER);
- if (title.contains(WfsServerList.DELIMITER))
- throw new IllegalArgumentException("Title may not contain "
- + WfsServerList.DELIMITER);
- }
- this.title = title;
- }
-
- public String getTitle() {
- if (title == null)
- return toString();
- return title;
- }
-
- abstract public boolean parsePropertiesString(String propString)
- throws MalformedURLException ;
-
+ public boolean parsePropertiesString(String propString);
}
Modified: trunk/src/skrueger/geotools/io/WfsServerList.java
===================================================================
--- trunk/src/skrueger/geotools/io/WfsServerList.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/WfsServerList.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,74 +1,23 @@
package skrueger.geotools.io;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.regex.Pattern;
+import skrueger.AbstractServerList;
-import org.jfree.util.Log;
-
/**
- * A list of {@link WfsServerSettings}.
+ * A list of {@link GtWfsServerSettings}.
*/
-public class WfsServerList extends ArrayList<WfsServerSettings> {
- /**
- * Character used to separate the parameters when serializing settings to a
- * String
- */
- static final String DELIMITER = "@";
+public class WfsServerList extends AbstractServerList<GtWfsServerSettings> {
- public WfsServerList(WfsServerSettings... wfss) {
- for (WfsServerSettings wfs : wfss) {
- add(wfs);
- }
+ public WfsServerList(GtWfsServerSettings... wfss) {
+ super(wfss);
}
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- */
- public String toPropertiesString() {
-
- StringBuffer serialized = new StringBuffer(100);
-
- for (WfsServerSettings wfs : this) {
- serialized.append(wfs.toPropertiesString());
- serialized.append(DELIMITER);
- }
-
- return serialized.toString();
+ public WfsServerList(String propertiesString) {
+ super(propertiesString);
}
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- * @throws MalformedURLException
- */
- public static WfsServerList parsePropertiesString(String propString) {
- WfsServerList wfsServerList = new WfsServerList();
-
- if (propString == null)
- return wfsServerList;
-
- String[] split = propString.split(Pattern.quote(DELIMITER));
-
- for (String s : split) {
- try {
- WfsServerSettings parsedWfsServer = new WfsServerSettings(s);
- if (parsedWfsServer == null) {
- Log.error("Could not import a "
- + WfsServerSettings.class.getSimpleName()
- + " from " + propString + ". Ignoring it.");
- } else {
- wfsServerList.add(parsedWfsServer);
- }
- } catch (Exception e) {
- Log.error(
- "Could not import a "
- + WfsServerSettings.class.getSimpleName()
- + " from " + propString + ". Ignoring it.", e);
- }
- }
-
- return wfsServerList;
+ @Override
+ protected GtWfsServerSettings newInstance() {
+ return new GtWfsServerSettings();
}
+
}
Deleted: trunk/src/skrueger/geotools/io/WfsServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/WfsServerSettings.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/WfsServerSettings.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,443 +0,0 @@
-package skrueger.geotools.io;
-
-import java.awt.Component;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.geotools.data.wfs.WFSDataStoreFactory;
-import org.jfree.util.Log;
-
-import schmitzm.swing.BooleanInputOption;
-import schmitzm.swing.ManualInputOption;
-import schmitzm.swing.ManualInputOption.Integer;
-import schmitzm.swing.ManualInputOption.PasswordViewable;
-import schmitzm.swing.ManualInputOption.Text;
-import schmitzm.swing.MultipleOptionPane;
-import schmitzm.swing.SelectionInputOption;
-import schmitzm.swing.SelectionInputOption.Combo;
-
-/**
- * This class describes all settings needed to connect to a WFS server. This
- * class extends a {@link HashMap} and contains two groups of keys:<br/>
- * The first group of keys, are all keys provided by Geotools to create a WFS
- * datastore, like: {@link WFSDataStoreFactory#URL} or
- * {@link WFSDataStoreFactory#USERNAME} .<br/>
- * The second group are additional keys defined in the enum
- * {@link WfsServerSettings.Key}.<br/>
- * This class can serialize all important parameters needed to define the
- * connection into a {@link String} with {@link #toPropertiesString()} and
- * re-import the String with {@link #parsePropertiesString(String)}.
- */
-public class WfsServerSettings extends ServerSettings<Object, Object> {
-
- public enum Key {
- BASE_URL, VERSION
- }
-
- public enum HttpProtocol {
- AUTO(null), POST(Boolean.TRUE), GET(Boolean.FALSE);
-
- private final Boolean value;
-
- private HttpProtocol(Boolean value) {
- this.value = value;
- }
-
- public Boolean getValue() {
- return value;
- }
-
- public static HttpProtocol parse(String object) {
- if (object.equalsIgnoreCase("true"))
- return POST;
- if (object.equals("false"))
- return GET;
- return AUTO;
- }
-
- public static HttpProtocol parse(Boolean object) {
- if (object == Boolean.TRUE)
- return POST;
- if (object == Boolean.FALSE)
- return GET;
- return AUTO;
- }
-
- }
-
- public enum WfsProtocollVersion {
- v1_0_0("1.0.0"), v1_1_0("1.1.0"), v1_1_1("1.1.1");
-
- private final String versionString;
-
- private WfsProtocollVersion(String versionString) {
- this.versionString = versionString;
- }
-
- public String getVersionString() {
- return versionString;
- }
- }
-
- private static final URL defaultURl;
- static {
- try {
- defaultURl = new URL("http://localhost:8080/geoserver/ows");
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Opens a GUI that asks the use define a DB connection.
- *
- * @param wfsServer
- * <code>null</code> to create a new instance, or an instance to
- * edit.
- * @return <code>null</code> if the user cancelled the creation of a new
- * {@link DbServerSettings}, otherwise the edited instance.
- */
- public static WfsServerSettings createOrEdit(Component owner,
- WfsServerSettings wfsServer) {
- boolean newCreated = false;
-
- if (wfsServer == null) {
- newCreated = true;
- wfsServer = new WfsServerSettings();
- }
-
- Text hostInput = new ManualInputOption.Text(
- "BaseURL (without any paramters)", true, wfsServer.getBaseUrl()
- .toString());
-
- Combo<WfsProtocollVersion> versionInput = new SelectionInputOption.Combo<WfsProtocollVersion>(
- "WFS Version", true, WfsProtocollVersion.values(),
- ArrayUtils.indexOf(WfsProtocollVersion.values(),
- wfsServer.getVersion()), WfsProtocollVersion.values());
- versionInput
- .setToolTipText("If you have problems with Curves in GML3, try version 1.0.0.");
-
- Integer maxFeaturesInput = new ManualInputOption.Integer(
- "Max. features per request (0=no limit)", false,
- wfsServer.getMaxFeatures());
- maxFeaturesInput
- .setToolTipText(WFSDataStoreFactory.MAXFEATURES.description
- .toString());
-
- Integer timeoutInput = new ManualInputOption.Integer("Timout in ms:",
- false, wfsServer.getTimeout());
- timeoutInput.setToolTipText(WFSDataStoreFactory.TIMEOUT.description
- .toString());
-
- BooleanInputOption lenientInput = new BooleanInputOption(
- "lenient (=ignore errors)", wfsServer.getLenient());
- lenientInput.setToolTipText(WFSDataStoreFactory.LENIENT.description
- .toString());
-
- SelectionInputOption.Combo<HttpProtocol> httpInput = new SelectionInputOption.Combo<HttpProtocol>(
- "Ust HTTP GET or POST:", true, HttpProtocol.values(),
- ArrayUtils.indexOf(HttpProtocol.values(),
- wfsServer.getHttpProtocol()), HttpProtocol.values());
- httpInput.setToolTipText(WFSDataStoreFactory.PROTOCOL.description
- .toString());
-
- Text userInput = new ManualInputOption.Text(
- "Optional HTTPAuth Username", false, wfsServer.getUsername());
-
- PasswordViewable passwdInput = new ManualInputOption.PasswordViewable(
- "Optional HTTPAuth Password", false, wfsServer.getPassword());
-
- // Show the options
- Object[] input = MultipleOptionPane.showMultipleInputDialog(owner,
- "WFS Connection parameters", hostInput, versionInput,
- maxFeaturesInput, timeoutInput, lenientInput, httpInput,
- userInput, passwdInput);
-
- if (input == null) {
- if (newCreated)
- return null;
- else
- return wfsServer;
- } else {
- wfsServer.setBaseUrl((String) input[0]);
- wfsServer.setVersion(((WfsProtocollVersion) input[1]));
- wfsServer.setMaxFeatures((java.lang.Integer) input[2]);
- wfsServer.setTimeout((java.lang.Integer) input[3]);
- wfsServer.setLenient((java.lang.Boolean) input[4]);
- wfsServer.setHttpProtocol((HttpProtocol) input[5]);
- wfsServer.setUsername((String) input[6]);
- wfsServer.setPassword(String.valueOf((char[]) input[7]));
- }
-
- return wfsServer;
-
- }
-
- public HttpProtocol getHttpProtocol() {
- return HttpProtocol
- .parse((Boolean) get(WFSDataStoreFactory.PROTOCOL.key));
- }
-
- public void setHttpProtocol(HttpProtocol protocol) {
- put(WFSDataStoreFactory.PROTOCOL.key, protocol.getValue());
- }
-
- private Boolean getLenient() {
- return (Boolean) get(WFSDataStoreFactory.LENIENT.key);
- }
-
- private void setLenient(Boolean lenient) {
- put(WFSDataStoreFactory.LENIENT.key, lenient);
- }
-
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- * @throws MalformedURLException
- */
- @Override
- public boolean parsePropertiesString(String propString)
- throws MalformedURLException {
-
- try {
- String[] split = propString.split(Pattern.quote(DELIMITER));
-
-// WfsServerSettings wfs = new WfsServerSettings();
-
- int i = 0;
- setTitle(split[i++]);
- setBaseUrl(new URL(split[i++]));
- setVersion(WfsProtocollVersion.valueOf(split[i++]));
- setMaxFeatures(intOrNull(split[i++]));
- setTimeout(intOrNull(split[i++]));
- setLenient(java.lang.Boolean.valueOf(split[i++]));
- setHttpProtocol(HttpProtocol.parse(split[i++]));
-
- setUsername(stringOrNull(split[i++]));
-
- setPassword(stringOrNull(split[i++]));
-
- return true;
- } catch (Exception e) {
- Log.warn("couldn't parse " + propString, e);
- return false;
- }
-
- }
-
- private String[] cachedTypeNames = null;
-
- public WfsServerSettings() {
- this(defaultURl, WfsProtocollVersion.v1_0_0);
- }
-
- public WfsServerSettings(URL baseUrl, WfsProtocollVersion version) {
- setVersion(version);
- setBaseUrl(baseUrl);
- setLenient(false);
- }
-
- public WfsServerSettings(String s) {
- try {
- parsePropertiesString(s);
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- public URL getBaseUrl() {
- return (URL) get(Key.BASE_URL);
- }
-
- public String[] getCachedTypeNames() {
- return cachedTypeNames;
- }
-
- /**
- * @return <code>null</code> if not correctly defined, otherwise the URL of
- * the GetCapabilites request.
- */
- public URL getCapabilitiesUrl() {
- return (URL) get(WFSDataStoreFactory.URL.key);
- }
-
- public java.lang.Integer getMaxFeatures() {
- return (java.lang.Integer) get(WFSDataStoreFactory.MAXFEATURES.key);
- }
-
- public java.lang.Integer getTimeout() {
- return (java.lang.Integer) get(WFSDataStoreFactory.TIMEOUT.key);
- }
-
- public WfsProtocollVersion getVersion() {
- return (WfsProtocollVersion) get(Key.VERSION);
- }
-
- /**
- * @return <code>true</code>, if all parameters look OK, without actually
- * opening any connection.
- */
- public boolean isWellDefined() {
- return updateCapabilitesUrl();
- }
-
- /**
- * Set the BaseUrl as a String. Any pending parameters are automatically cut
- * of.
- */
- public void setBaseUrl(String urlString) {
- try {
- // Cutoff any parameters
- if (urlString.indexOf("?") > -1) {
- urlString = urlString.substring(0, urlString.indexOf("?"));
- }
-
- setBaseUrl(new URL(urlString));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- public void setBaseUrl(URL baseUrl) {
-
- if (get(Key.BASE_URL) != baseUrl) {
- setCachedTypeNames(null);
- }
-
- put(Key.BASE_URL, baseUrl);
-
- updateCapabilitesUrl();
- }
-
- public void setCachedTypeNames(String[] cachedTypeNames) {
- this.cachedTypeNames = cachedTypeNames;
- }
-
- public void setMaxFeatures(java.lang.Integer maxFeatures) {
- put(WFSDataStoreFactory.MAXFEATURES.key, maxFeatures);
- }
-
- public void setTimeout(java.lang.Integer timeout) {
- put(WFSDataStoreFactory.TIMEOUT.key, timeout);
-
- }
-
- public void setVersion(WfsProtocollVersion version) {
-
- if (get(Key.VERSION) != version) {
- setCachedTypeNames(null);
- }
-
- put(Key.VERSION, version);
- updateCapabilitesUrl();
- }
-
- /**
- * @return transforms the settings to a String that can be stored in a
- * .properties line. @see #parsePropertiesString
- */
- public String toPropertiesString() {
-
- StringBuffer serialized = new StringBuffer(100);
-
- // Title
- serialized.append(getTitle());
- serialized.append(DELIMITER);
-
- // BaseUrl
- serialized.append(getBaseUrl().toString());
- serialized.append(DELIMITER);
-
- // Version
- serialized.append(getVersion().toString());
- serialized.append(DELIMITER);
-
- serialized.append(getMaxFeatures());
- serialized.append(DELIMITER);
-
- serialized.append(getTimeout());
- serialized.append(DELIMITER);
-
- serialized.append(getLenient());
- serialized.append(DELIMITER);
-
- serialized.append(getHttpProtocol().getValue());
- serialized.append(DELIMITER);
-
- serialized.append(getUsername());
- serialized.append(DELIMITER);
-
- serialized.append(getPassword());
- // serialized.append(DELIMITER);
-
- return serialized.toString();
- }
-
- @Override
- public String toString() {
- StringBuffer s = new StringBuffer();
-
- URL baseUrl = getBaseUrl();
- WfsProtocollVersion version = getVersion();
-
- if (baseUrl != null)
- s.append(baseUrl.toString() + " ");
-
- if (version != null)
- s.append(version.getVersionString());
-
- return s.toString();
- }
-
- public boolean updateCapabilitesUrl() {
- remove(WFSDataStoreFactory.URL.key);
-
- if (getBaseUrl() == null)
- return false;
-
- if (getVersion() == null)
- return false;
-
- try {
- URL base = getBaseUrl();
-
- String a = base.toExternalForm();
- if (a.endsWith("/"))
- a = a.substring(0, a.length() - 1);
-
- URL fullUrl = new URL(a + "?service=WFS&version="
- + getVersion().getVersionString()
- + "&request=GetCapabilities");
-
- put(WFSDataStoreFactory.URL.key, fullUrl);
-
- return true;
- } catch (MalformedURLException e) {
- return false;
- }
- }
-
- public void setPassword(String password) {
- if (password != null && password.isEmpty())
- password = null;
- put(WFSDataStoreFactory.PASSWORD.key, password);
- }
-
- public String getPassword() {
- return (String) get(WFSDataStoreFactory.PASSWORD.key);
- }
-
- public void setUsername(String username) {
- if (username != null && username.isEmpty())
- username = null;
- put(WFSDataStoreFactory.USERNAME.key, username);
- }
-
- public String getUsername() {
- return (String) get(WFSDataStoreFactory.USERNAME.key);
- }
-
-}
Modified: trunk/src/skrueger/geotools/io/WfsSettingsJComboBox.java
===================================================================
--- trunk/src/skrueger/geotools/io/WfsSettingsJComboBox.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src/skrueger/geotools/io/WfsSettingsJComboBox.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -8,7 +8,7 @@
private final WfsServerList wfsList;
public WfsSettingsJComboBox(WfsServerList wfsList) {
- super(wfsList.toArray(new WfsServerSettings[0]));
+ super(wfsList.toArray(new GtWfsServerSettings[0]));
this.wfsList = wfsList;
}
@@ -17,8 +17,8 @@
}
public void listChanged() {
- WfsServerSettings[] array = wfsList
- .toArray(new WfsServerSettings[wfsList.size()]);
+ GtWfsServerSettings[] array = wfsList
+ .toArray(new GtWfsServerSettings[wfsList.size()]);
setModel(new DefaultComboBoxModel(array));
}
Modified: trunk/src_junit/skrueger/geotools/io/DbServerListTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/DbServerListTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/DbServerListTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -6,14 +6,14 @@
import org.junit.Test;
-import skrueger.geotools.io.DbServerSettings.DbType;
+import skrueger.geotools.io.GtDbServerSettings.DbType;
public class DbServerListTest {
@Test
public void testSerializeAndParseServers() throws MalformedURLException {
- DbServerSettings dbDs1 = new DbServerSettings(DbType.postgis);
- DbServerSettings dbDs2 = new DbServerSettings(DbType.postgis);
+ GtDbServerSettings dbDs1 = new GtDbServerSettings(DbType.postgis);
+ GtDbServerSettings dbDs2 = new GtDbServerSettings(DbType.postgis);
DbServerList list1 = new DbServerList(dbDs1, dbDs2);
Deleted: trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,39 +0,0 @@
-package skrueger.geotools.io;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import skrueger.geotools.io.DbServerSettings.DbType;
-
-public class DbServerSettingsTest {
-
- @Test
- public void testParseAndSerialize1() {
- DbServerSettings dbStore1 = new DbServerSettings(DbType.postgis);
- dbStore1.setUsername("postgres");
- dbStore1.setPassword("secret");
- dbStore1.setDatabase("testDb");
- dbStore1.setSchema("myschema");
- dbStore1.setTitle("toms layer");
-
- assertTrue(dbStore1.isWellDefined());
-
- dbStore1.toPropertiesString();
-
- DbServerSettings dbStore2 = new DbServerSettings(dbStore1.toPropertiesString());
-
-
- assertEquals(dbStore1.getDbType(), dbStore2.getDbType());
-
- assertEquals(dbStore1.isWellDefined(), dbStore2.isWellDefined());
-
- assertEquals(dbStore1.getUsername(), dbStore2.getUsername());
- assertEquals(dbStore1.getPassword(), dbStore2.getPassword());
- assertEquals(dbStore1.getPort(), dbStore2.getPort());
- assertEquals(dbStore1.getSchema(), dbStore2.getSchema());
- assertEquals("toms layer", dbStore2.getTitle());
- }
-
-}
Modified: trunk/src_junit/skrueger/geotools/io/DbSettingsJComboBoxTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/DbSettingsJComboBoxTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/DbSettingsJComboBoxTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -6,7 +6,7 @@
@Test
public void testListChanged() {
- new DbSettingsJComboBox(new DbServerList(new DbServerSettings()))
+ new DbSettingsJComboBox(new DbServerList(new GtDbServerSettings()))
.listChanged();
}
Added: trunk/src_junit/skrueger/geotools/io/GsServerListTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/GsServerListTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/GsServerListTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,34 @@
+package skrueger.geotools.io;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class GsServerListTest {
+
+ @Test
+ public void testImportExxport() {
+ GsServerList gsl = new GsServerList();
+
+ {
+ GsServerSettings gs1 = new GsServerSettings();
+ gs1.setUrl("aaa");
+ gs1.setUsername("hans");
+ gs1.setPassword("asdasd");
+ gsl.add(gs1);
+ }
+ {
+ GsServerSettings gs2 = new GsServerSettings();
+ gs2.setUrl("bbb");
+ gs2.setUsername("ulf");
+ gs2.setPassword("pulse");
+ gsl.add(gs2);
+ }
+
+ GsServerList gsl2 = new GsServerList(gsl.toPropertiesString());
+ assertEquals(2, gsl2.size());
+ assertEquals(gsl.get(0).getUrl(), gsl2.get(0).getUrl());
+ assertEquals(gsl.get(0).getPassword(), gsl2.get(0).getPassword());
+ assertEquals(gsl.get(1).getPassword(), gsl2.get(1).getPassword());
+ }
+}
Property changes on: trunk/src_junit/skrueger/geotools/io/GsServerListTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src_junit/skrueger/geotools/io/GsServerSettingsTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/GsServerSettingsTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/GsServerSettingsTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,25 @@
+package skrueger.geotools.io;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class GsServerSettingsTest {
+
+ @Test
+ public void testParsePropertiesString() {
+ GsServerSettings s = new GsServerSettings();
+ s.setUrl("http://localhost:8085/gs");
+ s.setUsername("admin");
+ s.setPassword("geoserver");
+
+ String ps = s.toPropertiesString();
+
+ GsServerSettings s2 = new GsServerSettings(ps);
+ assertEquals(ps, s2.toPropertiesString());
+ assertEquals(s.getTitle(), s2.getTitle());
+ assertEquals(s.getUsername(), s2.getUsername());
+ assertEquals(s.getPassword(), s2.getPassword());
+ }
+
+}
Property changes on: trunk/src_junit/skrueger/geotools/io/GsServerSettingsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/src_junit/skrueger/geotools/io/GtDbServerSettingsTest.java (from rev 1292, trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java)
===================================================================
--- trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java 2010-11-22 10:39:13 UTC (rev 1292)
+++ trunk/src_junit/skrueger/geotools/io/GtDbServerSettingsTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,39 @@
+package skrueger.geotools.io;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import skrueger.geotools.io.GtDbServerSettings.DbType;
+
+public class GtDbServerSettingsTest {
+
+ @Test
+ public void testParseAndSerialize1() {
+ GtDbServerSettings dbStore1 = new GtDbServerSettings(DbType.postgis);
+ dbStore1.setUsername("postgres");
+ dbStore1.setPassword("secret");
+ dbStore1.setDatabase("testDb");
+ dbStore1.setSchema("myschema");
+ dbStore1.setTitle("toms layer");
+
+ assertTrue(dbStore1.isWellDefined());
+
+ dbStore1.toPropertiesString();
+
+ GtDbServerSettings dbStore2 = new GtDbServerSettings(dbStore1.toPropertiesString());
+
+
+ assertEquals(dbStore1.getDbType(), dbStore2.getDbType());
+
+ assertEquals(dbStore1.isWellDefined(), dbStore2.isWellDefined());
+
+ assertEquals(dbStore1.getUsername(), dbStore2.getUsername());
+ assertEquals(dbStore1.getPassword(), dbStore2.getPassword());
+ assertEquals(dbStore1.getPort(), dbStore2.getPort());
+ assertEquals(dbStore1.getSchema(), dbStore2.getSchema());
+ assertEquals("toms layer", dbStore2.getTitle());
+ }
+
+}
Property changes on: trunk/src_junit/skrueger/geotools/io/GtDbServerSettingsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Copied: trunk/src_junit/skrueger/geotools/io/GtWfsServerSettingsTest.java (from rev 1291, trunk/src_junit/skrueger/geotools/io/WfsServerSettingsTest.java)
===================================================================
--- trunk/src_junit/skrueger/geotools/io/WfsServerSettingsTest.java 2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src_junit/skrueger/geotools/io/GtWfsServerSettingsTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -0,0 +1,68 @@
+package skrueger.geotools.io;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.junit.Test;
+
+import skrueger.geotools.io.GtWfsServerSettings.HttpProtocol;
+import skrueger.geotools.io.GtWfsServerSettings.WfsProtocollVersion;
+
+public class GtWfsServerSettingsTest {
+
+ @Test
+ public void testParseAndSerialize1() throws MalformedURLException {
+ GtWfsServerSettings wfs1 = new GtWfsServerSettings(new URL(
+ "http://localhost:8085/geoserver/ows"),
+ WfsProtocollVersion.v1_1_0);
+
+ assertTrue(wfs1.isWellDefined());
+
+ GtWfsServerSettings wfs2 = new GtWfsServerSettings(wfs1
+ .toPropertiesString());
+
+ assertEquals(wfs1.getBaseUrl(), wfs2.getBaseUrl());
+ assertEquals(wfs1.getVersion(), wfs2.getVersion());
+ assertEquals(wfs1.getCapabilitiesUrl(), wfs2.getCapabilitiesUrl());
+ assertEquals(wfs1.isWellDefined(), wfs2.isWellDefined());
+ }
+
+ @Test
+ public void testParseAndSerialize2() throws MalformedURLException {
+ GtWfsServerSettings wfs1 = new GtWfsServerSettings(new URL(
+ "http://localhost:8085/geoserver/ows"),
+ WfsProtocollVersion.v1_0_0);
+
+ wfs1.setHttpProtocol(HttpProtocol.GET);
+ wfs1.setUsername("hans");
+ wfs1.setPassword("***");
+ wfs1.setTimeout(12345);
+ wfs1.setMaxFeatures(54321);
+ wfs1.setTitle("sweety");
+
+ GtWfsServerSettings wfs2 = new GtWfsServerSettings(wfs1
+ .toPropertiesString());
+
+ assertEquals(wfs1.getBaseUrl(), wfs2.getBaseUrl());
+ assertEquals(wfs1.getVersion(), wfs2.getVersion());
+ assertEquals(HttpProtocol.GET, wfs2.getHttpProtocol());
+ assertEquals("hans", wfs2.getUsername());
+ assertEquals("***", wfs2.getPassword());
+ assertEquals(12345, wfs2.getTimeout(), 0.0001);
+ assertEquals(54321, wfs2.getMaxFeatures(), 0.0001);
+ assertEquals("sweety", wfs2.getTitle());
+ assertEquals(wfs1.getCapabilitiesUrl(), wfs2.getCapabilitiesUrl());
+ assertEquals(wfs1.isWellDefined(), wfs2.isWellDefined());
+ }
+
+ @Test
+ public void testSetBaseUrl() {
+ GtWfsServerSettings wfs = new GtWfsServerSettings();
+ wfs.setBaseUrl("http://localhost?asd=2323");
+ assertEquals("http://localhost", wfs.getBaseUrl().toString());
+ }
+
+}
Property changes on: trunk/src_junit/skrueger/geotools/io/GtWfsServerSettingsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Modified: trunk/src_junit/skrueger/geotools/io/WfsServerListTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/WfsServerListTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/WfsServerListTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -7,22 +7,22 @@
import org.junit.Test;
-import skrueger.geotools.io.WfsServerSettings.WfsProtocollVersion;
+import skrueger.geotools.io.GtWfsServerSettings.WfsProtocollVersion;
public class WfsServerListTest {
@Test
public void testSerializeAndParseServers() throws MalformedURLException {
- WfsServerSettings wfs1 = new WfsServerSettings(new URL(
+ GtWfsServerSettings wfs1 = new GtWfsServerSettings(new URL(
"http://localhost:8085/geoserver/ows"),
WfsProtocollVersion.v1_1_1);
- WfsServerSettings wfs2 = new WfsServerSettings(new URL(
+ GtWfsServerSettings wfs2 = new GtWfsServerSettings(new URL(
"http://localhost:8080/geoserver2/ows"),
WfsProtocollVersion.v1_0_0);
WfsServerList list1 = new WfsServerList(wfs1, wfs2);
- WfsServerList list2 = WfsServerList.parsePropertiesString(list1
+ WfsServerList list2 = new WfsServerList(list1
.toPropertiesString());
assertEquals(list1.size(), list2.size());
@@ -32,8 +32,8 @@
@Test
public void testParseEmpty() {
- assertEquals(0, WfsServerList.parsePropertiesString(null).size());
- assertEquals(0, WfsServerList.parsePropertiesString("").size());
+ assertEquals(0, new WfsServerList((String)null).size());
+ assertEquals(0, new WfsServerList("").size());
}
}
Deleted: trunk/src_junit/skrueger/geotools/io/WfsServerSettingsTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/WfsServerSettingsTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/WfsServerSettingsTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -1,68 +0,0 @@
-package skrueger.geotools.io;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.junit.Test;
-
-import skrueger.geotools.io.WfsServerSettings.HttpProtocol;
-import skrueger.geotools.io.WfsServerSettings.WfsProtocollVersion;
-
-public class WfsServerSettingsTest {
-
- @Test
- public void testParseAndSerialize1() throws MalformedURLException {
- WfsServerSettings wfs1 = new WfsServerSettings(new URL(
- "http://localhost:8085/geoserver/ows"),
- WfsProtocollVersion.v1_1_0);
-
- assertTrue(wfs1.isWellDefined());
-
- WfsServerSettings wfs2 = new WfsServerSettings(wfs1
- .toPropertiesString());
-
- assertEquals(wfs1.getBaseUrl(), wfs2.getBaseUrl());
- assertEquals(wfs1.getVersion(), wfs2.getVersion());
- assertEquals(wfs1.getCapabilitiesUrl(), wfs2.getCapabilitiesUrl());
- assertEquals(wfs1.isWellDefined(), wfs2.isWellDefined());
- }
-
- @Test
- public void testParseAndSerialize2() throws MalformedURLException {
- WfsServerSettings wfs1 = new WfsServerSettings(new URL(
- "http://localhost:8085/geoserver/ows"),
- WfsProtocollVersion.v1_0_0);
-
- wfs1.setHttpProtocol(HttpProtocol.GET);
- wfs1.setUsername("hans");
- wfs1.setPassword("***");
- wfs1.setTimeout(12345);
- wfs1.setMaxFeatures(54321);
- wfs1.setTitle("sweety");
-
- WfsServerSettings wfs2 = new WfsServerSettings(wfs1
- .toPropertiesString());
-
- assertEquals(wfs1.getBaseUrl(), wfs2.getBaseUrl());
- assertEquals(wfs1.getVersion(), wfs2.getVersion());
- assertEquals(HttpProtocol.GET, wfs2.getHttpProtocol());
- assertEquals("hans", wfs2.getUsername());
- assertEquals("***", wfs2.getPassword());
- assertEquals(12345, wfs2.getTimeout(), 0.0001);
- assertEquals(54321, wfs2.getMaxFeatures(), 0.0001);
- assertEquals("sweety", wfs2.getTitle());
- assertEquals(wfs1.getCapabilitiesUrl(), wfs2.getCapabilitiesUrl());
- assertEquals(wfs1.isWellDefined(), wfs2.isWellDefined());
- }
-
- @Test
- public void testSetBaseUrl() {
- WfsServerSettings wfs = new WfsServerSettings();
- wfs.setBaseUrl("http://localhost?asd=2323");
- assertEquals("http://localhost", wfs.getBaseUrl().toString());
- }
-
-}
Modified: trunk/src_junit/skrueger/geotools/io/WfsSettingsJComboBoxTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/WfsSettingsJComboBoxTest.java 2010-11-22 12:00:28 UTC (rev 1294)
+++ trunk/src_junit/skrueger/geotools/io/WfsSettingsJComboBoxTest.java 2010-11-22 15:09:59 UTC (rev 1295)
@@ -6,7 +6,7 @@
@Test
public void testListChanged() {
- new WfsSettingsJComboBox(new WfsServerList(new WfsServerSettings()))
+ new WfsSettingsJComboBox(new WfsServerList(new GtWfsServerSettings()))
.listChanged();
}
More information about the Schmitzm-commits
mailing list