Example usage for javax.servlet.jsp PageContext PAGE_SCOPE

List of usage examples for javax.servlet.jsp PageContext PAGE_SCOPE

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext PAGE_SCOPE.

Prototype

int PAGE_SCOPE

To view the source code for javax.servlet.jsp PageContext PAGE_SCOPE.

Click Source Link

Document

Page scope: (this is the default) the named reference remains available in this PageContext until the return from the current Servlet.service() invocation.

Usage

From source file:org.hyperic.hq.ui.taglib.ConstantsTag.java

public void release() {
    super.release();
    className = symbol = var = scopeName = null;
    failmode = false;//from   w w w.j a v  a  2  s  . com
    failmode = scopeSpecified = false;
    scope = PageContext.PAGE_SCOPE;
}

From source file:org.hyperic.hq.ui.taglib.display.TableTag.java

/**
 * This functionality is borrowed from struts, but I've removed some struts
 * specific features so that this tag can be used both in a struts
 * application, and outside of one.//from   w w  w. j  a v  a2  s .c  om
 * 
 * Locate and return the specified bean, from an optionally specified scope,
 * in the specified page context. If no such bean is found, return
 * <code>null</code> instead.
 * 
 * @param pageContext
 *            Page context to be searched
 * @param name
 *            Name of the bean to be retrieved
 * @param scope
 *            Scope to be searched (page, request, session, application) or
 *            <code>null</code> to use <code>findAttribute()</code> instead
 * 
 * @exception JspException
 *                if an invalid scope name is requested
 */

public Object lookup(PageContext pageContext, String name, String scope) throws JspException {

    Object bean = null;
    if (scope == null)
        bean = pageContext.findAttribute(name);
    else if (scope.equalsIgnoreCase("page"))
        bean = pageContext.getAttribute(name, PageContext.PAGE_SCOPE);
    else if (scope.equalsIgnoreCase("request"))
        bean = pageContext.getAttribute(name, PageContext.REQUEST_SCOPE);
    else if (scope.equalsIgnoreCase("session"))
        bean = pageContext.getAttribute(name, PageContext.SESSION_SCOPE);
    else if (scope.equalsIgnoreCase("application"))
        bean = pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE);
    else {
        Object[] objs = { name, scope };
        if (prop.getProperty("error.msg.cant_find_bean") != null) {
            String msg = MessageFormat.format(prop.getProperty("error.msg.cant_find_bean"), objs);
            throw new JspException(msg);
        } else {
            throw new JspException("Could not find " + name + " in scope " + scope);

        }
    }

    return (bean);
}

From source file:org.jahia.modules.sociallib.taglib.GetSocialActivitiesTag.java

@Override
protected void resetState() {
    activityTypes = null;//  www . j  a  v a 2 s.  c  o  m
    limit = 100;
    offset = 0;
    pathFilter = null;
    scope = PageContext.PAGE_SCOPE;
    sourcePaths = null;
    startDate = 0;
    var = null;
    super.resetState();
}

From source file:org.jahia.taglibs.jcr.node.JCRFilterTag.java

@Override
protected void resetState() {
    list = null;//from   w  w  w.j a  v  a 2  s .co m
    node = null;
    properties = null;
    types = null;
    scope = PageContext.PAGE_SCOPE;
    var = null;
    super.resetState();
}

From source file:org.jahia.taglibs.jcr.node.JCRNodeTag.java

@Override
protected void resetState() {
    path = null;
    scope = PageContext.PAGE_SCOPE;
    var = null;
    uuid = null;
    super.resetState();
}

From source file:org.jahia.taglibs.query.QueryDefinitionTag.java

@Override
protected void resetState() {
    // let's reinitialize the tag variables to allow tag object reuse in
    // pooling.//from w  w  w . j  av  a 2  s  .c o  m
    qomBuilder = null;
    qomBeanName = null;
    queryObjectModel = null;
    id = null;
    var = null;
    statement = null;
    scope = PageContext.PAGE_SCOPE;
    limit = 0;
    offset = 0;
    super.resetState();
}

From source file:org.jahia.taglibs.search.ResultsTag.java

