| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
package net.sourceforge.pebble.domain; |
| 33 | |
|
| 34 | |
import java.io.File; |
| 35 | |
import java.util.Date; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public class FileMetaData { |
| 43 | |
|
| 44 | |
public static final String BLOG_FILE = "blogFile"; |
| 45 | |
public static final String BLOG_IMAGE = "blogImage"; |
| 46 | |
public static final String THEME_FILE = "themeFile"; |
| 47 | |
public static final String BLOG_DATA = "blogData"; |
| 48 | |
|
| 49 | |
private FileManager context; |
| 50 | |
|
| 51 | |
private String name; |
| 52 | |
private String path; |
| 53 | |
private Date lastModified; |
| 54 | |
private long size; |
| 55 | |
private boolean directory; |
| 56 | |
private String type; |
| 57 | |
|
| 58 | 1052 | FileMetaData(FileManager context, String absolutePath) { |
| 59 | 1052 | this.context = context; |
| 60 | |
|
| 61 | 1052 | if (absolutePath == null || absolutePath.equals("") || absolutePath.equals("/")) { |
| 62 | 376 | this.path="/"; |
| 63 | 376 | this.name = ""; |
| 64 | |
} else { |
| 65 | 676 | if (absolutePath.endsWith("/")) { |
| 66 | 20 | absolutePath = absolutePath.substring(0, absolutePath.length()-1); |
| 67 | |
} |
| 68 | |
|
| 69 | 676 | if (absolutePath.indexOf("/") > -1) { |
| 70 | 664 | this.path = absolutePath.substring(0, absolutePath.lastIndexOf("/")); |
| 71 | 664 | if (this.path.length() == 0) { |
| 72 | 596 | this.path = "/"; |
| 73 | |
} |
| 74 | 664 | this.name = absolutePath.substring(absolutePath.lastIndexOf("/")+1, absolutePath.length()); |
| 75 | |
} else { |
| 76 | 12 | this.path = absolutePath; |
| 77 | 12 | this.name = ""; |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | 676 | if (!this.path.startsWith("/")) { |
| 82 | 12 | this.path = "/" + this.path; |
| 83 | |
} |
| 84 | |
} |
| 85 | 1052 | } |
| 86 | |
|
| 87 | |
public String getName() { |
| 88 | 244 | return name; |
| 89 | |
} |
| 90 | |
|
| 91 | |
public void setName(String name) { |
| 92 | 4 | this.name = name; |
| 93 | 4 | } |
| 94 | |
|
| 95 | |
public Date getLastModified() { |
| 96 | 4 | return lastModified; |
| 97 | |
} |
| 98 | |
|
| 99 | |
public void setLastModified(Date lastModified) { |
| 100 | 900 | this.lastModified = lastModified; |
| 101 | 900 | } |
| 102 | |
|
| 103 | |
public boolean isDirectory() { |
| 104 | 176 | return directory; |
| 105 | |
} |
| 106 | |
|
| 107 | |
public void setDirectory(boolean directory) { |
| 108 | 608 | this.directory = directory; |
| 109 | 608 | } |
| 110 | |
|
| 111 | |
public String getPath() { |
| 112 | 108 | return path; |
| 113 | |
} |
| 114 | |
|
| 115 | |
public String getAbsolutePath() { |
| 116 | 2592 | if (!path.endsWith("/")) { |
| 117 | 96 | return path + "/" + name; |
| 118 | |
} else { |
| 119 | 2496 | return path + name; |
| 120 | |
} |
| 121 | |
} |
| 122 | |
|
| 123 | |
public String getUrl() { |
| 124 | 40 | String url = null; |
| 125 | |
|
| 126 | 40 | if (type != null && type.equals(FileMetaData.BLOG_IMAGE)) { |
| 127 | 12 | url = "images" + getAbsolutePath(); |
| 128 | 28 | } else if (type != null && type.equals(FileMetaData.BLOG_FILE)) { |
| 129 | 20 | url = "files" + getAbsolutePath(); |
| 130 | 8 | } else if (type != null && type.equals(FileMetaData.THEME_FILE)) { |
| 131 | 8 | url = "theme" + getAbsolutePath(); |
| 132 | |
} |
| 133 | |
|
| 134 | 40 | if (url != null && isDirectory() && !url.endsWith("/")) { |
| 135 | 0 | url += "/"; |
| 136 | |
} |
| 137 | |
|
| 138 | 40 | return url; |
| 139 | |
} |
| 140 | |
|
| 141 | |
public boolean isEditable() { |
| 142 | 52 | if (isDirectory()) { |
| 143 | 4 | return false; |
| 144 | |
} else { |
| 145 | 48 | String filename = name.toLowerCase(); |
| 146 | 48 | return |
| 147 | |
filename.endsWith(".txt") || |
| 148 | |
filename.endsWith(".properties") || |
| 149 | |
filename.endsWith(".jsp") || |
| 150 | |
filename.endsWith(".jspf") || |
| 151 | |
filename.endsWith(".html") || |
| 152 | |
filename.endsWith(".htm") || |
| 153 | |
filename.endsWith(".css") || |
| 154 | |
filename.endsWith(".xml"); |
| 155 | |
} |
| 156 | |
} |
| 157 | |
|
| 158 | |
public long getSize() { |
| 159 | 360 | return this.size; |
| 160 | |
} |
| 161 | |
|
| 162 | |
public double getSizeInKB() { |
| 163 | 12 | return (this.size / 1024.0); |
| 164 | |
} |
| 165 | |
|
| 166 | |
public void setSize(long size) { |
| 167 | 884 | this.size = size; |
| 168 | 884 | } |
| 169 | |
|
| 170 | |
public void setType(String type) { |
| 171 | 960 | this.type = type; |
| 172 | 960 | } |
| 173 | |
|
| 174 | |
public File getFile() { |
| 175 | 0 | return context.getFile(getAbsolutePath()); |
| 176 | |
} |
| 177 | |
|
| 178 | |
} |