001 //$HeadURL: https://sushibar/svn/deegree/base/trunk/src/org/deegree/framework/xml/Arc2ISO.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.ogcwebservices.csw.iso_profile;
037
038 import java.io.BufferedReader;
039 import java.io.IOException;
040 import java.io.InputStream;
041 import java.io.InputStreamReader;
042 import java.util.Properties;
043
044 import org.deegree.framework.util.StringTools;
045 import org.deegree.framework.xml.NamespaceContext;
046 import org.deegree.framework.xml.XMLParsingException;
047 import org.deegree.framework.xml.XMLTools;
048 import org.deegree.ogcbase.CommonNamespaces;
049 import org.w3c.dom.Node;
050
051 /**
052 *
053 *
054 * @version $Revision$
055 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
056 * @author last edited by: $Author$
057 *
058 * @version 1.0. $Revision$, $Date$
059 *
060 * @since 2.0
061 */
062 public class Mapping {
063
064 private static Properties mapping = null;
065 static {
066 mapping = new Properties();
067 try {
068 InputStream is = Mapping.class.getResourceAsStream( "mapping.properties" );
069 InputStreamReader isr = new InputStreamReader( is );
070 BufferedReader br = new BufferedReader( isr );
071 String line = null;
072 while ( ( line = br.readLine() ) != null ) {
073 if ( !line.trim().startsWith( "#" ) ) {
074 String[] tmp = StringTools.toArray( line.trim(), "=", false );
075 mapping.put( tmp[0], tmp[1] );
076 }
077 }
078 } catch ( IOException e ) {
079 e.printStackTrace();
080 }
081 }
082
083 private static NamespaceContext nsc = CommonNamespaces.getNamespaceContext();
084
085 /**
086 * maps a property name of GetRecords, Delete and Update request from the catalogue schema to
087 * the underlying WFS schema
088 *
089 * @param node
090 * @param hlevel
091 * @return the value
092 * @throws XMLParsingException
093 */
094 public static String mapPropertyValue( Node node, String hlevel )
095 throws XMLParsingException {
096
097 String s = XMLTools.getNodeAsString( node, ".", nsc, null );
098
099 if ( s.startsWith( "/" ) ) {
100 s = '.' + s;
101 } else if ( s.startsWith( "." ) ) {
102 // is this intentionally left blank?
103 } else {
104 s = "./" + s;
105 }
106
107 if ( "service".equals( hlevel ) ) {
108 s = mapping.getProperty( "service_" + s );
109 } else {
110 s = mapping.getProperty( s );
111 }
112 return s;
113
114 }
115
116 /**
117 * maps property names for sorting from the catalogue schema to the underlying WFS schema
118 *
119 * @param node
120 * @param hlevel
121 * @return the property
122 * @throws XMLParsingException
123 */
124 public static String mapSortProperty( Node node, String hlevel )
125 throws XMLParsingException {
126 String s = XMLTools.getNodeAsString( node, ".", nsc, null );
127
128 if ( s.startsWith( "/" ) ) {
129 s = '.' + s;
130 } else if ( s.startsWith( "." ) ) {
131 // again, intentionally left blank?
132 } else {
133 s = "./" + s;
134 }
135 s = StringTools.replace( s, "./", "./sortby/", false );
136
137 if ( "service".equals( hlevel ) ) {
138 s = mapping.getProperty( "service_" + s );
139 } else {
140 s = mapping.getProperty( s );
141 }
142
143 return s;
144 }
145
146 }