1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.application.viewstate.token;
20
21 import java.io.UnsupportedEncodingException;
22 import javax.faces.FacesException;
23 import javax.faces.context.FacesContext;
24 import org.apache.myfaces.shared.util.StateUtils;
25
26
27
28
29
30 public class ServiceSideStateTokenProcessor extends StateTokenProcessor
31 {
32 @Override
33 public Object decode(FacesContext facesContext, String token)
34 {
35 if (STATELESS_TOKEN.equals(token))
36 {
37
38
39 return null;
40 }
41
42 try
43 {
44 byte[] tokenBytes = token.getBytes(StateUtils.ZIP_CHARSET);
45 byte[] tokenBytesDecoded = StateUtils.decode(tokenBytes);
46 String tokenDecoded = new String(tokenBytesDecoded, StateUtils.ZIP_CHARSET);
47
48 return tokenDecoded;
49 }
50 catch (UnsupportedEncodingException e)
51 {
52 throw new FacesException(e);
53 }
54
55 }
56
57 @Override
58 public String encode(FacesContext facesContext, Object savedStateObject)
59 {
60 if (facesContext.getViewRoot().isTransient())
61 {
62 return STATELESS_TOKEN;
63 }
64
65 try
66 {
67
68 String token = (String) savedStateObject;
69 byte[] tokenBytes = token.getBytes(StateUtils.ZIP_CHARSET);
70 byte[] tokenBytesEncoded = StateUtils.encode(tokenBytes);
71 String tokenEncoded = new String(tokenBytesEncoded, StateUtils.ZIP_CHARSET);
72
73 return tokenEncoded;
74 }
75 catch (UnsupportedEncodingException e)
76 {
77 throw new FacesException(e);
78 }
79 }
80 }