/**
   * Calculate and return an absolute pathname to the XML file to contain our persistent storage
   * information.
   *
   * @exception Exception if an input/output error occurs
   */
  private String calculatePath() throws Exception {

    // Can we access the database via file I/O?
    String path = servlet.getServletContext().getRealPath(pathname);
    if (path != null) {
      return (path);
    }

    // Does a copy of this file already exist in our temporary directory
    File dir = (File) servlet.getServletContext().getAttribute("javax.servlet.context.tempdir");
    File file = new File(dir, "struts-example-database.xml");
    if (file.exists()) {
      return (file.getAbsolutePath());
    }

    // Copy the static resource to a temporary file and return its path
    InputStream is = servlet.getServletContext().getResourceAsStream(pathname);
    BufferedInputStream bis = new BufferedInputStream(is, 1024);
    FileOutputStream os = new FileOutputStream(file);
    BufferedOutputStream bos = new BufferedOutputStream(os, 1024);
    byte buffer[] = new byte[1024];
    while (true) {
      int n = bis.read(buffer);
      if (n <= 0) {
        break;
      }
      bos.write(buffer, 0, n);
    }
    bos.close();
    bis.close();
    return (file.getAbsolutePath());
  }
 /** 根据选择的图形类型设置图形属性 */
 private void showTypeResult() {
   if ("line".equals(showType)) {
     if ("bydate".equals(statType)) {
       picType = GetProperty.getProperties("pic.timeseries", servlet.getServletContext());
     } else {
       picType = GetProperty.getProperties("pic.line", servlet.getServletContext());
     }
     showOutLine = false;
   } else if ("bar".equals(showType)) {
     picType = GetProperty.getProperties("pic.bar", servlet.getServletContext());
     showOutLine = true;
   } else if ("stack".equals(showType)) {
     picType = GetProperty.getProperties("pic.stack", servlet.getServletContext());
     showOutLine = true;
   }
 }
示例#3
0
 public void setServlet(ActionServlet actionServlet) {
   super.setServlet(actionServlet);
   ServletContext servletContext = actionServlet.getServletContext();
   WebApplicationContext wac =
       WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
   this.petStore = (PetStoreFacade) wac.getBean("petStore");
 }
示例#4
0
  /** Initializes Hibernate with the config file found at <code>configFilePath</code>. */
  private void initHibernate() throws ServletException {
    Configuration configuration = null;
    URL configFileURL = null;
    ServletContext context = null;

    try {
      configFileURL = HibernatePlugIn.class.getResource(_configFilePath);

      context = _servlet.getServletContext();

      if (_log.isDebugEnabled()) {
        _log.debug("Initializing Hibernate from " + _configFilePath + "...");
      }

      configuration = (new Configuration()).configure(configFileURL);
      _factory = configuration.buildSessionFactory();

      if (_storedInServletContext) {
        _log.debug("Storing SessionFactory in ServletContext...");

        context.setAttribute(SESSION_FACTORY_KEY, _factory);
      }

    } catch (Throwable t) {
      _log.error("Exception while initializing Hibernate.");
      _log.error("Rethrowing exception...", t);

      throw (new ServletException(t));
    }
  }
    private void setInit(HttpServletRequest request) {

      HttpSession session = request.getSession();
      if ("bydate".equals(statType)) {
        beginDate = DateUtil.reFormatTime(request.getParameter("begindate"));
        endDate = DateUtil.reFormatTime(request.getParameter("enddate"));
        session.setAttribute("begindate45d", request.getParameter("begindate"));
        session.setAttribute("enddate45d", request.getParameter("enddate"));
        session.setAttribute("querytype45", "0");
        statTypeShow = GetProperty.getProperties("title.date", servlet.getServletContext());
        dateRange
            .append(GetProperty.getProperties("query.show.date", servlet.getServletContext()))
            .append(beginDate)
            .append("-")
            .append(endDate);
      } else if ("bymonth".equals(statType)) {
        beginDate = DateUtil.getMonth(request.getParameter("begindate"));
        endDate = DateUtil.getMonth(request.getParameter("enddate"));
        session.setAttribute("begindate45m", request.getParameter("begindate"));
        session.setAttribute("enddate45m", request.getParameter("enddate"));
        session.setAttribute("querytype45", "1");
        statTypeShow = GetProperty.getProperties("title.month", this.servlet.getServletContext());
        dateRange
            .append(GetProperty.getProperties("query.show.month", servlet.getServletContext()))
            .append(beginDate)
            .append("-")
            .append(endDate);
      } else if ("byweek".equals(statType)) {
        beginDate = DateUtil.reFormatTime(request.getParameter("begindate"));
        endDate = DateUtil.reFormatTime(request.getParameter("enddate"));
        session.setAttribute("begindate45w", request.getParameter("begindate"));
        session.setAttribute("enddate45w", request.getParameter("enddate"));
        session.setAttribute("querytype45", "2");
        // beginWeek = DateUtilExtend.getWeek(beginDate);
        // endWeek = DateUtilExtend.getWeek(endDate);
        statTypeShow = GetProperty.getProperties("title.week", servlet.getServletContext());
        dateRange
            .append(GetProperty.getProperties("query.show.week", servlet.getServletContext()))
            .append(beginDate)
            .append("-")
            .append(endDate);
      }
    }
