View Javadoc

1   /**
2    *
3    */
4   package org.appfuse.webapp.client.ui.users.updatePassword;
5   
6   import org.appfuse.webapp.client.ui.users.updatePassword.UpdatePasswordView.UserCredentials;
7   
8   import com.google.gwt.place.shared.Place;
9   import com.google.gwt.place.shared.PlaceTokenizer;
10  import com.google.gwt.place.shared.Prefix;
11  
12  /**
13   * @author ivangsa
14   *
15   */
16  public class UpdatePasswordPlace extends Place {
17  
18      private static final String PAIRS_SEPARATOR = "!";
19      private static final String LABEL_VALUE_SEPARATOR = "=";
20  
21      private final UserCredentials userCredentials = new UserCredentials();
22  
23      public UpdatePasswordPlace() {
24          super();
25      }
26  
27      public UpdatePasswordPlace(final String username) {
28          super();
29          userCredentials.setUsername(username);
30      }
31  
32      public UpdatePasswordPlace(final String username, final String token) {
33          super();
34          userCredentials.setUsername(username);
35          userCredentials.setToken(token);
36      }
37  
38      public UserCredentials getUserCredentials() {
39          return userCredentials;
40      }
41  
42      @Prefix("updatePassword")
43      public static class Tokenizer implements PlaceTokenizer<UpdatePasswordPlace> {
44          @Override
45          public String getToken(final UpdatePasswordPlace place) {
46              final StringBuffer sb = new StringBuffer();
47              if (place.userCredentials.getUsername() != null) {
48                  sb.append("username" + LABEL_VALUE_SEPARATOR + place.userCredentials.getUsername());
49              }
50              sb.append(PAIRS_SEPARATOR);
51              if (place.userCredentials.getToken() != null) {
52                  sb.append("token" + LABEL_VALUE_SEPARATOR + place.userCredentials.getToken());
53              }
54              return sb.toString();
55          }
56  
57          @Override
58          public UpdatePasswordPlace getPlace(final String token) {
59              final UpdatePasswordPlace place = new UpdatePasswordPlace();
60              final String[] pairs = token.split(PAIRS_SEPARATOR);
61              for (final String string : pairs) {
62                  if (string != null) {
63                      final String[] labelValue = string.split(LABEL_VALUE_SEPARATOR);
64                      if (labelValue.length == 2) {
65                          if ("username".equals(labelValue[0])) {
66                              place.userCredentials.setUsername(labelValue[1]);
67                          }
68                          if ("token".equals(labelValue[0])) {
69                              place.userCredentials.setToken(labelValue[1]);
70                          }
71                      }
72                  }
73              }
74              return place;
75          }
76      }
77  }