Subversion Repositories SmartDukaan

Rev

Rev 3298 | Rev 4152 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.social.controllers;

import in.shop2020.datalogger.SocialEventType;
import in.shop2020.utils.DataLogger;

import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.struts2.interceptor.ParameterAware;
import org.apache.struts2.util.ServletContextAware;
import com.thoughtworks.xstream.core.util.Base64Encoder;

public class CommunityPromotionController implements ParameterAware, ServletContextAware {

    protected Map<String, String[]> parameters;
    protected ServletContext context;
    private String pid;
    
    public CommunityPromotionController() {
    }

    public String index()  {
        DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
        return "success";
    }
    
    public String create()  {
        
        if (pid != null && pid.equals("bb"))    {
                DataLogger.logSocialData(SocialEventType.BLACKBERRY_PROMOTION_VIEWED , "1000");
                return "bb-promo";
        } else  {
                DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
                
            return "success";
        }
    }
    
    public void setPid(String pid) {
                this.pid = pid;
        }

    @Override
    public void setParameters(Map<String, String[]> parameters) {
        this.parameters = parameters;
    }
    
    @Override
    public void setServletContext(ServletContext context) {
        this.context = context;
    }
    
    public String getParameter(String key)    {
        String str = "";
        for (int i = 0; i < this.parameters.get(key).length; i ++)  {
            str += this.parameters.get(key)[i];
        }
        return str;
    }
    
    public Map<String, String[]> getParameters()   {
        return this.parameters;
    }
    
    public String getFBPostedJSON()  {
        System.out.println(this.parameters);

        String str = this.parameters.get("signed_request")[0];
        System.out.println(str);
        Base64Encoder decoder = new Base64Encoder();
        try {
                System.out.println(str.split("\\."));
            byte[] decodedBytes = decoder.decode(str.split("\\.")[1]);
            String s = new String(decodedBytes).trim();
            String encodedString = decoder.encode(s.getBytes());
            System.out.println(encodedString);
            System.out.println(encodedString.equals(str));
            System.out.println(s);
            return s;
        }
        catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            return "{}";
        }
    }
    
    public String test()  {
        String[] test = new String[] {"str1", "str2", "str3"};
        String str = "";
        
        for (int i = 0; i < test.length; i ++)  {
            str += test[i];
        }
        return str;
    }
    
    public String getServletContextPath(){
        return context.getContextPath();
    }
}