diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java @ 4841:ad0990a82ab8

Insert db connection into riveraxis map files. * Added new MapUtils. * Moved connection specific strings to maputils. * Updated mapfile template.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 23 Jan 2013 17:32:30 +0100
parents 442fbb290fa8
children 88014b9852d0
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Wed Jan 23 13:20:39 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Wed Jan 23 17:32:30 2013 +0100
@@ -14,6 +14,7 @@
 import de.intevation.flys.artifacts.states.DefaultState;
 import de.intevation.flys.backend.SessionFactoryProvider;
 import de.intevation.flys.utils.FLYSUtils;
+import de.intevation.flys.utils.MapUtils;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -146,8 +147,8 @@
             facet.setData(getDataString());
             facet.setFilter(getFilter());
             facet.setGeometryType(getGeometryType());
-            facet.setConnection(getConnection());
-            facet.setConnectionType(getConnectionType());
+            facet.setConnection(MapUtils.getConnection());
+            facet.setConnectionType(MapUtils.getConnectionType());
             facet.setLabelItem(getLabelItem());
 
             facets.add(facet);
@@ -155,128 +156,6 @@
             return null;
         }
 
-        /**
-         * This method returns a connection string for databases used by
-         * Mapserver's Mapfile.
-         *
-         * @return A connection string for Mapserver.
-         */
-        protected String getConnection() {
-            SessionFactoryImpl sf = (SessionFactoryImpl)
-                SessionFactoryProvider.getSessionFactory();
-
-            String user = SessionFactoryProvider.getUser(sf);
-            String pass = SessionFactoryProvider.getPass(sf);
-            String url  = SessionFactoryProvider.getURL(sf);
-
-            logger.debug("Parse connection url: " + url);
-
-            Matcher m = DB_URL_PATTERN.matcher(url);
-            if (!m.matches()) {
-                logger.warn("Could not parse Connection string." +
-                	"Try to parse PostgreSQL string.");
-                // maybe this is a PostgreSQL connection...
-                return getPostgreSQLConnection();
-            }
-
-            logger.debug("Groups for connection string: " + m.groupCount());
-            int groups = m.groupCount();
-
-            for (int i = 0; i <= groups; i++) {
-                logger.debug("Group " + i + ": " + m.group(i));
-            }
-
-            String connection = null;
-
-            if (FLYSUtils.isUsingOracle()) {
-                if (groups < 3) {
-                    logger.warn("Could only partially parse connection string.");
-                    return null;
-                }
-
-                String host = m.group(2);
-                String port = m.group(3);
-
-                connection = user + "/" + pass + "@" + host;
-            }
-            else {
-                if (groups < 4) {
-                    logger.warn("Could only partially parse connection string.");
-                    return null;
-                }
-
-                String host = m.group(2);
-                String port = m.group(3);
-                String db   = m.group(4);
-
-                StringBuilder sb = new StringBuilder();
-                sb.append("dbname=" + db);
-                sb.append("host='" + host + "'");
-                sb.append("port=" + port);
-                sb.append("password='" + pass + "'");
-                sb.append("sslmode=disable");
-
-                connection = sb.toString();
-            }
-
-            logger.debug("Created connection: '" + connection + "'");
-
-            return connection;
-        }
-
-        protected String getPostgreSQLConnection() {
-            SessionFactoryImpl sf = (SessionFactoryImpl)
-                SessionFactoryProvider.getSessionFactory();
-
-            String user = SessionFactoryProvider.getUser(sf);
-            String pass = SessionFactoryProvider.getPass(sf);
-            String url  = SessionFactoryProvider.getURL(sf);
-
-            Matcher m = DB_PSQL_URL_PATTERN.matcher(url);
-            if (!m.matches()) {
-                logger.warn("Could not parse PostgreSQL Connection string.");
-                return null;
-            }
-
-            int groups = m.groupCount();
-            logger.debug("Groups for PostgreSQL connection string: " + groups);
-
-            if (logger.isDebugEnabled()) {
-                for (int i = 0; i <= groups; i++) {
-                    logger.debug("Group " + i + ": " + m.group(i));
-                }
-            }
-
-            String connection = null;
-
-            if (groups < 4) {
-                logger.warn("Could only partially parse connection string.");
-                return null;
-            }
-
-            String host = m.group(2);
-            String port = m.group(3);
-            String db   = m.group(4);
-
-            StringBuilder sb = new StringBuilder();
-            sb.append("dbname=" + db);
-            sb.append(" host='" + host + "'");
-            sb.append(" port=" + port);
-            sb.append(" user=" + user);
-            sb.append(" password='" + pass + "'");
-            sb.append(" sslmode=disable");
-
-            connection = sb.toString();
-
-            logger.debug("Created connection: '" + connection + "'");
-
-            return connection;
-        }
-
-        protected String getConnectionType() {
-            return FLYSUtils.isUsingOracle() ? "oraclespatial" : "postgis";
-        }
-
         protected String getLabelItem() {
             return null;
         }

http://dive4elements.wald.intevation.org