Ignore:
Timestamp:
2003-11-24T14:26:35+13:00 (20 years ago)
Author:
cs025
Message:

Index document type, metadata extensions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/AbstractDocument.java

    r5800 r5944  
    33import java.util.List;
    44import java.util.ArrayList;
     5import java.util.Iterator;
    56import java.util.HashMap;
    67import java.util.Map;
     8
     9import java.sql.SQLException;
     10import java.sql.ResultSet;
     11
    712import java.net.URL;
    813
     
    1924
    2025import org.greenstone.gsdl3.gs3build.util.MultiMap;
     26import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
    2127
    2228/**
     
    3238  METSHeader       header;
    3339  DocumentID       id;
     40  boolean          isModified;
     41
     42  /**
     43   *  <p>Create a very vanilla document with a given document identifier.</p>
     44   *  <p>Most commonly used in dealing with loading files using DocumentFactory
     45   *  or similar.</p>
     46   *
     47   *  @param <code>DocumentID</code> the document identifier
     48   */
     49  public AbstractDocument(DocumentID id)
     50  { this.fileSet      = new METSFileSet();
     51    this.metadata     = new METSDescriptiveSet();
     52    this.header       = new METSHeader();
     53    this.structureSet = new METSStructureSet();
     54    this.id           = id;
     55  }
    3456 
     57  /**
     58   *  Create a basic document from a given <code>URL</code.  This is usually the form
     59   *  called through the recognisers.
     60   *
     61   *  @param <code>URL</code> the URL of the first file in the document package
     62   */
    3563  public AbstractDocument(URL url)
    3664  { this.fileSet      = new METSFileSet();
     
    3967    this.header       = new METSHeader();
    4068    this.structureSet = new METSStructureSet();
     69    this.id           = null;
    4170
    4271    METSStructure structure = new METSStructure("All", "All", "Whole Document");
     
    131160      namespace = GSDL3Namespace.GSDL3_NAMESPACE_ID;
    132161    }
     162
     163    // no need to set isModified, as the following call will do it anyway!
    133164    this.addDocumentMetadata(namespace, name, value);
    134165  }
     
    139170  public void addDocumentMetadata(String namespace, String label, String value)
    140171  { this.metadata.addMetadata("default", namespace, label, value);
    141   }
    142 
    143   /**
    144    *  @see DocumentInterace:setDocumentMetadata
     172    this.isModified = true;
     173  }
     174
     175  /**
     176   *  Post metadata to a file in this document - the appropriate changes
     177   *  should be made...
     178   */
     179  public void postFileMetadata(URL fileLocation, String namespace, String label, String value)
     180  {
     181    // First get the list of file groups, etc. that this file is associated with...
     182    List fileGroups = this.fileSet.findGroups(fileLocation);
     183
     184    // Next, get the METS divisions associated with each file group...
     185    List divisions = this.structureSet.findDivisionsForFiles(fileGroups);
     186   
     187    // Finally, post the metadata to the metadata group associated with each structure
     188    Iterator divisionIter = divisions.iterator();
     189    while (divisionIter.hasNext())
     190    { METSDivision division = (METSDivision) divisionIter.next();
     191
     192      // get the open namespace for this division
     193      METSNamespace namespaceMetadata = division.findNamespace(namespace, true, this.metadata);
     194
     195      // then post the metadata to it...
     196      namespaceMetadata.addMetadata(label, value);
     197    }
     198  }
     199
     200  /**
     201   *  @see DocumentInterface:setDocumentMetadata
    145202   */
    146203  public void setDocumentMetadata(String namespace, String label, String value)
    147204  { this.metadata.setMetadata("default", namespace, label, value);
     205    this.isModified = true;
    148206  }
    149207
     
    158216
    159217  /**
     218   *  Set the metadata structure for this document
     219   *
     220   *  @param <code>METSDescriptive</code> the new metadata holder for the document.
     221   */
     222  public void setDocumentMetadata(METSDescriptiveSet metadata)
     223  { this.metadata = metadata;
     224    this.isModified = true;
     225  }
     226
     227  /**
    160228   *  Get the metadata structure of the document
    161229   *
     
    164232  public METSStructureSet getDocumentStructure()
    165233  { return this.structureSet;
     234  }
     235
     236  public void setDocumentStructure(METSStructureSet structureSet)
     237  { this.structureSet = structureSet;
    166238  }
    167239
     
    207279  { return this.fileSet;
    208280  }
     281
     282  public void setDocumentFiles(METSFileSet fileSet)
     283  { this.fileSet = fileSet;
     284  }
    209285 
    210286  /**
     
    231307  { return new DocumentSQLWriter();
    232308  }
    233    
     309
     310  /**
     311   *  Obtain a document from the SQL database
     312   */
     313  public static AbstractDocument readSQL(GS3SQLConnection connection, ResultSet sqlResult)
     314  { try {
     315      DocumentID id = new DocumentID(sqlResult.getString("DocID"));
     316      String     type = sqlResult.getString("docType");
     317
     318      // Use a factory method to create the correct subtype...
     319      AbstractDocument document = DocumentFactory.createDocument(type, id);
     320
     321      // Get the individual components of the document
     322      METSFileSet fileSet = METSFileSet.readSQL(document, connection);
     323      document.setDocumentFiles(fileSet);
     324      METSDescriptiveSet descriptiveSet = METSDescriptiveSet.readSQL(document, connection);
     325      document.setDocumentMetadata(descriptiveSet);
     326      METSStructureSet structureSet = METSStructureSet.readSQL(document, connection);
     327      document.setDocumentStructure(structureSet);
     328
     329      // indicate that the document is not currently modified
     330      document.setModified(false);
     331      return document;
     332    }
     333    catch (SQLException sqlEx) {
     334    }
     335    return null;
     336  }
     337
     338  /**
     339   * 
     340   */
     341  public boolean isModified()
     342  { return this.isModified;
     343  }
     344
     345  public void setModified(boolean isModified)
     346  { this.isModified = isModified;
     347  }
    234348}
Note: See TracChangeset for help on using the changeset viewer.