001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/tools/shape/GenericSQLShapeImporter.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2006 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstr. 19
030 53177 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042 ---------------------------------------------------------------------------*/
043 package org.deegree.tools.shape;
044
045 import java.util.Properties;
046
047 import org.deegree.io.quadtree.DBQuadtreeManager;
048 import org.deegree.io.quadtree.DBQuadtreeManagerWithNumberId;
049
050 /**
051 *
052 *
053 *
054 * @version $Revision: 6259 $
055 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
056 * @author last edited by: $Author: bezema $
057 *
058 * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
059 *
060 * @since 2.0
061 */
062 public class GenericSQLShapeImporter {
063
064 private static void validate( Properties map )
065 throws Exception {
066 if ( map.get( "-driver" ) == null ) {
067 throw new Exception( "-driver must be set" );
068 }
069
070 if ( map.get( "-url" ) == null ) {
071 throw new Exception( "-url must be set" );
072 }
073
074 if ( map.get( "-user" ) == null ) {
075 throw new Exception( "-user must be set" );
076 }
077
078 if ( map.get( "-password" ) == null ) {
079 throw new Exception( "-password must be set" );
080 }
081
082 if ( map.get( "-indexName" ) == null ) {
083 throw new Exception( "-indexName must be set" );
084 }
085
086 if ( map.get( "-table" ) == null ) {
087 throw new Exception( "-table must be set" );
088 }
089
090 if ( map.get( "-shapeFile" ) == null ) {
091 throw new Exception( "-shapeFile must be set" );
092 }
093
094 if ( map.get( "-maxTreeDepth" ) == null ) {
095 map.put( "-maxTreeDepth", 6 );
096 }
097
098 }
099
100 private static void printHelp() {
101 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_driver" ) );
102 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_url" ) );
103 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_user" ) );
104 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_password" ) );
105 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_indexName" ) );
106 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_table" ) );
107 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_owner" ) );
108 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_shapeFile" ) );
109 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_maxTreeDepth" ) );
110 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help_idType" ) );
111 System.out.println( GenericSQLShapeImporterMessages.getString( "GenericSQLShapeImporter.help" ) );
112 }
113
114 /**
115 * @param args
116 */
117 public static void main( String[] args )
118 throws Exception {
119
120 Properties map = new Properties();
121 for ( int i = 0; i < args.length; i += 2 ) {
122 System.out.print( args[i] );
123 if ( args.length > i+1 ) {
124 map.put( args[i], args[i + 1] );
125 } else {
126 map.put( args[i], null );
127 }
128
129 System.out.println( ' ' + args[i+1] );
130 }
131
132 if ( map.get( "-?" ) != null || map.get( "-h" ) != null ) {
133 printHelp();
134 return;
135 }
136
137 try {
138 validate( map );
139 } catch ( Exception e ) {
140 System.out.println( e.getMessage() );
141 System.out.println();
142 printHelp();
143 return;
144 }
145
146 int depth = Integer.parseInt( map.getProperty( "-maxTreeDepth" ) );
147 DBQuadtreeManager qtm = null;
148 if ( "INTEGER".equals( map.get( "-idType" ) ) ) {
149 qtm = new DBQuadtreeManagerWithNumberId( map.getProperty( "-driver" ),
150 map.getProperty( "-url" ),
151 map.getProperty( "-user" ),
152 map.getProperty( "-password" ), "ISO-8859-1",
153 map.getProperty( "-indexName" ),
154 map.getProperty( "-table" ), "geometry",
155 map.getProperty( "-owner" ), depth );
156 } else {
157 qtm = new DBQuadtreeManager( map.getProperty( "-driver" ),
158 map.getProperty( "-url" ),
159 map.getProperty( "-user" ),
160 map.getProperty( "-password" ), "ISO-8859-1",
161 map.getProperty( "-indexName" ),
162 map.getProperty( "-table" ), "geometry",
163 map.getProperty( "-owner" ), depth );
164 }
165
166 qtm.importShape( map.getProperty( "-shapeFile" ) );
167
168 System.exit( 0 );
169
170 }
171
172 }
173 /* ********************************************************************
174 Changes to this class. What the people have been up to:
175 $Log$
176 Revision 1.6 2006/10/20 08:08:14 poth
177 required changes resulting from generalizing qudtree implementation
178
179 Revision 1.5 2006/07/26 12:45:04 poth
180 support for alternative object identifier type (integer) -> alternative QuadtreeManager
181
182 Revision 1.4 2006/07/12 14:46:14 poth
183 comment footer added
184
185 ********************************************************************** */