import gr.ebs.gss.client.rest.resource.TrashResource;
import gr.ebs.gss.client.rest.resource.UserResource;
-import java.util.HashMap;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import com.allen_sauer.gwt.dnd.client.DragContext;
import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
-import com.google.gwt.http.client.URL;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.Command;
private String token;
/**
- * A map that stores user's selection in order browser's
- * history functionality to be implemented.
- */
- private Map<String, Object> map = new HashMap<String, Object>();
-
- /**
* The WebDAV password of the current user
*/
private String webDAVPassword;
private PickupDragController dragController;
+ @Override
public void onModuleLoad() {
// Initialize the singleton before calling the constructors of the
// various widgets that might call GSS.get().
@Override
public void onSelection(SelectionEvent<Integer> event) {
int tabIndex = event.getSelectedItem();
- TreeItem treeItem = GSS.get().getFolders().getCurrent();
- PopupTree tree = GSS.get().getFolders().getPopupTree();
+// TreeItem treeItem = GSS.get().getFolders().getCurrent();
switch (tabIndex) {
case 0:
+// Files tab selected
fileList.clearSelectedRows();
fileList.updateCurrentlyShowingStats();
break;
- /**
- * When the Groups tab is selected a new
- */
case 1:
+// Groups tab selected
groups.updateCurrentlyShowingStats();
-// Add a new pair key - object in the History map.
- setHistory("Groups", treeItem);
-// Add a new browser history entry.
- History.newItem("Groups");
+ updateHistory("Groups");
break;
case 2:
+// Search tab selected
searchResults.clearSelectedRows();
searchResults.updateCurrentlyShowingStats();
- setHistory("Search", treeItem);
- History.newItem("Search");
+ updateHistory("Search");
break;
}
}
});
- // If the application starts with no history token, redirect to a new "Files" state
+// If the application starts with no history token, redirect to a new "Files" state
String initToken = History.getToken();
if(initToken.length() == 0)
History.newItem("Files");
-
- // Add history listener
- History.addValueChangeHandler(new ValueChangeHandler<String>() {
- public void onValueChange(ValueChangeEvent<String> event) {
- String historyToken = event.getValue();
- TreeItem treeItem = GSS.get().getFolders().getCurrent();
- try {
- if(historyToken.equals("Search"))
+// Add history listener to handle any history events
+ History.addValueChangeHandler(new ValueChangeHandler<String>() {
+ @Override
+ public void onValueChange(ValueChangeEvent<String> event) {
+ String tokenInput = event.getValue();
+ String historyToken = handleSpecialFolderNames(tokenInput);
+ try {
+ if(historyToken.equals("Search"))
inner.selectTab(2);
else if(historyToken.equals("Groups"))
inner.selectTab(1);
- else if(historyToken.equals("Files")){
- setHistory("Files", treeItem);
- History.newItem("Files");
- inner.selectTab(0);
- }
- else{
- PopupTree tree = GSS.get().getFolders().getPopupTree();
- String newHistoryToken = URL.decode(historyToken);
- System.out.println(map.keySet());
- SelectionEvent.fire(tree, (TreeItem) getHistoryItem(newHistoryToken));
- }
- } catch (IndexOutOfBoundsException e) {
- inner.selectTab(0);
- }
- }
- });
-
+ else if(historyToken.equals("Files")|| historyToken.length()==0)
+ inner.selectTab(0);
+ else {
+ PopupTree popupTree = GSS.get().getFolders().getPopupTree();
+ TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken);
+ SelectionEvent.fire(popupTree, treeObj);
+ }
+ } catch (IndexOutOfBoundsException e) {
+ inner.selectTab(0);
+ }
+ }
+ });
// Add the left and right panels to the split panel.
splitPanel.setLeftWidget(folders);
// sizes have been computed by the browser.
DeferredCommand.addCommand(new Command() {
+ @Override
public void execute() {
onWindowResized(Window.getClientHeight());
}
if (announcement != null)
DeferredCommand.addCommand(new Command() {
+ @Override
public void execute() {
displayInformation(announcement);
}
Configuration conf = (Configuration) GWT.create(Configuration.class);
String cookie = conf.authCookie();
String auth = Cookies.getCookie(cookie);
- String domain = Window.Location.getHostName();
- String path = Window.Location.getPath();
- Cookies.setCookie(cookie, "", null, domain, path, false);
if (auth == null) {
authenticateUser();
// Redundant, but silences warnings about possible auth NPE, below.
int sepIndex = auth.indexOf(conf.cookieSeparator());
if (sepIndex == -1)
authenticateUser();
- token = auth.substring(sepIndex + 1, auth.length());
+ token = auth.substring(sepIndex + 1);
final String username = auth.substring(0, sepIndex);
if (username == null)
authenticateUser();
DeferredCommand.addCommand(new Command() {
+ @Override
public void execute() {
fetchUser(username);
}
}
/**
- * Redirect the user to the logout page.
+ * Clear the cookie and redirect the user to the logout page.
*/
void logout() {
Configuration conf = (Configuration) GWT.create(Configuration.class);
+ String cookie = conf.authCookie();
+ String domain = Window.Location.getHostName();
+ String path = Window.Location.getPath();
+ Cookies.setCookie(cookie, "", null, domain, path, false);
Window.Location.assign(conf.logoutUrl());
}
webDAVPassword = Cookies.getCookie(cookie);
Cookies.setCookie(cookie, "", null, domain, path, false);
}
+
/**
+ * History support for folder navigation
+ * adds a new browser history entry
*
* @param key
- * @return Object of the corresponding key in the History map
*/
- public Object getHistoryItem(String key){
- return map.get(key);
+ public void updateHistory(String key){
+// Replace any whitespace of the initial string to "+"
+// String result = key.replaceAll("\\s","+");
+// Add a new browser history entry.
+// History.newItem(result);
+ History.newItem(key);
}
+
/**
- * Set a pair of key - object in the History (using a map)
- * @param key
- * @param obj
+ * This method examines the token input and add a "/" at the end in case it's omitted.
+ * This happens only in Files/trash/, Files/shared/, Files/others.
+ *
+ * @param tokenInput
+ * @return the formated token with a "/" at the end or the same tokenInput parameter
*/
- public void setHistory(String key, Object obj){
- map.put(key, obj);
+ private String handleSpecialFolderNames(String tokenInput){
+ List<String> pathsToCheck = Arrays.asList("Files/trash", "Files/shared", "Files/others");
+ if(pathsToCheck.contains(tokenInput))
+ return tokenInput + "/";
+ return tokenInput;
+
}
+
+ /**
+ * Reject illegal resource names, like '.' or '..'.
+ */
+ static boolean isValidResourceName(String name) {
+ if (".".equals(name) || "..".equals(name))
+ return false;
+ return true;
+ }
+
+
}