Example usage for javax.servlet.jsp PageContext getAttribute

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

Introduction

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

Prototype


abstract public Object getAttribute(String name);

Source Link

Document

Returns the object associated with the name in the page scope or null if not found.

Usage

From source file:com.crownpartners.cq.quickstart.core.component.AbstractComponent.java

/**
 * Get all important objects from pageContext.
 * // w w  w.ja  va 2s.  c  o  m
 * @param pageContext
 *            the page context.
 */
public AbstractComponent(final PageContext pageContext) {
    this(pageContext, (Resource) pageContext.getAttribute("resource"));
}

From source file:com.crownpartners.cq.quickstart.core.component.AbstractComponent.java

/**
 * Construct the component model from the given resource instead of the resource found in the page context. Page
 * context is still use for retrieving other values such as request & response objects.
 * //from w  w  w.  ja v a 2s . com
 * @param pageContext
 *            the page context
 * @param resource
 *            the resource
 */
public AbstractComponent(final PageContext pageContext, final Resource resource) {
    if (pageContext == null) {
        throw new IllegalArgumentException("pageContext must not be null.");
    }

    this.pageContext = pageContext;

    this.slingRequest = (SlingHttpServletRequest) pageContext.getAttribute("slingRequest");
    this.slingResponse = (SlingHttpServletResponse) pageContext.getAttribute("slingResponse");
    this.slingScriptHelper = (SlingScriptHelper) pageContext.getAttribute("sling");
    this.pageManager = (PageManager) pageContext.getAttribute("pageManager");

    this.currentNode = (Node) pageContext.getAttribute("currentNode");
    this.currentDesign = (Design) pageContext.getAttribute("currentDesign");
    this.resourceDesign = (Design) pageContext.getAttribute("resourceDesign");
    this.currentStyle = (Style) pageContext.getAttribute("currentStyle");
    this.editContext = (EditContext) pageContext.getAttribute("editContext");

    this.wcmMode = WCMMode.fromRequest(slingRequest);
    this.authorMode = wcmMode == WCMMode.EDIT || wcmMode == WCMMode.DESIGN;
    this.selectors = slingRequest.getRequestPathInfo().getSelectors();

    this.resource = resource;
    this.resourceResolver = resource.getResourceResolver();
    this.properties = resource.adaptTo(ValueMap.class);

    this.currentPage = pageManager.getContainingPage(resource);
    if (currentPage != null) {
        this.pageProperties = new HierarchyNodeInheritanceValueMap(currentPage.getContentResource());
    } else {
        this.pageProperties = null;
    }

    log.debug("Initializing component {}", this.getClass().getName());

    final ComponentAnnotationParser parser = new ComponentAnnotationParser();
    parser.parse(this);

    init();
}

From source file:jp.terasoluna.fw.web.struts.taglib.PageLinksTag.java

/**
 * wKEYl?^Ulp?B//  www .j av a 2  s . c  o  m
 * ?A?keynull???AIllegalArgumentException??B
 * 
 * @param pageContext y?[WReLXg
 * @param key FLGKEY
 * @return wKEY?o?tO
 */
protected boolean getPageContextFlg(PageContext pageContext, String key) {
    //y?[WReLXgtO?B
    Object obj = pageContext.getAttribute(key);
    Boolean bol = new Boolean(false);
    if (obj != null && obj instanceof Boolean) {
        bol = (Boolean) obj;
    }
    return bol.booleanValue();
}

From source file:org.displaytag.localization.I18nJstlAdapter.java

/**
 * @see I18nResourceProvider#getResource(String, String, Tag, PageContext)
 *//*from   w w w  .j av  a  2 s . c o m*/
