1 package org.splat.dal.bo.som;
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.dal.bo.kernel.Persistent;
17 import org.splat.dal.dao.som.Database;
20 public class File extends Persistent {
23 protected String format;
24 protected String path;
28 private java.io.File myfile; // For optimization
30 // ==============================================================================================================================
32 // ==============================================================================================================================
34 // Database fetch constructor
39 // Internal constructors
40 protected File (String path) {
41 // ----------------------------
42 Calendar current = Calendar.getInstance();
43 String[] table = path.split("\\x2E");
45 this.format = table[table.length-1];
46 this.path = path; // The corresponding physical file may not exist yet
47 this.date = current.getTime(); // Today
50 protected File (String path, String format, Date date) {
51 // ------------------------------------------------------
52 this.path = path; // The corresponding physical file may not exist yet
53 this.format = format; // The format name may be different from the physical file extension
56 Calendar current = Calendar.getInstance();
57 this.date = current.getTime(); // Today
62 // ==============================================================================================================================
63 // Public member functions
64 // ==============================================================================================================================
66 * Returns the data file associated to this meta file.
68 * @return the associated data file. If this meta data is an empty document, the returned file does not exist.
70 public java.io.File asFile () {
71 // -----------------------------
72 if (myfile == null) myfile = new java.io.File(Database.getRepositoryVaultPath() + path);
76 public Date getDate () {
77 // ----------------------
81 public String getFormat () {
82 // --------------------------
86 public String getName () {
87 // ------------------------
88 return this.asFile().getName();
91 public String getRelativePath () {
92 // --------------------------------
96 public boolean exists () { // Shortcut
97 // ------------------------
98 return (this.asFile().exists());
101 // ==============================================================================================================================
103 // ==============================================================================================================================
105 public void changePath (String path) {
106 // ---------------------------------------