44 |
44 |
import java.io.InputStreamReader;
|
45 |
45 |
import java.io.OutputStreamWriter;
|
46 |
46 |
import java.io.PrintWriter;
|
|
47 |
import java.io.UnsupportedEncodingException;
|
47 |
48 |
import java.net.URI;
|
48 |
49 |
import java.net.URISyntaxException;
|
49 |
50 |
import java.net.URLDecoder;
|
... | ... | |
52 |
53 |
import java.util.HashSet;
|
53 |
54 |
import java.util.List;
|
54 |
55 |
import java.util.Set;
|
|
56 |
import java.util.StringTokenizer;
|
55 |
57 |
|
56 |
58 |
import javax.servlet.ServletContext;
|
57 |
59 |
import javax.servlet.ServletException;
|
... | ... | |
417 |
419 |
}
|
418 |
420 |
String path = getInnerPath(req, PATH_FILES);
|
419 |
421 |
path = path.endsWith("/")? path: path + '/';
|
420 |
|
|
|
422 |
path = URLDecoder.decode(path, "UTF-8");
|
421 |
423 |
String newName = req.getParameter(NEW_FOLDER_PARAMETER);
|
422 |
424 |
boolean hasUpdateParam = req.getParameterMap().containsKey(RESOURCE_UPDATE_PARAMETER);
|
423 |
425 |
boolean hasTrashParam = req.getParameterMap().containsKey(RESOURCE_TRASH_PARAMETER);
|
... | ... | |
603 |
605 |
User destOwner = null;
|
604 |
606 |
boolean exists = true;
|
605 |
607 |
try {
|
606 |
|
destination = getDestinationPath(req, moveTo);
|
|
608 |
destination = getDestinationPath(req, encodePath(moveTo));
|
|
609 |
destination = URLDecoder.decode(destination, "UTF-8");
|
607 |
610 |
destOwner = getDestinationOwner(req);
|
608 |
611 |
getService().getResourceAtPath(destOwner.getId(), destination, true);
|
609 |
612 |
} catch (ObjectNotFoundException e) {
|
... | ... | |
670 |
673 |
User destOwner = null;
|
671 |
674 |
boolean exists = true;
|
672 |
675 |
try {
|
673 |
|
destination = getDestinationPath(req, copyTo);
|
|
676 |
destination = getDestinationPath(req, encodePath(copyTo));
|
|
677 |
destination = URLDecoder.decode(destination, "UTF-8");
|
674 |
678 |
destOwner = getDestinationOwner(req);
|
675 |
679 |
getService().getResourceAtPath(destOwner.getId(), destination, true);
|
676 |
680 |
} catch (ObjectNotFoundException e) {
|
... | ... | |
710 |
714 |
}
|
711 |
715 |
}
|
712 |
716 |
|
|
717 |
private String encodePath(String path) throws UnsupportedEncodingException{
|
|
718 |
StringTokenizer str = new StringTokenizer(path, "/:", true);
|
|
719 |
String result = new String();
|
|
720 |
while(str.hasMoreTokens()){
|
|
721 |
String token = str.nextToken();
|
|
722 |
if(!token.equals("/") && !token.equals(":"))
|
|
723 |
token = URLEncoder.encode(token,"UTF-8");
|
|
724 |
result = result + token;
|
|
725 |
}
|
|
726 |
return result;
|
|
727 |
}
|
713 |
728 |
/**
|
714 |
729 |
* A helper method that extracts the relative resource path,
|
715 |
730 |
* after removing the 'files' namespace.
|
... | ... | |
870 |
885 |
if (resource instanceof FolderDTO) {
|
871 |
886 |
FolderDTO folder = (FolderDTO) resource;
|
872 |
887 |
String name = json.optString("name");
|
873 |
|
if (!name.isEmpty())
|
|
888 |
if (!name.isEmpty()){
|
874 |
889 |
getService().modifyFolder(user.getId(), folder.getId(), name);
|
|
890 |
FolderDTO folderUpdated = getService().getFolder(user.getId(), folder.getId());
|
|
891 |
String parentUrl =URLDecoder.decode(getContextPath(req, true),"UTF-8");
|
|
892 |
String fpath = URLDecoder.decode(req.getPathInfo(), "UTF-8");
|
|
893 |
parentUrl = parentUrl.replaceAll(fpath, "");
|
|
894 |
if(!parentUrl.endsWith("/"))
|
|
895 |
parentUrl = parentUrl+"/";
|
|
896 |
parentUrl = parentUrl+folderUpdated.getOwner().getUsername()+PATH_FILES+folderUpdated.getPath();
|
|
897 |
resp.getWriter().println(parentUrl);
|
|
898 |
}
|
875 |
899 |
|
876 |
900 |
JSONArray permissions = json.optJSONArray("permissions");
|
877 |
901 |
if (permissions != null) {
|
... | ... | |
1154 |
1178 |
String path = getInnerPath(req, PATH_FILES);
|
1155 |
1179 |
if (logger.isDebugEnabled())
|
1156 |
1180 |
logger.debug("Deleting resource '" + path);
|
1157 |
|
|
|
1181 |
path = URLDecoder.decode(path, "UTF-8");
|
1158 |
1182 |
User user = getUser(req);
|
1159 |
1183 |
User owner = getOwner(req);
|
1160 |
1184 |
boolean exists = true;
|
... | ... | |
1297 |
1321 |
* the necessary privileges to read the directory
|
1298 |
1322 |
*/
|
1299 |
1323 |
private String renderJson(User user, FileHeaderDTO file, FileBodyDTO oldBody)
|
1300 |
|
throws ServletException, InsufficientPermissionsException {
|
|
1324 |
throws IOException, ServletException, InsufficientPermissionsException {
|
1301 |
1325 |
JSONObject json = new JSONObject();
|
1302 |
1326 |
try {
|
1303 |
|
json.put("name", file.getName()).
|
|
1327 |
//need to encode file name in order to properly display it in gwt
|
|
1328 |
json.put("name", URLEncoder.encode(file.getName(),"UTF-8")).
|
1304 |
1329 |
put("owner", file.getOwner().getUsername()).
|
1305 |
1330 |
put("versioned", file.isVersioned()).
|
1306 |
1331 |
put("version", oldBody != null ? oldBody.getVersion() : file.getVersion()).
|