Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / Pithos.java @ dddb75e2

History | View | Annotate | Download (43.9 kB)

1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
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.
16
 *
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.
29
 *
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.
34
 */
35
package gr.grnet.pithos.web.client;
36

    
37
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
38
import gr.grnet.pithos.web.client.foldertree.AccountResource;
39
import gr.grnet.pithos.web.client.foldertree.File;
40
import gr.grnet.pithos.web.client.foldertree.Folder;
41
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
42
import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel;
43
import gr.grnet.pithos.web.client.foldertree.Resource;
44
import gr.grnet.pithos.web.client.grouptree.Group;
45
import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
46
import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel;
47
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
48
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel;
49
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView;
50
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel;
51
import gr.grnet.pithos.web.client.rest.DeleteRequest;
52
import gr.grnet.pithos.web.client.rest.GetRequest;
53
import gr.grnet.pithos.web.client.rest.HeadRequest;
54
import gr.grnet.pithos.web.client.rest.PutRequest;
55
import gr.grnet.pithos.web.client.rest.RestException;
56
import gr.grnet.pithos.web.client.tagtree.Tag;
57
import gr.grnet.pithos.web.client.tagtree.TagTreeView;
58
import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel;
59

    
60
import java.util.ArrayList;
61
import java.util.Date;
62
import java.util.HashMap;
63
import java.util.Iterator;
64
import java.util.List;
65
import java.util.Set;
66

    
67
import com.google.gwt.core.client.EntryPoint;
68
import com.google.gwt.core.client.GWT;
69
import com.google.gwt.core.client.Scheduler;
70
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
71
import com.google.gwt.event.dom.client.ClickEvent;
72
import com.google.gwt.event.dom.client.ClickHandler;
73
import com.google.gwt.event.logical.shared.ResizeEvent;
74
import com.google.gwt.event.logical.shared.ResizeHandler;
75
import com.google.gwt.http.client.Request;
76
import com.google.gwt.http.client.RequestBuilder;
77
import com.google.gwt.http.client.RequestCallback;
78
import com.google.gwt.http.client.RequestException;
79
import com.google.gwt.http.client.Response;
80
import com.google.gwt.http.client.URL;
81
import com.google.gwt.i18n.client.NumberFormat;
82
import com.google.gwt.json.client.JSONArray;
83
import com.google.gwt.json.client.JSONObject;
84
import com.google.gwt.json.client.JSONParser;
85
import com.google.gwt.json.client.JSONString;
86
import com.google.gwt.json.client.JSONValue;
87
import com.google.gwt.resources.client.ImageResource;
88
import com.google.gwt.resources.client.ImageResource.ImageOptions;
89
import com.google.gwt.user.client.Command;
90
import com.google.gwt.user.client.Cookies;
91
import com.google.gwt.user.client.Event;
92
import com.google.gwt.user.client.History;
93
import com.google.gwt.user.client.Window;
94
import com.google.gwt.user.client.ui.AbstractImagePrototype;
95
import com.google.gwt.user.client.ui.Button;
96
import com.google.gwt.user.client.ui.Composite;
97
import com.google.gwt.user.client.ui.HTML;
98
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
99
import com.google.gwt.user.client.ui.HasVerticalAlignment;
100
import com.google.gwt.user.client.ui.HorizontalPanel;
101
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
102
import com.google.gwt.user.client.ui.Image;
103
import com.google.gwt.user.client.ui.RootPanel;
104
import com.google.gwt.user.client.ui.VerticalPanel;
105
import com.google.gwt.view.client.SelectionChangeEvent;
106
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
107
import com.google.gwt.view.client.SingleSelectionModel;
108

    
109
/**
110
 * Entry point classes define <code>onModuleLoad()</code>.
111
 */
