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