Changeset 7465


Ignore:
Timestamp:
2004-05-27T14:08:15+12:00 (20 years ago)
Author:
cs025
Message:

Changes to cope with better file functionality; also proper handling of
Windows file paths with URLTools

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFile.java

    r6014 r7465  
    139139  { String mimeType;
    140140 
    141     if (url.toString().startsWith("file://"))
     141    if (url.getProtocol().equals("file"))
    142142    { // TODO: Work out the MIME type
    143143      mimeType = URLConnection.getFileNameMap().getContentTypeFor(url.toString().substring(7));
     
    288288  }
    289289
     290  /**
     291   *  Get the location of this file as a URL
     292   */
    290293  public URL getURL()
    291294  { return this.location.getLocation();
    292295  }
    293296
     297  /**
     298   *
     299   */
     300  public long getModifiedDatestamp()
     301  { return this.location.getModifiedDatestamp();
     302  }
    294303
    295304  /**
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java

    r6287 r7465  
    3737  }
    3838
     39  /**
     40   *  Get the modified datestamp that applies for this file group.  An empty group
     41   *  will return <code>0</code>.
     42   *
     43   *  @return <code>long</code> the date modified as milliseconds from the 1st January 1970
     44   */
     45  public long getModifiedDatestamp()
     46  { long reply = 0; // empty groups reply '0'
     47
     48    Iterator childIter = children.iterator();
     49    while (childIter.hasNext())
     50    { METSFile file = (METSFile) childIter.next();
     51      long fileStamp = file.getModifiedDatestamp();
     52      if (fileStamp > reply) {
     53    reply = fileStamp;
     54      }
     55    }
     56
     57    childIter = childGroups.iterator();
     58    while (childIter.hasNext())
     59    { METSFileGroup fileGroup = (METSFileGroup) childIter.next();
     60      long fileStamp = fileGroup.getModifiedDatestamp();
     61      if (fileStamp > reply) {
     62    reply = fileStamp;
     63      }
     64    }
     65
     66    return reply;
     67  }
     68   
    3969  /**
    4070   *  Find all the occurrences of a given file, and place them
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFilePos.java

    r5945 r7465  
    2828  }
    2929
     30  public long getModifiedDatestamp()
     31  { return this.location.getModifiedDatestamp();
     32  }
     33
    3034  public String toString()
    3135  { return this.location.getLocation().toString();
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java

    r6287 r7465  
    4747  }
    4848
     49  public long getModifiedDatestamp()
     50  { long reply = 0;
     51
     52    Iterator groupsIter = this.fileGroups.values().iterator();
     53    while (groupsIter.hasNext())
     54    { METSFileGroup group = (METSFileGroup) groupsIter.next();
     55
     56      long groupStamp = group.getModifiedDatestamp();
     57      if (groupStamp > reply)
     58      { reply = groupStamp;
     59      }
     60    }
     61
     62    return reply;
     63  }
     64   
     65
    4966  /**
    5067   *  Get a new FileGroup to lie within this fileset.  The group is not initialised with
     
    92109  }
    93110
     111  /**
     112   *  Add a file to the default file group
     113   */
    94114  public void addFile(METSFile file)
    95115  { METSFileGroup defaultGroup = (METSFileGroup) this.fileGroups.get("default");
     
    97117  }
    98118
     119  /**
     120   *  Add a file to the default file group
     121   *
     122   *  @return <code>METSFile</code> an object that wraps the given url into
     123   *          a METS file object
     124   */
    99125  public METSFile addFile(URL url)
    100126  { METSFile file = METSFile.makeMETSFile(url);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSLocation.java

    r5945 r7465  
    33import java.io.File;
    44import java.net.URL;
     5import java.net.URLConnection;
     6
     7import org.greenstone.gsdl3.gs3build.util.URLTools;
    58
    69public class METSLocation
     
    1922  }
    2023
    21   public METSLocation(File file) throws java.net.MalformedURLException
     24  public METSLocation(File file)
    2225  { this.type = "URL";
    23     this.location = new URL("file://" + file.toString());
     26    this.location = URLTools.getFileURL(file);
    2427  }
    2528
     
    3235  }
    3336
     37  public long getModifiedDatestamp()
     38  { if (this.location != null) {
     39      if (this.location.getProtocol().equals("file")) {
     40    File file = new File(this.location.getPath());
     41    return file.lastModified();
     42      }
     43      else {
     44    try {
     45      URLConnection connection = this.location.openConnection();
     46      return connection.getLastModified();
     47    }
     48    catch (java.io.IOException io)
     49    { // TODO: report error
     50    }
     51      }
     52    }
     53    return System.currentTimeMillis();
     54  }
     55
    3456  public String getType()
    3557  { return this.type;
Note: See TracChangeset for help on using the changeset viewer.