File Source: filemetadata.java
/*
P/P * Method: net.sourceforge.pebble.domain.FileMetaData__static_init
*/
1 /*
2 * Copyright (c) 2003-2006, Simon Brown
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * - Neither the name of Pebble nor the names of its contributors may
17 * be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 package net.sourceforge.pebble.domain;
33
34 import java.io.File;
35 import java.util.Date;
36
37 /**
38 * Represents the meta data associated with a file.
39 *
40 * @author Simon Brown
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
/*
P/P * Method: void net.sourceforge.pebble.domain.FileMetaData(FileManager, String)
*
* Presumptions:
* java.lang.String:lastIndexOf(...)@74 <= 232-2
*
* Postconditions:
* this.context == context
* init'ed(this.context)
* this.name != null
* this.path != null
*
* Test Vectors:
* absolutePath: Addr_Set{null}, Inverse{null}
* java.lang.String:endsWith(...)@65: {0}, {1}
* java.lang.String:equals(...)@61: {1}, {0}
* java.lang.String:equals(...)@61: {0}, {1}
* java.lang.String:indexOf(...)@69: {-231..-1}, {0..232-1}
* java.lang.String:length(...)@71: {1..232-1}, {0}
* java.lang.String:startsWith(...)@81: {1}, {0}
*/
58 FileMetaData(FileManager context, String absolutePath) {
59 this.context = context;
60
61 if (absolutePath == null || absolutePath.equals("") || absolutePath.equals("/")) {
62 this.path="/";
63 this.name = "";
64 } else {
65 if (absolutePath.endsWith("/")) {
66 absolutePath = absolutePath.substring(0, absolutePath.length()-1);
67 }
68
69 if (absolutePath.indexOf("/") > -1) {
70 this.path = absolutePath.substring(0, absolutePath.lastIndexOf("/"));
71 if (this.path.length() == 0) {
72 this.path = "/";
73 }
74 this.name = absolutePath.substring(absolutePath.lastIndexOf("/")+1, absolutePath.length());
75 } else {
76 this.path = absolutePath;
77 this.name = "";
78 }
79
80 // finally, all paths must start with "/"
81 if (!this.path.startsWith("/")) {
82 this.path = "/" + this.path;
83 }
84 }
85 }
86
87 public String getName() {
/*
P/P * Method: String getName()
*
* Preconditions:
* init'ed(this.name)
*
* Postconditions:
* return_value == this.name
* init'ed(return_value)
*/
88 return name;
89 }
90
91 public void setName(String name) {
/*
P/P * Method: void setName(String)
*
* Postconditions:
* this.name == name
* init'ed(this.name)
*/
92 this.name = name;
93 }
94
95 public Date getLastModified() {
/*
P/P * Method: Date getLastModified()
*
* Preconditions:
* init'ed(this.lastModified)
*
* Postconditions:
* return_value == this.lastModified
* init'ed(return_value)
*/
96 return lastModified;
97 }
98
99 public void setLastModified(Date lastModified) {
/*
P/P * Method: void setLastModified(Date)
*
* Postconditions:
* this.lastModified == lastModified
* init'ed(this.lastModified)
*/
100 this.lastModified = lastModified;
101 }
102
103 public boolean isDirectory() {
/*
P/P * Method: bool isDirectory()
*
* Preconditions:
* init'ed(this.directory)
*
* Postconditions:
* return_value == this.directory
* init'ed(return_value)
*/
104 return directory;
105 }
106
107 public void setDirectory(boolean directory) {
/*
P/P * Method: void setDirectory(bool)
*
* Postconditions:
* this.directory == directory
* init'ed(this.directory)
*/
108 this.directory = directory;
109 }
110
111 public String getPath() {
/*
P/P * Method: String getPath()
*
* Preconditions:
* init'ed(this.path)
*
* Postconditions:
* return_value == this.path
* init'ed(return_value)
*/
112 return path;
113 }
114
115 public String getAbsolutePath() {
/*
P/P * Method: String getAbsolutePath()
*
* Preconditions:
* init'ed(this.name)
* this.path != null
*
* Postconditions:
* return_value != null
*
* Test Vectors:
* java.lang.String:endsWith(...)@116: {1}, {0}
*/
116 if (!path.endsWith("/")) {
117 return path + "/" + name;
118 } else {
119 return path + name;
120 }
121 }
122
123 public String getUrl() {
/*
P/P * Method: String getUrl()
*
* Preconditions:
* init'ed(this.type)
* (soft) init'ed(this.directory)
* (soft) init'ed(this.name)
* (soft) this.path != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.directory: {0}, {1}
* this.type: Addr_Set{null}, Inverse{null}
* java.lang.String:endsWith(...)@134: {1}, {0}
* java.lang.String:equals(...)@126: {0}, {1}
* java.lang.String:equals(...)@128: {0}, {1}
* java.lang.String:equals(...)@130: {0}, {1}
*/
124 String url = null;
125
126 if (type != null && type.equals(FileMetaData.BLOG_IMAGE)) {
127 url = "images" + getAbsolutePath();
128 } else if (type != null && type.equals(FileMetaData.BLOG_FILE)) {
129 url = "files" + getAbsolutePath();
130 } else if (type != null && type.equals(FileMetaData.THEME_FILE)) {
131 url = "theme" + getAbsolutePath();
132 }
133
134 if (url != null && isDirectory() && !url.endsWith("/")) {
135 url += "/";
136 }
137
138 return url;
139 }
140
141 public boolean isEditable() {
/*
P/P * Method: bool isEditable()
*
* Preconditions:
* init'ed(this.directory)
* (soft) this.name != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.directory: {0}, {1}
* java.lang.String:endsWith(...)@147: {1}, {0}
* java.lang.String:endsWith(...)@148: {1}, {0}
* java.lang.String:endsWith(...)@149: {1}, {0}
* java.lang.String:endsWith(...)@150: {1}, {0}
* java.lang.String:endsWith(...)@151: {1}, {0}
* java.lang.String:endsWith(...)@152: {1}, {0}
* java.lang.String:endsWith(...)@153: {1}, {0}
* java.lang.String:endsWith(...)@154: {1}, {0}
*/
142 if (isDirectory()) {
143 return false;
144 } else {
145 String filename = name.toLowerCase();
146 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() {
/*
P/P * Method: long getSize()
*
* Preconditions:
* init'ed(this.size)
*
* Postconditions:
* return_value == this.size
* init'ed(return_value)
*/
159 return this.size;
160 }
161
162 public double getSizeInKB() {
/*
P/P * Method: double getSizeInKB()
*
* Preconditions:
* init'ed(this.size)
*
* Postconditions:
* return_value == (float) (this.size)/1024
* return_value in (-Inf..+Inf)
*/
163 return (this.size / 1024.0);
164 }
165
166 public void setSize(long size) {
/*
P/P * Method: void setSize(long)
*
* Postconditions:
* this.size == size
* init'ed(this.size)
*/
167 this.size = size;
168 }
169
170 public void setType(String type) {
/*
P/P * Method: void setType(String)
*
* Postconditions:
* this.type == type
* init'ed(this.type)
*/
171 this.type = type;
172 }
173
174 public File getFile() {
/*
P/P * Method: File getFile()
*
* Preconditions:
* this.context != null
* init'ed(this.context.root)
* init'ed(this.name)
* this.path != null
*
* Postconditions:
* return_value == &new File(getFile#1*)
* new File(getFile#1*) num objects == 1
*/
175 return context.getFile(getAbsolutePath());
176 }
177
178 }
SofCheck Inspector Build Version : 2.22510
| filemetadata.java |
2010-Jun-25 19:40:32 |
| filemetadata.class |
2010-Jul-19 20:23:40 |