Ignore:
Timestamp:
2004-01-16T16:04:59+13:00 (20 years ago)
Author:
jmt12
Message:

Heres a bunch of other changed files. If it wasn't a Friday afternoon I might be bothered finding out what I actually changed in them. Such changes include: a new option or three on preferences, a bug fix for the GDM classes, several changes to CDM to allow for G2.39 configuration files, a fix to Codec to allow for quotes in format strings and more work on CommandTokenizer to allow for stupid, stupid, stupid collectionextra's starting with speech marks then a new line. Plus other stuff. And things. Peace Out.

Location:
trunk/gli/src/org/greenstone/gatherer/cdm
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java

    r6318 r6539  
    4747 */
    4848public class CollectionConfiguration
    49     extends StaticStrings {
    50 
    51     static public Document document;
     49    extends StaticStrings {
     50   
     51    static final public String ENCODING = "UTF-8";
     52
     53    static public Document document;
    5254
    5355    static public void main(String[] args) {
     
    310312    /** ************************** Public Data Members ***************************/
    311313
    312     /** ************************** Private Data Members ***************************/
    313 
    314     private File collect_config_file;
    315 
    316     /** ************************** Public Methods ***************************/
    317 
    318     public CollectionConfiguration(File collect_config_file) {
     314    /** ************************** Private Data Members ***************************/
     315   
     316    /** Is the configuration file currently being read in one of the infamous G2.39 ones. */
     317    private boolean is_twopointthreenine = false;
     318    private File collect_config_file;
     319
     320    /** ************************** Public Methods ***************************/
     321
     322    public CollectionConfiguration(File collect_config_file) {
    319323    this.self = this;
    320324    this.collect_config_file = collect_config_file;
     
    322326    String collect_config_name = collect_config_file.getName();
    323327    if(collect_config_name.equals(COLLECTCONFIGURATION_XML)) {
    324         // Parse with Utility but don't use class loader
    325         document = Utility.parse(collect_config_file, false);
     328        // Parse with Utility but don't use class loader
     329        document = Utility.parse(collect_config_file, false);
    326330    }
    327331    // Otherwise if this is a legacy collect.cfg file then read in the template and send to magic parser
    328332    else if(collect_config_name.equals(COLLECT_CFG)) {
    329         document = Utility.parse(PSEUDO_COLLECTCONFIGURATION_XML, true);
    330         parse(collect_config_file);
    331     }
    332     }
    333 
    334     /** This debug facility shows the currently loaded collect.cfg or CollectConfig.xml file as a DOM tree. */
    335     public void display() {
     333        document = Utility.parse(PSEUDO_COLLECTCONFIGURATION_XML, true);
     334        parse(collect_config_file);
     335    }
     336    }
     337
     338    /** This debug facility shows the currently loaded collect.cfg or CollectConfig.xml file as a DOM tree. */
     339    public void display() {
    336340    JDialog dialog = new JDialog(Gatherer.g_man, "Collection Configuration", false);
    337341    dialog.setSize(400,400);
     
    342346    refresh_button.addActionListener(new ActionListener() {
    343347        public void actionPerformed(ActionEvent event) {
    344             tree.setDocument(document);
    345         }
    346         });
     348            tree.setDocument(document);
     349        }
     350        });
    347351    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    348352    content_pane.setLayout(new BorderLayout());
     
    350354    content_pane.add(refresh_button, BorderLayout.SOUTH);
    351355    dialog.show();
    352     }
    353 
    354     public Element getBeta() {
     356    }
     357   
     358    public Element getBeta() {
    355359    Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_BETA_ELEMENT, null, null);
    356360    element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_BETA_STR);
    357361    element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
    358362    return element;
    359     }
     363    }
    360364
    361365    public Element getCreator() {
     
    451455    }
    452456
    453     public void save(boolean force_xml) {
     457    public void save(boolean force_xml) {
    454458    if(collect_config_file.exists()) {
    455         File original_file = new File(collect_config_file.getParentFile(), COLLECT_CFG);
    456         File backup_file = new File(collect_config_file.getParentFile(), "collect.bak");
    457         if(backup_file.exists()) {
     459        File original_file = new File(collect_config_file.getParentFile(), COLLECT_CFG);
     460        File backup_file = new File(collect_config_file.getParentFile(), "collect.bak");
     461        if(backup_file.exists()) {
    458462        backup_file.delete();
    459         }
    460         if(!original_file.renameTo(backup_file)) {
     463        }
     464        if(!original_file.renameTo(backup_file)) {
    461465        Gatherer.println("Can't rename collect.cfg");
    462         }
     466        }
    463467    }
    464468    if(force_xml || collect_config_file.getName().equals(COLLECTCONFIGURATION_XML)) {
    465         ///ystem.err.println("Writing XML");
    466         Utility.export(document, new File(collect_config_file.getParentFile(), COLLECTCONFIGURATION_XML));
     469        ///ystem.err.println("Writing XML");
     470        Utility.export(document, new File(collect_config_file.getParentFile(), COLLECTCONFIGURATION_XML));
    467471    }
    468472    else {
    469         ///ystem.err.println("Writing text");
    470         try {
    471         FileWriter file_writer = new FileWriter(collect_config_file, false);
     473        ///ystem.err.println("Writing text");
     474        try {       
     475        OutputStream ostream = new FileOutputStream(collect_config_file);
     476        Writer file_writer = new OutputStreamWriter(ostream, ENCODING);
     477        //FileWriter file_writer = new FileWriter(collect_config_file, false);
    472478        BufferedWriter buffered_writer = new BufferedWriter(file_writer);
    473479        // In order to write out an old style collect.cfg we have to traverse the model and do several 'cute' tricks to ensure the collect.cfg is valid (for instance while every metadata element has a language attribute, only second or subsequent metadata, for a certain name, needs a language argument - hence the known metadata array. Note that within GLI the language will always be shown, but it doesn't crash and burn like G2 does, te-he).
    474480        // is this still true?? now we are writing all metadata with a lang tag. can we get rid of known_metadata??
    475         known_metadata = new ArrayList();
     481        // Yes we can. Lets see..
     482        // known_metadata = new ArrayList(); 'blamo'
    476483        Element collect_config_element = document.getDocumentElement();
    477484        NodeList command_elements = collect_config_element.getChildNodes();
    478485        boolean just_wrote_newline = false; // Prevent two or more newlines in a row
    479486        for(int i = 0; i < command_elements.getLength(); i++) {
    480             Node command_node = command_elements.item(i);
    481             if(command_node instanceof Element) {
     487            Node command_node = command_elements.item(i);
     488            if(command_node instanceof Element) {
    482489            Element command_element = (Element) command_node;
    483490            // The only thing left are NewLine elements
    484491            if(command_element.getNodeName().equals(NEWLINE_ELEMENT) && !just_wrote_newline) {
    485                 buffered_writer.newLine();
    486                 just_wrote_newline = true;
     492                buffered_writer.newLine();
     493                just_wrote_newline = true;
    487494            }
    488495            // Anything else we write to file, but only if it has been assigned, the exception being the Indexes element which just get commented if unassigned (a side effect of MG && MGPP compatibility)
    489496            else if(!command_element.getAttribute(ASSIGNED_ATTRIBUTE).equals(FALSE_STR) || command_element.getNodeName().equals(INDEXES_ELEMENT) || command_element.getNodeName().equals(INDEX_DEFAULT_ELEMENT) || command_element.getNodeName().equals(LEVELS_ELEMENT)){
    490                 String command = toString(command_element, false);
    491                 if(command != null && command.length() > 0) {
     497                String command = toString(command_element, false);
     498                if(command != null && command.length() > 0) {
    492499                write(buffered_writer, command);
    493500                buffered_writer.newLine();
    494501                just_wrote_newline = false;
    495                 }
    496             }
    497             }
     502                }
     503            }
     504            }
    498505        }
    499506        buffered_writer.close();
    500         known_metadata = null;
    501         }
    502         catch (Exception exception) {
     507        // known_metadata = null; 'poof'
     508        }
     509        catch (Exception exception) {
    503510        Gatherer.println("Error in CollectionConfiguration.save(boolean): " + exception);
    504511        Gatherer.printStackTrace(exception);
    505         }
    506     }
    507     }
     512        }
     513    }
     514    }
    508515
    509516    /** ************************** Private Methods ***************************/
     
    801808    }
    802809
    803     /** Parse a collect.cfg into a DOM model representation. */
    804     private void parse(File collect_config_file) {
    805         try {
    806             Element collect_cfg_element = document.getDocumentElement();
    807             // Read in the file one command at a time.
    808             FileReader in_reader = new FileReader(collect_config_file);
    809             BufferedReader in = new BufferedReader(in_reader);
    810             String command_str = null;
    811             while((command_str = in.readLine()) != null) {
    812                 Element command_element = null;
    813                 // A command may be broken over several lines.
    814                 command_str = command_str.trim();
    815                 boolean eof = false;
    816                 while(!eof && command_str.endsWith(NEWLINE_CHARACTER)) {
    817                     String next_line = in.readLine();
    818                     if(next_line != null) {
    819                         next_line = next_line.trim();
    820                         if(next_line.length() > 0) {
    821                             // Remove the new line character
    822                             command_str = command_str.substring(0, command_str.lastIndexOf(NEWLINE_CHARACTER));
    823                             // And append the next line, which due to the test above must be non-zero length
    824                             command_str = command_str + next_line;
    825                         }
    826                         next_line = null;
     810    /** Parse a collect.cfg into a DOM model representation. */
     811    private void parse(File collect_config_file) {
     812    try {
     813        ArrayList acquired_collectionmeta_names = null;
     814        ArrayList obsolete_collectionmeta_names = null;
     815        HashMap changed_collectionmeta_names = null;
     816       
     817        // Life is made oh-so-more tricky by the existance of G2.39 config files. There are two ways to handle them:
     818        // 1. Notice that the file is G2.39 from the start, then as I parse it magic it into G2.4 standard
     819        // 2. Extend the parsing method to handle reading in G2.39, then afterwards go through the DOM changing it to G2.4 as appropriate.
     820        // As far as I can tell the second option is twice as much work, so I'll try option 1. The problem here is that I have to determine if the 'buildtype' command is somewhere in the collect.cfg file, which means I'm going to have to read the file twice - once seaching for 'buildtype' and the second time to parse it.
     821
     822        // Search for 'buildtype mgpp'
     823        InputStream input_stream_one = new FileInputStream(collect_config_file);
     824        Reader reader_one = new InputStreamReader(input_stream_one, ENCODING);
     825        BufferedReader buffered_reader_one = new BufferedReader(reader_one);
     826        String search_line_str = null;
     827        while(!is_twopointthreenine && (search_line_str = buffered_reader_one.readLine()) != null) {
     828        if(search_line_str.toLowerCase().indexOf(BUILDTYPE_STR) != -1) {
     829            is_twopointthreenine = true;
     830            acquired_collectionmeta_names = new ArrayList();
     831            changed_collectionmeta_names = new HashMap();
     832            obsolete_collectionmeta_names = new ArrayList();
     833        }
     834        }
     835        buffered_reader_one.close();
     836        reader_one.close();
     837        input_stream_one.close();
     838        buffered_reader_one = null;
     839        reader_one = null;
     840        input_stream_one = null;   
     841
     842        Element collect_cfg_element = document.getDocumentElement();
     843        // Read in the file one command at a time.
     844        InputStream istream = new FileInputStream(collect_config_file);
     845        Reader in_reader = new InputStreamReader(istream, ENCODING);
     846        //FileReader in_reader = new FileReader(collect_config_file);
     847        BufferedReader in = new BufferedReader(in_reader);
     848        String command_str = null;
     849        while((command_str = in.readLine()) != null) {
     850        boolean append_element = true;
     851        Element command_element = null;
     852        // A command may be broken over several lines.
     853        command_str = command_str.trim();
     854        boolean eof = false;
     855        while(!eof && command_str.endsWith(NEWLINE_CHARACTER)) {
     856            String next_line = in.readLine();
     857            if(next_line != null) {
     858            next_line = next_line.trim();
     859            if(next_line.length() > 0) {
     860                // Remove the new line character
     861                command_str = command_str.substring(0, command_str.lastIndexOf(NEWLINE_CHARACTER));
     862                // And append the next line, which due to the test above must be non-zero length
     863                command_str = command_str + next_line;
     864            }
     865            next_line = null;
     866            }
     867            // If we've reached the end of the file theres nothing more we can do
     868            else {
     869            eof = true;
     870            }
     871        }
     872        // If there is still a new line character, then we remove it and hope for the best
     873        if(command_str.endsWith(NEWLINE_CHARACTER)) {
     874            command_str = command_str.substring(0, command_str.lastIndexOf(NEWLINE_CHARACTER));
     875        }
     876        // Now we've either got a command to parse...
     877        if(command_str.length() != 0) {
     878            // Start trying to figure out what it is
     879            //StringTokenizer tokenizer = new StringTokenizer(command_str);
     880            // Instead of a standard string tokenizer I'm going to use the new version of CommandTokenizer, which is not only smart enough to correctly notice speech marks and correctly parse them out, but now also takes the input stream so it can rebuild tokens that stretch over several lines.
     881            CommandTokenizer tokenizer = new CommandTokenizer(command_str, in);
     882            String command_type = tokenizer.nextToken().toLowerCase();
     883            // Why can't you switch on strings eh? We pass it to the various subparsers who each have a bash at parsing the command. If none can parse the command, an unknown element is created
     884            if(command_element == null && command_type.equals(BUILDTYPE_STR)) {
     885            Gatherer.println("G2.39 Buildtype command detected. Ignoring.");
     886            command_element = document.createElement(UNKNOWN_ELEMENT);
     887            append_element = false;
     888            }
     889            if(command_element == null && command_type.equals(CLASSIFY_STR)) {
     890            command_element = parseClassify(command_str);
     891            }
     892            if(command_element == null && command_type.equals(FORMAT_STR)) {
     893            command_element = parseFormat(tokenizer); // Revised to handle multiple lines
     894            }
     895            if(command_element == null && (command_type.equals(INDEX_STR)  || command_type.equals(COMMENTED_INDEXES_STR))) {
     896            // If this was a G2.39 config file then we manipulate the command string a bit before we submit it to the parser. We start by adding allfields as the first index. We then space separate the remaining indexes, and remove duplicates when encountered. Of course before we do any of that we record the various space separated indexes so that we can remove the collection meta assigned to them.
     897            if(is_twopointthreenine) {
     898                Gatherer.println("G2.39 Index command detected. Modifying.");
     899                Gatherer.println("Before: " + command_str);
     900                StringBuffer new_command_str = new StringBuffer(command_type);
     901                new_command_str.append(SPACE_CHARACTER);
     902                new_command_str.append(ALLFIELDS_STR);
     903                new_command_str.append(SPACE_CHARACTER);
     904                ArrayList known_indexes = new ArrayList();
     905                while(tokenizer.hasMoreTokens()) {
     906                String old_index_str = tokenizer.nextToken();
     907                // If this index is a combination of sources, then we need to remove the old collectionmeta, split up the compound index, then request new metadata be added for each part
     908                if(old_index_str.indexOf(COMMA_CHARACTER) != -1) {
     909                    obsolete_collectionmeta_names.add(STOP_CHARACTER + old_index_str);
     910                    StringTokenizer string_tokenizer = new StringTokenizer(old_index_str, COMMA_CHARACTER);
     911                    while(string_tokenizer.hasMoreTokens()) {
     912                    String index_fragment_str = string_tokenizer.nextToken();
     913                    if(!known_indexes.contains(index_fragment_str)) {
     914                        known_indexes.add(index_fragment_str);
     915                        new_command_str.append(index_fragment_str);
     916                        new_command_str.append(SPACE_CHARACTER);
     917                        acquired_collectionmeta_names.add(STOP_CHARACTER + index_fragment_str);
    827918                    }
    828                     // If we've reached the end of the file theres nothing more we can do
    829                     else {
    830                         eof = true;
    831                     }
     919                    index_fragment_str = null;
     920                    }
     921                    string_tokenizer = null;
    832922                }
    833                 // If there is still a new line character, then we remove it and hope for the best
    834                 if(command_str.endsWith(NEWLINE_CHARACTER)) {
    835                     command_str = command_str.substring(0, command_str.lastIndexOf(NEWLINE_CHARACTER));
     923                // However if this was just a single index then a little choir of angels sing haleluja because we don't have to do -anything-. Nothing at all. Zip. Well no changes anyway. I obviously had to write this comment, and you can probably see, assuming you are not blind, that there are several lines of code below doing something, which is of course not nothing but something. And if we assume you are blind then you probably can't see the code, but then you probably didn't not see it doing the not nothing I said it would above.
     924                else {
     925                    if(!known_indexes.contains(old_index_str)) {
     926                    known_indexes.add(old_index_str);
     927                    new_command_str.append(old_index_str);
     928                    new_command_str.append(SPACE_CHARACTER);
     929                    }
     930                    else {
     931                    // Use the collectionmeta for the single index instead of generating a default one
     932                    acquired_collectionmeta_names.remove(STOP_CHARACTER + old_index_str);
     933                    }
    836934                }
    837                 // Now we've either got a command to parse...
    838                 if(command_str.length() != 0) {
    839                     // Start trying to figure out what it is
    840                     //StringTokenizer tokenizer = new StringTokenizer(command_str);
    841                     // Instead of a standard string tokenizer I'm going to use the new version of CommandTokenizer, which is not only smart enough to correctly notice speech marks and correctly parse them out, but now also takes the input stream so it can rebuild tokens that stretch over several lines.
    842                     CommandTokenizer tokenizer = new CommandTokenizer(command_str, in);
    843                     String command_type = tokenizer.nextToken().toLowerCase();
    844                     // Why can't you switch on strings eh? We pass it to the various subparsers who each have a bash at parsing the command. If none can parse the command, an unknown element is created
    845                     if(command_element == null && command_type.equals(CLASSIFY_STR)) {
    846                         command_element = parseClassify(command_str);
    847                     }
    848                     if(command_element == null && command_type.equals(FORMAT_STR)) {
    849                         command_element = parseFormat(tokenizer); // Revised to handle multiple lines
    850                     }
    851                     if(command_element == null && (command_type.equals(INDEX_STR)  || command_type.equals(COMMENTED_INDEXES_STR))) {
    852                         command_element = parseIndex(command_str);
    853                     }
    854                     if(command_element == null && (command_type.equals(INDEX_DEFAULT_STR) || command_type.equals(COMMENTED_INDEX_DEFAULT_STR))) {
    855                         command_element = parseIndexDefault(command_str);
    856                     }
    857                     if(command_element == null && command_type.equals(LANGUAGES_STR)) {
    858                         command_element = parseLanguage(command_str);
    859                     }
    860                     if(command_element == null && command_type.equals(LANGUAGE_DEFAULT_STR)) {
    861                         command_element = parseLanguageDefault(command_str);
    862                     }
    863                     if(command_element == null && (command_type.equals(LEVELS_STR) || command_type.equals(COMMENTED_LEVELS_STR))) {
    864                         command_element = parseLevels(command_str);
    865                     }
    866                     if(command_element == null && command_type.equals(COLLECTIONMETADATA_STR)) {
    867                         command_element = parseMetadata(tokenizer); // Revised to handle multiple lines
    868                     }
    869                     if(command_element == null && (command_type.equals(COLLECTIONMETADATA_BETA_STR) || command_type.equals(COLLECTIONMETADATA_PUBLIC_STR) || command_type.equals(COLLECTIONMETADATA_CREATOR_STR) || command_type.equals(COLLECTIONMETADATA_MAINTAINER_STR))) {
    870                         command_element = parseMetadataSpecial(command_str);
    871                     }
    872                     if(command_element == null && command_type.equals(PLUGIN_STR)) {
    873                         command_element = parsePlugIn(command_str);
    874                     }
    875                     if(command_element == null && command_type.equals(SEARCHTYPE_STR)) {
    876                         command_element = parseSearchType(command_str);
    877                     }
    878                     if(command_element == null && command_type.equals(SUBCOLLECTION_STR)) {
    879                         command_element = parseSubCollection(command_str);
    880                     }
    881                     if(command_element == null && command_type.equals(SUBCOLLECTION_DEFAULT_INDEX_STR)) {
    882                         command_element = parseSubCollectionDefaultIndex(command_str);
    883                     }
    884                     if(command_element == null && command_type.equals(SUBCOLLECTION_INDEX_STR)) {
    885                         command_element = parseSubCollectionIndex(command_str);
    886                     }
    887                     if(command_element == null && (command_type.equals(SUPERCOLLECTION_STR) || command_type.equals(CCS_STR))) {
    888                         command_element = parseSuperCollection(command_str);
    889                     }
    890             // Doesn't match any known type
    891             command_type = null;
    892             if(command_element == null) {
     935                old_index_str = null;
     936                }
     937                known_indexes = null;
     938                command_str = new_command_str.toString();
     939                new_command_str = null;
     940                Gatherer.println("After: " + command_str);
     941            }
     942            command_element = parseIndex(command_str);
     943            }
     944            if(command_element == null && (command_type.equals(INDEX_DEFAULT_STR) || command_type.equals(COMMENTED_INDEX_DEFAULT_STR))) {
     945           
     946            command_element = parseIndexDefault(command_str);
     947            // If this was a G2.39 config file then we squelch the default index (no such thing in G2.4)
     948            if(is_twopointthreenine) {
     949                Gatherer.println("G2.39 Default Index command detected. Ignoring.");
     950                append_element = false;
     951            }
     952            }
     953            if(command_element == null && command_type.equals(LANGUAGES_STR)) {
     954            command_element = parseLanguage(command_str);
     955            }
     956            if(command_element == null && command_type.equals(LANGUAGE_DEFAULT_STR)) {
     957            command_element = parseLanguageDefault(command_str);
     958            }
     959            if(command_element == null && (command_type.equals(LEVELS_STR) || command_type.equals(COMMENTED_LEVELS_STR))) {
     960            // Again if this is G2.39 we have to do a tiny bit of magic to the levels command. We need to add document level, and change the remainder to lower case.
     961            if(is_twopointthreenine) {
     962                Gatherer.println("G2.39 Levels command detected. Modifying.");
     963                Gatherer.println("Before: " + command_str);
     964                StringBuffer new_command_str = new StringBuffer(command_type);
     965                new_command_str.append(SPACE_CHARACTER);
     966                new_command_str.append(DOCUMENT_STR);
     967                while(tokenizer.hasMoreTokens()) {
     968                String token = tokenizer.nextToken();
     969                // Generate a lower case version
     970                String token_lc = token.toLowerCase();
     971                // If they are still the same then it is all good baby, otherwise we have to remember to transform their collectionmeta as well
     972                if(!token.equals(token_lc)) {
     973                    changed_collectionmeta_names.put(STOP_CHARACTER + token, STOP_CHARACTER + token_lc);
     974                }
     975                new_command_str.append(SPACE_CHARACTER);
     976                new_command_str.append(token_lc);
     977                token_lc = null;
     978                token = null;
     979                }
     980                command_str = new_command_str.toString();
     981                new_command_str = null;
     982                Gatherer.println("After: " + command_str);
     983            }
     984            command_element = parseLevels(command_str);
     985            }
     986            if(command_element == null && command_type.equals(COLLECTIONMETADATA_STR)) {
     987            command_element = parseMetadata(tokenizer); // Revised to handle multiple lines
     988            }
     989            if(command_element == null && (command_type.equals(COLLECTIONMETADATA_BETA_STR) || command_type.equals(COLLECTIONMETADATA_PUBLIC_STR) || command_type.equals(COLLECTIONMETADATA_CREATOR_STR) || command_type.equals(COLLECTIONMETADATA_MAINTAINER_STR))) {
     990            command_element = parseMetadataSpecial(command_str);
     991            }
     992            if(command_element == null && command_type.equals(PLUGIN_STR)) {
     993            command_element = parsePlugIn(command_str);
     994            }
     995            if(command_element == null && command_type.equals(SEARCHTYPE_STR)) {
     996            command_element = parseSearchType(command_str);
     997            }
     998            if(command_element == null && command_type.equals(SUBCOLLECTION_STR)) {
     999            command_element = parseSubCollection(command_str);
     1000            }
     1001            if(command_element == null && command_type.equals(SUBCOLLECTION_DEFAULT_INDEX_STR)) {
     1002            command_element = parseSubCollectionDefaultIndex(command_str);
     1003            }
     1004            if(command_element == null && command_type.equals(SUBCOLLECTION_INDEX_STR)) {
     1005            command_element = parseSubCollectionIndex(command_str);
     1006            }
     1007            if(command_element == null && (command_type.equals(SUPERCOLLECTION_STR) || command_type.equals(CCS_STR))) {
     1008            command_element = parseSuperCollection(command_str);
     1009            }
     1010            // Doesn't match any known type
     1011            command_type = null;
     1012            if(command_element == null) {
    8931013            // No-one knows what to do with this command, so we create an Unknown command element
    8941014            command_element = document.createElement(UNKNOWN_ELEMENT);
    8951015            MSMUtils.setValue(command_element, command_str);
    896            }
     1016            }
    8971017        }
    8981018        // Or an empty line to remember for later
    8991019        else {
    900             command_element = document.createElement(NEWLINE_ELEMENT);
    901         }
    902         // Now command element shouldn't be null so we append it to the collection config DOM
    903         collect_cfg_element.appendChild(command_element);
    904         }
     1020            command_element = document.createElement(NEWLINE_ELEMENT);
     1021        }
     1022        // Now command element shouldn't be null so we append it to the collection config DOM, but only if we haven't been told not to add it
     1023        if(append_element) {
     1024            collect_cfg_element.appendChild(command_element);
     1025        }
     1026        }
     1027
     1028        // We have completed parsing the collect configuration file. Now, if we are dealing with the G2.39 nightmare scenario, it's time to add the SearchType command and modify the collectionmeta commands as necessary.
     1029        if(is_twopointthreenine) {
     1030        Element search_type_element = getSearchType();
     1031        search_type_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
     1032        while(search_type_element.hasChildNodes()) {
     1033            search_type_element.removeChild(search_type_element.getFirstChild());
     1034        }
     1035        Element plain_search_type_element = document.createElement(CONTENT_ELEMENT);
     1036        plain_search_type_element.setAttribute(NAME_ATTRIBUTE, SearchTypeManager.SEARCH_TYPES[1]);
     1037        search_type_element.appendChild(plain_search_type_element);
     1038        plain_search_type_element = null;
     1039        Element form_search_type_element = document.createElement(CONTENT_ELEMENT);
     1040        form_search_type_element.setAttribute(NAME_ATTRIBUTE, SearchTypeManager.SEARCH_TYPES[0]);
     1041        search_type_element.appendChild(form_search_type_element);
     1042        form_search_type_element = null;
     1043        search_type_element = null;
     1044       
     1045        // Search through the existing collectionmeta
     1046        Element document_element = document.getDocumentElement();
     1047        NodeList collectionmeta_elements = document_element.getElementsByTagName(COLLECTIONMETADATA_ELEMENT);
     1048        Gatherer.println("There are " + obsolete_collectionmeta_names.size() + " collectionmeta to remove.");
     1049        Gatherer.println("There are " + changed_collectionmeta_names.size() + " collectionmeta to change.");
     1050        for(int z = collectionmeta_elements.getLength(); z > 0; z--) {
     1051            Element collectionmeta_element = (Element) collectionmeta_elements.item(z - 1);
     1052            String name = collectionmeta_element.getAttribute(NAME_ATTRIBUTE);
     1053            Gatherer.println("Checking " + name);
     1054            // Remove any obsolete metadata
     1055            if(obsolete_collectionmeta_names.contains(name)) {
     1056            Gatherer.println("G2.39 CollectMeta detected. Removing: " + name);
     1057            document_element.removeChild(collectionmeta_element);
     1058            }
     1059            // We may have been asked to change the index name to lower case
     1060            else if(changed_collectionmeta_names.containsKey(name)) {
     1061            String new_name = (String) changed_collectionmeta_names.get(name);
     1062            Gatherer.println("G2.39 CollectMeta detected. Changing: " + name + " -> " + new_name);
     1063            collectionmeta_element.setAttribute(NAME_ATTRIBUTE, new_name);
     1064            new_name = null;
     1065            }
     1066            name = null;
     1067        }
     1068
     1069        // Finally add any newly acquired collectionmeta. This general defaults to the collectionmeta name less the full stop
     1070        Gatherer.println("There are " + acquired_collectionmeta_names.size() + " collectionmeta to add.");
     1071        for(int y = 0; y < acquired_collectionmeta_names.size(); y++) {
     1072            String name = (String) acquired_collectionmeta_names.get(y);
     1073            String value = name.substring(1);
     1074            Gatherer.println("G2.39 CollectMeta missing. Adding: " + name + " [l=" + Gatherer.config.getLanguage() + "] \"" + value + "\"");
     1075            Element element = document.createElement(COLLECTIONMETADATA_ELEMENT);
     1076            element.setAttribute(NAME_ATTRIBUTE, name);
     1077            element.setAttribute(LANGUAGE_ATTRIBUTE, Gatherer.config.getLanguage());
     1078            element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
     1079            MSMUtils.setValue(element, value);
     1080            document_element.appendChild(element);
     1081            element = null;
     1082            value = null;
     1083            name = null;
     1084        }
     1085
     1086        document_element = null;
     1087        }
    9051088    }
    9061089    catch(Exception exception) {
    907         Gatherer.println("Error in CollectionConfiguration.parse(java.io.File): " + exception);
    908         Gatherer.printStackTrace(exception);
    909     }
    910     }
    911 
    912     private Element parseClassify(String command_str) {
     1090        Gatherer.println("Error in CollectionConfiguration.parse(java.io.File): " + exception);
     1091        Gatherer.printStackTrace(exception);
     1092    }
     1093    }
     1094   
     1095    private Element parseClassify(String command_str) {
    9131096    Element command_element = null;
    9141097    try {
     
    9631146    }
    9641147
    965     private Element parseFormat(CommandTokenizer tokenizer) {
    966         Element command_element = null;
    967         try {
    968             command_element = document.createElement(FORMAT_ELEMENT);
    969             String name_str = tokenizer.nextToken();
    970             String value_str = tokenizer.nextToken();
    971             if(name_str != null && value_str != null) {
    972                 command_element.setAttribute(NAME_ATTRIBUTE, name_str);
    973                 // If the value is true or false we add it as an attribute
    974                 if(value_str.equalsIgnoreCase(TRUE_STR) || value_str.equalsIgnoreCase(FALSE_STR)) {
    975                     command_element.setAttribute(VALUE_ATTRIBUTE, value_str.toLowerCase());
    976                 }
    977                 // Otherwise it gets added as a text node
    978                 else {
    979                     // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value
    980                     value_str = Codec.transform(value_str, Codec.GREENSTONE_TO_DOM);
    981                     MSMUtils.setValue(command_element, value_str);
    982                 }
    983             }
    984             else {
    985                 command_element = null;
    986             }
    987             name_str = null;
    988             value_str = null;
    989         }
    990         catch (Exception exception) {
    991             Gatherer.printStackTrace(exception);
    992             command_element = null;
    993         }
    994         return command_element;
    995     }
     1148    private Element parseFormat(CommandTokenizer tokenizer) {
     1149    Element command_element = null;
     1150    try {
     1151        command_element = document.createElement(FORMAT_ELEMENT);
     1152        String name_str = tokenizer.nextToken();
     1153        String value_str = tokenizer.nextToken();
     1154        if(name_str != null && value_str != null) {
     1155        command_element.setAttribute(NAME_ATTRIBUTE, name_str);
     1156        // If the value is true or false we add it as an attribute
     1157        if(value_str.equalsIgnoreCase(TRUE_STR) || value_str.equalsIgnoreCase(FALSE_STR)) {
     1158            command_element.setAttribute(VALUE_ATTRIBUTE, value_str.toLowerCase());
     1159        }
     1160        // Otherwise it gets added as a text node
     1161        else {
     1162            // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value
     1163            value_str = Codec.transform(value_str, Codec.GREENSTONE_TO_DOM);
     1164            MSMUtils.setValue(command_element, value_str);
     1165        }
     1166        }
     1167        else {
     1168        command_element = null;
     1169        }
     1170        name_str = null;
     1171        value_str = null;
     1172    }
     1173    catch (Exception exception) {
     1174        Gatherer.printStackTrace(exception);
     1175        command_element = null;
     1176    }
     1177    return command_element;
     1178    }
    9961179
    9971180    private Element parseIndex(String command_str) {
     
    11491332    }
    11501333
    1151     private Element parseMetadata(CommandTokenizer tokenizer) {
    1152         Element command_element = null;
    1153         try {
    1154             command_element = document.createElement(COLLECTIONMETADATA_ELEMENT);
    1155             String name_str = tokenizer.nextToken();
    1156             String value_str = tokenizer.nextToken();
    1157             if(name_str != null && value_str != null) {
    1158                 String language_str = "en"; // By default - why do we assume English???
    1159                 // Check if the value string is actually a language string
    1160                 if(value_str.startsWith(LBRACKET_CHARACTER) && value_str.endsWith(RBRACKET_CHARACTER)) {
    1161                     language_str = value_str.substring(value_str.indexOf(LANGUAGE_ARGUMENT) + 2, value_str.length() - 1);
    1162                     value_str = tokenizer.nextToken();
    1163                 }
    1164                 if(value_str != null) {
    1165                     // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value
    1166                     value_str = Codec.transform(value_str, Codec.GREENSTONE_TO_DOM);
    1167                     command_element.setAttribute(NAME_ATTRIBUTE, name_str);
    1168                     command_element.setAttribute(LANGUAGE_ATTRIBUTE, language_str);
    1169                     command_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
    1170                     MSMUtils.setValue(command_element, value_str);
    1171                 }
    1172                 else {
    1173                     command_element = null;
    1174                 }
    1175                 language_str = null;
    1176             }
    1177             else {
    1178                 command_element = null;
    1179             }
    1180             name_str = null;
    1181             value_str = null;
    1182         }
    1183         catch (Exception exception) {
    1184             Gatherer.printStackTrace(exception);
    1185             command_element = null;
    1186         }
    1187         return command_element;
    1188     }
     1334    private Element parseMetadata(CommandTokenizer tokenizer) {
     1335    Element command_element = null;
     1336    try {
     1337        command_element = document.createElement(COLLECTIONMETADATA_ELEMENT);
     1338        String name_str = tokenizer.nextToken();
     1339        String value_str = tokenizer.nextToken();
     1340        if(name_str != null && value_str != null) {
     1341        String language_str = Gatherer.config.getLanguage();
     1342        // Check if the value string is actually a language string
     1343        if(value_str.startsWith(LBRACKET_CHARACTER) && value_str.endsWith(RBRACKET_CHARACTER)) {
     1344            language_str = value_str.substring(value_str.indexOf(LANGUAGE_ARGUMENT) + 2, value_str.length() - 1);
     1345            value_str = tokenizer.nextToken();
     1346        }
     1347        if(value_str != null) {
     1348            // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value
     1349            value_str = Codec.transform(value_str, Codec.GREENSTONE_TO_DOM);
     1350            command_element.setAttribute(NAME_ATTRIBUTE, name_str);
     1351            command_element.setAttribute(LANGUAGE_ATTRIBUTE, language_str);
     1352            command_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
     1353            MSMUtils.setValue(command_element, value_str);
     1354        }
     1355        else {
     1356            command_element = null;
     1357        }
     1358        language_str = null;
     1359        }
     1360        else {
     1361        command_element = null;
     1362        }
     1363        name_str = null;
     1364        value_str = null;
     1365    }
     1366    catch (Exception exception) {
     1367        Gatherer.printStackTrace(exception);
     1368        command_element = null;
     1369    }
     1370    return command_element;
     1371    }
    11891372
    11901373    private Element parseMetadataSpecial(String command_str) {
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMeta.java

    r6389 r6539  
    6767    element = CollectionDesignManager.collect_config.document.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT);
    6868    element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
    69     element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, Gatherer.config.interface_language);
     69    element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, Gatherer.config.getLanguage());
    7070    element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
    7171    }
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMetaManager.java

    r5930 r6539  
    124124    for(int i = 0; i < size; i++) {
    125125        CollectionMeta metadatum = (CollectionMeta) getElementAt(i);
    126         if(metadatum.getName().equals(name) && metadatum.getLanguage().equals(Gatherer.config.interface_language)) {
     126        if(metadatum.getName().equals(name) && metadatum.getLanguage().equals(Gatherer.config.getLanguage())) {
    127127        Gatherer.println("Found '" + metadatum + "'");
    128128        return metadatum;
  • trunk/gli/src/org/greenstone/gatherer/cdm/CommandTokenizer.java

    r6139 r6539  
    119119        switch(buffer.charAt(0)) {
    120120        case StaticStrings.DOUBLEQUOTE_CHAR:
     121        ///ystem.err.println("Building token wrapped by double quotes.");
    121122        result = buildToken(buffer, StaticStrings.DOUBLEQUOTE_CHAR, true);
    122123        break;
    123124        case StaticStrings.SINGLEQUOTE_CHAR:
     125        ///ystem.err.println("Building token wrapped by single quotes.");
    124126        result = buildToken(buffer, StaticStrings.SINGLEQUOTE_CHAR, true);
    125127        break;
    126128        case StaticStrings.OPENBRACKET_CHAR:
     129        ///ystem.err.println("Building token wrapped by brackets.");
    127130        result = buildToken(buffer, StaticStrings.CLOSEBRACKET_CHAR, false);
    128131        break;
    129132        default:
     133        ///ystem.err.println("Returning plain string.");
    130134        result = buffer.toString();
    131135        }
     
    136140        count = count - 1;
    137141    }
    138     ///atherer.println("----- CommandTokenizer -----\ntoken:\t" + result + "\n----------------------------");
     142    ///ystem.err.println("----- CommandTokenizer -----\ntoken:\t" + result + "\n----------------------------");
    139143    return result;
    140144    }
     
    147151     */
    148152    private String buildToken(StringBuffer buffer, char end_char, boolean strip_characters) {
    149     while(buffer.charAt(buffer.length() - 1) != end_char || (buffer.length() > 3 && buffer.charAt(buffer.length() - 2) == StaticStrings.BACKSLASH_CHAR)) {
     153    while(buffer.length() == 1 || buffer.charAt(buffer.length() - 1) != end_char || (buffer.length() > 3 && buffer.charAt(buffer.length() - 2) == StaticStrings.BACKSLASH_CHAR)) {
    150154        try {
    151155        // The first version is for the basic tokenizer which has no idea of an input stream, so runs out tokens at the same time as the internal tokenizer does
     
    159163            while(!internal_tokenizer.hasMoreTokens() && (line_str = in_stream.readLine()) != null) {
    160164            ///atherer.println("+++++ CommandTokenizer +++++\nappend:\t" + line_str + "\n+++++++++++++++++++++++++++++");
    161             // Its at this stage the our token count becomes completely patu
     165            // Its at this stage the our token count becomes completely putu
    162166            internal_tokenizer = new StringTokenizer(line_str);
    163167            buffer.append(StaticStrings.NEW_LINE_CHAR); // A new line in the final token
  • trunk/gli/src/org/greenstone/gatherer/cdm/Format.java

    r5650 r6539  
    315315        }
    316316        else {
    317            temp.append("\"");
    318            // Retrieve the DOM encoded value, decode and then append
    319            value = MSMUtils.getValue(element);
    320            value = Codec.transform(value, Codec.DOM_TO_TEXT);
    321            temp.append(value);
    322            temp.append("\"");
     317        value = MSMUtils.getValue(element);
     318        if(value.equalsIgnoreCase(CollectionConfiguration.TRUE_STR) || value.equalsIgnoreCase(CollectionConfiguration.FALSE_STR)) {
     319            temp.append(value);
     320        }
     321        else {
     322            temp.append("\"");
     323            // Retrieve the DOM encoded value, decode and then append
     324            value = Codec.transform(value, Codec.DOM_TO_TEXT);
     325            temp.append(value);
     326            temp.append("\"");
     327        }
    323328        }
    324329        text = temp.toString();
  • trunk/gli/src/org/greenstone/gatherer/cdm/FormatManager.java

    r6318 r6539  
    349349        // Connect
    350350        add_button.addActionListener(new AddListener());
    351         //default_button.addActionListener(new DefaultFormatListener());
    352351        insert_button.addActionListener(new InsertListener());
    353352        remove_button.addActionListener(new RemoveListener());
     
    373372        part_pane.add(part_combobox, BorderLayout.CENTER);
    374373
    375         selection_pane.setLayout(new GridLayout(2,1,0,2));
    376         selection_pane.add(feature_pane);
    377         selection_pane.add(part_pane);
     374        //selection_pane.setLayout(new GridLayout(2,1,0,2));
     375        //selection_pane.add(feature_pane);
     376        //selection_pane.add(part_pane);
    378377
    379378        flag_pane.add(enabled_checkbox);
     
    382381        editor_header_pane.setLayout(new GridLayout(1,3));
    383382        editor_header_pane.add(editor_label);
    384         //editor_header_pane.add(new JPanel());
    385         //editor_header_pane.add(default_button);
    386383
    387384        variable_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
     
    394391        editor_pane.add(editor_header_pane, BorderLayout.NORTH);
    395392        editor_pane.add(new JScrollPane(editor_textarea), BorderLayout.CENTER);
    396         editor_pane.add(variable_pane, BorderLayout.SOUTH);
     393        //editor_pane.add(variable_pane, BorderLayout.SOUTH);
     394
     395        selection_pane.setLayout(new BorderLayout());
     396        selection_pane.add(part_pane, BorderLayout.NORTH);
     397        selection_pane.add(editor_pane, BorderLayout.CENTER);
     398        selection_pane.add(variable_pane, BorderLayout.SOUTH);
    397399
    398400        control_pane.setLayout(card_layout);
    399401        control_pane.add(flag_pane, FLAG);
    400         control_pane.add(editor_pane, VALUE);
     402        control_pane.add(selection_pane, VALUE);
    401403        control_pane.add(blank_pane, BLANK);
    402404
     
    408410        center_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("CDM.FormatManager.Editing_Controls")), BorderFactory.createEmptyBorder(2,2,2,2)));
    409411        center_pane.setLayout(new BorderLayout());
    410         center_pane.add(selection_pane, BorderLayout.NORTH);
     412        center_pane.add(feature_pane, BorderLayout.NORTH);
    411413        center_pane.add(control_pane, BorderLayout.CENTER);
    412414        center_pane.add(button_pane, BorderLayout.SOUTH);
     
    552554                   ///ystem.err.println("Flag type");
    553555                // Flags first.
    554                 selection_pane.remove(part_pane);
     556                ///election_pane.remove(part_pane);
    555557                card_layout.show(control_pane, FLAG);
    556558                view_type = FLAG;
     
    559561                }
    560562                else {
    561                    ///ystem.err.println("Value type");
    562                 selection_pane.add(part_pane);
     563                ///ystem.err.println("Value type");
     564                ///election_pane.add(part_pane);
    563565                card_layout.show(control_pane, VALUE);
    564566                view_type = VALUE;
     
    576578                   ///ystem.err.println("Flag type");
    577579                // Flags first.
    578                 selection_pane.remove(part_pane);
     580                ///election_pane.remove(part_pane);
    579581                card_layout.show(control_pane, FLAG);
    580582                view_type = FLAG;
     
    584586                else {
    585587                   ///ystem.err.println("Value type");
    586                 selection_pane.add(part_pane);
     588                ///election_pane.add(part_pane);
    587589                card_layout.show(control_pane, VALUE);
    588590                view_type = VALUE;
     
    626628            ///ystem.err.println("Determine the correct type.");
    627629            if(format.isParamType()) {
    628                ///ystem.err.println("Flag type - remove part");
    629                // Flags first.
    630                SwingUtilities.invokeLater(new GUIChangeTask(selection_pane, part_pane, blank_pane, false));
     630                ///ystem.err.println("Flag type - remove part");
     631                // Flags first.
     632                ///SwingUtilities.invokeLater(new GUIChangeTask(/election_pane, part_pane, blank_pane, false));
    631633               card_layout.show(control_pane, FLAG);
    632634               view_type = FLAG;
     
    636638            else {
    637639               ///ystem.err.println("Value type - show part");
    638                SwingUtilities.invokeLater(new GUIChangeTask(selection_pane, part_pane, blank_pane, true));
     640                ///SwingUtilities.invokeLater(new GUIChangeTask(/election_pane, part_pane, blank_pane, true));
    639641               card_layout.show(control_pane, VALUE);
    640642               view_type = VALUE;
     
    706708                if(format.isParamType()) {
    707709                // Flags first.
    708                 selection_pane.remove(part_pane);
     710                ///election_pane.remove(part_pane);
    709711                card_layout.show(control_pane, FLAG);
    710712                view_type = FLAG;
     
    713715                }
    714716                else {
    715                 selection_pane.add(part_pane);
     717                ///election_pane.add(part_pane);
    716718                card_layout.show(control_pane, VALUE);
    717719                view_type = VALUE;
     
    726728                if(Format.isParamType(name)) {
    727729                // Flags first.
    728                 selection_pane.remove(part_pane);
     730                ///election_pane.remove(part_pane);
    729731                card_layout.show(control_pane, FLAG);
    730732                view_type = FLAG;
     
    733735                }
    734736                else {
    735                 selection_pane.add(part_pane);
     737                ///election_pane.add(part_pane);
    736738                card_layout.show(control_pane, VALUE);
    737739                view_type = VALUE;
     
    869871    }
    870872
    871    private class GUIChangeTask
     873    /*
     874      private class GUIChangeTask
    872875      implements Runnable {
    873876      private boolean to_add;
     
    875878      private JPanel parent;
    876879      private JPanel replacement;
    877 
     880     
    878881      public GUIChangeTask(JPanel parent, JPanel child, JPanel replacement, boolean to_add) {
    879     this.child = child;
    880     this.parent = parent;
    881     this.replacement = replacement;
    882     this.to_add = to_add;
    883       }
    884 
     882      this.child = child;
     883      this.parent = parent;
     884      this.replacement = replacement;
     885      this.to_add = to_add;
     886      }
     887     
    885888      public void run() {
    886      if(to_add) {
    887         parent.remove(replacement);
    888         parent.add(child);
    889         parent.updateUI();
    890      }
    891      else {
    892         parent.remove(child);
    893         parent.add(replacement);
    894         parent.updateUI();
    895      }
    896       }
    897    }
     889      if(to_add) {
     890      parent.remove(replacement);
     891      parent.add(child);
     892      parent.updateUI();
     893      }
     894      else {
     895      parent.remove(child);
     896      parent.add(replacement);
     897      parent.updateUI();
     898      }
     899      }
     900      }
     901    */
    898902
    899903   /** This class encapsulates all of the information associated with a certain component part of a feature within a html page returned from the receptioninst. */
  • trunk/gli/src/org/greenstone/gatherer/cdm/Index.java

    r5937 r6539  
    4646    implements Comparable, DOMProxyListEntry {
    4747    /** An values of items in the index level enumeration. */
    48     static public final String LEVEL[] = {"document","paragraph","section"};
     48    static public final String LEVEL[] = {CollectionConfiguration.DOCUMENT_STR, CollectionConfiguration.PARAGRAPH_STR, CollectionConfiguration.SECTION_STR};
    4949
    5050    private ArrayList sources = null;
  • trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java

    r6389 r6539  
    116116        CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
    117117        // Retrieve the currently last index
    118         if(getSize() > 0) {
     118        if(levels_model.getSize() > 0) {
    119119        Level last_level = (Level)levels_model.getElementAt(levels_model.getSize() - 1);
    120120        levels_model.addAfter(level, last_level);
    121121        }
    122122        else {
    123         add(level);
     123        levels_model.add(level);
    124124        }
    125125        Gatherer.c_man.configurationChanged();
     
    589589        Dictionary.registerText(level_label, "CDM.IndexManager.Level");
    590590        level_combobox = new JComboBox();
    591         level_combobox.addItem(Dictionary.get("CDM.IndexManager.Document"));
    592         level_combobox.addItem(Dictionary.get("CDM.IndexManager.Paragraph"));
    593         level_combobox.addItem(Dictionary.get("CDM.IndexManager.Section"));
     591        level_combobox.addItem(CollectionConfiguration.DOCUMENT_STR);//Dictionary.get("CDM.IndexManager.Document"));
     592        level_combobox.addItem(CollectionConfiguration.PARAGRAPH_STR);//Dictionary.get("CDM.IndexManager.Paragraph"));
     593        level_combobox.addItem(CollectionConfiguration.SECTION_STR);//Dictionary.get("CDM.IndexManager.Section"));
    594594        level_combobox.setEditable(false);
    595595        Dictionary.registerTooltip(level_combobox, "CDM.IndexManager.Level_Tooltip");
     
    12171217        index_combobox.removeAllItems();
    12181218        index_combobox.addItem(CollectionConfiguration.ALLFIELDS_STR);
     1219        index_combobox.addItem(CollectionConfiguration.METADATA_STR);
    12191220        index_combobox.addItem(CollectionConfiguration.TEXT_STR);
    12201221        java.util.List assigned_elements = Gatherer.c_man.getCollection().msm.getAssignedElements();
     
    12241225        }
    12251226        assigned_elements = null;
     1227        // Ensure the level manager has at least documents assigned
     1228        if(levels_model.getSize() == 0) {
     1229        Level level = new Level(CollectionConfiguration.DOCUMENT_STR);
     1230        // Create new metadatum
     1231        CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + CollectionConfiguration.DOCUMENT_STR);
     1232        metadatum.setValue(CollectionConfiguration.DOCUMENT_STR);
     1233        // Assign new level
     1234        addLevel(level, metadatum);     
     1235        level = null;
     1236        }
    12261237    }
    12271238
     
    13431354            move_level_down_button.setEnabled((levels_model.indexOf(level) < levels_model.getSize() - 1));
    13441355            move_level_up_button.setEnabled((levels_model.indexOf(level) > 0));
    1345             remove_level_button.setEnabled(true);
     1356            remove_level_button.setEnabled(!level.getName().equals(CollectionConfiguration.DOCUMENT_STR) || levels_model.getSize() > 1);
    13461357            }
    13471358            else {
     
    15781589        // Disable remove button
    15791590        remove_level_button.setEnabled(false);
     1591        // If there are no levels left, put document back in
     1592        if(levels_model.getSize() == 0) {
     1593            Level level = new Level(CollectionConfiguration.DOCUMENT_STR);
     1594            // Create new metadatum
     1595            CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + CollectionConfiguration.DOCUMENT_STR);
     1596            metadatum.setValue(CollectionConfiguration.DOCUMENT_STR);
     1597            // Assign new level
     1598            addLevel(level, metadatum);     
     1599            level = null;
     1600        }
    15801601        // Check if add should be reenabled
    15811602        eal.validateAddButton();
  • trunk/gli/src/org/greenstone/gatherer/cdm/LanguageManager.java

    r6389 r6539  
    4747import org.greenstone.gatherer.cdm.LanguageListCellRenderer;
    4848import org.greenstone.gatherer.gui.GLIButton;
     49import org.greenstone.gatherer.util.Utility;
    4950import org.w3c.dom.*;
    5051
     
    5556public class LanguageManager
    5657    extends DOMProxyListModel {
     58
     59    static public Document LANGUAGES_DOCUMENT = Utility.parse("xml/languages.xml", true);
    5760
    5861    static final private Dimension LABEL_SIZE = new Dimension(125,25);
     
    7982        default_language = new Language((Element)default_language_elements.item(0));
    8083    }
    81     // Load a series of code->language mappings into known_languages, by reading from the 'languages.dat' file, which is essentially a subset of the ISO 639 Standard.
     84    // Load a series of code->language mappings into known_languages, by reading from the 'languages.xml' file, which is essentially a subset of the ISO 639 Standard.
    8285    known_languages = new LinkedHashMap();
    83     try {
     86    /*
     87      try {
    8488        File in_file = new File("languages.dat");
    8589        FileReader in_reader = new FileReader(in_file);
     
    104108    catch (Exception error) {
    105109        error.printStackTrace();
     110    }
     111    */
     112    NodeList language_elements = LANGUAGES_DOCUMENT.getDocumentElement().getElementsByTagName(CollectionConfiguration.LANGUAGE_ELEMENT);
     113    for(int i = 0; i < language_elements.getLength(); i++) {
     114        Element language_element = (Element) language_elements.item(i);
     115        String code = language_element.getAttribute(CollectionConfiguration.CODE_ATTRIBUTE);
     116        String name = language_element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
     117        known_languages.put(code.toLowerCase(), name);
     118        name = null;
     119        code = null;
     120        language_element = null;
    106121    }
    107122    }
  • trunk/gli/src/org/greenstone/gatherer/cdm/MetadataSetView.java

    r6389 r6539  
    191191    /** The text area of inline instructions. */
    192192    private JTextArea instructions = null;
     193
     194    private ListListener list_listener;
    193195    /** The element model for the currently selected set. */
    194196    private Vector element_model = null;
     
    248250        Dictionary.registerBoth(remove_button, "CDM.MetadataSetManager.Remove", "CDM.MetadataSetManager.Remove_Tooltip");
    249251        configure_action_listener = new ConfigureActionListener();
     252        list_listener = new ListListener();
    250253
    251254        // Add listeners
     
    253256        configure_button.addActionListener(configure_action_listener);
    254257        remove_button.addActionListener(new RemoveButtonListener());
    255         set_list.addListSelectionListener(new ListListener());
     258        set_list.addListSelectionListener(list_listener);
    256259        set_list.addMouseListener(configure_action_listener);
    257260        // Layout
     
    330333        instructions.setCaretPosition(0);
    331334        }
     335        // If no current selection, select first available set
     336        if(set_list.isSelectionEmpty() && set_list.getModel().getSize() > 0) {
     337        set_list.setSelectedIndex(0);
     338        MetadataSet set = ((SetWrapper)set_list.getSelectedValue()).getSet();
     339        NodeList elements = set.getElements();
     340        element_model = new Vector();
     341        for(int i = 0; i < elements.getLength(); i++) {
     342            element_model.add(new ElementWrapper(elements.item(i)));
     343        }
     344        element_list.setListData(element_model);
     345        configure_button.setEnabled(true);
     346        remove_button.setEnabled(true);
     347        elements = null;
     348        set = null;
     349        }
    332350    }
    333351
     
    400418            element_model.add(new ElementWrapper(elements.item(i)));
    401419            }
    402             Collections.sort(element_model);
     420            //Collections.sort(element_model);
    403421            element_list.setListData(element_model);
    404422            configure_button.setEnabled(true);
Note: See TracChangeset for help on using the changeset viewer.