001    //$HeadURL$
002    /*----------------    FILE HEADER  ------------------------------------------
003     This file is part of deegree.
004     Copyright (C) 2001-2008 by:
005     Department of Geography, University of Bonn
006     http://www.giub.uni-bonn.de/deegree/
007     lat/lon GmbH
008     http://www.lat-lon.de
009    
010     This library is free software; you can redistribute it and/or
011     modify it under the terms of the GNU Lesser General Public
012     License as published by the Free Software Foundation; either
013     version 2.1 of the License, or (at your option) any later version.
014     This library is distributed in the hope that it will be useful,
015     but WITHOUT ANY WARRANTY; without even the implied warranty of
016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     Lesser General Public License for more details.
018     You should have received a copy of the GNU Lesser General Public
019     License along with this library; if not, write to the Free Software
020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021     Contact:
022    
023     Andreas Poth
024     lat/lon GmbH
025     Aennchenstr. 19
026     53177 Bonn
027     Germany
028     E-Mail: poth@lat-lon.de
029    
030     Prof. Dr. Klaus Greve
031     Department of Geography
032     University of Bonn
033     Meckenheimer Allee 166
034     53115 Bonn
035     Germany
036     E-Mail: greve@giub.uni-bonn.de
037     ---------------------------------------------------------------------------*/
038    
039    package org.deegree.tools.raster;
040    
041    import java.io.IOException;
042    import java.io.InputStream;
043    import java.sql.Connection;
044    import java.util.Properties;
045    
046    import org.deegree.framework.util.FileUtils;
047    import org.deegree.io.DBConnectionPool;
048    import org.deegree.io.oraclegeoraster.GeoRasterWriter;
049    
050    /**
051     * Utitliy program to import a georeferenced image (worldfile must exist) into Oracle 10g GeoRaster
052     * Database
053     * 
054     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
055     * @author last edited by: $Author: poth $
056     * 
057     * @version. $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
058     */
059    public class OracleGeoRasterImporter {
060    
061        /**
062         * @param args
063         * @throws Exception
064         */
065        public static void main( String[] args )
066                                throws Exception {
067    
068            Properties map = new Properties();
069            for ( int i = 0; i < args.length; i += 2 ) {
070                if ( args[i].equals( "-h" ) || args[i].equals( "-?" ) ) {
071                    printHelp();
072                    System.exit( 0 );
073                }
074                map.put( args[i], args[i + 1] );
075            }
076    
077            if ( !validate( map ) ) {
078                System.exit( 1 );
079            }
080    
081            DBConnectionPool pool = DBConnectionPool.getInstance();
082    
083            Connection con = pool.acquireConnection( map.getProperty( "-driver" ), map.getProperty( "-url" ),
084                                                     map.getProperty( "-user" ), map.getProperty( "-password" ) );
085    
086            try {
087                GeoRasterWriter.importRaster( con, map.getProperty( "-imageFileName" ),
088                                              map.getProperty( "-worldFileName" ),
089                                              map.getProperty( "-rdtName" ).toUpperCase(),
090                                              map.getProperty( "-imageTableName" ).toUpperCase(),
091                                              map.getProperty( "-georColName" ).toUpperCase() );
092            } catch ( Exception e ) {
093                throw e;
094            } finally {
095                con.close();
096                System.exit( 0 );
097            }
098    
099        }
100    
101        /**
102         * prints help text read from OracleGeoRasterImporterHelp.txt
103         * @throws IOException
104         */
105        private static void printHelp()
106                                throws IOException {
107            InputStream is = OracleGeoRasterImporter.class.getResourceAsStream( "OracleGeoRasterImporterHelp.txt" );
108            String s = FileUtils.readTextFile( is ).toString();
109            System.out.println( s );
110        }
111    
112        /**
113         * validates that all required parameters has been set
114         * @param map
115         * @return true if valid
116         */
117        private static boolean validate( Properties map ) {
118            if ( map.getProperty( "-driver" ) == null ) {
119                System.out.println( "-driver must be defined" );
120                return false;
121            }
122            if ( map.getProperty( "-url" ) == null ) {
123                System.out.println( "-url must be defined" );
124                return false;
125            }
126            if ( map.getProperty( "-user" ) == null ) {
127                map.put( "-user", "" );
128            }
129            if ( map.getProperty( "-password" ) == null ) {
130                map.put( "-password", "" );
131            }
132            if ( map.getProperty( "-imageFileName" ) == null ) {
133                System.out.println( "-imageFileName must be defined" );
134                return false;
135            }
136            if ( map.getProperty( "-worldFileName" ) == null ) {
137                System.out.println( "-worldFileName must be defined" );
138                return false;
139            }
140            if ( map.getProperty( "-rdtName" ) == null ) {
141                System.out.println( "-rdtName must be defined" );
142                return false;
143            }
144            if ( map.getProperty( "-imageTableName" ) == null ) {
145                System.out.println( "-imageTableName must be defined" );
146                return false;
147            }
148            if ( map.getProperty( "-georColName" ) == null ) {
149                System.out.println( "-georColName must be defined" );
150                return false;
151            }
152            return true;
153        }
154    
155    }