001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/io/IODocument.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 53115 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.io;
044
045 import java.net.MalformedURLException;
046
047 import org.deegree.framework.util.CharsetUtils;
048 import org.deegree.framework.xml.XMLFragment;
049 import org.deegree.framework.xml.XMLParsingException;
050 import org.deegree.framework.xml.XMLTools;
051 import org.w3c.dom.Element;
052
053 /**
054 * This class provides method for reading IO configuration elements that are common to several
055 * services/applications.
056 *
057 * @version $Revision: 6259 $
058 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
059 * @author last edited by: $Author: bezema $
060 *
061 * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
062 *
063 * @since 2.0
064 */
065 public class IODocument extends XMLFragment {
066
067 private static final long serialVersionUID = -8166238044553562735L;
068
069 /**
070 * @param element
071 */
072 public IODocument( Element element ) {
073 super( element );
074 }
075
076 /**
077 * parses a JDBCConnection element and returns the object representation
078 *
079 * @return a jdbc connection object
080 * @throws XMLParsingException
081 */
082 public JDBCConnection parseJDBCConnection()
083 throws XMLParsingException {
084 JDBCConnection connection = null;
085
086 Element connectionElement = this.getRootElement();
087 if ( connectionElement != null ) {
088 String driver = XMLTools.getRequiredNodeAsString( connectionElement,
089 "dgjdbc:Driver/text()", nsContext );
090 String logon = XMLTools.getRequiredNodeAsString( connectionElement,
091 "dgjdbc:Url/text()", nsContext );
092 // following code handles the relative paths in the configuration of a hsql datatore,
093 // which was configured with the semi variable ${docRoot}, which actually is a
094 //stringconstant :-)
095 if ( logon.contains( "hsqldb" ) && logon.contains( "${docRoot}" ) ) {
096 String filename = logon.substring( logon.lastIndexOf( "${docRoot}" )
097 + "${docRoot}".length() );
098 int firstSlash = filename.indexOf( '/' );
099 if ( firstSlash != -1 && firstSlash == 0 ) {
100 filename = filename.substring( 1 );
101 }
102 LOG.logDebug( "found filename: " + filename );
103 String extension = ".script";
104 try {
105 filename = resolve( filename + extension ).toExternalForm();
106 } catch ( MalformedURLException e ) {
107 e.printStackTrace();
108 }
109 filename = filename.substring( 0, filename.indexOf( extension ) );
110 LOG.logDebug( "resolved filename: " + filename );
111 logon = "jdbc:hsqldb:" + filename;
112 }
113
114 String user = XMLTools.getNodeAsString( connectionElement, "dgjdbc:User/text()",
115 nsContext, null );
116 String password = XMLTools.getNodeAsString( connectionElement,
117 "dgjdbc:Password/text()", nsContext, null );
118 String securityConstraints = XMLTools.getNodeAsString(
119 connectionElement,
120 "dgjdbc:SecurityConstraints/text()",
121 nsContext, null );
122 String encoding = XMLTools.getNodeAsString( connectionElement,
123 "dgjdbc:Encoding/text()", nsContext,
124 CharsetUtils.getSystemCharset() );
125 String aliasPrefix = XMLTools.getNodeAsString( connectionElement,
126 "dgjdbc:AliasPrefix/text()", nsContext,
127 null );
128 String sdeDatabase = XMLTools.getNodeAsString( connectionElement,
129 "dgjdbc:SDEDatabase/text()", nsContext,
130 null );
131 String sdeVersion = XMLTools.getNodeAsString( connectionElement,
132 "dgjdbc:SDEVersion/text()", nsContext,
133 null );
134 connection = new JDBCConnection( driver, logon, user, password, securityConstraints,
135 encoding, aliasPrefix, sdeDatabase, sdeVersion );
136 }
137 return connection;
138 }
139
140 }
141 /***************************************************************************************************
142 * Changes to this class. What the people have been up to: $Log$
143 * Changes to this class. What the people have been up to: Revision 1.11 2007/01/31 16:57:10 bezema
144 * Changes to this class. What the people have been up to: added hsqldb relative path support
145 * Changes to this class. What the people have been up to:
146 * Changes to this class. What the people have been up to: Revision 1.10 2007/01/31 16:56:35 bezema
147 * Changes to this class. What the people have been up to: added hsqldb relative path support
148 * Changes to this class. What the people have been up to: Revision 1.9
149 * 2006/10/17 20:31:17 poth *** empty log message ***
150 *
151 * Revision 1.8 2006/08/07 14:52:14 poth set reading encoding to optional; use system charset as
152 * default
153 *
154 * Revision 1.7 2006/07/07 15:03:03 schmitz Fixed a few warnings. Added database options to WASS
155 * deegree params.
156 *
157 * Revision 1.6 2006/05/21 19:13:03 poth several changes required by implemented SDEDatastore /
158 * adapted to ArcSDE 9 java API
159 *
160 * Revision 1.2 2006/05/09 14:50:50 polli SDE parameters added
161 *
162 * Revision 1.1.1.1 2006/04/12 20:37:06 polli no message
163 *
164 * Revision 1.5 2006/04/06 20:25:31 poth *** empty log message ***
165 *
166 * Revision 1.4 2006/03/30 21:20:28 poth *** empty log message ***
167 *
168 * Revision 1.3 2005/11/17 08:18:35 deshmukh Renamed nsNode to nsContext
169 *
170 * Revision 1.2 2005/11/16 13:45:01 mschneider Merge of wfs development branch.
171 *
172 * Revision 1.1.2.3 2005/11/07 18:28:22 mschneider *** empty log message ***
173 *
174 * Revision 1.1.2.2 2005/11/07 15:38:04 mschneider Refactoring: use NamespaceContext instead of Node
175 * for namespace bindings.
176 *
177 * Revision 1.1.2.1 2005/11/07 13:09:26 deshmukh Switched namespace definitions in
178 * "CommonNamespaces" to URI.
179 *
180 * Revision 1.1 2005/10/07 10:30:41 poth no message
181 *
182 **************************************************************************************************/