Subversion Repositories SmartDukaan

Rev

Rev 2351 | Rev 2778 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2351 varun.gupt 1
package in.shop2020.social.controllers;
2
 
3
import java.util.Map;
4
import javax.servlet.ServletContext;
5
import org.apache.struts2.interceptor.ParameterAware;
6
import org.apache.struts2.util.ServletContextAware;
7
import com.thoughtworks.xstream.core.util.Base64Encoder;
8
 
9
public class CommunityPromotionController implements ParameterAware, ServletContextAware {
10
 
11
    protected Map<String, String[]> parameters;
12
    protected ServletContext context;
13
 
14
    public CommunityPromotionController() {
15
    }
16
 
17
    public String index()  {
18
        return "success";
19
    }
20
 
21
    public String create()  {
22
        return "success";
23
    }
24
 
25
    @Override
26
    public void setParameters(Map<String, String[]> parameters) {
27
        this.parameters = parameters;
28
    }
29
 
30
    @Override
31
    public void setServletContext(ServletContext context) {
32
        this.context = context;
33
    }
34
 
35
    public String getParameter(String key)    {
36
        String str = "";
37
        for (int i = 0; i < this.parameters.get(key).length; i ++)  {
38
            str += this.parameters.get(key)[i];
39
        }
40
        return str;
41
    }
42
 
43
    public Map<String, String[]> getParameters()   {
44
        return this.parameters;
45
    }
46
 
47
    public String getFBPostedJSON()  {
48
        String str = "";
49
        for(String key: this.parameters.keySet())   {
50
            str = this.parameters.get(key)[0];
51
        }
52
        Base64Encoder decoder = new Base64Encoder();
2468 varun.gupt 53
        try {
54
            byte[] decodedBytes = decoder.decode(str.split("\\.")[1]);
55
            return new String(decodedBytes);
56
        }
57
        catch (ArrayIndexOutOfBoundsException e) {
58
            e.printStackTrace();
59
            return "{}";
60
        }
2351 varun.gupt 61
    }
62
 
63
    public String test()  {
64
        String[] test = new String[] {"str1", "str2", "str3"};
65
        String str = "";
66
 
67
        for (int i = 0; i < test.length; i ++)  {
68
            str += test[i];
69
        }
70
        return str;
71
    }
72
 
73
    public String getServletContextPath(){
74
        return context.getContextPath();
75
    }
76
}