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
075: .getResourceAsStream("mapping.properties");
076: InputStreamReader isr = new InputStreamReader(is);
077: BufferedReader br = new BufferedReader(isr);
078: String line = null;
079: while ((line = br.readLine()) != null) {
080: if (!line.trim().startsWith("#")) {
081: String[] tmp = StringTools.toArray(line.trim(),
082: "=", false);
083: mapping.put(tmp[0], tmp[1]);
084: }
085: }
086: } catch (IOException e) {
087: e.printStackTrace();
088: }
089: }
090: private static NamespaceContext nsc = CommonNamespaces
091: .getNamespaceContext();
092:
093: /**
094: * maps a property name of GetRecords, Delete and Update request from the catalogue
095: * schema to the underlying WFS schema
096: *
097: * @param node
098: * @return
099: * @throws XMLParsingException
100: */
101: public static String mapPropertyValue(Node node, String hlevel)
102: throws XMLParsingException {
103:
104: String s = XMLTools.getNodeAsString(node, ".", nsc, null);
105:
106: if (s.startsWith("/")) {
107: s = '.' + s;
108: } else if (s.startsWith(".")) {
109:
110: } else {
111: s = "./" + s;
112: }
113:
114: if ("service".equals(hlevel)) {
115: s = mapping.getProperty("service_" + s);
116: } else {
117: s = mapping.getProperty(s);
118: }
119: return s;
120:
121: }
122:
123: /**
124: * maps property names for sorting from the catalogue
125: * schema to the underlying WFS schema
126: * @param node
127: * @return
128: * @throws XMLParsingException
129: */
130: public static String mapSortProperty(Node node, String hlevel)
131: throws XMLParsingException {
132: String s = XMLTools.getNodeAsString(node, ".", nsc, null);
133:
134: if (s.startsWith("/")) {
135: s = '.' + s;
136: } else if (s.startsWith(".")) {
137:
138: } else {
139: s = "./" + s;
140: }
141: s = StringTools.replace(s, "./", "./sortby/", false);
142:
143: if ("service".equals(hlevel)) {
144: s = mapping.getProperty("service_" + s);
145: } else {
146: s = mapping.getProperty(s);
147: }
148:
149: return s;
150: }
151:
152: }
|