@Override
public int doEndTag() throws JspException {
    pageContext.removeAttribute(getVar(), PageContext.PAGE_SCOPE);
    pageContext.removeAttribute(getCountVar(), PageContext.PAGE_SCOPE);
    pageContext.removeAttribute(getApproxCountVar(), PageContext.PAGE_SCOPE);
    pageContext.removeAttribute(getSearchCriteriaVar(), PageContext.PAGE_SCOPE);
    pageContext.removeAttribute(getTermVar(), PageContext.PAGE_SCOPE);
    resetState();/*from  w ww .ja  v  a 2s  . c om*/

    return EVAL_PAGE;
}

From source file:org.jahia.taglibs.search.SuggestionsTag.java

@Override
public int doEndTag() throws JspException {
    if (suggestionVar != null) {
        pageContext.removeAttribute(suggestionVar, PageContext.PAGE_SCOPE);
    }/* w w  w. j  av  a2 s.  co  m*/
    return super.doEndTag();
}

From source file:org.jahia.taglibs.template.include.AreaTag.java

protected void findNode(RenderContext renderContext, Resource currentResource) throws IOException {
    Resource mainResource = renderContext.getMainResource();
    showAreaButton = renderContext.getMainResource().getPath().startsWith("/modules")
            || !SettingsBean.getInstance().isAreaAutoActivated();
    if (renderContext.isAjaxRequest() && renderContext.getAjaxResource() != null) {
        mainResource = renderContext.getAjaxResource();
    }//from  w w w  . j a va2 s  .  c  o m
    renderContext.getRequest().removeAttribute("skipWrapper");
    renderContext.getRequest().removeAttribute("inArea");
    pageContext.setAttribute("org.jahia.emptyArea", Boolean.TRUE, PageContext.PAGE_SCOPE);
    try {
        // path is null in main resource display
        Template t = (Template) renderContext.getRequest().getAttribute("previousTemplate");
        templateNode = t;

        if ("absoluteArea".equals(moduleType)) {
            // No more areas in an absolute area
            renderContext.getRequest().setAttribute("previousTemplate", null);
            JCRNodeWrapper main = null;
            try {
                main = renderContext.getMainResource().getNode();
                if (level != null && main.getDepth() >= level + 3) {
                    node = (JCRNodeWrapper) main.getAncestor(level + 3);
                } else if (level == null) {
                    node = renderContext.getSite().getHome();
                } else {
                    return;
                }
                if (node == null) {
                    return;
                }
                if ((limitedAbsoluteAreaEdit && !mainResource.getNode().getPath().equals(node.getPath()))
                        || (mainResource.getNode().getPath().startsWith("/modules")
                                && mainResource.getNode().isNodeType("jnt:template"))) {
                    parameters.put("readOnly", "true");
                    editable = false;
                    renderContext.getRequest().setAttribute("inArea", Boolean.TRUE);
                }

                if (logger.isDebugEnabled()) {
                    logger.debug("Looking for absolute area " + path + ", will be searched in node "
                            + node.getPath() + " saved template = "
                            + (templateNode != null ? templateNode.serialize() : "none")
                            + ", previousTemplate set to null");
                }
                node = node.getNode(path);
                pageContext.setAttribute("org.jahia.emptyArea", Boolean.FALSE, PageContext.PAGE_SCOPE);
            } catch (RepositoryException e) {
                if (node != null) {
                    path = node.getPath() + "/" + path;
                }
                node = null;
                if (editable) {
                    missingResource(renderContext, currentResource);
                }
            } finally {
                if (node == null && logger.isDebugEnabled()) {
                    if (level == null) {
                        logger.debug(
                                "Cannot get a node {}, relative to the home page of site {}"
                                        + " for main resource {}",
                                new String[] { path,
                                        main != null && main.getResolveSite() != null
                                                ? main.getResolveSite().getPath()
                                                : null,
                                        main != null ? main.getPath() : null });
                    } else {
                        logger.debug("Cannot get a node {}, with level {} for main resource {}", new String[] {
                                path, String.valueOf(level), main != null ? main.getPath() : null });
                    }
                }
            }
        } else if (path != null) {
            if (!path.startsWith("/")) {
                List<JCRNodeWrapper> nodes = new ArrayList<JCRNodeWrapper>();
                if (t != null) {
                    for (Template currentTemplate : t.getNextTemplates()) {
                        nodes.add(0, mainResource.getNode().getSession()
                                .getNodeByIdentifier(currentTemplate.getNode()));
                    }
                }
                nodes.add(mainResource.getNode());
                boolean isCurrentResource = false;
                if (areaAsSubNode) {
                    nodes.add(0, currentResource.getNode());
                    isCurrentResource = true;
                }
                boolean found = false;
                boolean notMainResource = false;

                Set<String> allPaths = renderContext.getRenderedPaths();
                for (JCRNodeWrapper node : nodes) {
                    if (!path.equals("*") && node.hasNode(path)
                            && !allPaths.contains(node.getPath() + "/" + path)) {
                        notMainResource = mainResource.getNode() != node && !node.getPath()
                                .startsWith(renderContext.getMainResource().getNode().getPath());
                        this.node = node.getNode(path);
                        if (currentResource.getNode().getParent().getPath().equals(this.node.getPath())) {
                            this.node = null;
                        } else {
                            // now let's check if the content node matches the areaType. If not it means we have a
                            // conflict with another content created outside of the content of the area (DEVMINEFI-223)
                            if (!this.node.isNodeType(areaType)
                                    && !this.node.isNodeType("jmix:skipConstraintCheck")) {
                                //                                    conflictsWith = this.node.getPath();
                                found = false;
                                this.node = null;
                                break;
                            } else {
                                found = true;
                                pageContext.setAttribute("org.jahia.emptyArea", Boolean.FALSE,
                                        PageContext.PAGE_SCOPE);
                                // if the processed resource is an area, set area path to this node, else set it to the generated node.
                                renderContext.getRequest().setAttribute(
                                        AreaResourceCacheKeyPartGenerator.AREA_PATH,
                                        currentResource.getNode().isNodeType("jnt:area")
                                                ? currentResource.getNodePath()
                                                : this.node.getPath());
                                break;
                            }
                        }
                    }
                    if (t != null && !isCurrentResource) {
                        t = t.getNext();
                    }
                    isCurrentResource = false;
                }
                renderContext.getRequest().setAttribute("previousTemplate", t);
                if (logger.isDebugEnabled()) {
                    String tempNS = (templateNode != null) ? templateNode.serialize() : null;
                    String prevNS = (t != null) ? t.serialize() : null;
                    logger.debug("Looking for local area " + path + ", will be searched in node "
                            + (node != null ? node.getPath() : null) + " saved template = " + tempNS
                            + ", previousTemplate set to " + prevNS);
                }
                boolean templateEdit = mainResource.getModuleParams().containsKey("templateEdit")
                        && mainResource.getModuleParams().get("templateEdit")
                                .equals(node.getParent().getIdentifier());
                if (notMainResource && !templateEdit) {
                    renderContext.getRequest().setAttribute("inArea", Boolean.TRUE);
                }
                if (!found) {
                    missingResource(renderContext, currentResource);
                }
            } else if (path.startsWith("/")) {
                JCRSessionWrapper session = mainResource.getNode().getSession();

                // No more areas in an absolute area
                renderContext.getRequest().setAttribute("previousTemplate", null);

                if (logger.isDebugEnabled()) {
                    logger.debug("Looking for absolute area " + path + ", will be searched in node "
                            + (node != null ? node.getPath() : null) + " saved template = "
                            + (templateNode != null ? templateNode.serialize() : "none")
                            + ", previousTemplate set to null");

                }
                try {
                    node = (JCRNodeWrapper) session.getItem(path);
                    pageContext.setAttribute("org.jahia.emptyArea", Boolean.FALSE, PageContext.PAGE_SCOPE);
                } catch (PathNotFoundException e) {
                    missingResource(renderContext, currentResource);
                }
            }
            renderContext.getRequest().setAttribute("skipWrapper", Boolean.TRUE);
        } else {
            renderContext.getRequest().setAttribute("previousTemplate", null);
            renderContext.getRequest().removeAttribute("skipWrapper");
            node = mainResource.getNode();
            pageContext.setAttribute("org.jahia.emptyArea", Boolean.FALSE, PageContext.PAGE_SCOPE);
        }
    } catch (RepositoryException e) {
        logger.error(e.getMessage(), e);
    }

    if (node == null && logger.isDebugEnabled()) {
        logger.debug("Can not find the area node for path " + path + " with templates "
                + (templateNode != null ? templateNode.serialize() : "none") + "rendercontext " + renderContext
                + " main resource " + mainResource + " current resource " + currentResource);
    }
}

