Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
44   178   34   2,75
22   113   0,77   16
16     2,12  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  FileMetaData       Line # 42 44 0% 34 5 93,9% 0.9390244
 
  (108)
 
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   
 
58  526 toggle FileMetaData(FileManager context, String absolutePath) {
59  526 this.context = context;
60   
61  526 if (absolutePath == null || absolutePath.equals("") || absolutePath.equals("/")) {
62  188 this.path="/";
63  188 this.name = "";
64    } else {
65  338 if (absolutePath.endsWith("/")) {
66  10 absolutePath = absolutePath.substring(0, absolutePath.length()-1);
67    }
68   
69  338 if (absolutePath.indexOf("/") > -1) {
70  332 this.path = absolutePath.substring(0, absolutePath.lastIndexOf("/"));
71  332 if (this.path.length() == 0) {
72  298 this.path = "/";
73    }
74  332 this.name = absolutePath.substring(absolutePath.lastIndexOf("/")+1, absolutePath.length());
75    } else {
76  6 this.path = absolutePath;
77  6 this.name = "";
78    }
79   
80    // finally, all paths must start with "/"
81  338 if (!this.path.startsWith("/")) {
82  6 this.path = "/" + this.path;
83    }
84    }
85    }
86   
 
87  122 toggle public String getName() {
88  122 return name;
89    }
90   
 
91  2 toggle public void setName(String name) {
92  2 this.name = name;
93    }
94   
 
95  2 toggle public Date getLastModified() {
96  2 return lastModified;
97    }
98   
 
99  450 toggle public void setLastModified(Date lastModified) {
100  450 this.lastModified = lastModified;
101    }
102   
 
103  88 toggle public boolean isDirectory() {
104  88 return directory;
105    }
106   
 
107  304 toggle public void setDirectory(boolean directory) {
108  304 this.directory = directory;
109    }
110   
 
111  54 toggle public String getPath() {
112  54 return path;
113    }
114   
 
115  1296 toggle public String getAbsolutePath() {
116  1296 if (!path.endsWith("/")) {
117  48 return path + "/" + name;
118    } else {
119  1248 return path + name;
120    }
121    }
122   
 
123  20 toggle public String getUrl() {
124  20 String url = null;
125   
126  20 if (type != null && type.equals(FileMetaData.BLOG_IMAGE)) {
127  6 url = "images" + getAbsolutePath();
128  14 } else if (type != null && type.equals(FileMetaData.BLOG_FILE)) {
129  10 url = "files" + getAbsolutePath();
130  4 } else if (type != null && type.equals(FileMetaData.THEME_FILE)) {
131  4 url = "theme" + getAbsolutePath();
132    }
133   
134  20 if (url != null && isDirectory() && !url.endsWith("/")) {
135  0 url += "/";
136    }
137   
138  20 return url;
139    }
140   
 
141  26 toggle public boolean isEditable() {
142  26 if (isDirectory()) {
143  2 return false;
144    } else {
145  24 String filename = name.toLowerCase();
146  24 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  180 toggle public long getSize() {
159  180 return this.size;
160    }
161   
 
162  6 toggle public double getSizeInKB() {
163  6 return (this.size / 1024.0);
164    }
165   
 
166  442 toggle public void setSize(long size) {
167  442 this.size = size;
168    }
169   
 
170  480 toggle public void setType(String type) {
171  480 this.type = type;
172    }
173   
 
174  0 toggle public File getFile() {
175  0 return context.getFile(getAbsolutePath());
176    }
177   
178    }