Esempio n. 1
0
  @Override
  public void init() {
    ServletContext context = getServletContext();
    WebCache webCache =
        (WebCache)
            WebApplicationContextUtils.getRequiredWebApplicationContext(context)
                .getBean("webCache");
    // 站点信息
    webCache.initSite(context);
    // 模板索引
    webCache.initTemplate(context);
    // 初始化分类树
    webCache.initCategory(context);
    // 初始化分类属性
    webCache.initCategoryAttr(context);
    // 初始化品牌
    webCache.initBrand(context);
    // 初始化价格区域
    webCache.initPriceRange(context);

    webCache.initItemIdUrlMap(context);
    // 配置初始化
    Configuration.init();
    // 其他初始化都完成后 才做Lucene的初始化
    LuceneInit luceneInit =
        (LuceneInit)
            WebApplicationContextUtils.getRequiredWebApplicationContext(context)
                .getBean("luceneInit");
    luceneInit.addIndex(context);
  }
Esempio n. 2
0
 @Override
 public void init(FilterConfig filterConfig) throws ServletException {
   WebApplicationContext webApplicationContext =
       WebApplicationContextUtils.getRequiredWebApplicationContext(
           filterConfig.getServletContext());
   menuCache = (MenuCache) webApplicationContext.getBean("menuCache");
 }
