001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/tools/wms/WMS2WMC.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.wms;
044
045 import java.io.File;
046 import java.io.FileOutputStream;
047 import java.io.IOException;
048 import java.net.MalformedURLException;
049 import java.net.URL;
050 import java.util.Properties;
051
052 import javax.xml.transform.TransformerException;
053
054 import org.deegree.framework.xml.XMLFragment;
055 import org.deegree.framework.xml.XSLTDocument;
056 import org.xml.sax.SAXException;
057
058 /**
059 * program for creating a Web Map Context document from a
060 * WMS capabilities file
061 *
062 *
063 * @version $Revision: 6259 $
064 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
065 * @author last edited by: $Author: bezema $
066 *
067 * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
068 *
069 * @since 2.0
070 */
071 public class WMS2WMC {
072
073 private URL xsl = WMS2WMC.class.getResource( "wms2wmc.xsl" );
074
075 private String inFile;
076
077 private String outFile;
078
079 /**
080 *
081 * @param inFile
082 * @param outFile
083 */
084 public WMS2WMC( String inFile, String outFile ) {
085 this.inFile = inFile;
086 this.outFile = outFile;
087 }
088
089 /**
090 * does all the work
091 *
092 * @throws MalformedURLException
093 * @throws IOException
094 * @throws SAXException
095 * @throws TransformerException
096 */
097 public void run()
098 throws MalformedURLException, IOException, SAXException,
099 TransformerException {
100 File in = new File( inFile );
101 XMLFragment xml = new XMLFragment( in.toURL() );
102 XSLTDocument xslt = new XSLTDocument( xsl );
103 xml = xslt.transform( xml );
104
105 FileOutputStream fos = new FileOutputStream( new File( outFile ) );
106 xml.write( fos );
107 fos.close();
108 }
109
110 private static void validate( Properties map )
111 throws Exception {
112 if ( map.get( "-inFile" ) == null ) {
113 throw new Exception( "-inFile parameter must be set" );
114 }
115 if ( map.get( "-outFile" ) == null ) {
116 throw new Exception( "-outFile parameter must be set" );
117 }
118 }
119
120 public static void main( String[] args )
121 throws Exception {
122
123 Properties map = new Properties();
124 for ( int i = 0; i < args.length; i += 2 ) {
125 System.out.println( args[i + 1] );
126 map.put( args[i], args[i + 1] );
127 }
128 try {
129 validate( map );
130 } catch ( Exception e ) {
131 System.out.println( "!!! E R R O R !!!" );
132 System.out.println( e.getMessage() );
133 return;
134 }
135
136 WMS2WMC wms2wmc = new WMS2WMC( map.getProperty( "-inFile" ), map.getProperty( "-outFile" ) );
137 wms2wmc.run();
138
139 }
140
141 }
142
143 /* ********************************************************************
144 Changes to this class. What the people have been up to:
145 $Log$
146 Revision 1.1 2006/06/07 12:19:38 poth
147 *** empty log message ***
148
149
150 ********************************************************************** */