112
public class Pithos implements EntryPoint, ResizeHandler {
113

    
114
        public static final String HOME_CONTAINER = "pithos";
115

    
116
        public static final String TRASH_CONTAINER = "trash";
117
        
118
        /**
119
         * Instantiate an application-level image bundle. This object will provide
120
         * programmatic access to all the images needed by widgets.
121
         */
122
        static Images images = (Images) GWT.create(Images.class);
123

    
124
    public String getUsername() {
125
        return username;
126
    }
127

    
128
    public void setAccount(AccountResource acct) {
129
        account = acct;
130
    }
131

    
132
    public AccountResource getAccount() {
133
        return account;
134
    }
135

    
136
    public void updateFolder(Folder f, boolean showfiles, Command callback) {
137
        folderTreeView.updateFolder(f, showfiles, callback);
138
    }
139

    
140
    public void updateGroupNode(Group group) {
141
        groupTreeView.updateGroupNode(group);
142
    }
143

    
144
    public void updateMySharedRoot() {
145
            mysharedTreeView.updateRoot();
146
    }
147
    
148
    public void updateSharedFolder(Folder f, boolean showfiles) {
149
            mysharedTreeView.updateFolder(f, showfiles);
150
    }
151
    
152
    public void updateOtherSharedFolder(Folder f, boolean showfiles) {
153
            otherSharedTreeView.updateFolder(f, showfiles);
154
    }
155

    
156
    public List<Tag> getAllTags() {
157
        List<Tag> tagList = new ArrayList<Tag>();
158
        for (Folder f : account.getContainers()) {
159
            for (String t : f.getTags()) {
160
                tagList.add(new Tag(t));
161
            }
162
        }
163
        return tagList;
164
    }
165

    
166
    public MysharedTreeView getMySharedTreeView() {
167
        return mysharedTreeView;
168
    }
169

    
170
    /**
171
         * An aggregate image bundle that pulls together all the images for this
172
         * application into a single bundle.
173
         */
174
        public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images {
175

    
176
                @Source("gr/grnet/pithos/resources/document.png")
177
                ImageResource folders();
178

    
179
                @Source("gr/grnet/pithos/resources/advancedsettings.png")
180
                @ImageOptions(width=32, height=32)
181
                ImageResource tools();
182
        }
183

    
184
        private Throwable error;
185
        
186
        /**
187
         * The Application Clipboard implementation;
188
         */
189
        private Clipboard clipboard = new Clipboard();
190

    
191
        /**
192
         * The top panel that contains the menu bar.
193
         */
194
        private TopPanel topPanel;
195

    
196
        /**
197
         * The panel that contains the various system messages.
198
         */
199
        private MessagePanel messagePanel = new MessagePanel(this, Pithos.images);
200

    
201
        /**
202
         * The bottom panel that contains the status bar.
203
         */
204
        private StatusPanel statusPanel = null;
205

    
206
        /**
207
         * The file list widget.
208
         */
209
        private FileList fileList;
210

    
211
        /**
212
         * The tab panel that occupies the right side of the screen.
213
         */
214
        private VerticalPanel inner = new VerticalPanel();
215

    
216

    
217
        /**
218
         * The split panel that will contain the left and right panels.
219
         */
220
        private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
221

    
222
        /**
223
         * The currently selected item in the application, for use by the Edit menu
224
         * commands. Potential types are Folder, File, User and Group.
225
         */
226
        private Object currentSelection;
227

    
228
        public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
229

    
230
    private String username = null;
231

    
232
    /**
233
     * The authentication token of the current user.
234
     */
235
    private String token;
236

    
237
    VerticalPanel trees;
238
    
239
    SingleSelectionModel<Folder> folderTreeSelectionModel;
240
    FolderTreeViewModel folderTreeViewModel;
241
    FolderTreeView folderTreeView;
242

    
243
    SingleSelectionModel<Folder> mysharedTreeSelectionModel;
244
    MysharedTreeViewModel mysharedTreeViewModel;
245
    MysharedTreeView mysharedTreeView = null;;
246

    
247
    protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel;
248
    OtherSharedTreeViewModel otherSharedTreeViewModel;
249
    OtherSharedTreeView otherSharedTreeView = null;
250

    
251
    GroupTreeViewModel groupTreeViewModel;
252
    private GroupTreeView groupTreeView;
253

    
254
    TreeView selectedTree;
255
    protected AccountResource account;
256
    
257
    Folder trash;
258
    
259
    List<Composite> treeViews = new ArrayList<Composite>();
260

    
261
    @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
262
    
263
    Button upload;
264
    
265
    private HTML usedBytes;
266
    
267
    private HTML totalBytes;
268
    
269
    private HTML usedPercent;
270
    
271
    private HTML numOfFiles;
272
    
273
    private Image refreshButton;
274

    
275
    private Image toolsButton;
276

    
277
        @Override
278
        public void onModuleLoad() {
279
                if (parseUserCredentials())
280
            initialize();
281
        }
282

    
283
    private void initialize() {
284
            boolean bareContent = Window.Location.getParameter("noframe") != null;
285
            String contentWidth = bareContent ? "100%" : "75%";
286

    
287
            VerticalPanel outer = new VerticalPanel();
288
        outer.setWidth("100%");
289
            if (!bareContent) {
290
                    outer.addStyleName("pithos-outer");
291
            }
292

    
293
        if (!bareContent) {
294
                topPanel = new TopPanel(this, Pithos.images);
295
                topPanel.setWidth("100%");
296
                outer.add(topPanel);
297
                outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER);
298
        }
299
        
300
        HorizontalPanel header = new HorizontalPanel();
301
        header.addStyleName("pithos-header");
302
        header.setWidth(contentWidth);
303
        if (bareContent)
304
                header.addStyleName("pithos-header-noframe");
305
        upload = new Button("Upload File", new ClickHandler() {
306
            @Override
307
            public void onClick(@SuppressWarnings("unused") ClickEvent event) {
308
                new UploadFileCommand(Pithos.this, null, getSelection()).execute();
309
            }
310
        });
311
        upload.addStyleName("pithos-uploadButton");
312
        header.add(upload);
313
        header.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT);
314
        header.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE);
315
//        header.setCellWidth(upload, "146px");
316

    
317
        messagePanel.setVisible(false);
318
        header.add(messagePanel);
319
        header.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
320
        header.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE);
321
        
322
        refreshButton = new Image(images.refresh());
323
        refreshButton.addStyleName("pithos-toolsButton");
324
        refreshButton.setWidth("32px");
325
        refreshButton.setHeight("32px");
