Package javax.servlet.jsp

Examples of javax.servlet.jsp.JspFactory


        // save the old PageContext
        PageContext oldPageContext = ServletActionContext.getPageContext();

        // create a new PageContext
        JspFactory jspFactory = JspFactory.getDefaultFactory();

        PageContext pageContext = jspFactory.getPageContext(this, request, response, null, true, 8192, true);

        // put the new PageContext into ActionContext
        ActionContext actionContext = ActionContext.getContext();

        actionContext.put(ServletActionContext.PAGE_CONTEXT, pageContext);

        /*
         * Must put the stack into HttpServletRequest, because the WebWork JSP
         * Taglib will use it to judge whether there are some errors in stack.
         */
        OgnlValueStack stack = ActionContext.getContext().getValueStack();

        //request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,
        // stack);
        //Moved to WebWorkPortlet doService()

        VelocityManager velocityManager = VelocityManager.getInstance();
        Context resultContext = velocityManager.createContext(stack, request, response);

        response.setContentType("text/html");

        try {
            String location = (String) ActionContext.getContext().get("template");
            Template template = velocityManager.getVelocityEngine().getTemplate(location);

            Writer writer = pageContext.getOut();
            template.merge(resultContext, writer);
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // perform cleanup
            jspFactory.releasePageContext(pageContext);
            actionContext.put(ServletActionContext.PAGE_CONTEXT, oldPageContext);
        }

    }
View Full Code Here


   */
  private void handleRequest(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    // Create a page context
    JspFactory factory = JspFactory.getDefaultFactory();
    String errorPageURL = null;
    int bufferSize = (JspWriter.DEFAULT_BUFFER <= 0) ? 1024 : JspWriter.DEFAULT_BUFFER;
    boolean needsSession = false;
    boolean autoFlush = true;
    PageContext pageContext = null;
    try {
      req.setCharacterEncoding("UTF-8");
      pageContext = factory.getPageContext(this, req, resp,
        errorPageURL, needsSession, bufferSize, autoFlush);
   
      // Create a shared wrapper
      PageRequest request = new JspPageRequest(pageContext);
      PageResponse response = new JspPageResponse(pageContext);

      // Extract the file name
      String encoding = "utf-8"; // We use utf-8 in our JSPs
      String fileUrl = SearchToolkit.extractFileUrl(req.getRequestURI(), encoding);

      // Check the file
      try {
        if (SearchToolkit.allowFileAccess(request, fileUrl)) {
          // Access allowed -> Send the file
          SearchToolkit.sendFile(request, response, RegainToolkit.urlToFile(fileUrl));
        } else {
          // Access not allowed -> Send 403 Forbidden
          resp.sendError(403);
        }
      }
      catch (RegainException exc) {
        throw new ServletException("Checking file access failed: " + fileUrl, exc);
      }
    }
    catch (Exception exc) {
      pageContext.handlePageException(exc);
    } finally {
      factory.releasePageContext(pageContext);
    }
  }
View Full Code Here

  public ApplicationImpl()
  {
    WebApp webApp = WebApp.getLocal();

    JspFactory jspFactory = JspFactory.getDefaultFactory();

    JspApplicationContext appContext
      = jspFactory.getJspApplicationContext(webApp);

    _defaultNavigationHandler = new NavigationHandlerImpl();

    _bundleManager = BundleManager.create();
View Full Code Here

        bean = new Bean();


        ExpressionFactory expressionFactory = createMock(ExpressionFactory.class);
        JspApplicationContext applicationContext = createMock(JspApplicationContext.class);
        JspFactory jspFactory = createMock(JspFactory.class);
        expect(expressionFactory.coerceToType(VALUE, String.class)).andStubReturn(VALUE);
        expect(expressionFactory.coerceToType(null, String.class)).andStubReturn(null);
        expect(applicationContext.getExpressionFactory()).andStubReturn(expressionFactory);
        expect(jspFactory.getJspApplicationContext(null)).andStubReturn(applicationContext);
        replay(jspFactory, applicationContext, expressionFactory);
        JspFactory.setDefaultFactory(jspFactory);
    }
View Full Code Here

        /**
         * Reset the jsp factory.
         */
        public void destroy() {
            final JspFactory current = JspFactory.getDefaultFactory();
            if ( current == this ) {
                JspFactory.setDefaultFactory(this.original);
            }
        }