Esempio n. 3
0
  @Override
  public String execute() throws Exception {

    ActionContext ctx = ActionContext.getContext();

    ServletContext sc = (ServletContext) ctx.get(ServletActionContext.SERVLET_CONTEXT);

    ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);

    CourseManagerImpl cmi = (CourseManagerImpl) appContext.getBean("CourseManagerImpl");
    StudentManagerImpl smi = (StudentManagerImpl) appContext.getBean("StuManagerImpl");

    List cmiList = cmi.getCourses();
    List smiList = smi.getStudents();

    Map cmiMap = new HashMap();
    Map smiMap = new HashMap();

    for (int i = 0; i < cmiList.size(); i++) {
      Course course = (Course) cmiList.get(i);
      cmiMap.put(course.getCoursId(), course.getCoursName());
    }

    for (int i = 0; i < smiList.size(); i++) {
      Student student = (Student) smiList.get(i);
      smiMap.put(student.getStuId(), student.getStuName());
    }

    ActionContext actionContext = ActionContext.getContext();
    Map session = actionContext.getSession();
    session.put("cmiMap", cmiMap);
    session.put("smiMap", smiMap);
    return SUCCESS;
  }
	//普通字典
	private void makeGeneralDictinary(ServletContextEvent event){
		// TODO Auto-generated method stub
		//取得appliction上下文
		ServletContext context = event.getServletContext();
		ApplicationContext ctx =WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		//取得特定bean //spsxtDictionaryDao
		SpsxtDictionaryDao dao=(SpsxtDictionaryDao)ctx.getBean("spsxtDictionaryDao");
		try {
			List<Map<String,String>> list =(List<Map<String,String>>)dao.querySpsxtDictionary();	
			String prevDmlb="";
			List dmList=new ArrayList();
			
			for(Map<String,String> theMap :list){
				String currentDmlb=theMap.get("dmlb");
				if(!currentDmlb.equals(prevDmlb)){//新的代码开始
					//将dmList中的内容转换为JSON格式,然后写入到文件中,同时再次实例化dmList,为处理下一个代码表做准备
					if(!prevDmlb.equals("")){//排除首次					   
						saveJSON2File(dmList,prevDmlb);
					}
					prevDmlb=currentDmlb;//保存这个新的代码类别
					dmList=new ArrayList();
				}//end if(dmlb.equals(prevDmlb)
				dmList.add(new SpsxtDictionaryVO(theMap.get("dm"),theMap.get("dmyy"),theMap.get("pym")));
				
			}//end for
			//保存最后一个代码表
			saveJSON2File(dmList,prevDmlb);
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	
	}
Esempio n. 5
0
 @Override
 public void init() {
   ApplicationContext ctx =
       WebApplicationContextUtils.getRequiredWebApplicationContext(
           this.getServletConfig().getServletContext());
   zytzService = (ZytzService) ctx.getBean("zytzService");
 }
//为客户端翻译用的js对象
	private void makeJavascriptObject(ServletContextEvent event){
		// TODO Auto-generated method stub
		//取得appliction上下文
		ServletContext context = event.getServletContext();
		ApplicationContext ctx =WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		//取得特定bean //spsxtDictionaryDao
		SpsxtDictionaryDao dao=(SpsxtDictionaryDao)ctx.getBean("spsxtDictionaryDao");
		try {
			List<String> list =(List<String>)dao.getQueryForTranslation();
			StringBuilder sb=new StringBuilder();
			for(int i=0;i<list.size();i++){
				sb.append(list.get(i)+"\n");
			}
			//Gson gson = new Gson();
		    String jsonList=sb.toString();//转换为json字符串	    
		    System.out.println(jsonList);
			//保存js脚本代码
		    OutputStreamWriter writer;			
			String fileName=dictPath+"/js/"+"jf_sxtScript.js";
			writer = new OutputStreamWriter(new FileOutputStream(fileName),"UTF-8");
			System.out.println(fileName+"---js脚本写入成功!!!");
		    writer.write(jsonList);
		    writer.close();			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	
	}
Esempio n. 7
0
 public void init(ServletConfig config) throws ServletException {
   ServletContext servletContext = config.getServletContext();
   this.wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
   this.customerMgm = (CustomerMgm) this.wac.getBean("customerMgmImpl");
   baseDao = (BaseDAO) wac.getBean("systemDao");
   servletConfig = config;
 }
Esempio n. 8
0
 @Override
 public void doTag() throws JspException, IOException {
   if (org == null) { // 如果标签的org属性没有值则读取数据库取得组织结构信息
     ServletContext servletContext = ((PageContext) this.getJspContext()).getServletContext();
     WebApplicationContext ctx =
         WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
     OrgService orgService = (OrgService) ctx.getBean("orgService");
     this.setOrg(orgService.findRoot());
   }
   // 生成第一层组织结构
   List<OrgProfile> orgList = this.getOrg().getChildren();
   StringBuffer html = new StringBuffer();
   if (this.getTopOrgClass() == null) {
     html.append("<ul>");
   } else {
     html.append("<ul class=\"").append(this.getTopOrgClass()).append("\">");
   }
   for (OrgProfile orgItem : orgList) {
     html.append("<li>");
     html.append("<a id=\"")
         .append(orgItem.getId())
         .append("\" href=\"#\">")
         .append(orgItem.getName())
         .append("</a>");
     // 递归生成组织结构
     html.append(this.writeHTML(orgItem));
     html.append("</li>");
   }
   html.append("</ul>");
   try {
     getJspContext().getOut().print(html);
   } catch (Exception ex) {
     log.error("orgtree's tag error.", ex);
   }
 }
Esempio n. 9
0
 public void Install() {
   ServletContext sc = getServletContext();
   WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
   RealPathResolver realPathResolver = (RealPathResolver) ac.getBean("realPathResolver");
   UpdateMng updateMng = (UpdateMng) ac.getBean("updateMng");
   updateMng.update();
   String dbXmlFileName = "/WEB-INF/classes/jdbc.properties";
   String url, dbUser, dbPassword;
   InputStream in;
   try {
     in = new FileInputStream(realPathResolver.get(dbXmlFileName));
     Properties p = new Properties();
     p.load(in);
     url = p.getProperty("jdbc.url");
     String[] urls = url.split("[?]");
     dbUser = p.getProperty("jdbc.username");
     dbPassword = p.getProperty("jdbc.password");
     createTable(urls[0], dbUser, dbPassword);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
	//Tree字典
	private void makeTreeDictinary(ServletContextEvent event){
		// TODO Auto-generated method stub		
		//取得appliction上下文
		ServletContext context = event.getServletContext();
		ApplicationContext ctx =WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		//取得特定bean //spsxtDictionaryDao
		SpsxtDictionaryDao dao=(SpsxtDictionaryDao)ctx.getBean("spsxtDictionaryDao");
		List<TreeJson> spsxtTree=null;
		try {
			spsxtTree=dao.getQueryIndustryTree();//行业类别Tree			
			saveJSONTree2File(TreeJson.formatTree(spsxtTree),"IndustryTree");//保存到代码表文件中
			
			spsxtTree=dao.getQueryResolutionTree();//分辨率Tree			
			saveJSONTree2File(TreeJson.formatTree(spsxtTree),"ResolutionTree");//保存到代码表文件中

			spsxtTree=dao.getQuerySightTree();//是否夜视Tree			
			saveJSONTree2File(TreeJson.formatTree(spsxtTree),"SighTree");//保存到代码表文件中			
		
			spsxtTree=dao.getQueryPropertyTree();//属性Tree			
			saveJSONTree2File(TreeJson.formatTree(spsxtTree),"PropertyTree");//保存到代码表文件中
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	
	}
Esempio n. 11
0
 /**
  * Get the validator resources from a ValidatorFactory defined in the web application context or
  * one of its parent contexts. The bean is resolved by type
  * (org.springframework.validation.commons.ValidatorFactory).
  *
  * @return ValidatorResources from a ValidatorFactory.
  */
 private ValidatorResources getValidatorResources() {
   // look in servlet beans definition (i.e. action-servlet.xml)
   WebApplicationContext ctx =
       (WebApplicationContext)
           pageContext
               .getRequest()
               .getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
   ValidatorFactory factory = null;
   try {
     factory =
         (ValidatorFactory)
             BeanFactoryUtils.beanOfTypeIncludingAncestors(
                 ctx, ValidatorFactory.class, true, true);
   } catch (NoSuchBeanDefinitionException e) {
     // look in main application context (i.e. applicationContext.xml)
     ctx =
         WebApplicationContextUtils.getRequiredWebApplicationContext(
             pageContext.getServletContext());
     factory =
         (ValidatorFactory)
             BeanFactoryUtils.beanOfTypeIncludingAncestors(
                 ctx, ValidatorFactory.class, true, true);
   }
   return factory.getValidatorResources();
 }
Esempio n. 12
0
 public void init(ServletConfig config) throws ServletException {
   super.init(config);
   ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
   dao = (DerbyDao) ctx.getBean("personDao");
   txManager = (PlatformTransactionManager) ctx.getBean("transactionManager");
   dao.createTable();
 }
  private WebApplicationContext springSetup() {
    if (logger.isDebugEnabled()) {
      String msg = String.format(" '%s'", "spring setup");
      logger.debug(msg);
    }
    StringBuilder sb = new StringBuilder();

    // in web.xml this is loaded through the contextloaderlistener
    // here since we're mocking we need to load it ourselves
    // String s = String.format("classpath:%s classpath:%s classpath:%s",
    // "spring-service-layer.xml", "spring-db-testing.xml",
    // "spring-test.xml");
    // sb.append(s);

    // TODO make this configurable
    sb.append("classpath:spring-service-layer.xml");

    // spring class in spring-test
    MockServletContext sc = new MockServletContext();

    // spring's ContextLoader.createWebApplicationContext looks for this key
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, sb.toString());

    ServletContextListener contextListener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    contextListener.contextInitialized(event);
    WebApplicationContext wac =
        (WebApplicationContext)
            sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    if (logger.isDebugEnabled()) {
      String msg = String.format("just created '%s'", wac);
      logger.debug(msg);
    }
    getSession()
        .getServletContext()
        .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    getActionServlet()
        .getServletContext()
        .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

    // if (applicationContext == null) {
    // // this is the first time. Initialize the Spring context.
    // applicationContext = (new ContextLoader())
    // .initWebApplicationContext(getRequest().getSession()
    // .getServletContext());
    // } else {
    // // Spring context is already initialized. Set it in servlet context
    // // so that Spring's ContextLoaderPlugIn will not initialize it again
    // getRequest()
    // .getSession()
    // .getServletContext()
    // .setAttribute(
    // WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
    // applicationContext);
    // }

    return WebApplicationContextUtils.getRequiredWebApplicationContext(
        getSession().getServletContext());
  }
 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException if an error occurs
  */
 public void init(ServletConfig config) throws ServletException {
   // Put your code here
   ServletContext servletContext = config.getServletContext();
   this.wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
   this.investmentPlanService = (InvestmentPlanService) this.wac.getBean("investmentPlanService");
   this.fundMonthPlanService = (FundMonthPlanService) this.wac.getBean("fundMonthPlanService");
 }
Esempio n. 15
0
 @Override
 public void init(ServletConfig config) throws ServletException {
   super.init(config);
   WebApplicationContext context =
       WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
   jookService = (JookService) context.getBean(Jook.SPRING_BEAN_NAME_JOOK_SERVICE);
 }
Esempio n. 16
0
 public void setServlet(ActionServlet actionServlet) {
   super.setServlet(actionServlet);
   ServletContext servletContext = actionServlet.getServletContext();
   WebApplicationContext wac =
       WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
   this.petStore = (PetStoreFacade) wac.getBean("petStore");
 }
Esempio n. 17
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    WebApplicationContext ctx =
        WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
    CourseManager manager = (CourseManager) ctx.getBean("courseManager");

    InternetAddress addr;
    InternetAddress address[] = new InternetAddress[1];
    addr = new InternetAddress("*****@*****.**", "cust", "BIG5");
    address[0] = addr;

    manager.sendMail(
        "",
        "",
        "www.cust.edu.tw",
        "*****@*****.**",
        "王小明",
        new Date(),
        "測試",
        "<img src='http://192.192.237.19/CIS/CountImage?userid=77'>",
        address,
        null);

    // response.setContentType("image/jpeg");
    // response.sendRedirect("/CIS/pages/images/transparent.gif");
  }
Esempio n. 18
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    log.info("HelloServlet doGet");

    ServletContext servletContext = this.getServletContext();
    WebApplicationContext wac =
        WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    personService = (PersonService) wac.getBean("personService");

    Person person = new Person();
    person.setFirst_name("Lee");
    person.setLast_name("Brian");

    person = personService.create(person);

    log.info("persion id created -> " + person.getEmplid());

    log.info("person -> " + personService.findByEmplid(person.getEmplid()));

    personService.delete(person);

    log.info("person deleted id -> " + person.getEmplid());

    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().println("<h1>Hello Servlet</h1>");
    response.getWriter().println("session=" + request.getSession(true).getId());
  }
Esempio n. 19
0
  @Override
  public void init(FilterConfig fc) {
    super.init(fc);
    this.filterConfig = fc;
    containerTweaks = new ContainerTweaks();
    Config config = new Config(fc);
    // DefaultFactory defaultFactory = new DefaultFactory(config);
    Grails5535Factory defaultFactory =
        new Grails5535Factory(config); // TODO revert once Sitemesh bug is fixed
    fc.getServletContext().setAttribute(FACTORY_SERVLET_CONTEXT_ATTRIBUTE, defaultFactory);
    defaultFactory.refresh();
    FactoryHolder.setFactory(defaultFactory);

    contentProcessor = new PageParser2ContentProcessor(defaultFactory);
    decoratorMapper = defaultFactory.getDecoratorMapper();

    applicationContext =
        WebApplicationContextUtils.getRequiredWebApplicationContext(fc.getServletContext());
    layoutViewResolver = WebUtils.lookupViewResolver(applicationContext);

    final GrailsApplication grailsApplication =
        GrailsWebUtil.lookupApplication(fc.getServletContext());
    String encoding = (String) grailsApplication.getFlatConfig().get(CONFIG_OPTION_GSP_ENCODING);
    if (encoding != null) {
      defaultEncoding = encoding;
    }

    Map<String, PersistenceContextInterceptor> interceptors =
        applicationContext.getBeansOfType(PersistenceContextInterceptor.class);
    if (!interceptors.isEmpty()) {
      persistenceInterceptor = interceptors.values().iterator().next();
    }
  }
Esempio n. 20
0
  @Override
  public void init(ServletConfig config) throws ServletException {

    ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());

    db = ctx.getBean("DataBroker", DataBroker.class);
  }
Esempio n. 21
0
  public void prepare() throws Exception {
    logger.debug("Inside PatientProfile:prepare()");
    try {
      WebApplicationContext context =
          WebApplicationContextUtils.getRequiredWebApplicationContext(
              ServletActionContext.getServletContext());
      userService = (UserService) context.getBean("userService");
      auditInfoService = (AuditInfoService) context.getBean("auditInfoService");
      patientService = (PatientService) context.getBean("patientService");
      contactService = (ContactService) context.getBean("contactService");
      logger.debug("In prepare patientService =" + patientService);
      // is client behind something?
      ipAddress = request.getHeader("X-FORWARDED-FOR");
      if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
      }
      logger.debug("client's ipAddress =" + ipAddress);
      Object obj = request.getSession().getAttribute("user");
      if (obj != null) {
        userInSession = (UserVO) obj;
      }
      logger.debug("userInSession is " + userInSession.getAttributesAsString());
      //			path = context.getServletContext().getRealPath("/");
      //			String app = context.getServletContext().getContextPath();
      //			path = path.substring(0, path.lastIndexOf(app.split("/")[1]));

    } catch (Exception e) {
      e.printStackTrace();
    }
    logger.debug("Completing PatientProfile:prepare()");
  }
