/**
*#########################################################################
*
* A component of the Gatherer application, part of the Greenstone digital
* library suite from the New Zealand Digital Library Project at the
* University of Waikato, New Zealand.
*
*
*
* Author: Shaoqun Wu, Greenstone Digital Library, University of Waikato
*
*
*
* Copyright (C) 2006 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.io.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import org.greenstone.gatherer.Configuration;
import org.greenstone.gatherer.util.Utility;
import org.greenstone.gatherer.file.*;
import org.greenstone.gatherer.util.XMLTools;
import org.greenstone.gatherer.Dictionary;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;
import org.w3c.dom.*;
import org.xml.sax.*;
/** This class is responsible for managing all the metadata sets in the collection and for providing methods for manipulating the aforementioned sets contents.
* @author Shaoqun Wu, Greenstone Digital Library, University of Waikato
* @version 2.4
*/
public class MetadataSetManager
{
private ArrayList mds_list = new ArrayList();
private MetadataSetModel metadata_set_model;
private ArrayList languageList;
private String current_language = GEMSConstants.DEFAULT_LANGUAGE;
/** Constructor. */
public MetadataSetManager(String gsdl_path) {
// Determine the GLI user directory path
String gli_user_directory_path = System.getProperty("user.home") + File.separator;
if (Utility.isWindows()) {
gli_user_directory_path += "Application Data" + File.separator + "Greenstone" + File.separator + "GLI" + File.separator;
}
else {
gli_user_directory_path += ".gli" + File.separator;
}
new Configuration(gli_user_directory_path, gsdl_path, null, null, null);
current_language = Configuration.getLanguage();
languageList = new ArrayList();
}
public ArrayList getLanguageList(){
//already loaded
if (languageList.size() > 0 ) return languageList;
Document document = XMLTools.parseXMLFile(getLanguageXMLPath(), true);
NodeList languages = document.getDocumentElement().getElementsByTagName(GEMSConstants.LANGUAGE_ELEMENT);
for(int i=0; i< languages.getLength();i++){
Element language_element = (Element)languages.item(i);
languageList.add(language_element.getAttribute(GEMSConstants.CODE_ATTRIBUTE).toLowerCase()+" "+language_element.getAttribute(GEMSConstants.NAME_ATTRIBUTE));
}
return languageList;
}
public boolean isAttributeRequired(String name){
String tmp_name = name.trim();
for(int i=0;i0){
info.setCurrentLanguage(((Attribute)attrs.get(0)).getLanguage());
}
info.setFilePath(metadata_path);
return info;
}
public void deleteMetadataSet(MetadataSetInfo info){
String filepath = info.getFilePath();
if(filepath != null && !filepath.trim().equals("")){
File file = new File(filepath);
boolean deleted = file.delete();
if (!deleted){
JOptionPane.showMessageDialog(null,Dictionary.get("GEMS.File_Deletion_Error_Message"), Dictionary.get("GEMS..File_Deletion_Error"),JOptionPane.ERROR_MESSAGE);
}
else{
for(int i=0;i elements
NodeList setLanguages = document.getDocumentElement().getElementsByTagName(GEMSConstants.SET_LANGUAGE_ELEMENT);
if (setLanguages.getLength() >0){
for(int i=0;i 0){
Element name_element = (Element)names.get(0);
Attribute attr = new Attribute(GEMSConstants.NAME_ATTRIBUTE,XMLTools.getElementTextValue(name_element), true);
if (lang == null){
attr.setLanguage(name_element.getAttribute(GEMSConstants.LANGUAGE_ATTRIBUTE));
name_lang = attr.getLanguage();
}
else{
attr.setLanguage(lang);
}
languageList.add(attr);
// if (current_language.equals(attr.getLanguage())){
// attr.setRequired(true);
// languageList.add(0,attr);
// }
// else{
// languageList.add(attr);
// }
}
ArrayList des = XMLTools.getChildElementsByTagName(parent,GEMSConstants.DESCRIPTION_ELEMENT);
if (des.size() > 0){
Element des_element = (Element)des.get(0);
Attribute attr = new Attribute(GEMSConstants.DESCRIPTION_ATTRIBUTE,XMLTools.getElementTextValue(des_element), true);
if (lang == null){
attr.setLanguage(des_element.getAttribute(GEMSConstants.LANGUAGE_ATTRIBUTE));
}
else{
attr.setLanguage(lang);
}
languageList.add(attr);
}
else{
Attribute attr = new Attribute(GEMSConstants.DESCRIPTION_ATTRIBUTE,"", true);
if (lang == null){
attr.setLanguage(name_lang);
}
else{
attr.setLanguage(lang);
}
languageList.add(attr);
}
}
static public String getGLIDirectoryPath()
{
return System.getProperty("user.dir") + File.separator;
}
static public String getGLIMetadataDirectoryPath()
{
return getGLIDirectoryPath() + "metadata" + File.separator;
}
static public String getLanguageXMLPath()
{
return getGLIDirectoryPath() + "classes" + File.separator+"xml"+ File.separator+ "languages.xml";
}
static public String getCollectionPath()
{
return Configuration.gsdl_path + File.separator + "collect";
}
}