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