001: //==============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.geonet.apps;
025:
026: import java.io.BufferedReader;
027: import java.io.BufferedWriter;
028: import java.io.File;
029: import java.io.FileInputStream;
030: import java.io.FileOutputStream;
031: import java.io.InputStreamReader;
032: import java.io.OutputStreamWriter;
033: import java.util.HashSet;
034: import jeeves.utils.Xml;
035: import org.dlib.tools.FullTokenizer;
036: import org.jdom.Document;
037: import org.jdom.Element;
038:
039: //==============================================================================
040:
041: public class MakeISO {
042: public static void main(String args[]) throws Exception {
043: // check args
044: if (args.length != 1) {
045: System.err.println("usage: makeISO file");
046: System.exit(1);
047: }
048:
049: FileInputStream is = new FileInputStream(new File(args[0]));
050: FileOutputStream os = new FileOutputStream(new File(args[0]
051: + ".sql"));
052:
053: BufferedReader ir = new BufferedReader(
054: new InputStreamReader(is));
055: // BufferedWriter ow = new BufferedWriter(new OutputStreamWriter(os));
056:
057: String line;
058:
059: int id = 1;
060:
061: // DbmsPool pool = Util.getDbmsPool("../config.xml");
062: // Dbms dbms = (Dbms)pool.open();
063:
064: Element root = new Element("mapping");
065:
066: HashSet<String> set = new HashSet<String>();
067:
068: while ((line = ir.readLine()) != null) {
069: FullTokenizer ft = new FullTokenizer(line, "|");
070:
071: // String code = ft.nextToken();
072: // ft.nextToken();
073: // ft.nextToken();
074: // String engDes = ft.nextToken().trim();
075: // String fraDes = ft.nextToken().trim();
076:
077: // ow.write("INSERT INTO IsoLanguages(id, code) VALUES ("+ id +",\""+ code +"\");\n");
078: // ow.write("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES ("+ id +",\"en\", \""+up(engDes)+"\");\n");
079: // ow.write("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES ("+ id +",\"es\", \""+up(engDes)+"\");\n");
080: // ow.write("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES ("+ id +",\"cn\", \""+up(engDes)+"\");\n");
081: // ow.write("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES ("+ id +",\"fr\", \""+up(fraDes)+"\");\n");
082: // ow.write("\n");
083:
084: // dbms.execute("INSERT INTO IsoLanguages(id, code) VALUES (?,?)", id, code);
085: // dbms.execute("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES (?,?,?)", id, "en", up(engDes));
086: // dbms.execute("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES (?,?,?)", id, "es", up(engDes));
087: // dbms.execute("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES (?,?,?)", id, "cn", up(engDes));
088: // dbms.execute("INSERT INTO IsoLanguagesDes(idDes, langId, label) VALUES (?,?,?)", id, "fr", up(fraDes));
089: // dbms.commit();
090:
091: String longCode = ft.nextToken();
092: ft.nextToken();
093: String shortCode = ft.nextToken();
094:
095: if (shortCode.length() == 2) {
096: if (set.contains(shortCode))
097: System.out.println("Skipped short code : "
098: + shortCode);
099: else {
100: set.add(shortCode);
101:
102: Element elem = new Element("map");
103: elem.setAttribute("longCode", longCode);
104: elem.setAttribute("shortCode", shortCode);
105: root.addContent(elem);
106: }
107: }
108: // id++;
109: }
110:
111: String xml = Xml.getString(new Document(root));
112: BufferedWriter ow = new BufferedWriter(new OutputStreamWriter(
113: os, "UTF-8"));
114: ow.write(xml);
115:
116: // pool.close(dbms);
117: ir.close();
118: ow.close();
119: }
120:
121: //-------------------------------------------------------------------------------
122:
123: private static String up(String s) {
124: char c = s.charAt(0);
125:
126: if (Character.isLowerCase(c))
127: return Character.toUpperCase(c) + s.substring(1);
128:
129: return s;
130: }
131: }
132:
133: //==============================================================================
|