Subversion Repositories SmartDukaan

Rev

Rev 387 | Blame | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.serving.controllers;


import in.shop2020.serving.pages.PageContentKeys;
import in.shop2020.serving.pages.PageEnum;
import in.shop2020.serving.pages.PageManager;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ModelDriven;

/**
 * 
 * @author naveen
 *
 */
@Results({
    @Result(name="success", type="redirectAction", params = {"actionName" , 
                "entity"})
})
public class EntityController extends BaseController 
        implements  ModelDriven<Object>, ServletContextAware  {
        
        private PageManager pageManager = null;
        
        /**
         * 
         */
        private static Log log = LogFactory.getLog(EntityController.class);
        
        /**
         * 
         */
        @SuppressWarnings("unused")
        private ServletContext servletContext = null;
        
        /**
         * 
         */
        private String id;
        
        private Map<String,String> htmlSnippets;
        
        
        public EntityController(){
                super();
                pageManager = PageManager.getPageManager();
        }
    // GET /entity/1000001
    public HttpHeaders show() throws SecurityException, IOException {
        log.info("id=" + id);
        Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
        params.put(PageContentKeys.ENTITY_ID, id);
        Map<String,String> contents = pageManager.getPageContents(PageEnum.PRODUCT_PAGE, params);
        htmlSnippets = pageManager.getPageContents(PageEnum.PRODUCT_PAGE, params); 
        
        System.out.println(htmlSnippets);
        /*
        String contextPath = this.servletContext.getContextPath();
        log.info("contextPath=" + contextPath);
        
        String realPath = this.servletContext.getRealPath("/");
        log.info("realPath=" + realPath);
        
        String path = this.servletContext.getRealPath(
                        "/WEB-INF/testdir/test.txt");
        
        log.info("path=" + path);
        
        FileReader fr = new FileReader(new File(path));
        LineNumberReader lnr = new LineNumberReader(fr);
        
        String line = lnr.readLine();
        log.info("line=" + line);
        */
        return new DefaultHttpHeaders("show");
    }
    
    /**
     * 
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

        /* (non-Javadoc)
         * @see com.opensymphony.xwork2.ModelDriven#getModel()
         */
        @Override
        public Object getModel() {
                System.out.println(" getModer  is called");
                return htmlSnippets;
                //return this.id;
        }
        
        /**
         * 
         */
        @Override
        public void setServletContext(ServletContext servletContext) {
                this.servletContext = servletContext;
        }
        
        public Map<String,String> getHtmlSnippets(){
                System.out.println(" getHtmlSnippets  is called");
                return htmlSnippets;
        }
        
        public String getPriceSnippets(){
                return htmlSnippets.get("PRICE_DIV");
        }

        public String getSlideGuideSnippets(){
                return htmlSnippets.get("SLIDE_GUIDE");
        }

        public String getWidgetSnippets(){
                return htmlSnippets.get("WIDGET_DIV");
        }

}