public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext) {

    // if titleKey isn't defined either, use property
    String key = (resourceKey != null) ? resourceKey : defaultValue;
    String title = null;
    ResourceBundle bundle = null;

    // jakarta jstl implementation, there is no other way to get the bundle from the parent fmt:bundle tag
    Tag bundleTag = TagSupport.findAncestorWithClass(tag, BundleSupport.class);
    if (bundleTag != null) {
        BundleSupport parent = (BundleSupport) bundleTag;
        if (key != null) {
            String prefix = parent.getPrefix();
            if (prefix != null) {
                key = prefix + key;
            }
        }
        bundle = parent.getLocalizationContext().getResourceBundle();
    }

    // resin jstl implementation, more versatile (we don't need to look up resin classes)
    if (bundle == null) {
        Object cauchoBundle = pageContext.getAttribute("caucho.bundle"); //$NON-NLS-1$
        if (cauchoBundle != null && cauchoBundle instanceof LocalizationContext) {
            bundle = ((LocalizationContext) cauchoBundle).getResourceBundle();

            // handle prefix just like resin does
            String prefix = (String) pageContext.getAttribute("caucho.bundle.prefix"); //$NON-NLS-1$
            if (prefix != null) {
                key = prefix + key;
            }
        }
    }

    // standard jstl localizationContest
    if (bundle == null) {
        // check for the localizationContext in applicationScope, set in web.xml
        LocalizationContext localization = BundleSupport.getLocalizationContext(pageContext);

        if (localization != null) {
            bundle = localization.getResourceBundle();
        }
    }

    if (bundle != null) {
        try {
            title = bundle.getString(key);
        } catch (MissingResourceException e) {
            log.debug(Messages.getString("Localization.missingkey", key)); //$NON-NLS-1$

            // if user explicitely added a titleKey we guess this is an error
            if (resourceKey != null) {
                title = UNDEFINED_KEY + resourceKey + UNDEFINED_KEY;
            }
        }
    }

    return title;
}

From source file:org.qifu.ui.UIComponentValueUtils.java

public static boolean foundIfResult(PageContext pageContext) {
    if (pageContext.getAttribute(UIComponent.IfResultVariableName) != null) {
        return true;
    }//from   w w w. ja  va 2s.c  o m
    return false;
}

From source file:org.qifu.ui.UIComponentValueUtils.java

public static boolean getIfResult(PageContext pageContext) {
    if (pageContext.getAttribute(UIComponent.IfResultVariableName) != null) {
        return (Boolean) pageContext.getAttribute(UIComponent.IfResultVariableName);
    }//from w  w  w .ja  v a2  s  .  c  o m
    return false;
}

From source file:org.qifu.ui.UIComponentValueUtils.java

public static Object getObjectFromPageContextOrRequest(PageContext pageContext, String paramName) {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    /**/*from w  ww. java  2s.co  m*/
     * ?: pageContext.getAttribute > request.getParameter > request.getAttribute
     */
    if (pageContext.getAttribute(paramName) != null) {
        return pageContext.getAttribute(paramName);
    }
    return (request.getParameter(paramName) != null ? request.getParameter(paramName)
            : request.getAttribute(paramName));
}

From source file:org.qifu.ui.UIComponentValueUtils.java

public static Object getOgnlProcessObjectFromPageContextOrRequest(PageContext pageContext, String expression) {
    Map<String, Object> ognlRoot = new HashMap<String, Object>();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    Enumeration<String> pcNames = pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE);
    Enumeration<String> pNames = request.getParameterNames();
    Enumeration<String> aNames = request.getAttributeNames();
    /**//w w w  . j a v a2  s . c  om
     * ognlRoot , ?: pageContext.getAttribute > request.getParameter > request.getAttribute
     */
    while (pcNames.hasMoreElements()) {
        String key = pcNames.nextElement();
        ognlRoot.put(key, pageContext.getAttribute(key));
    }
    while (pNames.hasMoreElements()) {
        String key = pNames.nextElement();
        if (ognlRoot.get(key) == null) {
            ognlRoot.put(key, request.getParameter(key));
        }
    }
    while (aNames.hasMoreElements()) {
        String key = aNames.nextElement();
        if (ognlRoot.get(key) == null) {
            ognlRoot.put(key, request.getAttribute(key));
        }
    }
    if (ognlRoot.size() == 0) {
        ognlRoot = null;
        return null;
    }
    Object val = null;
    try {
        val = Ognl.getValue(expression, ognlRoot);
    } catch (OgnlException e) {
        //e.printStackTrace();
    }
    ognlRoot.clear();
    ognlRoot = null;
    return val;
}