326
        refreshButton.addClickHandler(new ClickHandler() {
327
                        
328
                        @Override
329
                        public void onClick(@SuppressWarnings("unused") ClickEvent event) {
330
                            boolean isFolderTreeSelected = selectedTree.equals(getFolderTreeView());
331
                            boolean otherSharedTreeSelected = selectedTree.equals(getOtherSharedTreeView());
332
                            Folder folder = getSelectedTree().getSelection();
333
                            
334
                            if (folder != null && (isFolderTreeSelected || otherSharedTreeSelected))
335
                                    updateFolder(folder, true, new Command() {
336
                                            
337
                                            @Override
338
                                            public void execute() {
339
                                                    updateStatistics();
340
                                            }
341
                                    });
342
                        }
343
                });
344
        header.add(refreshButton);
345
        header.setCellHorizontalAlignment(refreshButton, HasHorizontalAlignment.ALIGN_CENTER);
346
        header.setCellVerticalAlignment(refreshButton, HasVerticalAlignment.ALIGN_MIDDLE);
347
        header.setCellWidth(refreshButton, "40px");
348

    
349
        toolsButton = new Image(images.tools());
350
        toolsButton.addStyleName("pithos-toolsButton");
351
        toolsButton.addClickHandler(new ClickHandler() {
352
                        
353
                        @Override
354
                        public void onClick(ClickEvent event) {
355
                ToolsMenu menu = new ToolsMenu(Pithos.this, images, getSelectedTree(), getSelectedTree().getSelection(), getFileList().getSelectedFiles());
356
                if (!menu.isEmpty()) {
357
                            menu.setPopupPosition(event.getClientX(), event.getClientY());
358
                            menu.show();
359
                }
360
                        }
361
                });
362
        header.add(toolsButton);
363
        header.setCellHorizontalAlignment(toolsButton, HasHorizontalAlignment.ALIGN_CENTER);
364
        header.setCellVerticalAlignment(toolsButton, HasVerticalAlignment.ALIGN_MIDDLE);
365
        header.setCellWidth(toolsButton, "40px");
366
       
367
        HorizontalPanel folderStatistics = new HorizontalPanel();
368
        folderStatistics.addStyleName("pithos-folderStatistics");
369
        numOfFiles = new HTML();
370
        folderStatistics.add(numOfFiles);
371
        folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE);
372
        HTML numOfFilesLabel = new HTML("&nbsp;Files");
373
        folderStatistics.add(numOfFilesLabel);
374
        folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE);
375
        header.add(folderStatistics);
376
        header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT);
377
        header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE);
378
        header.setCellWidth(folderStatistics, "40px");
379
        outer.add(header);
380
        outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER);
381
        // Inner contains the various lists.nner
382
        inner.sinkEvents(Event.ONCONTEXTMENU);
383
        inner.setWidth("100%");
384

    
385
        folderTreeSelectionModel = new SingleSelectionModel<Folder>();
386
        folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
387
            @Override
388
            public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
389
                if (folderTreeSelectionModel.getSelectedObject() != null) {
390
                    deselectOthers(folderTreeView, folderTreeSelectionModel);
391
                    applyPermissions(folderTreeSelectionModel.getSelectedObject());
392
                    Folder f = folderTreeSelectionModel.getSelectedObject();
393
                            updateFolder(f, true, new Command() {
394
                                    
395
                                    @Override
396
                                    public void execute() {
397
                                            updateStatistics();
398
                                    }
399
                            });
400
                }
401
            }
402
        });
403
        selectionModels.add(folderTreeSelectionModel);
404

    
405
        folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel);
406
        folderTreeView = new FolderTreeView(folderTreeViewModel);
407
        treeViews.add(folderTreeView);
408
        
409
        fileList = new FileList(this, images, folderTreeView);
410
        inner.add(fileList);
411

    
412
        groupTreeViewModel = new GroupTreeViewModel(this);
413
        groupTreeView = new GroupTreeView(groupTreeViewModel);
414
        treeViews.add(groupTreeView);
415
        
416
        trees = new VerticalPanel();
417
        trees.setWidth("100%");
418

    
419
        
420
        HorizontalPanel treeHeader = new HorizontalPanel();
421
        treeHeader.addStyleName("pithos-treeHeader");
422
        treeHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
423
        treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
424
        HorizontalPanel statistics = new HorizontalPanel();
425
        statistics.addStyleName("pithos-statistics");
426
        statistics.add(new HTML("Used:&nbsp;"));
427
        usedBytes = new HTML();
428
        statistics.add(usedBytes);
429
        statistics.add(new HTML("&nbsp;of&nbsp;"));
430
        totalBytes = new HTML();
431
        statistics.add(totalBytes);
432
        statistics.add(new HTML("&nbsp;("));
433
        usedPercent = new HTML();
434
        statistics.add(usedPercent);
435
        statistics.add(new HTML(")"));
436
        treeHeader.add(statistics);
437
        treeHeader.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_LEFT);
438
        trees.add(treeHeader);
439

    
440
        trees.add(folderTreeView);
441
        trees.add(groupTreeView);
442
        // Add the left and right panels to the split panel.
443
        splitPanel.setLeftWidget(trees);
444
        splitPanel.setRightWidget(inner);
445
        splitPanel.setSplitPosition("35%");
