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
178: .put("5-1/4 inch floppy disk", "5quarterInchFloppy");
179: mediumNameCd.put("7-track tape", "7trackTape");
180: mediumNameCd.put("9-track tape", "9trackTape");
181: mediumNameCd.put("4 mm cartridge tape", "4mmCartridgeTape");
182: mediumNameCd.put("8 mm cartridge tape", "8mmCartridgeTape");
183: mediumNameCd.put("1/4-inch cartridge tape",
184: "1quarterInchCartridgeTape");
185:
186: mediumFormatCd.put("cpio", "cpio");
187: mediumNameCd.put("tar", "tar");
188: mediumNameCd.put("High Sierra", "highSierra");
189: mediumNameCd.put("ISO 9660", "iso9660");
190: mediumNameCd.put("ISO 9660 with Rock Ridge extensions",
191: "iso9660RockRidge");
192: mediumNameCd.put("ISO 9660 with Apple HFS extensions",
193: "iso9660AppleHFS");
194: }
195:
196: /**
197: * transforms a esri arc catalog date into a ISO8601 date format
198: *
199: * @param node
200: * @return
201: */
202: public static String getISODate(Node node) {
203: String result = "0000-01-01";
204: String s = XMLTools.getStringValue(node);
205: if (s.length() == 8) {
206: String y = s.substring(0, 4);
207: String m = s.substring(4, 6);
208: String d = s.substring(6, s.length());
209: result = y + '-' + m + '-' + d;
210: } else if (s.length() == 4) {
211: String y = s.substring(0, 4);
212: result = y + "-01-01";
213: }
214: return result;
215: }
216:
217: /**
218: * transforms a esri arc catalog date into a ISO8601 date format
219: *
220: * @param node
221: * @return
222: */
223: public static String getISODate2(Node node) {
224:
225: String s = XMLTools.getStringValue(node);
226: LOG.logDebug("s: " + s);
227: String[] arr = StringTools.toArray(s, ".", false);
228:
229: return arr[2] + '-' + arr[1] + '-' + arr[0];
230:
231: }
232:
233: /**
234: * transforms a esri arc catalog date into a ISO8601 date format
235: *
236: * @param node
237: * @return
238: */
239: public static String getISOTime(Node node) {
240: String result = "00:00:00";
241: String s = XMLTools.getStringValue(node);
242: LOG.logDebug("s: " + s);
243: if (s.length() == 6) {
244: String std = s.substring(0, 2);
245: String m = s.substring(2, 4);
246: String sec = s.substring(4, 6);
247: result = std + ':' + m + ':' + sec;
248: }
249: return result;
250: }
251:
252: /**
253: * returns the role code value matching the passed role code ID
254: *
255: * @param node
256: * @return
257: */
258: public static String getRoleCode(Node node) {
259: return roleCd.get(XMLTools.getStringValue(node));
260: }
261:
262: /**
263: * returns the role security code value matching the passed security code ID
264: *
265: * @param node
266: * @return the role security code value matching the passed security code ID
267: */
268: public static String getSecurityCode(Node node) {
269: if (securityCd.containsKey(XMLTools.getStringValue(node))) {
270: return securityCd.get(XMLTools.getStringValue(node));
271: }
272: return "unclassified";
273:
274: }
275:
276: /**
277: * returns the role security code value matching the passed security code ID
278: *
279: * @param node
280: * @return the role security code value matching the passed security code ID
281: */
282: public static String getMaintenanceCode(Node node) {
283: if (maintenanceCd.containsKey(XMLTools.getStringValue(node))) {
284: return maintenanceCd.get(XMLTools.getStringValue(node));
285: }
286: return "unknown";
287:
288: }
289:
290: /**
291: * returns the GeometricObjectTypeCode value matching the passed ESRI efeageom value
292: *
293: * @param node
294: * @return the GeometricObjectTypeCode value matching the passed ESRI
295: */
296: public static String getGeometricObjectTypeCode(Node node) {
297: return geomObjTypeCd.get(XMLTools.getStringValue(node));
298: }
299:
300: /**
301: * returns the date type code value matching the passed date type code ID
302: *
303: * @param node
304: * @return the date type code value matching the passed date type code ID
305: */
306: public static String getDateTypeCode(Node node) {
307: return dateTypCd.get(XMLTools.getStringValue(node));
308: }
309:
310: /**
311: * returns the topic category code value matching the passed topic category code ID. As default
312: * 'geoscientificInformation' will be returned if passed node is null.
313: *
314: * @param node
315: * @return
316: */
317: public static String getTopCatTypeCode(Node node) {
318: if (node != null) {
319: return topCatCd.get(XMLTools.getStringValue(node));
320: }
321: return "geoscientificInformation";
322: }
323:
324: /**
325: * returns the CharacterSetCode value matching the passed CharacterSetCode ID
326: *
327: * @param node
328: * @return the CharacterSetCode value matching the passed
329: */
330: public static String getCharacterSetCode(Node node) {
331: return charSetCd.get(XMLTools.getStringValue(node));
332: }
333:
334: /**
335: * formats a number to a String formatted: ###.##
336: *
337: * @param node
338: * @return
339: */
340: public static String formatCoord(Node node) {
341: String s = XMLTools.getStringValue(node);
342: DecimalFormat dc = new DecimalFormat("###.##");
343: return dc.format(Double.parseDouble(s)).replace(',', '.');
344: }
345:
346: /**
347: * returns the ProgressCode value matching the passed progressCode
348: *
349: * @param node
350: * @return the ProgressCode value matching the passed progressCode
351: */
352: public static String getProgressCode(Node node) {
353: return progressCd.get(XMLTools.getStringValue(node));
354: }
355:
356: /**
357: * returns the MediumNameCode value matching the passed MediumNameCode
358: *
359: * @param node
360: * @return the MediumNameCode value matching the passed MediumNameCode
361: */
362: public static String getMediumNameCode(Node node) {
363: if (mediumNameCd.containsKey(XMLTools.getStringValue(node))) {
364: return mediumNameCd.get(XMLTools.getStringValue(node));
365: }
366: return "UNKNOWN";
367:
368: }
369:
370: /**
371: * returns the MediumFormatCode value matching the passed MediumFormatCode
372: *
373: * @param node
374: * @return the MediumFormatCode value matching the passed MediumFormatCode
375: */
376: public static String getMediumFormatCode(Node node) {
377: if (mediumFormatCd.containsKey(XMLTools.getStringValue(node))) {
378: return mediumFormatCd.get(XMLTools.getStringValue(node));
379: }
380: return "UNKNOWN";
381:
382: }
383: }
|