001 /*---------------- FILE HEADER ------------------------------------------
002
003 This file is part of deegree.
004 Copyright (C) 2001-2008 by:
005 EXSE, Department of Geography, University of Bonn
006 http://www.giub.uni-bonn.de/exse/
007 lat/lon GmbH
008 http://www.lat-lon.de
009
010 This library is free software; you can redistribute it and/or
011 modify it under the terms of the GNU Lesser General Public
012 License as published by the Free Software Foundation; either
013 version 2.1 of the License, or (at your option) any later version.
014
015 This library is distributed in the hope that it will be useful,
016 but WITHOUT ANY WARRANTY; without even the implied warranty of
017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018 Lesser General Public License for more details.
019
020 You should have received a copy of the GNU Lesser General Public
021 License along with this library; if not, write to the Free Software
022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023
024 Contact:
025
026 Andreas Poth
027 lat/lon GmbH
028 Aennchenstr. 19
029 53115 Bonn
030 Germany
031 E-Mail: poth@lat-lon.de
032
033 Prof. Dr. Klaus Greve
034 Department of Geography
035 University of Bonn
036 Meckenheimer Allee 166
037 53115 Bonn
038 Germany
039 E-Mail: greve@giub.uni-bonn.de
040
041 ---------------------------------------------------------------------------*/
042 package org.deegree.ogcwebservices.csw.iso_profile;
043
044 import java.io.BufferedReader;
045 import java.io.IOException;
046 import java.io.InputStream;
047 import java.io.InputStreamReader;
048 import java.util.Properties;
049
050 import org.deegree.framework.util.StringTools;
051 import org.deegree.framework.xml.NamespaceContext;
052 import org.deegree.framework.xml.XMLParsingException;
053 import org.deegree.framework.xml.XMLTools;
054 import org.deegree.ogcbase.CommonNamespaces;
055 import org.w3c.dom.Node;
056
057 /**
058 *
059 *
060 * @version $Revision$
061 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
062 * @author last edited by: $Author$
063 *
064 * @version 1.0. $Revision$, $Date$
065 *
066 * @since 2.0
067 */
068 public class Mapping {
069
070 private static Properties mapping = null;
071 static {
072 mapping = new Properties();
073 try {
074 InputStream is = Mapping.class.getResourceAsStream( "mapping.properties" );
075 InputStreamReader isr = new InputStreamReader( is );
076 BufferedReader br = new BufferedReader( isr );
077 String line = null;
078 while ( (line = br.readLine() ) != null ) {
079 if ( !line.trim().startsWith( "#" ) ) {
080 String[] tmp = StringTools.toArray( line.trim(), "=", false );
081 mapping.put( tmp[0], tmp[1] );
082 }
083 }
084 } catch (IOException e) {
085 e.printStackTrace();
086 }
087 }
088 private static NamespaceContext nsc = CommonNamespaces.getNamespaceContext();
089
090 /**
091 * maps a property name of GetRecords, Delete and Update request from the catalogue
092 * schema to the underlying WFS schema
093 *
094 * @param node
095 * @return
096 * @throws XMLParsingException
097 */
098 public static String mapPropertyValue( Node node, String hlevel ) throws XMLParsingException {
099
100 String s = XMLTools.getNodeAsString( node, ".", nsc, null );
101
102 if ( s.startsWith( "/" ) ) {
103 s = '.' + s;
104 } else if ( s.startsWith( "." ) ) {
105
106 } else {
107 s = "./" + s;
108 }
109
110 if ( "service".equals( hlevel ) ) {
111 s = mapping.getProperty( "service_" + s );
112 } else {
113 s = mapping.getProperty( s );
114 }
115 return s;
116
117 }
118
119 /**
120 * maps property names for sorting from the catalogue
121 * schema to the underlying WFS schema
122 * @param node
123 * @return
124 * @throws XMLParsingException
125 */
126 public static String mapSortProperty(Node node, String hlevel) throws XMLParsingException {
127 String s = XMLTools.getNodeAsString( node, ".", nsc, null );
128
129 if ( s.startsWith( "/" ) ) {
130 s = '.' + s;
131 } else if ( s.startsWith( "." ) ) {
132
133 } else {
134 s = "./" + s;
135 }
136 s = StringTools.replace( s, "./", "./sortby/", false );
137
138 if ( "service".equals( hlevel ) ) {
139 s = mapping.getProperty( "service_" + s );
140 } else {
141 s = mapping.getProperty( s );
142 }
143
144 return s;
145 }
146
147
148 }