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