446
        splitPanel.setSize("100%", "100%");
447
        splitPanel.addStyleName("pithos-splitPanel");
448
        splitPanel.setWidth(contentWidth);
449
        outer.add(splitPanel);
450
        outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER);
451

    
452
        if (!bareContent) {
453
                statusPanel = new StatusPanel();
454
                statusPanel.setWidth("100%");
455
                outer.add(statusPanel);
456
                outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER);
457
        }
458
        else
459
                splitPanel.addStyleName("pithos-splitPanel-noframe");
460

    
461
        // Hook the window resize event, so that we can adjust the UI.
462
        Window.addResizeHandler(this);
463
        // Clear out the window's built-in margin, because we want to take
464
        // advantage of the entire client area.
465
        Window.setMargin("0px");
466
        // Finally, add the outer panel to the RootPanel, so that it will be
467
        // displayed.
468
        RootPanel.get().add(outer);
469
        // Call the window resized handler to get the initial sizes setup. Doing
470
        // this in a deferred command causes it to occur after all widgets'
471
        // sizes have been computed by the browser.
472
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
473

    
474
            @Override
475
            public void execute() {
476
                onWindowResized(Window.getClientHeight());
477
            }
478
        });
479

    
480
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
481
            @Override
482
            public void execute() {
483
                fetchAccount(new Command() {
484
                                        
485
                                        @Override
486
                                        public void execute() {
487
                                if (!account.hasHomeContainer())
488
                                    createHomeContainer(account, this);
489
                                else if (!account.hasTrashContainer())
490
                                        createTrashContainer(this);
491
                                else {
492
                                        for (Folder f : account.getContainers())
493
                                                if (f.getName().equals(Pithos.TRASH_CONTAINER)) {
494
                                                        trash = f;
495
                                                        break;
496
                                                }
497
                                    folderTreeViewModel.initialize(account, new Command() {
498
                                                                
499
                                                                @Override
500
                                                                public void execute() {
501
                                                    createMySharedTree();
502
                                                                }
503
                                                        });
504
                                    groupTreeViewModel.initialize();
505
                                    showStatistics();
506
                                }
507
                                        }
508
                                });
509
            }
510
        });
511
        
512
//        Scheduler.get().scheduleDeferred(new Command() {
513
//                        
514
//                        @Override
515
//                        public void execute() {
516
//                                displayError("lalala");
517
//                                
518
//                        }
519
//                });
520
    }
521

    
522
    public void applyPermissions(Folder f) {
523
            if (f != null) {
524
                    if (f.isInTrash())
525
                            upload.setEnabled(false);
526
                    else {
527
                            Boolean[] perms = f.getPermissions().get(username);
528
                            if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
529
                                    upload.setEnabled(true);
530
                            }
531
                            else
532
                                    upload.setEnabled(false);
533
                    }
534
            }
535
            else
536
                    upload.setEnabled(false);
537
        }
538

    
539
        @SuppressWarnings({ "rawtypes", "unchecked" })
540
        public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
541
            selectedTree = _selectedTree;
542
            
543
            for (Composite c : treeViews)
544
                    if (c.equals(selectedTree))
545
                            c.addStyleName("cellTreeWidget-selectedTree");
546
                    else
547
                            c.removeStyleName("cellTreeWidget-selectedTree");
548
            
549
        for (SingleSelectionModel s : selectionModels)
550
            if (!s.equals(model))
551
                s.setSelected(s.getSelectedObject(), false);
552
    }
553

    
554
    public void showFiles(final Folder f) {
555
        Set<File> files = f.getFiles();
556
        showFiles(files);
557
    }
558

    
559
    public void showFiles(Set<File> files) {
560
        fileList.setFiles(new ArrayList<File>(files));
561
    }
562

    
563
    protected void fetchFile(final Iterator<File> iter, final Set<File> files) {
564
        if (iter.hasNext()) {
565
            File file = iter.next();
566
            String path = file.getUri() + "?format=json";
567
            GetRequest<File> getFile = new GetRequest<File>(File.class, getApiPath(), username, path, file) {
568
                @Override
569
                public void onSuccess(@SuppressWarnings("unused") File _result) {
570
                    fetchFile(iter, files);
571
                }
572

    
573
                @Override
574
                public void onError(Throwable t) {
575
                    GWT.log("Error getting file", t);
576
                                        setError(t);
577
                    if (t instanceof RestException)
578
                        displayError("Error getting file: " + ((RestException) t).getHttpStatusText());
579
                    else
580
                        displayError("System error fetching file: " + t.getMessage());
581
                }
582

    
583
                                @Override
584
                                protected void onUnauthorized(Response response) {
585
                                        sessionExpired();
586
                                }
587
            };
588
            getFile.setHeader("X-Auth-Token", "0000");
589
            Scheduler.get().scheduleDeferred(getFile);
590
        }
591
        else
592
            fileList.setFiles(new ArrayList<File>(files));
593
    }
594

    
595
    /**
596
         * Parse and store the user credentials to the appropriate fields.
597
         */