View Full Code Here

            this.delegate = rd;
        }

        public void forward(ServletRequest request, ServletResponse response) throws ServletException,
                IOException {
            JspFactory jspFactory = JspFactory.getDefaultFactory();
            if (jspFactory instanceof JspFactoryHandler) {
                pageContext.getOut().flush();
                final int count = ((JspFactoryHandler)jspFactory).resetUsage();
                try {
                    delegate.forward(request, response);
View Full Code Here

            }
        }

        public void include(ServletRequest request, ServletResponse response) throws ServletException,
                IOException {
            JspFactory jspFactory = JspFactory.getDefaultFactory();
            if (jspFactory instanceof JspFactoryHandler) {
                pageContext.getOut().flush();
                final int count = ((JspFactoryHandler)jspFactory).resetUsage();
                try {
                    delegate.include(request, response);
View Full Code Here

    ValueStack stack = ActionContext.getContext().getValueStack();

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    JspFactory jspFactory = null;
    ServletContext servletContext = ServletActionContext
        .getServletContext();
    Servlet servlet = JspSupportServlet.jspSupportServlet;

    velocityManager.init(servletContext);

    boolean usedJspFactory = false;
    PageContext pageContext = (PageContext) ActionContext.getContext().get(
        ServletActionContext.PAGE_CONTEXT);

    if (pageContext == null && servlet != null)
    {
      jspFactory = JspFactory.getDefaultFactory();
      pageContext = jspFactory.getPageContext(servlet, request, response,
          null, true, 8192, true);
      ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT,
          pageContext);
      usedJspFactory = true;
    }

    try
    {
      // ------------- 1. render the screen template ------------
      String encoding = getEncoding(finalLocation);
      String contentType = getContentType(finalLocation);

      if (encoding != null)
      {
        contentType = contentType + ";charset=" + encoding;
      }
      Template t = getTemplate(stack,
          velocityManager.getVelocityEngine(), invocation,
          finalLocation, encoding);
      Context context = createContext(velocityManager, stack, request,
          response, finalLocation);
      Writer screenWriter = new StringWriter();
      response.setContentType(contentType);
      t.merge(context, screenWriter);
      context.put(KEY_SCREEN_CONTENT, screenWriter.toString());

      // ------------- 2. render the layout template -------------

      initLayoutTemplateParameters();

      String layout = getLayoutTemplate(context);

      try
      {
        // load the layout template
        t = getTemplate(stack, velocityManager.getVelocityEngine(),
            invocation, layout, encoding);
      }
      catch (Exception e)
      {

        // if it was an alternate layout we couldn't get...
        if (!layout.equals(defaultLayout))
        {
          // try to get the default layout
          // if this also fails, let the exception go
          t = getTemplate(stack, velocityManager.getVelocityEngine(),
              invocation, defaultLayout, encoding);
        }
      }

      Writer writer = new OutputStreamWriter(response.getOutputStream(),
          encoding);
      // Render the layout template into the response
      t.merge(context, writer);

      // generator exec template time
      Date cur_time = Calendar.getInstance(
          invocation.getInvocationContext().getLocale()).getTime();
      writer.write("\r\n<!-- Generated by EATELE.NET (");
      writer.write(cur_time + "");
      writer.write(") ");
      writer.write((cur_time.getTime() - runtime) + "");
      writer.write("ms -->");
      // always flush the writer (we used to only flush it if this was a
      // jspWriter, but someone asked
      // to do it all the time (WW-829). Since Velocity support is being
      // deprecated, we'll oblige :)
      writer.flush();

    }
    catch (Exception e)
    {
      LOG.error("Unable to render Velocity Template, '" + finalLocation
          + "'", e);
      throw e;
    }
    finally
    {
      if (usedJspFactory)
      {
        jspFactory.releasePageContext(pageContext);
      }
    }

    return;
  }
View Full Code Here

            } catch (Exception e) {
                logger.error("Error merging Java EE JNDI entries in to war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
            }

            JspFactory factory = JspFactory.getDefaultFactory();
            if (factory != null) {
                JspApplicationContext applicationCtx = factory.getJspApplicationContext(standardContext.getServletContext());
                WebBeansContext context = appContext.getWebBeansContext();
                if (context != null && context.getBeanManagerImpl().isInUse()) {
                    // Registering ELResolver with JSP container
                    ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
                    ELResolver resolver = elAdaptor.getOwbELResolver();
View Full Code Here

        ELResolver resolver = elAdaptor.getOwbELResolver();
        //Application is configured as JSP
        if (context.getOpenWebBeansConfiguration().isJspApplication()) {
            logger.debug("Application is configured as JSP. Adding EL Resolver.");

            JspFactory factory = JspFactory.getDefaultFactory();
            if (factory != null) {
                JspApplicationContext applicationCtx = factory.getJspApplicationContext(servletContext);
                applicationCtx.addELResolver(resolver);
            } else {
                logger.debug("Default JspFactory instance was not found");
            }
        }
View Full Code Here

TOP

Related Classes of javax.servlet.jsp.JspFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.