Changeset 6201 for trunk


Ignore:
Timestamp:
2003-12-10T16:30:33+13:00 (20 years ago)
Author:
jmt12
Message:

Added a new method to remove all of the extracted metadata in the collection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java

    r6036 r6201  
    3737package org.greenstone.gatherer.msm;
    3838
     39import java.awt.*;
     40import java.awt.event.*;
    3941import java.io.*;
    4042import java.util.*;
     43import javax.swing.*;
     44import javax.swing.event.*;
    4145import javax.swing.tree.*;
    4246import org.greenstone.gatherer.Gatherer;
     
    4953import org.greenstone.gatherer.msm.MSMEvent;
    5054import org.greenstone.gatherer.msm.MSMListener;
     55import org.greenstone.gatherer.util.DOMTree;
    5156import org.greenstone.gatherer.util.HashMap3D;
    5257import org.greenstone.gatherer.util.StaticStrings;
     
    6267    /** A list of the known metadata instances, thus we only store one of each unique metadata, and reference the rest. */
    6368    static public HashMap3D metadata_cache = null;
     69    private DOMTree tree = null;
     70    private JComboBox documents_in_cache_combobox = null;
    6471    /** The root file node. */
    6572    private TreeNode root = null;
     
    7481    // Connect
    7582    Gatherer.c_man.getCollection().msm.addMSMListener(this);
     83    // We also have a debug dialog
     84    if(Gatherer.debug != null) {
     85        display();
     86    }
    7687    }
    7788
     
    109120    // Done!
    110121    }
     122
     123    /** This debug facility shows the currently loaded collect.cfg or CollectConfig.xml file as a DOM tree. */
     124    public void display() {
     125    JDialog dialog = new JDialog(Gatherer.g_man, "Greenstone Metadata Document Manager", false);
     126    dialog.setSize(400,400);
     127    JPanel content_pane = (JPanel) dialog.getContentPane();
     128    GDMDocument metadata_xml = new GDMDocument();
     129    tree = new DOMTree(metadata_xml.getDocument());
     130    metadata_xml = null;
     131    documents_in_cache_combobox = new JComboBox();
     132    documents_in_cache_combobox.addItemListener(new DOMItemListener());
     133    JButton refresh_button = new JButton("Refresh Tree");
     134    refresh_button.addActionListener(new ActionListener() {
     135        public void actionPerformed(ActionEvent event) {
     136            File metadata_file = (File) documents_in_cache_combobox.getSelectedItem();
     137            if(metadata_file != null) {
     138            GDMDocument document = (GDMDocument) get(metadata_file);
     139            tree.setDocument(document.getDocument());
     140            document = null;
     141            metadata_file = null;
     142            }
     143        }
     144        });
     145    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     146    content_pane.setLayout(new BorderLayout());
     147    content_pane.add(documents_in_cache_combobox, BorderLayout.NORTH);
     148    content_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
     149    content_pane.add(refresh_button, BorderLayout.SOUTH);
     150    dialog.show();
     151    }
     152
     153    private class DOMItemListener
     154    implements ItemListener {
     155   
     156    public void itemStateChanged(ItemEvent event) {
     157        if(event.getStateChange() == ItemEvent.SELECTED) {
     158        File metadata_file = (File) documents_in_cache_combobox.getSelectedItem();
     159        if(metadata_file != null) {
     160            GDMDocument document = (GDMDocument) get(metadata_file);
     161            tree.setDocument(document.getDocument());
     162            document = null;
     163            metadata_file = null;
     164        }
     165        }
     166    }
     167    }
     168
    111169    /** Method that is called whenever an element within a set is changed or modified. Ensure all cached GDMDocuments are marked as stale.
    112170     * @param event A <strong>MSMEvent</strong> containing details of the event that caused this message to be fired.
     
    150208        }
    151209        put(metadata_file, metadata_xml);
     210        if(documents_in_cache_combobox != null) {
     211        documents_in_cache_combobox.addItem(metadata_file);
     212        }
    152213        //Gatherer.println("[0ms]\tCached " + metadata_file);
    153214    }
     
    224285    }
    225286    GDMDocument document = getDocument(file);
    226     if(document != null) {
     287    if(file != null && document != null) {
    227288        metadata = document.getMetadata(filename, remove, metadata, file, append_folder_level);
    228289        document = null;
     
    341402        }
    342403    }
     404    }
     405
     406    public void removeExtractedMetadata() {
     407    try {
     408        // Remove all of the extracted metadata in the collection
     409        removeExtractedMetadata(new File(Gatherer.c_man.getCollectionImport()));
     410    }
     411    catch (Exception exception) {
     412        Gatherer.println("Exception in GDMManager.removeExtractedMetadata - unexpected");
     413        Gatherer.printStackTrace(exception);
     414    }
     415    }
     416
     417    private void removeExtractedMetadata(File file) {
     418    // Retrieve the gdm document for this file
     419    GDMDocument metadata_xml_document = getDocument(file);
     420    // Remove the extracted metadata
     421    System.err.println("Removing the extracted metadata from the file: " + file);
     422    metadata_xml_document.removeExtractedMetadata();
     423    metadata_xml_document = null;
     424    // Then recurse down the directory structure looking for other metadata.xml files
     425    File child_files[] = file.listFiles();
     426    for(int i = 0; i < child_files.length; i++) {
     427        if(child_files[i].isDirectory()) {
     428        removeExtractedMetadata(child_files[i]);
     429        }
     430    }
     431    child_files = null;
    343432    }
    344433
     
    509598        GDMDocument document = (GDMDocument) eldest.getValue();
    510599        save(file, document);
     600       
     601        if(documents_in_cache_combobox != null) {
     602        documents_in_cache_combobox.removeItem(file);
     603        }
    511604        // And then dump it
    512605        return true;
Note: See TracChangeset for help on using the changeset viewer.