3 * Class of meta files representing physical files under the control of Study Manager.
4 * Typically, the files represented by this class are source files of Documents and exports in different formats.
5 * The path of such files is relative to the vault of the repository of Study Manager.
6 * When creating a Document, as the source file is produced by the caller which creates the Document, the corresponding
7 * physical file may not exist at instantiation time.
9 * @author Daniel Brunier-Coulin
10 * @copyright OPEN CASCADE 2012
13 import java.util.Calendar;
14 import java.util.Date;
16 import org.splat.kernel.Persistent;
19 public class File extends Persistent {
22 protected String format;
23 protected String path;
27 private java.io.File myfile; // For optimization
29 // ==============================================================================================================================
31 // ==============================================================================================================================
33 // Database fetch constructor
38 // Internal constructors
39 protected File (String path) {
40 // ----------------------------
41 Calendar current = Calendar.getInstance();
42 String[] table = path.split("\\x2E");
44 this.format = table[table.length-1];
45 this.path = path; // The corresponding physical file may not exist yet
46 this.date = current.getTime(); // Today
49 protected File (String path, String format, Date date) {
50 // ------------------------------------------------------
51 this.path = path; // The corresponding physical file may not exist yet
52 this.format = format; // The format name may be different from the physical file extension
55 Calendar current = Calendar.getInstance();
56 this.date = current.getTime(); // Today
61 // ==============================================================================================================================
62 // Public member functions
63 // ==============================================================================================================================
65 * Returns the data file associated to this meta file.
67 * @return the associated data file. If this meta data is an empty document, the returned file does not exist.
69 public java.io.File asFile () {
70 // -----------------------------
71 if (myfile == null) myfile = new java.io.File(Database.getRepositoryVaultPath() + path);
75 public Date getDate () {
76 // ----------------------
80 public String getFormat () {
81 // --------------------------
85 public String getName () {
86 // ------------------------
87 return this.asFile().getName();
90 public String getRelativePath () {
91 // --------------------------------
95 public boolean exists () { // Shortcut
96 // ------------------------
97 return (this.asFile().exists());
100 // ==============================================================================================================================
102 // ==============================================================================================================================
104 protected void changePath (String path) {
105 // ---------------------------------------