Subversion Repositories SmartDukaan

Rev

Rev 15183 | Rev 15192 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15183 Rev 15185
Line 33... Line 33...
33
    private static MemCache memCache = new MemCache();
33
    private static MemCache memCache = new MemCache();
34
    private static MemCachedClient memcachedClient = memCache.getClient();
34
    private static MemCachedClient memcachedClient = memCache.getClient();
35
    
35
    
36
    
36
    
37
 
37
 
38
    public String getColorMessage() throws IOException, JSONException, URISyntaxException{
38
    public UserMessagePojo getColorMessage() throws IOException, JSONException, URISyntaxException{
39
        try{
39
        try{
40
            parseUrl();
40
            parseUrl();
41
            if (!checkCache()){
41
            if (!checkCache()){
42
                System.out.println(productUrl);
42
                System.out.println(productUrl);
43
                Document doc = Jsoup.connect(productUrl).get();
43
                Document doc = Jsoup.connect(productUrl).get();
44
                doc.outputSettings().charset("UTF-8");
44
                doc.outputSettings().charset("UTF-8");
45
                JSONArray jsonArray = new JSONArray(doc.getElementById("productAttributesJson").attr("value"));
45
                JSONArray jsonArray = new JSONArray(doc.getElementById("productAttributesJson").attr("value"));
46
                for (int element=0; element<jsonArray.length();element++){
46
                for (int element=0; element<jsonArray.length();element++){
47
                    if (supc.equalsIgnoreCase(jsonArray.getJSONObject(element).getString("supc"))){
47
                    if (supc.equalsIgnoreCase(jsonArray.getJSONObject(element).getString("supc"))){
48
                        color = jsonArray.getJSONObject(element).getString("value");
48
                        color = jsonArray.getJSONObject(element).getString("value");
49
                        populateCache(supc, color);
-
 
50
                    }
49
                    }
51
                }
50
                }
52
            }
51
            }
53
        }
52
        }
54
        catch (Exception e){
53
        catch (Exception e){
55
            log.error("Error while getting product details " +e);
54
            log.error("Error while getting product details " +e);
56
        }
55
        }
57
        setResultJson(getMsg());
-
 
58
        return INDEX;
56
        return getMsg();
59
 
-
 
60
    }
57
    }
61
    
58
    
62
    private UserMessagePojo getMsg(){
59
    private UserMessagePojo getMsg(){
63
    	UserMessagePojo ump = new UserMessagePojo();
60
    	UserMessagePojo ump = new UserMessagePojo();
64
    	if (color.isEmpty()){
61
    	if (color.isEmpty()){
Line 129... Line 126...
129
        return url;
126
        return url;
130
    }
127
    }
131
 
128
 
132
    public static void main(String[] args) throws URISyntaxException, IOException, JSONException{
129
    public static void main(String[] args) throws URISyntaxException, IOException, JSONException{
133
        SnapdealProductPageParserController s = new SnapdealProductPageParserController();
130
        SnapdealProductPageParserController s = new SnapdealProductPageParserController();
134
        String url = "http://m.snapdeal.com/product/samsung-galaxy-grand-max/647437791381?supc=SDL021483758&aff_id=1&bhalala=0";
131
        String url = "aHR0cDovL20uc25hcGRlYWwuY29tL3Byb2R1Y3Qvc3BpY2UtYm9zcy1lbnRlcnRhaW5lci0zLW01NDA2LzEwNTA2ODk2MjM/c3VwYz1TREw3MDA0MzYzMTUmdXRtX3NvdXJjZT1hZmZfcHJvZyZ1dG1fY2FtcGFpZ249YWZ0cyZvZmZlcl9pZD0xNyZhZmZfaWQ9MTc5MTUmYWZmX3N1Yj1TSEEzMTQzMTY3NzM0NQ==";
135
        s.setUrl(Base64.encode(url.getBytes()));
132
        byte[] decoded = Base64.decode(url);
-
 
133
        System.out.println(new String(decoded));
-
 
134
        s.setUrl(url);
136
        s.getColorMessage();
135
        s.getColorMessage();
137
        System.out.println(s.getResultJson());
136
        System.out.println(s.getResultJson());
138
    }
137
    }
139
 
138
 
140
}
139
}
141
140