598
        private boolean parseUserCredentials() {
599
        username = Window.Location.getParameter("user");
600
        token = Window.Location.getParameter("token");
601
        Configuration conf = (Configuration) GWT.create(Configuration.class);
602
        if (username == null || username.length() == 0 || token == null || token.length() == 0) {
603
            String cookie = conf.authCookie();
604
            String auth = Cookies.getCookie(cookie);
605
            if (auth == null) {
606
                authenticateUser();
607
                return false;
608
            }
609
            if (auth.startsWith("\""))
610
                    auth = auth.substring(1);
611
            if (auth.endsWith("\""))
612
                    auth = auth.substring(0, auth.length() - 1);
613
                        String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
614
                        if (authSplit.length != 2) {
615
                            authenticateUser();
616
                            return false;
617
                        }
618
                        username = authSplit[0];
619
                        token = authSplit[1];
620
                        return true;
621
        }
622
        
623
                Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token, null, "", "/", false);
624
                return true;
625
    }
626

    
627
    /**
628
         * Redirect the user to the login page for authentication.
629
         */
630
        protected void authenticateUser() {
631
                Configuration conf = (Configuration) GWT.create(Configuration.class);
632
        Window.Location.assign(conf.loginUrl() + "?next=" + Window.Location.getHref());
633
        }
634

    
635
        protected void fetchAccount(final Command callback) {
636
        String path = "?format=json";
637

    
638
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
639
            @Override
640
            public void onSuccess(AccountResource _result) {
641
                account = _result;
642
                if (callback != null)
643
                        callback.execute();
644
            }
645

    
646
            @Override
647
            public void onError(Throwable t) {
648
                GWT.log("Error getting account", t);
649
                                setError(t);
650
                if (t instanceof RestException)
651
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
652
                else
653
                    displayError("System error fetching user data: " + t.getMessage());
654
            }
655

    
656
                        @Override
657
                        protected void onUnauthorized(Response response) {
658
                                sessionExpired();
659
                        }
660
        };
661
        getAccount.setHeader("X-Auth-Token", token);
662
        Scheduler.get().scheduleDeferred(getAccount);
663
    }
664

    
665
    public void updateStatistics() {
666
            HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) {
667

    
668
                        @Override
669
                        public void onSuccess(@SuppressWarnings("unused") AccountResource _result) {
670
                                showStatistics();
671
                        }
672

    
673
                        @Override
674
                        public void onError(Throwable t) {
675
                GWT.log("Error getting account", t);
676
                                setError(t);
677
                if (t instanceof RestException)
678
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
679
                else
680
                    displayError("System error fetching user data: " + t.getMessage());
681
                        }
682

    
683
                        @Override
684
                        protected void onUnauthorized(Response response) {
685
                                sessionExpired();
686
                        }
687
                };
688
                headAccount.setHeader("X-Auth-Token", token);
689
                Scheduler.get().scheduleDeferred(headAccount);
690
        }
691

    
692
        protected void showStatistics() {
693
            usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
694
            totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
695
            NumberFormat nf = NumberFormat.getPercentFormat();
696
            usedPercent.setHTML(nf.format(account.getUsedPercentage()));
697
        }
698

    
699
        protected void createHomeContainer(final AccountResource _account, final Command callback) {
700
        String path = "/" + Pithos.HOME_CONTAINER;
701
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
702
            @Override
703
            public void onSuccess(@SuppressWarnings("unused") Resource result) {
704
                    if (!_account.hasTrashContainer())
705
                            createTrashContainer(callback);
706
                    else
707
                            fetchAccount(callback);
708
            }
709

    
710
            @Override
711
            public void onError(Throwable t) {
712
                GWT.log("Error creating pithos", t);
713
                                setError(t);
714
                if (t instanceof RestException)
715
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
716
                else
717
                    displayError("System error Error creating pithos: " + t.getMessage());
718
            }
719

    
720
                        @Override
721
                        protected void onUnauthorized(Response response) {
722
                                sessionExpired();
723
                        }
724
        };
725
        createPithos.setHeader("X-Auth-Token", getToken());
726
        Scheduler.get().scheduleDeferred(createPithos);
727
    }
728

    
729
    protected void createTrashContainer(final Command callback) {
730
        String path = "/" + Pithos.TRASH_CONTAINER;
731
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
732
            @Override
733
            public void onSuccess(@SuppressWarnings("unused") Resource result) {
734
                           fetchAccount(callback);
735
            }
736

    
737
            @Override
738
            public void onError(Throwable t) {
739
                GWT.log("Error creating pithos", t);
740
                                setError(t);
741
                if (t instanceof RestException)
742
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
743
                else
744
                    displayError("System error Error creating pithos: " + t.getMessage());
745
            }
746

    
747
                        @Override
748
                        protected void onUnauthorized(Response response) {
749
                                sessionExpired();
750
                        }
751
        };
752
        createPithos.setHeader("X-Auth-Token", getToken());
753
        Scheduler.get().scheduleDeferred(createPithos);
754
    }
755

    
756
    /**
757
         * Creates an HTML fragment that places an image & caption together, for use
758
         * in a group header.
759
         *
760
         * @param imageProto an image prototype for an image
761
         * @param caption the group caption
762
         * @return the header HTML fragment
763
         */
764
        private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
765
                String captionHTML = "<table class='caption' cellpadding='0' " 
