Changeset 8013


Ignore:
Timestamp:
2004-08-20T13:14:21+12:00 (20 years ago)
Author:
mdewsnip
Message:

More new code, this time for the MetadataAuditTable.

Location:
trunk/gli/src/org/greenstone/gatherer/metadata
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/metadata/DocXMLFileManager.java

    r7978 r8013  
    3535    static public void loadDocXMLFiles(File directory)
    3636    {
     37    // Make sure the directory (archives) exists
     38    if (directory.exists() == false) {
     39        return;
     40    }
     41
    3742    // Look recursively at each subfile of the directory for doc.xml files
    3843    File[] directory_files = directory.listFiles();
  • trunk/gli/src/org/greenstone/gatherer/metadata/MetadataAuditTableModel.java

    r7978 r8013  
    88import javax.swing.table.*;
    99import org.greenstone.gatherer.Configuration;
    10 import org.greenstone.gatherer.Dictionary;
    1110import org.greenstone.gatherer.Gatherer;
    1211import org.greenstone.gatherer.file.FileNode;
     
    1817    /** The FileNodes this model is built for */
    1918    private FileNode[] file_nodes = null;
    20     private ArrayList metadata_values = null;
     19    /** The list of MetadataElements in the table (columns) */
     20    private ArrayList metadata_elements = new ArrayList();
     21    /** The list of MetadataAuditTableEntries in the table (rows) */
     22    private ArrayList metadata_audit_table_entries = new ArrayList();
    2123
    2224
     
    2426    public int getColumnCount()
    2527    {
    26     return 1;  // !!! TO DO
     28    return metadata_elements.size();
    2729    }
    2830
    2931
    30     //    /** Retrieves the name of the specified column. */
    31     //    public String getColumnName(int col)
    32     //    {
    33     //       return COLUMN_NAMES[col];
    34     //    }
     32    /** Retrieves the name of the specified column. */
     33    public String getColumnName(int col)
     34    {
     35        return metadata_elements.get(col).toString();
     36    }
    3537
    3638
    37 //    /* Called to retrieve the MetadataValueTableEntry at a certain row. Usually caused by the user selecting a row in the table. It is synchronized so that the model doesn't up and change while we're trying to retrieve the indicated element. */
    38 //    public synchronized MetadataValueTableEntry getMetadataValueTableEntry(int row)
    39 //    {
    40 //       if (row >= 0 && row < metadata_value_table_entries.size()) {
    41 //   return (MetadataValueTableEntry) metadata_value_table_entries.get(row);
    42 //       }
    43 
    44 //       return null;
    45 //    }
    46 
    47 
    48    /** Returns the number of rows in this table. */
     39    /** Returns the number of rows in this table. */
    4940    public int getRowCount()
    5041    {
    51     return metadata_values.size();
     42    return metadata_audit_table_entries.size();
    5243    }
    5344
     
    5748    {
    5849    // Check values are reasonable
    59     if (row < 0 || row >= metadata_values.size() || col < 0 || col >= getColumnCount()) {
     50    if (row < 0 || row >= metadata_audit_table_entries.size() || col < 0 || col >= metadata_elements.size()) {
    6051        return null;
    6152    }
    6253
    63     return null;
     54    MetadataAuditTableEntry metadata_audit_table_entry = (MetadataAuditTableEntry) metadata_audit_table_entries.get(row);
     55    return metadata_audit_table_entry.getMetadataValueTreeNode(col);
    6456    }
    6557
     
    6759    public void rebuild(FileNode[] file_nodes)
    6860    {
    69     metadata_values.clear();
     61    metadata_elements = MetadataSetManager.getEveryMetadataSetElement();
     62    metadata_audit_table_entries.clear();
    7063
    7164    this.file_nodes = file_nodes;
     65    if (file_nodes != null && file_nodes.length > 0) {
     66        // Create model builder
     67        MetadataAuditTableModelBuilder builder = new MetadataAuditTableModelBuilder();
     68        builder.run();
     69    }
    7270    }
    7371
    7472
    75     //    public void rebuild(FileNode[] file_nodes)
    76     //    {
    77     //       metadata_value_table_entries.clear();
     73    private class MetadataAuditTableModelBuilder
     74    {
     75    public void run()
     76    {
     77        // Build a list of MetadataAuditTableEntries that represent the metadata asssigned to the selected files
     78        System.err.println("Building MetadataAuditTableModel...");
    7879
    79     //       if (!Gatherer.c_man.ready()) {
    80     //   Gatherer.println("Not ready!");
    81     //   return;
    82     //       }
     80        // Process each of the selected files in turn
     81        for (int i = 0; i < file_nodes.length; i++) {
     82        File current_file = file_nodes[i].getFile();
     83        System.err.println("  File: " + current_file);
    8384
    84     //       this.file_nodes = file_nodes;
    85     //       if (file_nodes != null && file_nodes.length > 0) {
    86     //   // Create model builder
    87     //   MetadataValueTableModelBuilder builder = new MetadataValueTableModelBuilder();
    88     //   builder.run();
    89     //       }
    90     //    }
     85        // Get the metadata assigned to this file
     86        ArrayList current_file_metadata = MetadataXMLFileManager.getMetadataAssignedToFile(current_file);
     87
     88        // Get the extracted metadata for this file, if desired
     89        if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC) == true) {
     90            current_file_metadata.addAll(DocXMLFileManager.getMetadataExtractedFromFile(current_file));
     91        }
     92
     93        MetadataAuditTableEntry metadata_audit_table_entry = new MetadataAuditTableEntry(current_file, current_file_metadata);
     94        metadata_audit_table_entries.add(metadata_audit_table_entry);
     95        }
     96    }
     97    }
    9198
    9299
    93     //    private class MetadataValueTableModelBuilder
    94     //    {
    95     //       public void run()
    96     //       {
    97     //   // Build a list of MetadataValueTableEntries that represent the metadata asssigned to the selected files
    98     //   boolean hid_extracted_metadata = false;
    99     //   boolean has_inherited_metadata = false;
    100     //   ArrayList metadata_elements_seen = new ArrayList();
    101 
    102     //   // Process each of the selected files in turn
    103     //   for (int i = 0; i < file_nodes.length; i++) {
    104     //      File current_file = file_nodes[i].getFile();
    105 
    106     //      // Get the metadata assigned to this file
    107     //      ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedToFile(current_file);
    108     //      for (int j = 0; j < assigned_metadata.size(); j++) {
    109     //         MetadataValue metadata_value = (MetadataValue) assigned_metadata.get(j);
    110     //         MetadataElement metadata_element = metadata_value.getMetadataElement();
    111 
    112     //         // Note if there is inherited (folder-level) metadata in the table
    113     //         has_inherited_metadata = has_inherited_metadata || metadata_value.isInheritedMetadata();
    114 
    115     //         // Insert this metadata value into the table, unless it already exists (in which case increment its count)
    116     //         insertMetadataValueIntoTable(metadata_value);
    117 
    118     //         // Remember we have seen this metadata element
    119     //         if (metadata_elements_seen.contains(metadata_element) == false) {
    120     //        metadata_elements_seen.add(metadata_element);
    121     //         }
    122     //      }
    123 
    124     //      // Get the extracted metadata for this file, if desired
    125     //      if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC) == true) {
    126     //         ArrayList extracted_metadata = DocXMLFileManager.getMetadataExtractedFromFile(current_file);
    127     //         for (int k = 0; k < extracted_metadata.size(); k++) {
    128     //        MetadataValue metadata_value = (MetadataValue) extracted_metadata.get(k);
    129 
    130     //        // Insert this metadata value into the table, unless it already exists (in which case increment its count)
    131     //        insertMetadataValueIntoTable(metadata_value);
    132     //         }
    133     //      }
    134     //   }
    135 
    136     //   // Make sure each non-extracted metadata element appears in the table (even if blank)
    137     //   ArrayList every_metadata_set_element = MetadataSetManager.getEveryMetadataSetElement();
    138     //   for (int i = 0; i < every_metadata_set_element.size(); i++) {
    139     //      MetadataElement metadata_element = (MetadataElement) every_metadata_set_element.get(i);
    140 
    141     //      // If we haven't seen this metadata element and it isn't extracted, add it now
    142     //      if (!metadata_elements_seen.contains(metadata_element) && !metadata_element.isExtractedMetadata()) {
    143     //         MetadataValueTableEntry metadata_value_table_entry = new MetadataValueTableEntry(metadata_element, new MetadataValueTreeNode(""));
    144 
    145     //         // Blank metadata is common to all selected files (otherwise it wouldn't be blank!)
    146     //         metadata_value_table_entry.setOccurrences(file_nodes.length);
    147 
    148     //         // Add it to the table
    149     //         insertMetadataValueIntoTable(metadata_value_table_entry);
    150     //      }
    151     //   }
    152 
    153     //   // If extracted metadata was hidden, display the warning
    154     //   if (hid_extracted_metadata) {
    155     //      showExtractedMetadataWarning();
    156     //   }
    157 
    158     //   // If there is inherited metadata, display the warning
    159     //   if (has_inherited_metadata) {
    160     //      showInheritedMetadataWarning();
    161     //   }
    162     //       }
     100    /** This class represents one (file, metadata) pair */
     101    private class MetadataAuditTableEntry
     102    {
     103    private File file = null;
     104    private MetadataValue[] metadata_values = null;
    163105
    164106
    165     //       /** Alphabetically inserts the new metadata value into the table */
    166     //       private void insertMetadataValueIntoTable(MetadataValue metadata_value)
    167     //       {
    168     //   for (int i = 0; i < metadata_value_table_entries.size(); i++) {
    169     //      MetadataValueTableEntry current_metadata_value_table_entry = (MetadataValueTableEntry) metadata_value_table_entries.get(i);
    170     //      int c = current_metadata_value_table_entry.compareTo(metadata_value);
     107    public MetadataAuditTableEntry(File file, ArrayList metadata_values_list)
     108    {
     109        this.file = file;
    171110
    172     //      // Insert value before existing entry
    173     //      if (c > 0) {
    174     //         metadata_value_table_entries.add(i, new MetadataValueTableEntry(metadata_value));
    175     //         fireTableRowsInserted(i, i);
    176     //         return;
    177     //      }
     111        metadata_values = new MetadataValue[metadata_elements.size()];
     112        for (int i = 0; i < metadata_values_list.size(); i++) {
     113        MetadataValue metadata_value = (MetadataValue) metadata_values_list.get(i);
     114        MetadataElement metadata_element = metadata_value.getMetadataElement();
    178115
    179     //      // Entry already exists (increment existing count)
    180     //      if (c == 0) {
    181     //         current_metadata_value_table_entry.anotherOccurrence();
    182     //         return;
    183     //      }
    184     //   }
     116        // Find the right column to put the value in
     117        for (int j = 0; j < metadata_elements.size(); j++) {
     118            if (metadata_element.equals(metadata_elements.get(j))) {
     119            metadata_values[j] = metadata_value;
     120            break;
     121            }
     122        }
     123        }
     124    }
    185125
    186     //   // Must go at the end of the table
    187     //   metadata_value_table_entries.add(new MetadataValueTableEntry(metadata_value));
    188     //   fireTableRowsInserted(metadata_value_table_entries.size() - 1, metadata_value_table_entries.size() - 1);
    189     //       }
     126
     127    public MetadataValueTreeNode getMetadataValueTreeNode(int col)
     128    {
     129        if (metadata_values[col] == null) {
     130        return null;
     131        }
     132
     133        return metadata_values[col].getMetadataValueTreeNode();
     134    }
     135    }
    190136}
  • trunk/gli/src/org/greenstone/gatherer/metadata/MetadataValueTableModel.java

    r7978 r8013  
    2222    private ArrayList metadata_value_table_entries = new ArrayList();
    2323
    24     static final private String[] COLUMN_NAMES = {"", Dictionary.get("Metadata.Element"),  Dictionary.get("Metadata.Value")};
     24    static final private String[] COLUMN_NAMES = { "", Dictionary.get("Metadata.Element"), Dictionary.get("Metadata.Value") };
    2525
    2626
  • trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFileManager.java

    r7978 r8013  
    9292    static public void loadMetadataXMLFiles(File directory)
    9393    {
     94    // Make sure the directory (import) exists
     95    if (directory.exists() == false) {
     96        return;
     97    }
     98
    9499    // Look recursively at each subfile of the directory for metadata.xml files
    95100    File[] directory_files = directory.listFiles();
Note: See TracChangeset for help on using the changeset viewer.