|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This report was generated with an evaluation server license. Purchase Clover or configure your license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Theme | Line # 49 | 47 | 0% | 20 | 18 | 75% |
0.75
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(18) | |||
Result | |||
0.6388889
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStarted
![]() |
1 PASS | |
0.6388889
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStarted
![]() |
1 PASS | |
0.31944445
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStopped
![]() |
1 PASS | |
0.31944445
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStopped
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.domain.FileManagerTest.testCreateFileManagerForThemeFiles
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.domain.FileManagerTest.testUrlForThemeFile
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.domain.FileManagerTest.testGetFilesFromNonExistentDirectory
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.domain.FileManagerTest.testCreateFileManagerForThemeFiles
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.web.action.ViewFilesActionTest.testUploadActionForThemeFiles
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.domain.FileManagerTest.testGetFilesFromNonExistentDirectory
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.web.action.ViewFilesActionTest.testUploadActionForThemeFiles
![]() |
1 PASS | |
0.083333336
|
net.sourceforge.pebble.domain.FileManagerTest.testUrlForThemeFile
![]() |
1 PASS | |
0.027777778
|
net.sourceforge.pebble.domain.ThemeTest.testBackupThemeDirectory
![]() |
1 PASS | |
0.027777778
|
net.sourceforge.pebble.domain.ThemeTest.testPathToLiveTheme
![]() |
1 PASS | |
0.027777778
|
net.sourceforge.pebble.domain.ThemeTest.testBackupThemeDirectory
![]() |
1 PASS | |
0.027777778
|
net.sourceforge.pebble.domain.ThemeTest.testConstruction
![]() |
1 PASS | |
0.027777778
|
net.sourceforge.pebble.domain.ThemeTest.testConstruction
![]() |
1 PASS | |
0.027777778
|
net.sourceforge.pebble.domain.ThemeTest.testPathToLiveTheme
![]() |
1 PASS | |
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 net.sourceforge.pebble.util.FileUtils; | |
35 | import org.apache.commons.logging.Log; | |
36 | import org.apache.commons.logging.LogFactory; | |
37 | ||
38 | import java.io.File; | |
39 | import java.io.FileInputStream; | |
40 | import java.io.FileOutputStream; | |
41 | import java.io.IOException; | |
42 | import java.nio.channels.FileChannel; | |
43 | ||
44 | /** | |
45 | * Represents the user's editable theme. | |
46 | * | |
47 | * @author Simon Brown | |
48 | */ | |
49 | public class Theme { | |
50 | ||
51 | /** the log used by this class */ | |
52 | private static Log log = LogFactory.getLog(Theme.class); | |
53 | ||
54 | /** the name of the theme that should be used as a default */ | |
55 | public static final String DEFAULT_THEME_NAME = "default"; | |
56 | ||
57 | /** the blog to which this theme belongs */ | |
58 | private Blog blog; | |
59 | ||
60 | /** the name of the theme */ | |
61 | private String name; | |
62 | ||
63 | /** the path of the live theme (under the webapp root) */ | |
64 | private String pathToLiveThemes; | |
65 | ||
66 | /** | |
67 | * Creates a new Theme instance with the specified details. | |
68 | * | |
69 | * @param blog the owning Blog instance | |
70 | * @param name the name of the theme | |
71 | * @param pathToLiveThemes the path to the live themes | |
72 | */ | |
73 | 1332 |
![]() |
74 | 1332 | this.blog = blog; |
75 | 1332 | this.name = name; |
76 | 1332 | this.pathToLiveThemes = pathToLiveThemes; |
77 | } | |
78 | ||
79 | /** | |
80 | * Gets the location where the backup version of the blog theme is stored - | |
81 | * under the blog.dir directory, in a sub-directory called "theme". | |
82 | * | |
83 | * @return an absolute, local path on the filing system | |
84 | */ | |
85 | 10568 |
![]() |
86 | 10568 | return blog.getRoot() + File.separator + "theme"; |
87 | } | |
88 | ||
89 | 1332 |
![]() |
90 | 1332 | return new File(pathToLiveThemes, name); |
91 | } | |
92 | ||
93 | /** | |
94 | * Restores the theme from the blog.dir to the webapp. | |
95 | */ | |
96 | 1320 |
![]() |
97 | 1320 | restore(DEFAULT_THEME_NAME); |
98 | } | |
99 | ||
100 | /** | |
101 | * Restores the theme from the blog.dir to the webapp. | |
102 | */ | |
103 | 1320 |
![]() |
104 | 1320 | File blogTheme = new File(getBackupThemeDirectory()); |
105 | 1320 | if (!blogTheme.exists() || blogTheme.listFiles().length == 0) { |
106 | 1320 | copy(themeName); |
107 | } | |
108 | ||
109 | 1320 | log.debug("Restoring " + name + " theme from " + getBackupThemeDirectory()); |
110 | 1320 | copy(blogTheme, getPathToLiveTheme()); |
111 | } | |
112 | ||
113 | /** | |
114 | * Restores the theme from the blog.dir to the webapp. | |
115 | */ | |
116 | 0 |
![]() |
117 | 0 | File blogTheme = new File(getBackupThemeDirectory()); |
118 | 0 | FileUtils.deleteFile(blogTheme); |
119 | 0 | FileUtils.deleteFile(getPathToLiveTheme()); |
120 | 0 | restore(themeName); |
121 | } | |
122 | ||
123 | /** | |
124 | * Backs up the theme from the webapp to the blog.dir. | |
125 | */ | |
126 | 1322 |
![]() |
127 | 1322 | backup(name); |
128 | } | |
129 | ||
130 | /** | |
131 | * Backs up the named theme from the webapp to the blog.dir. | |
132 | * | |
133 | * @param themeName the name of the theme to backup | |
134 | */ | |
135 | 1322 |
![]() |
136 | 1322 | log.debug("Backing up " + themeName + " theme to " + getBackupThemeDirectory()); |
137 | 1322 | File liveTheme = new File(pathToLiveThemes, themeName); |
138 | 1322 | File blogTheme = new File(getBackupThemeDirectory()); |
139 | 1322 | File blogThemeBackup = new File(getBackupThemeDirectory() + ".bak"); |
140 | ||
141 | 1322 | if (blogTheme.exists()) { |
142 | 1320 | blogTheme.renameTo(blogThemeBackup); |
143 | } | |
144 | 1322 | copy(liveTheme, blogTheme); |
145 | 1322 | FileUtils.deleteFile(blogThemeBackup); |
146 | } | |
147 | ||
148 | /** | |
149 | * Copies the named theme from the webapp to blog.dir/theme. | |
150 | * | |
151 | * @param themeName the name of the theme to backup | |
152 | */ | |
153 | 1320 |
![]() |
154 | 1320 | log.info("Copying " + themeName + " theme to " + getBackupThemeDirectory()); |
155 | 1320 | File liveTheme = new File(pathToLiveThemes, themeName); |
156 | 1320 | File blogTheme = new File(getBackupThemeDirectory()); |
157 | 1320 | File blogThemeBackup = new File(getBackupThemeDirectory() + ".bak"); |
158 | ||
159 | 1320 | if (blogTheme.exists()) { |
160 | 2 | blogTheme.renameTo(blogThemeBackup); |
161 | } | |
162 | 1320 | copy(liveTheme, blogTheme); |
163 | 1320 | FileUtils.deleteFile(blogThemeBackup); |
164 | } | |
165 | ||
166 | /** | |
167 | * Copies one file to another. | |
168 | * | |
169 | * @param source the source | |
170 | * @param destination the destination | |
171 | */ | |
172 | 3962 |
![]() |
173 | 3962 | if (!destination.exists()) { |
174 | 3960 | destination.mkdir(); |
175 | } | |
176 | ||
177 | 3962 | File files[] = source.listFiles(); |
178 | 3962 | if (files != null) { |
179 | 2636 | for (int i = 0; i < files.length; i++) { |
180 | 0 | if (files[i].isDirectory()) { |
181 | 0 | copy(files[i], new File(destination, files[i].getName())); |
182 | } else { | |
183 | 0 | try { |
184 | 0 | FileChannel srcChannel = new FileInputStream(files[i]).getChannel(); |
185 | 0 | FileChannel dstChannel = new FileOutputStream(new File(destination, files[i].getName())).getChannel(); |
186 | 0 | dstChannel.transferFrom(srcChannel, 0, srcChannel.size()); |
187 | 0 | srcChannel.close(); |
188 | 0 | dstChannel.close(); |
189 | } catch (IOException ioe) { | |
190 | 0 | log.error("Could not write to " + destination.getAbsolutePath(), ioe); |
191 | } | |
192 | } | |
193 | } | |
194 | } | |
195 | } | |
196 | ||
197 | /** | |
198 | * Gets the name of this theme. | |
199 | * | |
200 | * @return the name | |
201 | */ | |
202 | 2 |
![]() |
203 | 2 | return name; |
204 | } | |
205 | ||
206 | } |
|