1111*/
1212package org .zkoss .zss .app .ui ;
1313
14- //import com.sun.org.glassfish.external.statistics.RangeStatistic;
1514import org .zkoss .image .AImage ;
1615import org .zkoss .lang .Library ;
1716import org .zkoss .lang .Strings ;
7170import java .util .Date ;
7271
7372/**
73+ *
7474 * @author dennis
75+ *
7576 */
76-
7777public class AppCtrl extends CtrlBase <Component > {
78+ public static final String ZSS_USERNAME = "zssUsername" ;
7879 private static final Log log = Log .lookup (AppCtrl .class );
7980 private static final long serialVersionUID = 1L ;
80- public static final String ZSS_USERNAME = "zssUsername" ;
8181 private static final String UNSAVED_MESSAGE = "Do you want to leave this book without save??" ;
8282 private static final String UTF8 = "UTF-8" ;
8383 private static final boolean DISABLE_BOOKMARK = Boolean .valueOf (Library .getProperty ("zssapp.bookmark.disable" , "false" ));
@@ -86,7 +86,6 @@ public class AppCtrl extends CtrlBase<Component> {
8686 private static BookRepository repo = BookRepositoryFactory .getInstance ().getRepository ();
8787 private static CollaborationInfo collaborationInfo = CollaborationInfoImpl .getInstance ();
8888 private static BookManager bookManager = BookManagerImpl .getInstance (repo );
89- private ModelEventListener dirtyChangeEventListener ;
9089
9190 static {
9291 collaborationInfo .addEvent (new CollaborationEventListener () {
@@ -112,24 +111,19 @@ public void onEvent(CollaborationEvent event) {
112111 });
113112 }
114113
115- private String username ;
116-
117114 @ Wire
118115 Spreadsheet ss ;
119-
120116 @ Wire
121117 Script confirmMsgWorkaround ;
122-
123118 @ Wire
124119 Script gaScript ;
125-
126120 @ Wire
127121 Html usersPopContent ; //ZSS-998
128-
129122 BookInfo selectedBookInfo ;
130123 Book loadedBook ;
131124 Desktop desktop = Executions .getCurrent ().getDesktop ();
132-
125+ private ModelEventListener dirtyChangeEventListener ;
126+ private String username ;
133127 private UnsavedAlertState isNeedUnsavedAlert = UnsavedAlertState .DISABLED ;
134128
135129 public AppCtrl () {
@@ -310,6 +304,16 @@ private void initBook() throws UnsupportedEncodingException {
310304
311305 BookInfo bookinfo = getBookInfo (bookName );
312306 String sheetName = Executions .getCurrent ().getParameter ("sheet" );
307+
308+ Cookie [] cookies = ((HttpServletRequest ) Executions .getCurrent ().getNativeRequest ()).getCookies ();
309+ if (cookies != null ) {
310+ for (Cookie cookie : cookies ) {
311+ if (cookie .getName ().equals (ZSS_USERNAME )) {
312+ username = cookie .getValue ();
313+ break ;
314+ }
315+ }
316+ }
313317 if (bookinfo != null ) {
314318 doLoadBook (bookinfo , null , sheetName , false );
315319 } else {
@@ -377,8 +381,7 @@ public void onEvent(DlgCallbackEvent event) throws Exception {
377381 return ;
378382 }
379383 }
380- }
381- }, name , loadedBook , "Save Book for sharing" , "Next" );
384+ }}, name , loadedBook , "Save Book for sharing" , "Next" );
382385 } else {
383386 ShareBookCtrl .show ();
384387 }
@@ -410,7 +413,7 @@ public void onEvent(DlgCallbackEvent event) throws Exception {
410413 pushAppEvent (AppEvts .ON_AFTER_CHANGED_USERNAME , username );
411414 }
412415 }
413- }, username == null ? "" : username , message == null ? "" : message );
416+ }, username == null ? "admin " : username , message == null ? "" : message );
414417 } else {
415418 // already in cookie
416419 Cookie [] cookies = ((HttpServletRequest ) Executions .getCurrent ().getNativeRequest ()).getCookies ();
@@ -575,7 +578,7 @@ private void doOpenNewBook0(boolean renewState) {
575578 if (renewState )
576579 setBookmark ("" );
577580
578- collaborationInfo .removeRelationship (username );
581+ collaborationInfo .setRelationship (username , loadedBook );
579582 ss .setBook (loadedBook );
580583 initSaveNotification (loadedBook );
581584 pushAppEvent (AppEvts .ON_CHANGED_FILE_STATE , BookInfo .STATE_UNSAVED );
0 commit comments