1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | *
|
---|
4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
5 | * library suite from the New Zealand Digital Library Project at th * University of Waikato, New Zealand.
|
---|
6 | *
|
---|
7 | * <BR><BR>
|
---|
8 | *
|
---|
9 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
10 | *
|
---|
11 | * <BR><BR>
|
---|
12 | *
|
---|
13 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
14 | *
|
---|
15 | * <BR><BR>
|
---|
16 | *
|
---|
17 | * This program is free software; you can redistribute it and/or modify
|
---|
18 | * it under the terms of the GNU General Public License as published by
|
---|
19 | * the Free Software Foundation; either version 2 of the License, or
|
---|
20 | * (at your option) any later version.
|
---|
21 | *
|
---|
22 | * <BR><BR>
|
---|
23 | *
|
---|
24 | * This program is distributed in the hope that it will be useful,
|
---|
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
27 | * GNU General Public License for more details.
|
---|
28 | *
|
---|
29 | * <BR><BR>
|
---|
30 | *
|
---|
31 | * You should have received a copy of the GNU General Public License
|
---|
32 | * along with this program; if not, write to the Free Software
|
---|
33 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
34 | *
|
---|
35 | *############################################## ##########################
|
---|
36 | */
|
---|
37 |
|
---|
38 | package org.greenstone.gatherer.gems;
|
---|
39 |
|
---|
40 | import java.awt.*;
|
---|
41 | import java.awt.event.*;
|
---|
42 | import java.io.*;
|
---|
43 | import java.util.*;
|
---|
44 | import javax.swing.*;
|
---|
45 | import javax.swing.event.*;
|
---|
46 | import org.greenstone.gatherer.cdm.*;
|
---|
47 | import org.greenstone.gatherer.Configuration;
|
---|
48 | import org.greenstone.gatherer.DebugStream;
|
---|
49 | import org.greenstone.gatherer.Dictionary;
|
---|
50 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
51 | import org.w3c.dom.*;
|
---|
52 |
|
---|
53 | import javax.xml.parsers.DocumentBuilder;
|
---|
54 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
55 | import javax.xml.parsers.FactoryConfigurationError;
|
---|
56 | import javax.xml.parsers.ParserConfigurationException;
|
---|
57 |
|
---|
58 | import org.xml.sax.SAXException;
|
---|
59 | import org.xml.sax.SAXParseException;
|
---|
60 | import org.w3c.dom.Document;
|
---|
61 | import org.w3c.dom.DOMException;
|
---|
62 |
|
---|
63 | /** This class manages the language commands, remembering both a list of languages to build indexes in, plus the default language.
|
---|
64 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
65 | * @version 2.3
|
---|
66 | * Created on October 27, 2004, 3:31 PM
|
---|
67 | * Modified 1/02/05 by Matthew Whyte
|
---|
68 | */
|
---|
69 | public class GEMSLanguageManager {
|
---|
70 | private Document document;
|
---|
71 | private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
---|
72 | private Vector languageCodes;
|
---|
73 | private Vector languageCodesAndNames;
|
---|
74 | public GEMSLanguageManager(String languagexml_location) {
|
---|
75 |
|
---|
76 | this.languageCodes = new Vector();
|
---|
77 | this.languageCodesAndNames = new Vector();
|
---|
78 |
|
---|
79 | try {
|
---|
80 |
|
---|
81 | File f = new File(languagexml_location);
|
---|
82 |
|
---|
83 | DocumentBuilder builder = factory.newDocumentBuilder();
|
---|
84 | document = builder.parse(f);
|
---|
85 | org.w3c.dom.Element docelement = document.getDocumentElement();
|
---|
86 |
|
---|
87 | //get all language nodes
|
---|
88 | NodeList mynodelist = docelement.getChildNodes();
|
---|
89 |
|
---|
90 | //get a single language text
|
---|
91 | //System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue()); //debug
|
---|
92 |
|
---|
93 | for(int j = 1; j < mynodelist.getLength(); j++){
|
---|
94 |
|
---|
95 | //read text value for the element
|
---|
96 | NodeList childnodesofelement = mynodelist.item(j).getChildNodes();
|
---|
97 | NamedNodeMap nnm = mynodelist.item(j).getAttributes();
|
---|
98 |
|
---|
99 | if(childnodesofelement.getLength() == 1)
|
---|
100 | {
|
---|
101 | String code = nnm.item(0).getNodeValue();
|
---|
102 | String name = nnm.item(4).getNodeValue();
|
---|
103 | String name_value = childnodesofelement.item(0).getNodeValue();
|
---|
104 | //language_box.addItem(code.toLowerCase());
|
---|
105 | this.languageCodes.add(code.toLowerCase());
|
---|
106 | this.languageCodesAndNames.add(name.toLowerCase() + " \t(" + code.toLowerCase() + ")");
|
---|
107 | } //end if
|
---|
108 | }//end for
|
---|
109 | } //end try
|
---|
110 | catch(SAXException sxe) {
|
---|
111 | System.out.println("sxe exception\n");
|
---|
112 | }
|
---|
113 | catch(ParserConfigurationException pce) {
|
---|
114 | System.out.println("pce exception\n");
|
---|
115 | }
|
---|
116 | catch(IOException ioe){
|
---|
117 | System.out.println("ioe exception\n");
|
---|
118 | }
|
---|
119 |
|
---|
120 | //end create dom object for language_box
|
---|
121 |
|
---|
122 | }
|
---|
123 | public Vector getLanguageCodesAndNames() {
|
---|
124 | return languageCodesAndNames;
|
---|
125 | }
|
---|
126 |
|
---|
127 | public Vector getLanguageCodes() {
|
---|
128 | return languageCodes;
|
---|
129 | }
|
---|
130 | public Object[] getLanguageCodesToArray() {
|
---|
131 | return languageCodes.toArray();
|
---|
132 | }
|
---|
133 | public String getEnabledLanguageCodes() {
|
---|
134 | String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true);
|
---|
135 | return enabled_languages;
|
---|
136 | }
|
---|
137 | public String[] getEnabledLanguageCodesToArray() {
|
---|
138 | String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true);
|
---|
139 | String [] enabled_languages_split = enabled_languages.split(",");
|
---|
140 | // String [] trimmed_enabled_lang_split = null;
|
---|
141 |
|
---|
142 | // for(int p = 0; p < enabled_languages_split.length; p++) {
|
---|
143 | //trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim();
|
---|
144 | // System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim());
|
---|
145 | // }//for p < enabled lang split
|
---|
146 |
|
---|
147 | return enabled_languages_split;
|
---|
148 | }
|
---|
149 | }
|
---|