766
                + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() 
767
                + "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'>&nbsp;" 
768
                + caption + "</b></td></tr></table>";
769
                return captionHTML;
770
        }
771

    
772
        protected void onWindowResized(int height) {
773
                // Adjust the split panel to take up the available room in the window.
774
                int newHeight = height - splitPanel.getAbsoluteTop();
775
                if (newHeight < 1)
776
                        newHeight = 1;
777
                splitPanel.setHeight("" + newHeight);
778
                inner.setHeight("" + newHeight);
779
        }
780

    
781
        @Override
782
        public void onResize(ResizeEvent event) {
783
                int height = event.getHeight();
784
                onWindowResized(height);
785
        }
786

    
787
        /**
788
         * Display an error message.
789
         *
790
         * @param msg the message to display
791
         */
792
        public void displayError(String msg) {
793
                messagePanel.displayError(msg);
794
        }
795

    
796
        /**
797
         * Display a warning message.
798
         *
799
         * @param msg the message to display
800
         */
801
        public void displayWarning(String msg) {
802
                messagePanel.displayWarning(msg);
803
        }
804

    
805
        /**
806
         * Display an informational message.
807
         *
808
         * @param msg the message to display
809
         */
810
        public void displayInformation(String msg) {
811
                messagePanel.displayInformation(msg);
812
        }
813

    
814
        /**
815
         * Retrieve the fileList.
816
         *
817
         * @return the fileList
818
         */
819
        public FileList getFileList() {
820
                return fileList;
821
        }
822

    
823
        /**
824
         * Retrieve the topPanel.
825
         *
826
         * @return the topPanel
827
         */
828
        TopPanel getTopPanel() {
829
                return topPanel;
830
        }
831

    
832
        /**
833
         * Retrieve the clipboard.
834
         *
835
         * @return the clipboard
836
         */
837
        public Clipboard getClipboard() {
838
                return clipboard;
839
        }
840

    
841
        public StatusPanel getStatusPanel() {
842
                return statusPanel;
843
        }
844

    
845
        public String getToken() {
846
                return token;
847
        }
848

    
849
        public static native void preventIESelection() /*-{
850
                $doc.body.onselectstart = function () { return false; };
851
        }-*/;
852

    
853
        public static native void enableIESelection() /*-{
854
                if ($doc.body.onselectstart != null)
855
                $doc.body.onselectstart = null;
856
        }-*/;
857

    
858
        /**
859
         * @return the absolute path of the API root URL
860
         */
861
        public String getApiPath() {
862
                Configuration conf = (Configuration) GWT.create(Configuration.class);
863
                return conf.apiPath();
864
        }
865

    
866
        /**
867
         * History support for folder navigation
868
         * adds a new browser history entry
869
         *
870
         * @param key
871
         */
872
        public void updateHistory(String key){
873
//                Replace any whitespace of the initial string to "+"
874
//                String result = key.replaceAll("\\s","+");
875
//                Add a new browser history entry.
876
//                History.newItem(result);
877
                History.newItem(key);
878
        }
879

    
880
    public void deleteFolder(final Folder folder) {
881
        String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(folder.getPrefix()) + "&t=" + System.currentTimeMillis();
882
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
883
        builder.setHeader("X-Auth-Token", getToken());
884
        try {
885
            builder.sendRequest("", new RequestCallback() {
886
                @Override
887
                public void onResponseReceived(@SuppressWarnings("unused") Request request, Response response) {
888
                    if (response.getStatusCode() == Response.SC_OK) {
889
                        JSONValue json = JSONParser.parseStrict(response.getText());
890
                        JSONArray array = json.isArray();
891
                        int i = 0;
892
                        if (array != null) {
893
                            deleteObject(folder, i, array);
894
                        }
895
                    }
896
                }
897

    
898
                @Override
899
                public void onError(@SuppressWarnings("unused") Request request, Throwable exception) {
900
                        setError(exception);
901
                    displayError("System error unable to delete folder: " + exception.getMessage());
902
                }
903
            });
904
        }
905
        catch (RequestException e) {
906
        }
907
    }
908

    
909
    void deleteObject(final Folder folder, final int i, final JSONArray array) {
910
        if (i < array.size()) {
911
            JSONObject o = array.get(i).isObject();
912
            if (o != null && !o.containsKey("subdir")) {
913
                JSONString name = o.get("name").isString();
914
                String path = "/" + folder.getContainer() + "/" + name.stringValue();
915
                DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), path) {
916
                    @Override
917
                    public void onSuccess(@SuppressWarnings("unused") Resource result) {
918
                        deleteObject(folder, i + 1, array);
919
                    }
920

    
921
                    @Override
922
                    public void onError(Throwable t) {
923
                        GWT.log("", t);
924
                                                setError(t);
925
                        displayError("System error unable to delete folder: " + t.getMessage());
926
                    }
927

    
928
                                    @Override
929
                                    protected void onUnauthorized(Response response) {
930
                                            sessionExpired();
931
                                    }
932
                };
933
                delete.setHeader("X-Auth-Token", getToken());
934
                Scheduler.get().scheduleDeferred(delete);
935
            }
