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