if (!source.isCollection()) throw new RuntimeException(colName + " is not a collection!");
return source;
}
public static void save(Request request, String dirName) throws Exception {
TraversableSource collection = getCollection(dirName);
ModifiableTraversableSource result;
Enumeration params = request.getParameterNames();
while (params.hasMoreElements()) {
String name = (String) params.nextElement();
if (name.indexOf("..") > -1) throw new Exception("We are under attack!!");
//System.out.println("[param] " + name);
if (name.startsWith("save:")) {
Part part = (Part) request.get(name);
String code = name.substring(5);
if (!(collection instanceof ModifiableSource)) {
throw new RuntimeException("Cannot modify the given source");
}
result = (ModifiableTraversableSource)resolve(collection.getURI() + "/" + code);
save(part, result);
} else if (name.startsWith("delete:")) {
String value = request.getParameter(name);
if (value.length() > 0) {