936
            else if (o != null) {
937
                String subdir = o.get("subdir").isString().stringValue();
938
                subdir = subdir.substring(0, subdir.length() - 1);
939
                String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis();
940
                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
941
                builder.setHeader("X-Auth-Token", getToken());
942
                try {
943
                    builder.sendRequest("", new RequestCallback() {
944
                        @Override
945
                        public void onResponseReceived(@SuppressWarnings("unused") Request request, Response response) {
946
                            if (response.getStatusCode() == Response.SC_OK) {
947
                                JSONValue json = JSONParser.parseStrict(response.getText());
948
                                JSONArray array2 = json.isArray();
949
                                if (array2 != null) {
950
                                    int l = array.size();
951
                                    for (int j=0; j<array2.size(); j++) {
952
                                        array.set(l++, array2.get(j));
953
                                    }
954
                                }
955
                                deleteObject(folder, i + 1, array);
956
                            }
957
                        }
958

    
959
                        @Override
960
                        public void onError(@SuppressWarnings("unused") Request request, Throwable exception) {
961
                                setError(exception);
962
                            displayError("System error unable to delete folder: " + exception.getMessage());
963
                        }
964
                    });
965
                }
966
                catch (RequestException e) {
967
                }
968
            }
969
        }
970
        else {
971
            String path = folder.getUri();
972
            DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), path) {
973
                @Override
974
                public void onSuccess(@SuppressWarnings("unused") Resource result) {
975
                    updateFolder(folder.getParent(), true, new Command() {
976
                                                
977
                                                @Override
978
                                                public void execute() {
979
                                                        updateStatistics();
980
                                                }
981
                                        });
982
                }
983

    
984
                @Override
985
                public void onError(Throwable t) {
986
                    GWT.log("", t);
987
                                        setError(t);
988
                    if (t instanceof RestException) {
989
                            if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
990
                                    displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
991
                            else
992
                                    onSuccess(null);
993
                    }
994
                    else
995
                        displayError("System error unable to delete folder: " + t.getMessage());
996
                }
997

    
998
                                @Override
999
                                protected void onUnauthorized(Response response) {
1000
                                        sessionExpired();
1001
                                }
1002
            };
1003
            deleteFolder.setHeader("X-Auth-Token", getToken());
1004
            Scheduler.get().scheduleDeferred(deleteFolder);
1005
        }
1006
    }
1007

    
1008
    public FolderTreeView getFolderTreeView() {
1009
        return folderTreeView;
1010
    }
1011

    
1012
    public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) {
1013
        if (iter.hasNext()) {
1014
            File file = iter.next();
1015
            String path = targetUri + "/" + file.getName();
1016
            PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
1017
                @Override
1018
                public void onSuccess(@SuppressWarnings("unused") Resource result) {
1019
                    copyFiles(iter, targetUsername, targetUri, callback);
1020
                }
1021

    
1022
                @Override
1023
                public void onError(Throwable t) {
1024
                    GWT.log("", t);
1025
                                        setError(t);
1026
                    if (t instanceof RestException) {
1027
                        displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
1028
                    }
1029
                    else
1030
                        displayError("System error unable to copy file: "+t.getMessage());
1031
                }
1032

    
1033
                                @Override
1034
                                protected void onUnauthorized(Response response) {
1035
                                        sessionExpired();
1036
                                }
1037
            };
1038
            copyFile.setHeader("X-Auth-Token", getToken());
1039
            copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri()));
1040
            if (!file.getOwner().equals(targetUsername))
1041
                    copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner()));
1042
            copyFile.setHeader("Content-Type", file.getContentType());
1043
            Scheduler.get().scheduleDeferred(copyFile);
1044
        }
1045
        else  if (callback != null) {
1046
            callback.execute();
1047
        }
1048
    }
1049

    
1050
    public void copySubfolders(final Iterator<Folder> iter, final String targetUsername, final String targetUri, final Command callback) {
1051
        if (iter.hasNext()) {
1052
            final Folder f = iter.next();
1053
            copyFolder(f, targetUsername, targetUri, new Command() {
1054
                                
1055
                                @Override
1056
                                public void execute() {
1057
                                        copySubfolders(iter, targetUsername, targetUri, callback);
1058
                                }
1059
                        });
1060
        }
1061
        else  if (callback != null) {
1062
            callback.execute();
1063
        }
1064
    }
1065

    
1066
    public void copyFolder(final Folder f, final String targetUsername, final String targetUri, final Command callback) {
1067
        String path = targetUri + "/" + f.getName();
1068
        PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
1069
            @Override
1070
            public void onSuccess(@SuppressWarnings("unused") Resource result) {
1071
                    GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) {
1072

    
1073
                                        @Override
1074
                                        public void onSuccess(final Folder _f) {
1075
                                Iterator<File> iter = _f.getFiles().iterator();
1076
                                copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() {
1077
                                    @Override
1078
                                    public void execute() {
1079
                                        Iterator<Folder> iterf = _f.getSubfolders().iterator();
1080
                                        copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
1081
                                    }
1082
                                });
1083
                                        }
1084

    
1085
                                        @Override
1086
                                        public void onError(Throwable t) {
1087
                                GWT.log("", t);
1088
                                                setError(t);
1089
                                if (t instanceof RestException) {
1090
                                    displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
1091
                                }
1092
                                else
1093
                                    displayError("System error getting folder: " + t.getMessage());
1094
                                        }
1095

    
1096
                                        @Override
1097
                                        protected void onUnauthorized(Response response) {
1098
                                                sessionExpired();
1099
                                        }
1100
                                };
