Revision 4106
Added by daigle over 16 years ago
src/edu/ucsb/nceas/metacat/admin/SkinsAdmin.java | ||
---|---|---|
40 | 40 |
import edu.ucsb.nceas.metacat.service.SkinPropertyService; |
41 | 41 |
import edu.ucsb.nceas.metacat.util.RequestUtil; |
42 | 42 |
import edu.ucsb.nceas.metacat.util.SkinUtil; |
43 |
import edu.ucsb.nceas.utilities.FileUtil; |
|
43 | 44 |
import edu.ucsb.nceas.utilities.PropertiesMetaData; |
44 | 45 |
import edu.ucsb.nceas.utilities.GeneralPropertyException; |
46 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
|
45 | 47 |
import edu.ucsb.nceas.utilities.SortedProperties; |
46 | 48 |
|
47 | 49 |
/** |
... | ... | |
135 | 137 |
for (String propertyName : backupProperties.getPropertyNames()) |
136 | 138 |
{ |
137 | 139 |
localSkinProperties.put(propertyName, |
138 |
backupProperties.getProperty(propertyName));
|
|
140 |
backupProperties.getProperty(propertyName)); |
|
139 | 141 |
} |
140 | 142 |
|
141 | 143 |
localPropertyMap.put(skinName, localSkinProperties); |
... | ... | |
164 | 166 |
Vector<String> processingErrors = new Vector<String>(); |
165 | 167 |
Vector<String> validationErrors = new Vector<String>(); |
166 | 168 |
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
// Now that the options have been set, change the 'skinsConfigured' |
|
171 |
// option to 'true' so that normal metacat requests will go through |
|
172 | 169 |
try { |
170 |
// For each skin property, check if it is changed and save it |
|
171 |
Vector<String> skinNames = SkinUtil.getSkinNames(); |
|
172 |
for (String skinName : skinNames) { |
|
173 |
Vector<String> propertyNames = SkinPropertyService |
|
174 |
.getPropertyNames(skinName); |
|
175 |
for (String propertyName : propertyNames) { |
|
176 |
SkinPropertyService.checkAndSetProperty(request, skinName, |
|
177 |
propertyName); |
|
178 |
} |
|
179 |
|
|
180 |
// we need to write the options from memory to the |
|
181 |
// properties file |
|
182 |
SkinPropertyService.persistProperties(skinName); |
|
183 |
|
|
184 |
// Validate that the options provided are legitimate. Note |
|
185 |
// that we've allowed them to persist their entries. As of |
|
186 |
// this point there is no other easy way to go back to the |
|
187 |
// configure form and preserve their entries. |
|
188 |
validationErrors.addAll(validateOptions(request, skinName)); |
|
189 |
|
|
190 |
// Try to create backup directories if necessary. |
|
191 |
String backupDir = PropertyService.getBackupDir(); |
|
192 |
if (!FileUtil.createDirectory(backupDir)) { |
|
193 |
String errorString = "Could not create directory: " + backupDir; |
|
194 |
logMetacat.error(errorString); |
|
195 |
validationErrors.add(errorString); |
|
196 |
} |
|
197 |
|
|
198 |
// write the backup properties to a location outside the |
|
199 |
// application directories so they will be available after |
|
200 |
// the next upgrade |
|
201 |
SkinPropertyService.persistBackupProperties(skinName, |
|
202 |
request.getSession().getServletContext()); |
|
203 |
} |
|
204 |
|
|
205 |
// Now that the options have been set, change the |
|
206 |
// 'skinsConfigured' |
|
207 |
// option to 'true' so that normal metacat requests will go |
|
208 |
// through |
|
173 | 209 |
PropertyService.setProperty("configutil.skinsConfigured", |
174 | 210 |
PropertyService.CONFIGURED); |
175 |
|
|
176 | 211 |
} catch (GeneralPropertyException gpe) { |
177 | 212 |
String errorMessage = "problem setting property while processing skins " |
178 | 213 |
+ "properties page: " + gpe.getMessage(); |
179 | 214 |
logMetacat.error(errorMessage); |
180 | 215 |
processingErrors.add(errorMessage); |
216 |
} catch (IOException ioe) { |
|
217 |
String errorMessage = "IO problem while processing skins " |
|
218 |
+ "properties page: " + ioe.getMessage(); |
|
219 |
logMetacat.error(errorMessage); |
|
220 |
processingErrors.add(errorMessage); |
|
181 | 221 |
} |
182 | 222 |
try { |
183 | 223 |
if (validationErrors.size() > 0 || processingErrors.size() > 0) { |
... | ... | |
213 | 253 |
} |
214 | 254 |
} |
215 | 255 |
|
256 |
protected Vector<String> validateOptions(HttpServletRequest request) { |
|
257 |
Vector<String> errorVector = new Vector<String>(); |
|
258 |
Vector<String> skinNames = null; |
|
259 |
try { |
|
260 |
skinNames = SkinUtil.getSkinNames(); |
|
261 |
} catch (PropertyNotFoundException pnfe) { |
|
262 |
errorVector.add("Could not find skin names: " + pnfe.getMessage()); |
|
263 |
} |
|
264 |
|
|
265 |
for (String skinName : skinNames) { |
|
266 |
errorVector.addAll(validateOptions(request, skinName)); |
|
267 |
} |
|
268 |
|
|
269 |
return errorVector; |
|
270 |
} |
|
271 |
|
|
216 | 272 |
/** |
217 | 273 |
* Validate the most important configuration options submitted by the user. |
218 | 274 |
* |
219 | 275 |
* @return a vector holding error message for any fields that fail |
220 | 276 |
* validation. |
221 | 277 |
*/ |
222 |
protected Vector<String> validateOptions(HttpServletRequest request) { |
|
278 |
protected Vector<String> validateOptions(HttpServletRequest request, String skinName) {
|
|
223 | 279 |
Vector<String> errorVector = new Vector<String>(); |
224 | 280 |
|
225 | 281 |
//TODO MCD validate options. |
Also available in: Unified diff
Implement form submittal processing.