2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client;
37 import com.google.gwt.core.client.Scheduler;
38 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
39 import com.google.gwt.http.client.Request;
40 import com.google.gwt.http.client.RequestBuilder;
41 import com.google.gwt.http.client.RequestCallback;
42 import com.google.gwt.http.client.RequestException;
43 import com.google.gwt.http.client.Response;
44 import com.google.gwt.json.client.JSONArray;
45 import com.google.gwt.json.client.JSONObject;
46 import com.google.gwt.json.client.JSONParser;
47 import com.google.gwt.json.client.JSONString;
48 import com.google.gwt.json.client.JSONValue;
49 import com.google.gwt.user.client.Command;
50 import com.google.gwt.view.client.SelectionChangeEvent;
51 import com.google.gwt.view.client.SelectionChangeEvent.Handler;
52 import com.google.gwt.view.client.SingleSelectionModel;
53 import gr.grnet.pithos.web.client.foldertree.AccountResource;
54 import gr.grnet.pithos.web.client.foldertree.File;
55 import gr.grnet.pithos.web.client.foldertree.Folder;
56 import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
57 import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel;
58 import gr.grnet.pithos.web.client.foldertree.Resource;
59 import gr.grnet.pithos.web.client.rest.DeleteRequest;
60 import gr.grnet.pithos.web.client.rest.GetRequest;
61 import gr.grnet.pithos.web.client.rest.PutRequest;
62 import gr.grnet.pithos.web.client.rest.RestException;
64 import gr.grnet.pithos.web.client.tagtree.Tag;
65 import gr.grnet.pithos.web.client.tagtree.TagTreeView;
66 import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel;
67 import java.util.ArrayList;
68 import java.util.Arrays;
69 import java.util.Date;
70 import java.util.HashMap;
71 import java.util.Iterator;
72 import java.util.List;
74 import com.google.gwt.core.client.EntryPoint;
75 import com.google.gwt.core.client.GWT;
76 import com.google.gwt.event.logical.shared.ResizeEvent;
77 import com.google.gwt.event.logical.shared.ResizeHandler;
78 import com.google.gwt.event.logical.shared.SelectionEvent;
79 import com.google.gwt.event.logical.shared.SelectionHandler;
80 import com.google.gwt.i18n.client.DateTimeFormat;
81 import com.google.gwt.resources.client.ClientBundle;
82 import com.google.gwt.resources.client.ImageResource;
83 import com.google.gwt.user.client.Cookies;
84 import com.google.gwt.user.client.Event;
85 import com.google.gwt.user.client.History;
86 import com.google.gwt.user.client.Window;
87 import com.google.gwt.user.client.ui.AbstractImagePrototype;
88 import com.google.gwt.user.client.ui.DecoratedTabPanel;
89 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
90 import com.google.gwt.user.client.ui.HorizontalSplitPanel;
91 import com.google.gwt.user.client.ui.RootPanel;
92 import com.google.gwt.user.client.ui.TabPanel;
93 import com.google.gwt.user.client.ui.VerticalPanel;
97 * Entry point classes define <code>onModuleLoad()</code>.
99 public class Pithos implements EntryPoint, ResizeHandler {
102 * A constant that denotes the completion of an IncrementalCommand.
104 public static final boolean DONE = false;
106 public static final int VISIBLE_FILE_COUNT = 25;
109 * Instantiate an application-level image bundle. This object will provide
110 * programmatic access to all the images needed by widgets.
112 private static Images images = (Images) GWT.create(Images.class);
114 public String getUsername() {
118 public void setAccount(AccountResource acct) {
122 public AccountResource getAccount() {
126 public void updateFolder(Folder f, boolean showfiles) {
127 folderTreeView.updateFolder(f, showfiles);
130 public void updateTag(Tag t) {
131 tagTreeView.updateTag(t);
134 public void updateTags() {
135 tagTreeViewModel.initialize(getAllTags());
138 public List<Tag> getAllTags() {
139 List<Tag> tagList = new ArrayList<Tag>();
140 for (Folder f : account.getContainers()) {
141 for (String t : f.getTags()) {
142 tagList.add(new Tag(t));
149 * An aggregate image bundle that pulls together all the images for this
150 * application into a single bundle.
152 public interface Images extends ClientBundle, TopPanel.Images, StatusPanel.Images, FilePropertiesDialog.Images, MessagePanel.Images, FileList.Images {
154 @Source("gr/grnet/pithos/resources/document.png")
155 ImageResource folders();
157 @Source("gr/grnet/pithos/resources/edit_group_22.png")
158 ImageResource groups();
160 @Source("gr/grnet/pithos/resources/search.png")
161 ImageResource search();
165 * The Application Clipboard implementation;
167 private Clipboard clipboard = new Clipboard();
170 * The top panel that contains the menu bar.
172 private TopPanel topPanel;
175 * The panel that contains the various system messages.
177 private MessagePanel messagePanel = new MessagePanel(Pithos.images);
180 * The bottom panel that contains the status bar.
182 private StatusPanel statusPanel = null;
185 * The file list widget.
187 private FileList fileList;
190 * The tab panel that occupies the right side of the screen.
192 private TabPanel inner = new DecoratedTabPanel(){
194 // public void onBrowserEvent(com.google.gwt.user.client.Event event) {
195 // if (DOM.eventGetType(event) == Event.ONCONTEXTMENU){
196 // if(isFileListShowing()){
197 // getFileList().showContextMenu(event);
205 * The split panel that will contain the left and right panels.
207 private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
210 * The currently selected item in the application, for use by the Edit menu
211 * commands. Potential types are Folder, File, User and Group.
213 private Object currentSelection;
217 * The WebDAV password of the current user
219 private String webDAVPassword;
221 public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
223 private String username = null;
226 * The authentication token of the current user.
228 private String token;
230 private SingleSelectionModel<Folder> folderTreeSelectionModel;
231 private FolderTreeViewModel folderTreeViewModel;
232 private FolderTreeView folderTreeView;
234 private SingleSelectionModel<Tag> tagTreeSelectionModel;
235 private TagTreeViewModel tagTreeViewModel;
236 private TagTreeView tagTreeView;
238 private AccountResource account;
241 public void onModuleLoad() {
242 if (parseUserCredentials())
246 private void initialize() {
247 topPanel = new TopPanel(this, Pithos.images);
248 topPanel.setWidth("100%");
250 messagePanel.setWidth("100%");
251 messagePanel.setVisible(false);
254 // Inner contains the various lists.
255 inner.sinkEvents(Event.ONCONTEXTMENU);
256 inner.setAnimationEnabled(true);
257 inner.getTabBar().addStyleName("pithos-MainTabBar");
258 inner.getDeckPanel().addStyleName("pithos-MainTabPanelBottom");
260 inner.setWidth("100%");
262 inner.addSelectionHandler(new SelectionHandler<Integer>() {
265 public void onSelection(SelectionEvent<Integer> event) {
266 int tabIndex = event.getSelectedItem();
269 fileList.updateCurrentlyShowingStats();
275 folderTreeSelectionModel = new SingleSelectionModel<Folder>();
276 folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
278 public void onSelectionChange(SelectionChangeEvent event) {
279 if (folderTreeSelectionModel.getSelectedObject() != null) {
280 tagTreeSelectionModel.setSelected(tagTreeSelectionModel.getSelectedObject(), false);
281 Folder f = folderTreeSelectionModel.getSelectedObject();
282 updateFolder(f, true);
287 folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel);
288 folderTreeView = new FolderTreeView(folderTreeViewModel);
290 fileList = new FileList(this, images, folderTreeView);
291 inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true);
293 tagTreeSelectionModel = new SingleSelectionModel<Tag>();
294 tagTreeSelectionModel.addSelectionChangeHandler(new Handler() {
296 public void onSelectionChange(SelectionChangeEvent event) {
297 if (tagTreeSelectionModel.getSelectedObject() != null) {
298 folderTreeSelectionModel.setSelected(folderTreeSelectionModel.getSelectedObject(), false);
299 Tag t = tagTreeSelectionModel.getSelectedObject();
304 tagTreeViewModel = new TagTreeViewModel(this, tagTreeSelectionModel);
305 tagTreeView = new TagTreeView(tagTreeViewModel);
307 VerticalPanel trees = new VerticalPanel();
308 trees.add(folderTreeView);
309 trees.add(tagTreeView);
310 // Add the left and right panels to the split panel.
311 splitPanel.setLeftWidget(trees);
312 splitPanel.setRightWidget(inner);
313 splitPanel.setSplitPosition("25%");
314 splitPanel.setSize("100%", "100%");
315 splitPanel.addStyleName("pithos-splitPanel");
317 // Create a dock panel that will contain the menu bar at the top,
318 // the shortcuts to the left, the status bar at the bottom and the
319 // right panel taking the rest.
320 VerticalPanel outer = new VerticalPanel();
322 outer.add(messagePanel);
323 outer.add(splitPanel);
324 statusPanel = new StatusPanel(this, Pithos.images);
325 outer.add(statusPanel);
326 outer.setWidth("100%");
327 outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
331 // Hook the window resize event, so that we can adjust the UI.
332 Window.addResizeHandler(this);
333 // Clear out the window's built-in margin, because we want to take
334 // advantage of the entire client area.
335 Window.setMargin("0px");
336 // Finally, add the outer panel to the RootPanel, so that it will be
338 RootPanel.get().add(outer);
339 // Call the window resized handler to get the initial sizes setup. Doing
340 // this in a deferred command causes it to occur after all widgets'
341 // sizes have been computed by the browser.
342 Scheduler.get().scheduleDeferred(new ScheduledCommand() {
345 public void execute() {
346 onWindowResized(Window.getClientHeight());
350 Scheduler.get().scheduleDeferred(new ScheduledCommand() {
352 public void execute() {
358 public void showFiles(Folder f) {
361 fileList.showTrash();
364 fileList.showFiles();
365 Set<File> files = f.getFiles();
369 public void showFiles(Set<File> files) {
370 //Iterator<File> iter = files.iterator();
371 //fetchFile(iter, files);
372 fileList.setFiles(new ArrayList<File>(files));
375 private void fetchFile(final Iterator<File> iter, final Set<File> files) {
376 if (iter.hasNext()) {
377 File file = iter.next();
378 String path = file.getUri() + "?format=json";
379 GetRequest<File> getFile = new GetRequest<File>(File.class, getApiPath(), username, path, file) {
381 public void onSuccess(File result) {
382 fetchFile(iter, files);
386 public void onError(Throwable t) {
387 GWT.log("Error getting file", t);
388 if (t instanceof RestException)
389 displayError("Error getting file: " + ((RestException) t).getHttpStatusText());
391 displayError("System error fetching file: " + t.getMessage());
394 getFile.setHeader("X-Auth-Token", "0000");
395 Scheduler.get().scheduleDeferred(getFile);
398 fileList.setFiles(new ArrayList<File>(files));
402 * Parse and store the user credentials to the appropriate fields.
404 private boolean parseUserCredentials() {
405 Configuration conf = (Configuration) GWT.create(Configuration.class);
406 String cookie = conf.authCookie();
407 String auth = Cookies.getCookie(cookie);
413 String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
414 if (authSplit.length != 2) {
419 username = authSplit[0];
420 token = authSplit[1];
427 * Redirect the user to the login page for authentication.
429 protected void authenticateUser() {
430 Configuration conf = (Configuration) GWT.create(Configuration.class);
432 // Window.Location.assign(GWT.getModuleBaseURL() + conf.loginUrl() + "?next=" + Window.Location.getHref());
433 Cookies.setCookie(conf.authCookie(), "test" + conf.cookieSeparator() + "0000");
434 Window.Location.assign(GWT.getModuleBaseURL() + "pithos.html");
437 private void fetchAccount() {
438 String path = "?format=json";
440 GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
442 public void onSuccess(AccountResource result) {
444 statusPanel.displayStats(account);
446 if (account.getContainers().isEmpty())
447 createHomeContainers();
449 folderTreeViewModel.initialize(account);
453 public void onError(Throwable t) {
454 GWT.log("Error getting account", t);
455 if (t instanceof RestException)
456 displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
458 displayError("System error fetching user data: " + t.getMessage());
461 getAccount.setHeader("X-Auth-Token", token);
462 Scheduler.get().scheduleDeferred(getAccount);
465 private void createHomeContainers() {
466 String path = "/pithos";
467 PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
469 public void onSuccess(Resource result) {
474 public void onError(Throwable t) {
475 GWT.log("Error creating pithos", t);
476 if (t instanceof RestException)
477 displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
479 displayError("System error Error creating pithos: " + t.getMessage());
482 createPithos.setHeader("X-Auth-Token", getToken());
483 Scheduler.get().scheduleDeferred(createPithos);
487 * Clear the cookie and redirect the user to the logout page.
490 Configuration conf = (Configuration) GWT.create(Configuration.class);
491 String cookie = conf.authCookie();
492 String domain = Window.Location.getHostName();
493 String path = Window.Location.getPath();
494 Cookies.setCookie(cookie, "", null, domain, path, false);
495 String baseUrl = GWT.getModuleBaseURL();
496 String homeUrl = baseUrl.substring(0, baseUrl.indexOf(path));
497 Window.Location.assign(homeUrl + conf.logoutUrl());
501 * Creates an HTML fragment that places an image & caption together, for use
504 * @param imageProto an image prototype for an image
505 * @param caption the group caption
506 * @return the header HTML fragment
508 private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
509 String captionHTML = "<table class='caption' cellpadding='0' "
510 + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML()
511 + "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'> "
512 + caption + "</b></td></tr></table>";
516 private void onWindowResized(int height) {
517 // Adjust the split panel to take up the available room in the window.
518 int newHeight = height - splitPanel.getAbsoluteTop() - 44;
521 splitPanel.setHeight("" + newHeight);
522 inner.setHeight("" + newHeight);
526 public void onResize(ResizeEvent event) {
527 int height = event.getHeight();
528 onWindowResized(height);
531 public boolean isFileListShowing() {
532 int tab = inner.getTabBar().getSelectedTab();
538 public boolean isSearchResultsShowing() {
539 int tab = inner.getTabBar().getSelectedTab();
546 * A native JavaScript method to reach out to the browser's window and
547 * invoke its resizeTo() method.
549 * @param x the new width
550 * @param y the new height
552 public static native void resizeTo(int x, int y) /*-{
557 * Display an error message.
559 * @param msg the message to display
561 public void displayError(String msg) {
562 messagePanel.displayError(msg);
566 * Display a warning message.
568 * @param msg the message to display
570 public void displayWarning(String msg) {
571 messagePanel.displayWarning(msg);
575 * Display an informational message.
577 * @param msg the message to display
579 public void displayInformation(String msg) {
580 messagePanel.displayInformation(msg);
584 * Retrieve the folders.
586 * @return the folders
588 public Folders getFolders() {
593 * Retrieve the currentSelection.
595 * @return the currentSelection
597 public Object getCurrentSelection() {
598 return currentSelection;
602 * Modify the currentSelection.
604 * @param newCurrentSelection the currentSelection to set
606 public void setCurrentSelection(Object newCurrentSelection) {
607 currentSelection = newCurrentSelection;
611 * Retrieve the fileList.
613 * @return the fileList
615 public FileList getFileList() {
620 * Retrieve the topPanel.
622 * @return the topPanel
624 TopPanel getTopPanel() {
629 * Retrieve the clipboard.
631 * @return the clipboard
633 public Clipboard getClipboard() {
637 public StatusPanel getStatusPanel() {
641 public String getToken() {
645 public String getWebDAVPassword() {
646 return webDAVPassword;
649 public static native void preventIESelection() /*-{
650 $doc.body.onselectstart = function () { return false; };
653 public static native void enableIESelection() /*-{
654 if ($doc.body.onselectstart != null)
655 $doc.body.onselectstart = null;
659 * @return the absolute path of the API root URL
661 public String getApiPath() {
662 Configuration conf = (Configuration) GWT.create(Configuration.class);
663 return conf.apiPath();
667 * Convert server date to local time according to browser timezone
668 * and format it according to localized pattern.
669 * Time is always formatted to 24hr format.
670 * NB: This assumes that server runs in UTC timezone. Otherwise
671 * we would need to adjust for server time offset as well.
676 public static String formatLocalDateTime(Date date) {
677 Date convertedDate = new Date(date.getTime() - date.getTimezoneOffset());
678 final DateTimeFormat dateFormatter = DateTimeFormat.getShortDateFormat();
679 final DateTimeFormat timeFormatter = DateTimeFormat.getFormat("HH:mm");
680 String datePart = dateFormatter.format(convertedDate);
681 String timePart = timeFormatter.format(convertedDate);
682 return datePart + " " + timePart;
686 * History support for folder navigation
687 * adds a new browser history entry
691 public void updateHistory(String key){
692 // Replace any whitespace of the initial string to "+"
693 // String result = key.replaceAll("\\s","+");
694 // Add a new browser history entry.
695 // History.newItem(result);
696 History.newItem(key);
700 * This method examines the token input and add a "/" at the end in case it's omitted.
701 * This happens only in Files/trash/, Files/shared/, Files/others.
704 * @return the formated token with a "/" at the end or the same tokenInput parameter
707 private String handleSpecialFolderNames(String tokenInput){
708 List<String> pathsToCheck = Arrays.asList("Files/trash", "Files/shared", "Files/others");
709 if(pathsToCheck.contains(tokenInput))
710 return tokenInput + "/";
716 * Reject illegal resource names, like '.' or '..' or slashes '/'.
718 static boolean isValidResourceName(String name) {
719 if (".".equals(name) || "..".equals(name) || name.contains("/"))
724 public void putUserToMap(String _userName, String _userFullName){
725 userFullNameMap.put(_userName, _userFullName);
728 public String findUserFullName(String _userName){
729 return userFullNameMap.get(_userName);
732 public void deleteFolder(final Folder folder) {
733 String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + folder.getPrefix();
734 RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
735 builder.setHeader("If-Modified-Since", "0");
736 builder.setHeader("X-Auth-Token", getToken());
738 builder.sendRequest("", new RequestCallback() {
740 public void onResponseReceived(Request request, Response response) {
741 if (response.getStatusCode() == Response.SC_OK) {
742 JSONValue json = JSONParser.parseStrict(response.getText());
743 JSONArray array = json.isArray();
746 deleteObject(folder, i, array);
752 public void onError(Request request, Throwable exception) {
753 displayError("System error unable to delete folder: " + exception.getMessage());
757 catch (RequestException e) {
761 public void deleteObject(final Folder folder, final int i, final JSONArray array) {
762 if (i < array.size()) {
763 JSONObject o = array.get(i).isObject();
764 if (o != null && !o.containsKey("subdir")) {
765 JSONString name = o.get("name").isString();
766 String path = "/" + folder.getContainer() + "/" + name.stringValue();
767 DeleteRequest delete = new DeleteRequest(getApiPath(), getUsername(), path) {
769 public void onSuccess(Resource result) {
770 deleteObject(folder, i + 1, array);
774 public void onError(Throwable t) {
776 displayError("System error unable to delete folder: " + t.getMessage());
779 delete.setHeader("X-Auth-Token", getToken());
780 Scheduler.get().scheduleDeferred(delete);
783 String subdir = o.get("subdir").isString().stringValue();
784 subdir = subdir.substring(0, subdir.length() - 1);
785 String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + subdir;
786 RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
787 builder.setHeader("If-Modified-Since", "0");
788 builder.setHeader("X-Auth-Token", getToken());
790 builder.sendRequest("", new RequestCallback() {
792 public void onResponseReceived(Request request, Response response) {
793 if (response.getStatusCode() == Response.SC_OK) {
794 JSONValue json = JSONParser.parseStrict(response.getText());
795 JSONArray array2 = json.isArray();
796 if (array2 != null) {
797 int l = array.size();
798 for (int j=0; j<array2.size(); j++) {
799 array.set(l++, array2.get(j));
802 deleteObject(folder, i + 1, array);
807 public void onError(Request request, Throwable exception) {
808 displayError("System error unable to delete folder: " + exception.getMessage());
812 catch (RequestException e) {
817 String path = folder.getUri();
818 DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), path) {
820 public void onSuccess(Resource result) {
821 updateFolder(folder.getParent(), true);
825 public void onError(Throwable t) {
827 if (t instanceof RestException) {
828 displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
831 displayError("System error unable to delete folder: " + t.getMessage());
834 deleteFolder.setHeader("X-Auth-Token", getToken());
835 Scheduler.get().scheduleDeferred(deleteFolder);
839 public FolderTreeView getFolderTreeView() {
840 return folderTreeView;
843 public void copyFiles(final Iterator<File> iter, final String targetUri, final Command callback) {
844 if (iter.hasNext()) {
845 File file = iter.next();
846 String path = targetUri + "/" + file.getName();
847 PutRequest copyFile = new PutRequest(getApiPath(), getUsername(), path) {
849 public void onSuccess(Resource result) {
850 copyFiles(iter, targetUri, callback);
854 public void onError(Throwable t) {
856 if (t instanceof RestException) {
857 displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
860 displayError("System error unable to copy file: "+t.getMessage());
863 copyFile.setHeader("X-Auth-Token", getToken());
864 copyFile.setHeader("X-Copy-From", file.getUri());
865 Scheduler.get().scheduleDeferred(copyFile);
867 else if (callback != null) {
872 public void copySubfolders(final Iterator<Folder> iter, final String targetUri, final Command callback) {
873 if (iter.hasNext()) {
874 final Folder f = iter.next();
875 copyFolder(f, targetUri, callback);
877 else if (callback != null) {
882 public void copyFolder(final Folder f, final String targetUri, final Command callback) {
883 String path = targetUri + "/" + f.getName();
884 PutRequest createFolder = new PutRequest(getApiPath(), getUsername(), path) {
886 public void onSuccess(Resource result) {
887 Iterator<File> iter = f.getFiles().iterator();
888 copyFiles(iter, targetUri + "/" + f.getName(), new Command() {
890 public void execute() {
891 Iterator<Folder> iterf = f.getSubfolders().iterator();
892 copySubfolders(iterf, targetUri + "/" + f.getName(), new Command() {
894 public void execute() {
903 public void onError(Throwable t) {
905 if (t instanceof RestException) {
906 displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText());
909 displayError("System error creating folder:" + t.getMessage());
912 createFolder.setHeader("X-Auth-Token", getToken());
913 createFolder.setHeader("Accept", "*/*");
914 createFolder.setHeader("Content-Length", "0");
915 createFolder.setHeader("Content-Type", "application/folder");
916 Scheduler.get().scheduleDeferred(createFolder);