1101
                                getFolder.setHeader("X-Auth-Token", getToken());
1102
                                Scheduler.get().scheduleDeferred(getFolder);
1103
            }
1104

    
1105
            @Override
1106
            public void onError(Throwable t) {
1107
                GWT.log("", t);
1108
                                setError(t);
1109
               if (t instanceof RestException) {
1110
                    displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText());
1111
                }
1112
                else
1113
                    displayError("System error creating folder: " + t.getMessage());
1114
            }
1115

    
1116
                        @Override
1117
                        protected void onUnauthorized(Response response) {
1118
                                sessionExpired();
1119
                        }
1120
        };
1121
        createFolder.setHeader("X-Auth-Token", getToken());
1122
        createFolder.setHeader("Accept", "*/*");
1123
        createFolder.setHeader("Content-Length", "0");
1124
        createFolder.setHeader("Content-Type", "application/folder");
1125
        Scheduler.get().scheduleDeferred(createFolder);
1126
    }
1127
    
1128
    public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) {
1129
            selectionModels.add(model);
1130
    }
1131

    
1132
        public OtherSharedTreeView getOtherSharedTreeView() {
1133
                return otherSharedTreeView;
1134
        }
1135

    
1136
        public void updateTrash(boolean showFiles, Command callback) {
1137
                updateFolder(trash, showFiles, callback);
1138
        }
1139

    
1140
        public void updateGroupsNode() {
1141
                groupTreeView.updateGroupNode(null);
1142
        }
1143

    
1144
        public void addGroup(String groupname) {
1145
                Group newGroup = new Group(groupname);
1146
                account.addGroup(newGroup);
1147
                groupTreeView.updateGroupNode(null);
1148
        }
1149

    
1150
        public void removeGroup(Group group) {
1151
                account.removeGroup(group);
1152
                updateGroupsNode();
1153
        }
1154

    
1155
        public TreeView getSelectedTree() {
1156
                return selectedTree;
1157
        }
1158
        
1159
        public Folder getSelection() {
1160
                return selectedTree.getSelection();
1161
        }
1162

    
1163
        public void showFolderStatistics(int folderFileCount) {
1164
                numOfFiles.setHTML(String.valueOf(folderFileCount));
1165
        }
1166

    
1167
        public GroupTreeView getGroupTreeView() {
1168
                return groupTreeView;
1169
        }
1170

    
1171
        public void sessionExpired() {
1172
                new SessionExpiredDialog(this).center();
1173
        }
1174

    
1175
        public void updateRootFolder(Command callback) {
1176
                updateFolder(account.getPithos(), false, callback);
1177
        }
1178

    
1179
        void createMySharedTree() {
1180
                mysharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1181
                mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1182
                    @Override
1183
                    public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
1184
                        if (mysharedTreeSelectionModel.getSelectedObject() != null) {
1185
                            deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
1186
                            upload.setEnabled(false);
1187
                            updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
1188
                        }
1189
                     }
1190
                });
1191
                selectionModels.add(mysharedTreeSelectionModel);
1192
                mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
1193
                mysharedTreeViewModel.initialize(new Command() {
1194
                        
1195
                        @Override
1196
                        public void execute() {
1197
                            mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
1198
                                trees.insert(mysharedTreeView, 2);
1199
                                treeViews.add(mysharedTreeView);
1200
                                createOtherSharedTree();
1201
                        }
1202
                });
1203
        }
1204

    
1205
        void createOtherSharedTree() {
1206
                otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1207
                otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1208
                    @Override
1209
                    public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
1210
                        if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
1211
                            deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
1212
                            otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree");
1213
                            applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
1214
                            updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
1215
                        }
1216
                     }
1217
                });
1218
                selectionModels.add(otherSharedTreeSelectionModel);
1219
                otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
1220
                otherSharedTreeViewModel.initialize(new Command() {
1221
                        
1222
                        @Override
1223
                        public void execute() {
1224
                            otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
1225
                                trees.insert(otherSharedTreeView, 3);
1226
                                treeViews.add(otherSharedTreeView);
1227
                        }
1228
                });
1229
        }
1230

    
1231
        public void logoff() {
1232
        Configuration conf = (Configuration) GWT.create(Configuration.class);
1233
                Cookies.removeCookie(conf.authCookie(), "/");
1234
                Cookies.removeCookie(conf.authTokenCookie(), "/");
1235
                for (String s: Cookies.getCookieNames())
1236
                        if (s.startsWith(conf.shibSessionCookiePrefix()))
1237
                                Cookies.removeCookie(s, "/");
1238
                Window.Location.assign(Window.Location.getPath());
1239
        }
1240

    
1241
        public String getErrorData() {
1242
                if (error != null)
1243
                        return error.toString();
1244
                return "";
1245
        }
1246
        
1247
        public void setError(Throwable t) {
1248
                error = t;
1249
        }
1250
}