Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
2652 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.serving.utils.FileUtils;
4
import in.shop2020.serving.utils.Utils;
5
 
6
import java.io.File;
7
import java.io.FileNotFoundException;
8
import java.io.IOException;
9
 
10
import org.apache.log4j.Logger;
3052 vikas 11
import org.apache.struts2.convention.annotation.Action;
12
import org.apache.struts2.convention.annotation.InterceptorRef;
2652 rajveer 13
 
14
@SuppressWarnings("serial")
15
public class RelatedAccessoriesController extends BaseController {
16
 
17
    private static Logger logger = Logger.getLogger(RelatedAccessoriesController.class);
18
	private String id;
19
    private String snippets="";
20
 
21
	public RelatedAccessoriesController(){
22
		super();
23
	}
24
 
3052 vikas 25
	@Action(interceptorRefs={@InterceptorRef("caching"),@InterceptorRef("myDefault")})
2652 rajveer 26
    public String show() {
27
        return "show";
28
    }
29
 
30
    public void setId(String id) {
31
    	this.id = id;
32
    }
33
 
34
    public String getSnippets(){
35
    	String itemIds = "";
36
	    try {
37
	    	itemIds = FileUtils.read( Utils.EXPORT_ENTITIES_PATH + id + File.separator +"RelatedAccessories.html");
38
	    }
39
	    catch (FileNotFoundException e) {
40
	        logger.error("File not found : " + Utils.EXPORT_ENTITIES_PATH + id + File.separator +"RelatedAccessories.html");
41
	    }
42
	    catch (IOException e) {
43
	        logger.error("IO exception : " + Utils.EXPORT_ENTITIES_PATH + id + File.separator +"RelatedAccessories.html");
44
	    }
45
	    if(!itemIds.equals("")){
46
	    	String[] items = itemIds.split("\\s|\\n|\\t");
47
	    	for(String item: items){
2662 rajveer 48
	    		logger.info("Getting widget snippet for item: " + item);
2652 rajveer 49
	    		try{
50
	    			long itemId = Long.parseLong(item.trim());
51
		    		try {
52
						snippets += FileUtils.read( Utils.EXPORT_ENTITIES_PATH + itemId + File.separator + "WidgetSnippet.html");
53
			    	}
54
		            catch (FileNotFoundException e) {
2662 rajveer 55
		                logger.warn("File not found : " + Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
2652 rajveer 56
		            }
57
		            catch (IOException e) {
2662 rajveer 58
		            	logger.warn("IO exception : " + Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
2652 rajveer 59
		            }	
60
	    		}catch (NumberFormatException nf){
61
	    			logger.error("Unable to convert string to long");
62
	    		}
63
	    	}
64
	    }
65
	    return snippets;
66
    }
67
}