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    
037    package org.deegree.ogcwebservices.csw.iso_profile;
038    
039    import java.io.BufferedReader;
040    import java.io.IOException;
041    import java.io.InputStream;
042    import java.io.InputStreamReader;
043    import java.util.Properties;
044    
045    import org.deegree.framework.util.IDGenerator;
046    import org.deegree.framework.util.StringTools;
047    import org.deegree.framework.xml.NamespaceContext;
048    import org.deegree.framework.xml.XMLParsingException;
049    import org.deegree.framework.xml.XMLTools;
050    import org.deegree.ogcbase.CommonNamespaces;
051    import org.w3c.dom.Node;
052    
053    /**
054     *
055     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
056     * @author last edited by: $Author: buesching $
057     *
058     * @version $Revision: 1.9 $, $Date: 2008-01-25 14:36:09 $
059     */
060    public class Mapping2_0_2_blob {
061    
062        private static IDGenerator idgen = IDGenerator.getInstance();
063    
064        private static Properties mapping = null;
065    
066        private Properties nsp = null;
067    
068        private static Properties namespaces = new Properties();
069    
070        private static Properties namespacesInverse = new Properties();
071    
072        static {
073            mapping = new Properties();
074            try {
075                InputStream is = Mapping2_0_2.class.getResourceAsStream( "mapping2_0_2_blob.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(), "=", false );
082                        if ( tmp[0].startsWith( "$namespace." ) ) {
083                            String pre = tmp[0].substring( tmp[0].indexOf( '.' ) + 1, tmp[0].length() );
084                            namespaces.put( pre, tmp[1] );
085                            namespacesInverse.put( tmp[1], pre );
086                        } else {
087                            mapping.put( tmp[0], tmp[1] );
088                        }
089                    }
090                }
091            } catch ( IOException e ) {
092                e.printStackTrace();
093            }
094        }
095    
096        private static NamespaceContext nsc = CommonNamespaces.getNamespaceContext();
097    
098        /**
099         * maps a property name of GetRecords, Delete and Update request from the catalogue schema to
100         * the underlying WFS schema
101         *
102         * @param node
103         * @param nspDec
104         * @return the value
105         * @throws XMLParsingException
106         */
107        public String mapPropertyValue( Node node, String nspDec )
108                                throws XMLParsingException {
109            if ( nsp == null ) {
110                createNsp( nspDec );
111            }
112    
113            String s = XMLTools.getNodeAsString( node, ".", nsc, null );
114            String prefix = s.substring( 0, s.indexOf( ':' ) );
115            String localPre = namespacesInverse.getProperty( nsp.getProperty( prefix ) );
116    
117            String propertyValue = "./" + localPre + s.substring( s.indexOf( ':' ) );
118            propertyValue = mapping.getProperty( propertyValue );
119    
120            return propertyValue;
121    
122        }
123    
124        private void createNsp( String nspDec ) {
125            nsp = new Properties();
126            String[] tmp = StringTools.toArray( nspDec, ";", false );
127            for ( int i = 0; i < tmp.length; i++ ) {
128                int p = tmp[i].indexOf( ':' );
129                String pre = tmp[i].substring( 0, p );
130                String val = tmp[i].substring( p + 1 );
131                nsp.put( pre, val );
132            }
133    
134        }
135    
136        /**
137         * maps property names for sorting from the catalogue schema to the underlying WFS schema
138         *
139         * @param node
140         * @param nspDec
141         * @return the property
142         * @throws XMLParsingException
143         */
144        public String mapSortProperty( Node node, String nspDec )
145                                throws XMLParsingException {
146            if ( nsp == null ) {
147                createNsp( nspDec );
148            }
149    
150            String s = XMLTools.getNodeAsString( node, ".", nsc, null );
151            String prefix = s.substring( 0, s.indexOf( ':' ) );
152            String localPre = namespacesInverse.getProperty( nsp.getProperty( prefix ) );
153    
154            String propertyValue = "./sortby/" + localPre + s.substring( s.indexOf( ':' ) );
155            propertyValue = mapping.getProperty( propertyValue );
156    
157            return propertyValue;
158        }
159    
160        /**
161         * @param node
162         * @param propName
163         * @param wildCard
164         * @return the literal
165         * @throws XMLParsingException
166         */
167        public String getLiteralValueIsLike( Node node, String propName, String wildCard )
168                                throws XMLParsingException {
169    
170            String literal = XMLTools.getNodeAsString( node, ".", nsc, null );
171            String propertyName = propName.substring( propName.indexOf( ':' ) + 1 );
172    
173            String newLiteral = literal;
174            if ( propertyName.equals( "subject" ) || propertyName.equals( "AlternateTitle" )
175                 || propertyName.equals( "ResourceIdentifier" ) || propertyName.equals( "ResourceLanguage" )
176                 || propertyName.equals( "AlternateTitle" ) || propertyName.equals( "ResourceIdentifier" )
177                 || propertyName.equals( "GeographicDescriptionCode" ) || propertyName.equals( "TopicCategory" ) ) {
178                newLiteral = StringTools.concat( 500, "%|", wildCard, literal, wildCard, "|%" );
179            }
180    
181            return newLiteral;
182        }
183    
184        /**
185         * @param node
186         * @return the value
187         * @throws XMLParsingException
188         */
189        public String getLiteralValueIsEqualTo( Node node )
190                                throws XMLParsingException {
191            String literal = XMLTools.getNodeAsString( node, ".", nsc, null );
192            return StringTools.concat( 100, "%|", literal, "|%" );
193        }
194    
195        /**
196         * @return a new generated id
197         */
198        public static String getId() {
199            return "unknown" + Long.toString( idgen.generateUniqueID() );
200        }
201    
202    }