001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/enterprise/servlet/WFSRequestMapping.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.enterprise.servlet;
044
045 import java.io.BufferedReader;
046 import java.io.IOException;
047 import java.io.InputStream;
048 import java.io.InputStreamReader;
049 import java.util.Properties;
050
051 import org.deegree.framework.log.ILogger;
052 import org.deegree.framework.log.LoggerFactory;
053 import org.deegree.framework.util.StringTools;
054 import org.deegree.framework.xml.NamespaceContext;
055 import org.deegree.framework.xml.XMLParsingException;
056 import org.deegree.framework.xml.XMLTools;
057 import org.deegree.ogcbase.CommonNamespaces;
058 import org.w3c.dom.Node;
059
060 /**
061 * <p>The class or in detail its method @see #mapPropertyValue(Node) can be used
062 * by a XSLT script to map a node value (key) to another,
063 * corresponding value (value). The mapping will be defined by a properties
064 * file containing key-value-pairs as can be read by @see #java.util.Properties.
065 * as default org.deegree.enterprise.servlet.wfsrequestmapping.properties
066 * will be read (which per default is empty). If no matching value for a key
067 * is defined in the properties file the key will be returned instead.</p>
068 * <p>The node passed to this method must include a text and no other nodes.
069 * E.g. <PropertyName>/MyProperty/value</PropertyName></p>
070 * <p>If special behaviors are needed by an deegree WFS instance and/or
071 * you do not want to edit the default properties and use your own one
072 * you should write a class that extends this or it as pattern.
073 *
074 *
075 * @version $Revision: 6259 $
076 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
077 * @author last edited by: $Author: bezema $
078 *
079 * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
080 *
081 * @since 2.0
082 */
083 public class WFSRequestMapping {
084
085 private static ILogger LOG = LoggerFactory.getLogger( WFSRequestMapping.class );
086
087 protected static String propertiesFile = "wfsrequestmapping.properties";
088 private static Properties mapping = null;
089 static {
090 mapping = new Properties();
091 try {
092 InputStream is =
093 WFSRequestMapping.class.getResourceAsStream( "wfsrequestmapping.properties" );
094 InputStreamReader isr = new InputStreamReader( is );
095 BufferedReader br = new BufferedReader( isr );
096 String line = null;
097 while ( (line = br.readLine() ) != null ) {
098 if ( !line.trim().startsWith("#") ) {
099 String[] tmp = StringTools.toArray( line, "=", false );
100 mapping.put( tmp[0], tmp[1] );
101 }
102 }
103 } catch (IOException e) {
104 e.printStackTrace();
105 }
106 }
107 private static NamespaceContext nsc = CommonNamespaces.getNamespaceContext();
108
109 /**
110 * The method is used by a XSLT script to map a node value (key) to another,
111 * corresponding value (value). The mapping will be defined by a properties
112 * file containing key-value-pairs as can be read by @see #java.util.Properties.
113 * as default org.deegree.enterprise.servlet.wfsrequestmapping.properties
114 * will be read (which per default is empty). If no matching value for a key
115 * is defined in the properties file the key will be returned instead.
116 * <p>The node passed to this method must include a text and no other nodes.
117 * E.g. <PropertyName>/MyProperty/value</PropertyName></p>
118 *
119 * @param node
120 * @return
121 * @throws XMLParsingException
122 */
123 public static String mapPropertyValue( Node node ) {
124
125 String nde = null;
126 String key = null;
127 try {
128 nde = XMLTools.getNodeAsString( node, ".", nsc, null );
129 if ( nde.startsWith( "/" ) ) {
130 key = '.' + nde;
131 } else if ( nde.startsWith( "." ) ) {
132 key = nde;
133 } else {
134 key = "./" + nde;
135 }
136 } catch (Exception e) {
137 e.printStackTrace();
138 }
139
140
141 if ( mapping.getProperty( key ) != null ) {
142 nde = mapping.getProperty( key );
143 }
144 LOG.logDebug( "mapped property: " + nde );
145 return nde;
146 }
147
148 }
149
150 /* ********************************************************************
151 Changes to this class. What the people have been up to:
152 $Log$
153 Revision 1.6 2006/08/29 19:54:14 poth
154 footer corrected
155
156 Revision 1.5 2006/04/06 20:25:23 poth
157 *** empty log message ***
158
159 Revision 1.4 2006/03/30 21:20:24 poth
160 *** empty log message ***
161
162 Revision 1.3 2006/03/30 07:15:36 poth
163 *** empty log message ***
164
165 Revision 1.2 2006/02/16 08:26:48 poth
166 *** empty log message ***
167
168 Revision 1.1 2006/02/10 08:56:54 poth
169 *** empty log message ***
170
171 Revision 1.1 2006/01/09 07:47:09 ap
172 *** empty log message ***
173
174
175 ********************************************************************** */