Package javax.servlet.jsp

Examples of javax.servlet.jsp.PageContext


  public static Map createSessionScopeMap (PageContext pContext)

  {

    final PageContext context = pContext;

    return new EnumeratedMap ()

      {

  public Enumeration enumerateKeys ()

  {

    return context.getAttributeNamesInScope

      (PageContext.SESSION_SCOPE);

  }



  public Object getValue (Object pKey)

  {

    if (pKey instanceof String) {

      return context.getAttribute

        ((String) pKey,

         PageContext.SESSION_SCOPE);
View Full Code Here


  public static Map createApplicationScopeMap (PageContext pContext)

  {

    final PageContext context = pContext;

    return new EnumeratedMap ()

      {

  public Enumeration enumerateKeys ()

  {

    return context.getAttributeNamesInScope

      (PageContext.APPLICATION_SCOPE);

  }



  public Object getValue (Object pKey)

  {

    if (pKey instanceof String) {

      return context.getAttribute

        ((String) pKey,

         PageContext.APPLICATION_SCOPE);
View Full Code Here

   **/
  public Object resolveVariable (String pName,
         Object pContext)
    throws ELException
  {
    PageContext ctx = (PageContext) pContext;

    // Check for implicit objects
    if ("pageContext".equals (pName)) {
      return ctx;
    }
    else if ("pageScope".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getPageScopeMap ();
    }
    else if ("requestScope".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getRequestScopeMap ();
    }
    else if ("sessionScope".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getSessionScopeMap ();
    }
    else if ("applicationScope".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getApplicationScopeMap ();
    }
    else if ("param".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getParamMap ();
    }
    else if ("paramValues".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getParamsMap ();
    }
    else if ("header".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getHeaderMap ();
    }
    else if ("headerValues".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getHeadersMap ();
    }
    else if ("initParam".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getInitParamMap ();
    }
    else if ("cookie".equals (pName)) {
      return ImplicitObjects.
  getImplicitObjects (ctx).
  getCookieMap ();
    }

    // Otherwise, just look it up in the page context
    else {
      return ctx.findAttribute (pName);
    }
  }
View Full Code Here

   **/
  public static void runTests (DataInput pIn,
             PrintStream pOut)
    throws IOException
  {
    PageContext context = createTestContext ();

    while (true) {
      String str = pIn.readLine ();
      if (str == null) break;
      if (str.startsWith ("#") ||
View Full Code Here

   * Creates and returns the test PageContext that will be used for
   * the tests.
   **/
  static PageContext createTestContext ()
  {
    PageContext ret = new PageContextImpl ();

    // Create some basic values for lookups
    ret.setAttribute ("val1a", "page-scoped1", PageContext.PAGE_SCOPE);
    ret.setAttribute ("val1b", "request-scoped1", PageContext.REQUEST_SCOPE);
    ret.setAttribute ("val1c", "session-scoped1", PageContext.SESSION_SCOPE);
    ret.setAttribute ("val1d", "app-scoped1", PageContext.APPLICATION_SCOPE);

    // Create a bean
    {
      Bean1 b1 = new Bean1 ();
      b1.setBoolean1 (true);
      b1.setByte1 ((byte) 12);
      b1.setShort1 ((short) -124);
      b1.setChar1 ('b');
      b1.setInt1 (4);
      b1.setLong1 (222423);
      b1.setFloat1 ((float) 12.4);
      b1.setDouble1 (89.224);
      b1.setString1 ("hello");
      b1.setStringArray1 (new String [] {
  "string1",
  "string2",
  "string3",
  "string4"
      });
      {
  List l = new ArrayList ();
  l.add (new Integer (14));
  l.add ("another value");
  l.add (b1.getStringArray1 ());
  b1.setList1 (l);
      }
      {
  Map m = new HashMap ();
  m.put ("key1", "value1");
  m.put (new Integer (14), "value2");
  m.put (new Long (14), "value3");
  m.put ("recurse", b1);
  b1.setMap1 (m);
      }
      ret.setAttribute ("bean1a", b1);

      Bean1 b2 = new Bean1 ();
      b2.setInt2 (new Integer (-224));
      b2.setString2 ("bean2's string");
      b1.setBean1 (b2);

      Bean1 b3 = new Bean1 ();
      b3.setDouble1 (1422.332);
      b3.setString2 ("bean3's string");
      b2.setBean2 (b3);
    }

    // Create the public/private beans
    {
      ret.setAttribute ("pbean1", Factory.createBean1 ());
      ret.setAttribute ("pbean2", Factory.createBean2 ());
      ret.setAttribute ("pbean3", Factory.createBean3 ());
      ret.setAttribute ("pbean4", Factory.createBean4 ());
      ret.setAttribute ("pbean5", Factory.createBean5 ());
      ret.setAttribute ("pbean6", Factory.createBean6 ());
      ret.setAttribute ("pbean7", Factory.createBean7 ());
    }

    // Create the empty tests
    {
      Map m = new HashMap ();
      m.put ("emptyArray", new Object [0]);
      m.put ("nonemptyArray", new Object [] {"abc"});
      m.put ("emptyList", new ArrayList ());
      {
  List l = new ArrayList ();
  l.add ("hello");
  m.put ("nonemptyList", l);
      }
      m.put ("emptyMap", new HashMap ());
      {
  Map m2 = new HashMap ();
  m2.put ("a", "a");
  m.put ("nonemptyMap", m2);
      }
      m.put ("emptySet", new HashSet ());
      {
  Set s = new HashSet ();
  s.add ("hello");
  m.put ("nonemptySet", s);
      }
      ret.setAttribute ("emptyTests", m);
    }

    return ret;
  }
View Full Code Here

                    reportErrors();
            }
        }

        // Set the image Root if it is not set.
        PageContext pageContext = getPageContext();
        if (_iState.getImageRoot() == null)
            _iState.setImageRoot(((HttpServletRequest) pageContext.getRequest()).getContextPath() + "/" +
                    TagConfig.getTreeImageLocation());

        //  errors should have been caught above
        TreeElement treeRoot = getTreeRoot(_expr);

        // if the tree root hasn't been defined, then we need to update the what the object that is
        // pointed at by the dataSource expression.
        if (treeRoot == null) {
            if (_rootNode != null) {
                try {
                    String datasource = "{" + _dataSource + "}";
                    _expr.updateExpression(datasource, _rootNode, pageContext);
                }
                catch (ExpressionUpdateException e) {
                    String s = Bundle.getString("Tags_UnableToWriteTree", new Object[]{_dataSource, e.getMessage()});
                    registerTagError(s, null);
                    reportErrors();
                    return;
                }
                treeRoot = _rootNode;
            }

            // indicate an update error and return
            if (treeRoot == null) {
                String s = Bundle.getString("Tags_TreeNoAttribute", _dataSource);
                registerTagError(s, null);
                reportErrors();
                return;
            }

        }

        // set the root image
        if (treeRoot instanceof ITreeRootElement) {
            ITreeRootElement tre = (ITreeRootElement) treeRoot;
            if (tre.getRootNodeExpandedImage() == null) {
                tre.setRootNodeExpandedImage((_rootNodeExpandedImage != null) ?
                        _rootNodeExpandedImage : InheritableState.IMAGE_ROOT_EXPANDED);
            }
            if (tre.getRootNodeCollapsedImage() == null) {
                tre.setRootNodeCollapsedImage((_rootNodeCollapsedImage != null) ?
                        _rootNodeCollapsedImage : InheritableState.IMAGE_ROOT_COLLAPSED);
            }
        }

        // if we are running the tree at the client, then
        // we need to register the tree with the NameService
        if (_trs.runAtClient) {
            // it's currently not legal to have a runAtClient but not be an instance of INameable which is
            // implemented by the ITreeRootElement.
            if (!(treeRoot instanceof INameable)) {
                String s = Bundle.getString("Tags_TreeRunAtClientRoot", null);
                registerTagError(s, null);
                reportErrors();
                return;
            }

            // name the tree if it hasn't been named already
            INameable in = (INameable) treeRoot;
            String o = in.getObjectName();
            if (o == null) {
                NameService ns = NameService.instance(pageContext.getSession());
                ns.nameObject("Tree", in);
                ns.put(in);
            }
        }


        // prepare to render the tree
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
        InternalStringBuilder sb = new InternalStringBuilder(1024);
        StringBuilderRenderAppender writer = new StringBuilderRenderAppender(sb);

        // this is the treeId from the request.  If there was an tree expansion this will be
        // non-null and it identifies what tree had the expansion request.
        // we need to qualify the tree based upon the tagId
        assert(_trs.tagId != null);
        _trs.tagId = getIdForTagId(_trs.tagId);

        String treeId = request.getParameter(TreeElement.TREE_ID);
        if (treeId != null && _trs.tagId.equals(treeId)) {
            TreeHelpers.processTreeRequest(treeId, treeRoot, request, response);
        }

        // check for the nodes that are expanded...
        // Add the script support for the tree.
        if (_trs.runAtClient) {
            IScriptReporter sr = getScriptReporter();
            if (sr == null) {
                String s = Bundle.getString("Tags_TreeRunAtClientSC", null);
                registerTagError(s, null);
                reportErrors();
                return;
            }

            ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request);
            if (!srs.isFeatureWritten(CoreScriptFeature.DYNAMIC_INIT)) {
                String s = Bundle.getString("Tags_TreeHtmlRunAtClient", null);
                registerTagError(s, null);
                reportErrors();
                return;
            }

            assert(treeRoot instanceof ITreeRootElement);
            ITreeRootElement tre = (ITreeRootElement) treeRoot;

            Object[] args = new Object[8];
            args[0] = _iState.getImageRoot() + "/";
            args[1] = tre.getObjectName();
            args[2] = _iState.getNodeCollapsedImage();
            args[3] = _iState.getNodeExpandedImage();
            args[4] = _iState.getLastNodeCollapsedImage();
            args[5] = _iState.getLastNodeExpandedImage();
            args[6] = Bundle.getString("Tags_TreeAltTextExpand", null);
            args[7] = Bundle.getString("Tags_TreeAltTextCollapse", null);
            srs.writeFeature(sr, writer, CoreScriptFeature.TREE_INIT, false, false, args);

            tre.setTreeRenderState(_trs);
            tre.setInheritableState(_iState);
        }

        // create a containing tree level <div> and place the tree level styles on it.
        _divState.styleClass = _treeStyleClass;
        _divState.style = _treeStyle;
        String divId = null;
        if (_renderTagIdLookup) {
            _divState.id = _trs.tagId;
            divId = _divState.id;
        }

        // if we are running on the client then we need to output the tree name into the top level tree <div> tag
        if (_trs.runAtClient) {
            _divState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, "netui:treeName",
                    ((INameable) treeRoot).getObjectName());
        }

        TagRenderingBase divRenderer = TagRenderingBase.Factory.getRendering(TagRenderingBase.DIV_TAG, request);
        divRenderer.doStartTag(writer, _divState);
        sb.append("\n");

        // Render the tree.
        AttributeRenderer extraAttrs = new AttributeRenderer();
        TagTreeRenderer ttr = new TagTreeRenderer(this, _trs, request, response, pageContext.getServletContext());
        ttr.render(sb, treeRoot, 0, extraAttrs, _iState);
        if (hasErrors()) {
            reportErrors();
            return;
        }
View Full Code Here

    protected String getErrorMessage(ActionMessage report, String bundleName)
            throws JspException
    {
        String key = report.getKey();
        Object[] messageArgs = report.getValues();
        PageContext pageContext = getPageContext();

        String message = null;
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        if (key.length() == 0) {
            return "";
        }
        else {
            ModuleConfig curModuleConfig = RequestUtils.getModuleConfig(pageContext);
            ServletContext servletContext = pageContext.getServletContext();
           
            // First, look in the message bundle for a shared flow that was involved in this request.
            String sharedFlowModulePath = InternalUtils.getForwardingModule(pageContext.getRequest());
            if (sharedFlowModulePath != null &&
                (curModuleConfig == null || !sharedFlowModulePath.equals(curModuleConfig.getPrefix()))) {
                ModuleConfig sfModule = InternalUtils.getModuleConfig(sharedFlowModulePath, servletContext);
                if (bundleName != null || !isMissingUserDefaultMessages(sfModule)) {
                    String msgAttr = (bundleName != null ? bundleName : Globals.MESSAGES_KEY) + sfModule.getPrefix();
View Full Code Here

    public void setUp()
    {
        tag = new JspFlipTag(FeatureState.ENABLED);
        featureService = mock(FeatureService.class);

        final PageContext pageContext = mock(PageContext.class);
        tag.setPageContext(pageContext);
        request = mock(HttpServletRequest.class);
        when(pageContext.getRequest()).thenReturn(request);

        FlipContext.setFeatureService(null);
    }
View Full Code Here

   **/
  public static void runTests (DataInput pIn,
             PrintStream pOut)
    throws IOException
  {
    PageContext context = createTestContext ();

    while (true) {
      String str = pIn.readLine ();
      if (str == null) break;
      if (str.startsWith ("#") ||
View Full Code Here

   * Creates and returns the test PageContext that will be used for
   * the tests.
   **/
  static PageContext createTestContext ()
  {
    PageContext ret = new PageContextImpl ();

    // Create some basic values for lookups
    ret.setAttribute ("val1a", "page-scoped1", PageContext.PAGE_SCOPE);
    ret.setAttribute ("val1b", "request-scoped1", PageContext.REQUEST_SCOPE);
    ret.setAttribute ("val1c", "session-scoped1", PageContext.SESSION_SCOPE);
    ret.setAttribute ("val1d", "app-scoped1", PageContext.APPLICATION_SCOPE);

    // Create a bean
    {
      Bean1 b1 = new Bean1 ();
      b1.setBoolean1 (true);
      b1.setByte1 ((byte) 12);
      b1.setShort1 ((short) -124);
      b1.setChar1 ('b');
      b1.setInt1 (4);
      b1.setLong1 (222423);
      b1.setFloat1 ((float) 12.4);
      b1.setDouble1 (89.224);
      b1.setString1 ("hello");
      b1.setStringArray1 (new String [] {
  "string1",
  "string2",
  "string3",
  "string4"
      });
      {
  List l = new ArrayList ();
  l.add (new Integer (14));
  l.add ("another value");
  l.add (b1.getStringArray1 ());
  b1.setList1 (l);
      }
      {
  Map m = new HashMap ();
  m.put ("key1", "value1");
  m.put (new Integer (14), "value2");
  m.put (new Long (14), "value3");
  m.put ("recurse", b1);
  b1.setMap1 (m);
      }
      ret.setAttribute ("bean1a", b1);

      Bean1 b2 = new Bean1 ();
      b2.setInt2 (new Integer (-224));
      b2.setString2 ("bean2's string");
      b1.setBean1 (b2);

      Bean1 b3 = new Bean1 ();
      b3.setDouble1 (1422.332);
      b3.setString2 ("bean3's string");
      b2.setBean2 (b3);
    }

    // Create the public/private beans
    {
      ret.setAttribute ("pbean1", Factory.createBean1 ());
      ret.setAttribute ("pbean2", Factory.createBean2 ());
      ret.setAttribute ("pbean3", Factory.createBean3 ());
      ret.setAttribute ("pbean4", Factory.createBean4 ());
      ret.setAttribute ("pbean5", Factory.createBean5 ());
      ret.setAttribute ("pbean6", Factory.createBean6 ());
      ret.setAttribute ("pbean7", Factory.createBean7 ());
    }

    // Create the empty tests
    {
      Map m = new HashMap ();
      m.put ("emptyArray", new Object [0]);
      m.put ("nonemptyArray", new Object [] {"abc"});
      m.put ("emptyList", new ArrayList ());
      {
  List l = new ArrayList ();
  l.add ("hello");
  m.put ("nonemptyList", l);
      }
      m.put ("emptyMap", new HashMap ());
      {
  Map m2 = new HashMap ();
  m2.put ("a", "a");
  m.put ("nonemptyMap", m2);
      }
      m.put ("emptySet", new HashSet ());
      {
  Set s = new HashSet ();
  s.add ("hello");
  m.put ("nonemptySet", s);
      }
      ret.setAttribute ("emptyTests", m);
    }

    return ret;
  }
View Full Code Here

TOP

Related Classes of javax.servlet.jsp.PageContext

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.