001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/tools/wms/WMS2WMC.java $
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 package org.deegree.tools.wms;
037
038 import java.io.File;
039 import java.io.FileOutputStream;
040 import java.io.IOException;
041 import java.net.MalformedURLException;
042 import java.net.URL;
043 import java.util.Properties;
044
045 import javax.xml.transform.TransformerException;
046
047 import org.deegree.framework.xml.XMLFragment;
048 import org.deegree.framework.xml.XSLTDocument;
049 import org.xml.sax.SAXException;
050
051 /**
052 * program for creating a Web Map Context document from a WMS capabilities file
053 *
054 *
055 * @version $Revision: 18195 $
056 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
057 * @author last edited by: $Author: mschneider $
058 *
059 * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
060 *
061 * @since 2.0
062 */
063 public class WMS2WMC {
064
065 private URL xsl = WMS2WMC.class.getResource( "wms2wmc.xsl" );
066
067 private String inFile;
068
069 private String outFile;
070
071 private String wmsCapabilities;
072
073 /**
074 *
075 * @param inFile
076 * @param outFile
077 */
078 public WMS2WMC( String inFile, String outFile, String wmsCapabilities ) {
079 this.inFile = inFile;
080 this.outFile = outFile;
081 this.wmsCapabilities = wmsCapabilities;
082 }
083
084 /**
085 * does all the work
086 *
087 * @throws MalformedURLException
088 * @throws IOException
089 * @throws SAXException
090 * @throws TransformerException
091 */
092 public void run()
093 throws MalformedURLException, IOException, SAXException, TransformerException {
094 // TODO
095 // consider already existing WMS capabilities
096
097 File in = new File( inFile );
098 XMLFragment xml = new XMLFragment( in.toURL() );
099 XSLTDocument xslt = new XSLTDocument( xsl );
100 xml = xslt.transform( xml );
101
102 FileOutputStream fos = new FileOutputStream( new File( outFile ) );
103 xml.write( fos );
104 fos.close();
105 }
106
107 private static void validate( Properties map )
108 throws Exception {
109 if ( map.get( "-inFile" ) == null ) {
110 throw new Exception( "-inFile parameter must be set" );
111 }
112 if ( map.get( "-outFile" ) == null ) {
113 throw new Exception( "-outFile parameter must be set" );
114 }
115 // TODO
116 // validate -WMSCapabilities target if parameter is available
117 }
118
119 public static void main( String[] args )
120 throws Exception {
121
122 Properties map = new Properties();
123 for ( int i = 0; i < args.length; i += 2 ) {
124 System.out.println( args[i + 1] );
125 map.put( args[i], args[i + 1] );
126 }
127 try {
128 validate( map );
129 } catch ( Exception e ) {
130 System.out.println( "!!! E R R O R !!!" );
131 System.out.println( e.getMessage() );
132 return;
133 }
134
135 WMS2WMC wms2wmc = new WMS2WMC( map.getProperty( "-inFile" ), map.getProperty( "-outFile" ),
136 map.getProperty( "-WMSCapabilities" ) );
137 wms2wmc.run();
138
139 }
140
141 }