/**
*#########################################################################
*
* A component of the Gatherer application, part of the Greenstone digital
* library suite from the New Zealand Digital Library Project at th * University of Waikato, New Zealand.
*
*
*
* Author: John Thompson, Greenstone Digital Library, University of Waikato
*
*
*
* Copyright (C) 1999 New Zealand Digital Library Project
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*############################################## ##########################
*/
package org.greenstone.gatherer.gems;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import org.greenstone.gatherer.cdm.*;
import org.greenstone.gatherer.Configuration;
import org.greenstone.gatherer.DebugStream;
import org.greenstone.gatherer.Dictionary;
import org.greenstone.gatherer.gui.GLIButton;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.w3c.dom.Document;
import org.w3c.dom.DOMException;
/** This class manages the language commands, remembering both a list of languages to build indexes in, plus the default language.
* @author John Thompson, Greenstone Digital Library, University of Waikato
* @version 2.3
* Created on October 27, 2004, 3:31 PM
* Modified 1/02/05 by Matthew Whyte
*/
public class GEMSLanguageManager {
private Document document;
private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
private Vector languageCodes;
private Vector languageCodesAndNames;
public GEMSLanguageManager(String languagexml_location) {
this.languageCodes = new Vector();
this.languageCodesAndNames = new Vector();
try {
File f = new File(languagexml_location);
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(f);
org.w3c.dom.Element docelement = document.getDocumentElement();
//get all language nodes
NodeList mynodelist = docelement.getChildNodes();
//get a single language text
//System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue()); //debug
for(int j = 1; j < mynodelist.getLength(); j++){
//read text value for the element
NodeList childnodesofelement = mynodelist.item(j).getChildNodes();
NamedNodeMap nnm = mynodelist.item(j).getAttributes();
if(childnodesofelement.getLength() == 1)
{
String code = nnm.item(0).getNodeValue();
String name = nnm.item(4).getNodeValue();
String name_value = childnodesofelement.item(0).getNodeValue();
//language_box.addItem(code.toLowerCase());
this.languageCodes.add(code.toLowerCase());
this.languageCodesAndNames.add(name.toLowerCase() + " \t(" + code.toLowerCase() + ")");
} //end if
}//end for
} //end try
catch(SAXException sxe) {
System.out.println("sxe exception\n");
}
catch(ParserConfigurationException pce) {
System.out.println("pce exception\n");
}
catch(IOException ioe){
System.out.println("ioe exception\n");
}
//end create dom object for language_box
}
public Vector getLanguageCodesAndNames() {
return languageCodesAndNames;
}
public Vector getLanguageCodes() {
return languageCodes;
}
public Object[] getLanguageCodesToArray() {
return languageCodes.toArray();
}
public String getEnabledLanguageCodes() {
String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true);
return enabled_languages;
}
public String[] getEnabledLanguageCodesToArray() {
String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true);
String [] enabled_languages_split = enabled_languages.split(",");
// String [] trimmed_enabled_lang_split = null;
// for(int p = 0; p < enabled_languages_split.length; p++) {
//trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim();
// System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim());
// }//for p < enabled lang split
return enabled_languages_split;
}
}