Esempio n. 22
0
 public void contextInitialized(ServletContextEvent event) {
   WebApplicationContext wac =
       WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
   remoteAppCtx =
       new ClassPathXmlApplicationContext(
           new String[] {"classpath:/com/tctest/spring/spring-remoting.xml"}, wac);
 }
Esempio n. 23
0
  /** 初始化全局变量。 */
  private void initGlobal(ServletContextEvent servletContextEvent) {

    Global.APP_REAL_PATH = servletContextEvent.getServletContext().getRealPath("/");
    Global.IPDATE_FILE_PATH = Global.APP_REAL_PATH + "static/IPDate/";
    Global._ctx =
        WebApplicationContextUtils.getRequiredWebApplicationContext(
            servletContextEvent.getServletContext());
  }
  @Override
  public void init() throws ServletException {
    super.init();

    // 初始化SpringContext
    ApplicationContext.init(
        WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()));
  }
 /**
  * Look up the SessionFactory that this filter should use.
  *
  * <p>The default implementation looks for a bean with the specified name in Spring's root
  * application context.
  *
  * @return the SessionFactory to use
  * @see #getSessionFactoryBeanName
  */
 protected SessionFactory lookupSessionFactory() {
   if (logger.isDebugEnabled()) {
     logger.debug(
         "Using SessionFactory '" + getSessionFactoryBeanName() + "' for OpenSessionInViewFilter");
   }
   WebApplicationContext wac =
       WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
   return wac.getBean(getSessionFactoryBeanName(), SessionFactory.class);
 }