From source file:org.squale.welcom.outils.Access.java

/**
 * Calcule le droit du tag .../* ww w.j a  va  2s . c om*/
 * 
 * @param pageContext contexte
 * @param accessKey valeur de l'accessKey du tag
 * @param forceReadWrite si on est on forcage
 * @param overridePageAccess sur on surchage le page page
 * @return le droit calcul
 * @throws JspException leve une execption si le droit retoun n'est pas NONE, READWRITE, READONLY
 */
public static String computeTagReadWriteAccess(PageContext pageContext, String accessKey,
        boolean forceReadWrite, boolean overridePageAccess) throws JspException {
    // Recupere le droit sur la page
    String pageAccess = (String) pageContext.getAttribute("access");

    // Par defaut met un droit Lecture/Ecriture
    String accessTag = Access.READWRITE;

    // Retourne un accs /lecture ecriture si on force le flag en lecture
    // ecriture.
    // l'attribut accessKey est ignor sur le pageaccess est null
    if (forceReadWrite) {
        return accessTag;
    }

    if (overridePageAccess == false) {
        if (pageAccess == null) {
            overridePageAccess = true;
        } else {
            if (isNotPageAccess(pageAccess)) {
                throw new JspException(
                        "L'attribut accessKey doit retourner une valeur READWRITE ou READONLY ou NONE (cf getSecuritePage()) : "
                                + pageAccess);
            }
            accessTag = pageAccess;
        }
    }
    // Si on a definit un access sur le tag !
    if (!GenericValidator.isBlankOrNull(accessKey)) {

        String accessTagMerge = getAccessTagMergeWithPageAccess(pageContext, overridePageAccess, pageAccess,
                accessKey);
        if (accessTagMerge != null) {
            accessTag = accessTagMerge;
        }
    }

    return accessTag;
}

From source file:ru.runa.wf.web.customtag.impl.AbstractAutoCompletionComboBoxVarTag.java

private void displayComboboxScript(Script script, PageContext pageContext) {
    if (pageContext != null && pageContext.getAttribute(COMBOBOX_SCRIPT_RENDERED_ATTRIBUTE_NAME) == null) {
        script.addElement(//from ww  w .java  2  s .c om
                "function handleKeyUp(selectName,actorList,codeList) {\n inputElement = document.forms["
                        + formName + "].elements[selectName+'" + inputNameSuffix
                        + "'];\n selectElement = document.forms[" + formName
                        + "].elements[selectName];\n strText = '^'+inputElement.value;\n var numShown = 0;\n re = new RegExp(strText,'gi');\n selectElement.length = 0;\n for(i = 0; i < actorList.length; i++) {\n if(actorList[i].search(re) != -1) {\n selectElement[numShown] = new Option(actorList[i], codeList[i]);\n numShown++;\n }\n }\n }\n");
        script.addElement("function handleSelectClick(selectName) {\n selectElement = document.forms["
                + formName
                + "].elements[selectName];\n selectedValue = selectElement.options[selectElement.selectedIndex].text;\n selectedValue = selectedValue.replace(/_/g, '-') ; }\n");
        // script.addElement("function initpage() { inputElement = document.forms["
        // + formName + "]." + inputNameSuffix +
        // "; handleKeyUp(); inputElement.focus(); }\n");
        pageContext.setAttribute(COMBOBOX_SCRIPT_RENDERED_ATTRIBUTE_NAME, Boolean.TRUE);
    }
}