示例#6
0
 /*    */ protected void process(HttpServletRequest request, HttpServletResponse response)
     /*    */ throws IOException, ServletException
       /*    */ {
   /* 32 */ response.setContentType("text/html;charset=UTF-8");
   /* 33 */ request.setCharacterEncoding("UTF-8");
   /*    */
   /* 35 */ String sAction = processPath(request, response);
   /* 36 */ String sOperation = request.getParameter("operation");
   /* 37 */ System.out.println("Current Module Name: " + sAction + " operation = " + sOperation);
   /*    */
   /* 39 */ processLockDocument(request, response);
   /*    */
   /* 41 */ super.process(request, response);
   /*    */ }
  /**
   * Gracefully shut down this database, releasing any resources that were allocated at
   * initialization.
   */
  public void destroy() {

    log.info("Finalizing memory database plug in");

    if (database != null) {
      try {
        database.close();
      } catch (Exception e) {
        log.error("Closing memory database", e);
      }
    }

    servlet.getServletContext().removeAttribute(Constants.DATABASE_KEY);
    database = null;
    servlet = null;
    database = null;
  }
示例#8
0
  /* (non-Javadoc)
   * @see org.apache.struts.action.PlugIn#init(org.apache.struts.action.ActionServlet, org.apache.struts.config.ModuleConfig)
   */
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    String absoltuePath = (servlet.getServletContext()).getRealPath("/");
    String prefix = config.getPrefix();
    String path = absoltuePath + prefix + confPath;

    InputStream is = null;
    try {
      is = new FileInputStream(path);
    } catch (FileNotFoundException e) {
      throw new ServletException("Cannot found or open the file : " + path);
    }

    //	Import preference data
    try {
      Preferences.importPreferences(is);
    } catch (InvalidPreferencesFormatException e) {
      System.err.println("InvalidPreferencesFormatException in PlugIn PrefsPlugin : " + e);
    } catch (IOException e) {
      System.err.println("IOException in PlugIn PrefsPlugin : " + e);
    }
  }
  /**
   * Initialize and load our initial database from persistent storage.
   *
   * @param servlet The ActionServlet for this web application
   * @param config The ApplicationConfig for our owning module
   * @exception ServletException if we cannot configure ourselves correctly
   */
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    log.info("Initializing memory database plug in from '" + pathname + "'");

    // Remember our associated configuration and servlet
    this.servlet = servlet;

    // Construct a new database and make it available
    database = new MemoryUserDatabase();
    try {
      String path = calculatePath();
      if (log.isDebugEnabled()) {
        log.debug(" Loading database from '" + path + "'");
      }
      database.setPathname(path);
      database.open();
    } catch (Exception e) {
      log.error("Opening memory database", e);
      throw new ServletException("Cannot load database from '" + pathname + "'", e);
    }

    // Make the initialized database available
    servlet.getServletContext().setAttribute(Constants.DATABASE_KEY, database);
  }
示例#10
0
  protected void processGlobalShutdownEvents() throws Exception {
    EventsProcessorUtil.process(
        PropsKeys.GLOBAL_SHUTDOWN_EVENTS, PropsValues.GLOBAL_SHUTDOWN_EVENTS);

    super.destroy();
  }
示例#11
0
  protected void callParentService(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    super.service(request, response);
  }
示例#12
0
 protected void callParentInit() throws ServletException {
   super.init();
 }
示例#13
0
 protected void callParentDestroy() {
   super.destroy();
 }
 protected void process(HttpServletRequest request, HttpServletResponse response)
     throws java.io.IOException, javax.servlet.ServletException {
   request.setCharacterEncoding("GB2312");
   super.process(request, response);
 }
示例#15
0
 /** Expose as public so that test classes can exercise things which retrieve messages. */
 public void initInternal() throws ServletException {
   super.initInternal();
 }