Esempio n. 26
0
 private BussinessService getBussinessService(HttpServletRequest request) {
   if (bussinessService == null) {
     ServletContext servletContext = request.getSession().getServletContext();
     WebApplicationContext wac =
         WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
     bussinessService = (BussinessService) wac.getBean("bussinessService");
   }
   return bussinessService;
 }
 protected SqlMapClientImpl[] getSqlMapClientImplInstances(FilterConfig filterConfig)
     throws Exception {
   // find them in a ContextLoaderListener-loaded Spring WebApplicationContext
   WebApplicationContext ctx =
       WebApplicationContextUtils.getRequiredWebApplicationContext(
           filterConfig.getServletContext());
   Map clientsMap = ctx.getBeansOfType(SqlMapClientImpl.class);
   return (SqlMapClientImpl[]) clientsMap.values().toArray(new SqlMapClientImpl[] {});
 }
Esempio n. 28
0
 @Override
 public void contextDestroyed(ServletContextEvent sce) {
   log.info("Destroying Web application");
   WebApplicationContext ac =
       WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
   AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac;
   gwac.close();
   log.debug("Web application destroyed");
 }
Esempio n. 29
0
 @Override
 public void init(ServletConfig config) throws ServletException {
   super.init(config);
   WebApplicationContext wac =
       WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
   factory = (NotificationFactory) wac.getBean("notificationFactory");
   emailService = (NotificationService) wac.getBean("emailService");
   smsService = (NotificationService) wac.getBean("smsService");
 }
Esempio n. 30
0
 private WebApplicationContext getContext() {
   WebApplicationContext context =
       WebApplicationContextUtils.getRequiredWebApplicationContext(
           ServletActionContext.getServletContext());
   for (int ii = 0; ii < context.getBeanDefinitionCount(); ii++) {
     logger.debug("bean - " + context.getBeanDefinitionNames()[ii]);
   }
   return context;
 }