001    //$HeadURL: https://sushibar/svn/deegree/base/trunk/src/org/deegree/framework/xml/Arc2ISO.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2008 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     ---------------------------------------------------------------------------*/
044    package org.deegree.ogcwebservices.csw.iso_profile;
045    
046    import java.text.DecimalFormat;
047    import java.util.HashMap;
048    import java.util.Map;
049    
050    import org.deegree.framework.log.ILogger;
051    import org.deegree.framework.log.LoggerFactory;
052    import org.deegree.framework.util.StringTools;
053    import org.deegree.framework.xml.XMLTools;
054    import org.w3c.dom.Node;
055    
056    /**
057     * @version $Revision: 6259 $
058     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
059     * @author last edited by: $Author: bezema $
060     * 
061     * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mrz 2007) $
062     */
063    public class Arc2ISO {
064        
065        private static ILogger LOG = LoggerFactory.getLogger( Arc2ISO.class );
066    
067        private static Map<String, String> roleCd = new HashMap<String, String>();
068    
069        private static Map<String, String> geomObjTypeCd = new HashMap<String, String>();
070    
071        private static Map<String, String> dateTypCd = new HashMap<String, String>();
072    
073        private static Map<String, String> topCatCd = new HashMap<String, String>();
074    
075        private static Map<String, String> charSetCd = new HashMap<String, String>();
076    
077        private static Map<String, String> securityCd = new HashMap<String, String>();
078    
079        private static Map<String, String> maintenanceCd = new HashMap<String, String>();
080    
081        private static Map<String, String> progressCd = new HashMap<String, String>();
082    
083        private static Map<String, String> mediumNameCd = new HashMap<String, String>();
084    
085        private static Map<String, String> mediumFormatCd = new HashMap<String, String>();
086    
087        static {
088            // fill role code map
089            roleCd.put( "001", "resourceProvider" );
090            roleCd.put( "002", "custodian" );
091            roleCd.put( "003", "owner" );
092            roleCd.put( "004", "user" );
093            roleCd.put( "005", "distributor" );
094            roleCd.put( "006", "originator" );
095            roleCd.put( "007", "pointOfContact" );
096            roleCd.put( "008", "principalInvestigator" );
097            roleCd.put( "009", "processor" );
098            roleCd.put( "010", "publisher" );
099            roleCd.put( "011", "author" );
100    
101            // fill GeometricObjectTypeCode map
102            geomObjTypeCd.put( "Point", "point" );
103            geomObjTypeCd.put( "MultiPoint", "NO MATCHING AVAILABLE" );
104            geomObjTypeCd.put( "Polyline", "curve" );
105            geomObjTypeCd.put( "Polygon", "surface" );
106            geomObjTypeCd.put( "Arc", "NO MATCHING AVAILABLE" );
107            geomObjTypeCd.put( "Node", "NO MATCHING AVAILABLE" );
108            geomObjTypeCd.put( "Region", "NO MATCHING AVAILABLE" );
109            geomObjTypeCd.put( "Route", "NO MATCHING AVAILABLE" );
110            geomObjTypeCd.put( "Tic", "NO MATCHING AVAILABLE" );
111            geomObjTypeCd.put( "Label", "NO MATCHING AVAILABLE" );
112            geomObjTypeCd.put( "Annotation", "NO MATCHING AVAILABLE" );
113            geomObjTypeCd.put( "Triangle", "NO MATCHING AVAILABLE" );
114            geomObjTypeCd.put( "Edge", "NO MATCHING AVAILABLE" );
115    
116            // fill dateTypCd map
117            dateTypCd.put( "001", "creation" );
118            dateTypCd.put( "002", "publication" );
119            dateTypCd.put( "003", "revision" );
120    
121            // fill topic category code map
122            topCatCd.put( "001", "farming" );
123            topCatCd.put( "002", "biota" );
124            topCatCd.put( "003", "boundaries" );
125            topCatCd.put( "004", "climatologyMeteorologyAtmosphere" );
126            topCatCd.put( "005", "economy" );
127            topCatCd.put( "006", "elevation" );
128            topCatCd.put( "007", "environment" );
129            topCatCd.put( "008", "geoscientificInformation" );
130            topCatCd.put( "009", "health" );
131            topCatCd.put( "010", "imageryBaseMapsEarthCover" );
132            topCatCd.put( "011", "intelligenceMilitary" );
133            topCatCd.put( "012", "inlandWaters" );
134            topCatCd.put( "013", "location" );
135            topCatCd.put( "014", "oceans" );
136            topCatCd.put( "015", "planningCadastre" );
137            topCatCd.put( "016", "society" );
138            topCatCd.put( "017", "structure" );
139            topCatCd.put( "018", "transportation" );
140            topCatCd.put( "019", "utilitiesCommunication" );
141    
142            // fill MD_CharacterSetCode list
143            charSetCd.put( "003", "utf7" );
144            charSetCd.put( "004", "utf8" );
145            charSetCd.put( "005", "utf16" );
146            charSetCd.put( "006", "8859part1" );
147            charSetCd.put( "007", "8859part2" );
148            charSetCd.put( "025", "usAscii" );
149    
150            // fill MD_ClassificationCode list
151            securityCd.put( "Top secret", "topSecret" );
152            securityCd.put( "Secret", "secret" );
153            securityCd.put( "Confidential", "confidential" );
154            securityCd.put( "Restricted", "restricted" );
155            securityCd.put( "Unclassified", "unclassified" );
156            securityCd.put( "Sensitive", "unclassified" );
157    
158            // fill MD_MaintenanceFrequencyCode list
159            maintenanceCd.put( "Continually", "continual" );
160            maintenanceCd.put( "Daily", "daily" );
161            maintenanceCd.put( "Weekly", "weekly" );
162            maintenanceCd.put( "Monthly", "monthly" );
163            maintenanceCd.put( "Annually", "annually" );
164            maintenanceCd.put( "Unknown", "unknown" );
165            maintenanceCd.put( "As needed", "asNeeded" );
166            maintenanceCd.put( "Irregular", "irregular" );
167            maintenanceCd.put( "None planned", "notPlanned" );
168    
169            progressCd.put( "Complete", "completed" );
170            progressCd.put( "In work", "onGoing" );
171            progressCd.put( "Planned", "planned" );
172    
173            mediumNameCd.put( "CD-ROM", "cdRom" );
174            mediumNameCd.put( "DVD", "dvd" );
175            mediumNameCd.put( "DVD-ROM", "dvdRom" );
176            mediumNameCd.put( "3-1/2 inch floppy disk", "3halfInchFloppy" );
177            mediumNameCd.put( "5-1/4 inch floppy disk", "5quarterInchFloppy" );
178            mediumNameCd.put( "7-track tape", "7trackTape" );
179            mediumNameCd.put( "9-track tape", "9trackTape" );
180            mediumNameCd.put( "4 mm cartridge tape", "4mmCartridgeTape" );
181            mediumNameCd.put( "8 mm cartridge tape", "8mmCartridgeTape" );
182            mediumNameCd.put( "1/4-inch cartridge tape", "1quarterInchCartridgeTape" );
183    
184            mediumFormatCd.put( "cpio", "cpio" );
185            mediumNameCd.put( "tar", "tar" );
186            mediumNameCd.put( "High Sierra", "highSierra" );
187            mediumNameCd.put( "ISO 9660", "iso9660" );
188            mediumNameCd.put( "ISO 9660 with Rock Ridge extensions", "iso9660RockRidge" );
189            mediumNameCd.put( "ISO 9660 with Apple HFS extensions", "iso9660AppleHFS" );
190        }
191    
192        /**
193         * transforms a esri arc catalog date into a ISO8601 date format
194         * 
195         * @param node
196         * @return
197         */
198        public static String getISODate( Node node ) {
199            String result = "0000-01-01";
200            String s = XMLTools.getStringValue( node );
201            if ( s.length() == 8 ) {
202                String y = s.substring( 0, 4 );
203                String m = s.substring( 4, 6 );
204                String d = s.substring( 6, s.length() );
205                result = y + '-' + m + '-' + d;
206            } else if ( s.length() == 4 ) {
207                String y = s.substring( 0, 4 );
208                result = y + "-01-01";
209            }
210            return result;
211        }
212    
213        /**
214         * transforms a esri arc catalog date into a ISO8601 date format
215         * 
216         * @param node
217         * @return
218         */
219        public static String getISODate2( Node node ) {
220    
221            String s = XMLTools.getStringValue( node );
222            LOG.logDebug( "s: " + s );
223            String[] arr = StringTools.toArray( s, ".", false );
224    
225            return arr[2] + '-' + arr[1] + '-' + arr[0];
226    
227        }
228    
229        /**
230         * transforms a esri arc catalog date into a ISO8601 date format
231         * 
232         * @param node
233         * @return
234         */
235        public static String getISOTime( Node node ) {
236            String result = "00:00:00";
237            String s = XMLTools.getStringValue( node );
238            LOG.logDebug( "s: " + s );
239            if ( s.length() == 6 ) {
240                String std = s.substring( 0, 2 );
241                String m = s.substring( 2, 4 );
242                String sec = s.substring( 4, 6 );
243                result = std + ':' + m + ':' + sec;
244            }
245            return result;
246        }
247    
248        /**
249         * returns the role code value matching the passed role code ID
250         * 
251         * @param node
252         * @return
253         */
254        public static String getRoleCode( Node node ) {
255            return roleCd.get( XMLTools.getStringValue( node ) );
256        }
257    
258        /**
259         * returns the role security code value matching the passed security code ID
260         * 
261         * @param node
262         * @return the role security code value matching the passed security code ID
263         */
264        public static String getSecurityCode( Node node ) {
265            if ( securityCd.containsKey( XMLTools.getStringValue( node ) ) ) {
266                return securityCd.get( XMLTools.getStringValue( node ) );
267            }
268            return "unclassified";
269    
270        }
271    
272        /**
273         * returns the role security code value matching the passed security code ID
274         * 
275         * @param node
276         * @return the role security code value matching the passed security code ID
277         */
278        public static String getMaintenanceCode( Node node ) {
279            if ( maintenanceCd.containsKey( XMLTools.getStringValue( node ) ) ) {
280                return maintenanceCd.get( XMLTools.getStringValue( node ) );
281            }
282            return "unknown";
283    
284        }
285    
286        /**
287         * returns the GeometricObjectTypeCode value matching the passed ESRI efeageom value
288         * 
289         * @param node
290         * @return the GeometricObjectTypeCode value matching the passed ESRI
291         */
292        public static String getGeometricObjectTypeCode( Node node ) {
293            return geomObjTypeCd.get( XMLTools.getStringValue( node ) );
294        }
295    
296        /**
297         * returns the date type code value matching the passed date type code ID
298         * 
299         * @param node
300         * @return the date type code value matching the passed date type code ID
301         */
302        public static String getDateTypeCode( Node node ) {
303            return dateTypCd.get( XMLTools.getStringValue( node ) );
304        }
305    
306        /**
307         * returns the topic category code value matching the passed topic category code ID. As default
308         * 'geoscientificInformation' will be returned if passed node is null.
309         * 
310         * @param node
311         * @return
312         */
313        public static String getTopCatTypeCode( Node node ) {
314            if ( node != null ) {
315                return topCatCd.get( XMLTools.getStringValue( node ) );
316            }
317            return "geoscientificInformation";
318        }
319    
320        /**
321         * returns the CharacterSetCode value matching the passed CharacterSetCode ID
322         * 
323         * @param node
324         * @return the CharacterSetCode value matching the passed
325         */
326        public static String getCharacterSetCode( Node node ) {
327            return charSetCd.get( XMLTools.getStringValue( node ) );
328        }
329    
330        /**
331         * formats a number to a String formatted: ###.##
332         * 
333         * @param node
334         * @return
335         */
336        public static String formatCoord( Node node ) {
337            String s = XMLTools.getStringValue( node );
338            DecimalFormat dc = new DecimalFormat( "###.##" );
339            return dc.format( Double.parseDouble( s ) ).replace( ',', '.' );
340        }
341    
342        /**
343         * returns the ProgressCode value matching the passed progressCode
344         * 
345         * @param node
346         * @return the ProgressCode value matching the passed progressCode
347         */
348        public static String getProgressCode( Node node ) {
349            return progressCd.get( XMLTools.getStringValue( node ) );
350        }
351    
352        /**
353         * returns the MediumNameCode value matching the passed MediumNameCode
354         * 
355         * @param node
356         * @return the MediumNameCode value matching the passed MediumNameCode
357         */
358        public static String getMediumNameCode( Node node ) {
359            if ( mediumNameCd.containsKey( XMLTools.getStringValue( node ) ) ) {
360                return mediumNameCd.get( XMLTools.getStringValue( node ) );
361            }
362            return "UNKNOWN";
363    
364        }
365    
366        /**
367         * returns the MediumFormatCode value matching the passed MediumFormatCode
368         * 
369         * @param node
370         * @return the MediumFormatCode value matching the passed MediumFormatCode
371         */
372        public static String getMediumFormatCode( Node node ) {
373            if ( mediumFormatCd.containsKey( XMLTools.getStringValue( node ) ) ) {
374                return mediumFormatCd.get( XMLTools.getStringValue( node ) );
375            }
376            return "UNKNOWN";
377    
378        }
379    }