From source file:org.jahia.taglibs.uicomponents.i18n.DisplayLanguageSwitchLinkTag.java

public int doStartTag() {
    try {/* w  ww .  j a  va 2 s . com*/
        final StringBuilder buff = new StringBuilder();

        final boolean isCurrentBrowsingLanguage = isCurrentBrowsingLanguage(languageCode);
        final boolean isRedirectToHomePageActivated = InitLangBarAttributes.GO_TO_HOME_PAGE
                .equals(onLanguageSwitch);

        if (!isCurrentBrowsingLanguage) {
            if (isRedirectToHomePageActivated) {
                if (redirectCssClassName == null || redirectCssClassName.length() == 0) {
                    redirectCssClassName = InitLangBarAttributes.REDIRECT_DEFAULT_STYLE;
                }
                buff.append("<div class='");
                buff.append(redirectCssClassName);
                buff.append("'>");
            }
            buff.append("<a href='");
            final String link;
            if (onLanguageSwitch == null || onLanguageSwitch.length() == 0
                    || InitLangBarAttributes.STAY_ON_CURRENT_PAGE.equals(onLanguageSwitch)) {
                link = generateCurrentNodeLangSwitchLink(languageCode) + "##requestParameters##";

            } else if (isRedirectToHomePageActivated) {
                link = generateNodeLangSwitchLink(rootPage, languageCode) + "##requestParameters##";

            } else {
                throw new JspTagException("Unknown onLanguageSwitch attribute value " + onLanguageSwitch);
            }

            buff.append(StringEscapeUtils.escapeXml(link));
            if (urlVar != null && urlVar.length() > 0) {
                pageContext.setAttribute(urlVar, link);
            }
            buff.append("' ");
            buff.append("title='");
            if (isRedirectToHomePageActivated) {
                titleKey += "." + onLanguageSwitch;
            }
            buff.append(getMessage(titleKey, title));
            buff.append("'>");
        } else {
            buff.append("<span>");
            if (urlVar != null)
                pageContext.removeAttribute(urlVar, PageContext.PAGE_SCOPE);
        }

        String attributeValue = null;
        if (linkKind == null || linkKind.length() == 0 || LANGUAGE_CODE.equals(linkKind)
                || linkKind.startsWith(FLAG)) {
            attributeValue = languageCode;
            buff.append(languageCode);

        } else if (NAME_CURRENT_LOCALE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(getRenderContext().getMainResource().getLocale());
            attributeValue = value;
            buff.append(value);

        } else if (NAME_IN_LOCALE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale);
            attributeValue = value;
            buff.append(value);

        } else if (LETTER.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale).substring(0, 1).toUpperCase();
            attributeValue = value;
            buff.append(value);

        } else if (DOUBLE_LETTER.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale).substring(0, 2).toUpperCase();
            attributeValue = value;
            buff.append(value);

        } else if (ISOLOCALECOUNTRY_CODE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            StringBuilder value = new StringBuilder(locale.getLanguage().toUpperCase());
            if (locale.getCountry() != null && locale.getCountry().length() != 0) {
                value.append("(").append(locale.getCountry()).append(")");
            }
            attributeValue = value.toString();
            buff.append(value);

        } else {
            throw new JspTagException("Unknown linkKind value '" + linkKind + "'");
        }

        if (getVar() != null) {
            pageContext.setAttribute(getVar(), attributeValue);
        }

        if (!isCurrentBrowsingLanguage) {
            buff.append("</a>");
            if (isRedirectToHomePageActivated)
                buff.append("</div>");
        } else {
            buff.append("</span>");
        }

        if (display) {
            pageContext.getOut().print(buff.toString());
        }

    } catch (final Exception e) {
        logger.error("Error while getting language switch URL", e);
    }
    return SKIP_BODY;
}