Java Code Examples for javax.portlet.PortletSession#APPLICATION_SCOPE

The following examples show how to use javax.portlet.PortletSession#APPLICATION_SCOPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void setAttribute(String name, Object value, int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		if (value != null) {
			this.portletAttributes.put(name, value);
		}
		else {
			this.portletAttributes.remove(name);
		}
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		if (value != null) {
			this.applicationAttributes.put(name, value);
		}
		else {
			this.applicationAttributes.remove(name);
		}
	}
}
 
Example 2
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void setAttribute(String name, Object value, int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		if (value != null) {
			this.portletAttributes.put(name, value);
		}
		else {
			this.portletAttributes.remove(name);
		}
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		if (value != null) {
			this.applicationAttributes.put(name, value);
		}
		else {
			this.applicationAttributes.remove(name);
		}
	}
}
 
Example 3
Source File: PortletSessionImpl.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public Enumeration<String> getAttributeNames(int scope) {
	// Return all attribute names in the nested HttpSession object.
    if (scope == PortletSession.APPLICATION_SCOPE) {
        return httpSession.getAttributeNames();
    }
    // Return attribute names with the portlet-scoped prefix.
    Vector<String> portletScopedNames = new Vector<String>();
    for (Enumeration<String> en = httpSession.getAttributeNames();
    en.hasMoreElements(); ) {
    	String name = en.nextElement();
    	if (isInCurrentPortletScope(name)) {
    		portletScopedNames.add(
    				PortletSessionUtil.decodeAttributeName(name));
    	}
    }
    return portletScopedNames.elements();
    
}
 
Example 4
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object getAttribute(String name, int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		return this.portletAttributes.get(name);
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		return this.applicationAttributes.get(name);
	}
	return null;
}
 
Example 5
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Enumeration<String> getAttributeNames(int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		return Collections.enumeration(this.portletAttributes.keySet());
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		return Collections.enumeration(this.applicationAttributes.keySet());
	}
	return null;
}
 
Example 6
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void removeAttribute(String name, int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		this.portletAttributes.remove(name);
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		this.applicationAttributes.remove(name);
	}
}
 
Example 7
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getAttributeMap(int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		return Collections.unmodifiableMap(this.portletAttributes);
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		return Collections.unmodifiableMap(this.applicationAttributes);
	}
	else {
		return Collections.emptyMap();
	}
}
 
Example 8
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object getAttribute(String name, int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		return this.portletAttributes.get(name);
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		return this.applicationAttributes.get(name);
	}
	return null;
}
 
Example 9
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Enumeration<String> getAttributeNames(int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		return Collections.enumeration(new LinkedHashSet<String>(this.portletAttributes.keySet()));
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		return Collections.enumeration(new LinkedHashSet<String>(this.applicationAttributes.keySet()));
	}
	return null;
}
 
Example 10
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void removeAttribute(String name, int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		this.portletAttributes.remove(name);
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		this.applicationAttributes.remove(name);
	}
}
 
Example 11
Source File: MockPortletSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getAttributeMap(int scope) {
	if (scope == PortletSession.PORTLET_SCOPE) {
		return Collections.unmodifiableMap(this.portletAttributes);
	}
	else if (scope == PortletSession.APPLICATION_SCOPE) {
		return Collections.unmodifiableMap(this.applicationAttributes);
	}
	else {
		return Collections.emptyMap();
	}
}
 
Example 12
Source File: PortletSessionImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public void removeAttribute(String name, int scope) {
	ArgumentUtility.validateNotNull("attributeName", name);
	if (scope == PortletSession.APPLICATION_SCOPE) {
		httpSession.removeAttribute(name);
	} else {
		httpSession.removeAttribute(createPortletScopedId(name));
	}
}
 
Example 13
Source File: PortletSessionImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public void setAttribute(String name, Object value, int scope) {
	ArgumentUtility.validateNotNull("attributeName", name);
	if (scope == PortletSession.APPLICATION_SCOPE) {
		httpSession.setAttribute(name, value);
	} else {
		httpSession.setAttribute(createPortletScopedId(name),  value);
	}
}
 
Example 14
Source File: EnvironmentTests_PortletSessionUtil_ApiRender.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
    throws PortletException, IOException {

  long tid = Thread.currentThread().getId();
  portletReq.setAttribute(THREADID_ATTR, tid);

  PrintWriter writer = portletResp.getWriter();

  JSR286ApiTestCaseDetails tcd = new JSR286ApiTestCaseDetails();

  // Create result objects for the tests

  /* TestCase: V2EnvironmentTests_PortletSessionUtil_ApiRender_decodeAttributeName1 */
  /* Details: "Method decodeAttributeName(String): Returns a String */
  /* containing the decoded name of the attribute if the input name is */
  /* an encoded name in PORTLET_SCOPE" */
  TestResult tr0 = tcd
      .getTestResultFailed(V2ENVIRONMENTTESTS_PORTLETSESSIONUTIL_APIRENDER_DECODEATTRIBUTENAME1);
  portletReq.getPortletSession().setAttribute("javax.portlet.p.id?tr0", "true", PORTLET_SCOPE);
  if (PortletSessionUtil.decodeAttributeName("javax.portlet.p.id?tr0").equals("tr0")) {
    tr0.setTcSuccess(true);
  } else {
    tr0.appendTcDetail("Failed because decoded attribute name is not tr0 but "
        + PortletSessionUtil.decodeAttributeName("javax.portlet.p.id?tr0"));
  }
  tr0.writeTo(writer);

  /* TestCase: V2EnvironmentTests_PortletSessionUtil_ApiRender_decodeAttributeName2 */
  /* Details: "Method decodeAttributeName(String): Returns a String */
  /* containing the input name unchanged if the input name is in */
  /* APPLICATION_SCOPE " */
  TestResult tr1 = tcd
      .getTestResultFailed(V2ENVIRONMENTTESTS_PORTLETSESSIONUTIL_APIRENDER_DECODEATTRIBUTENAME2);
  portletReq.getPortletSession().setAttribute("javax.portlet.p.id?tr1", "true",
      APPLICATION_SCOPE);
  if (PortletSessionUtil.decodeAttributeName("javax.portlet.p.id?tr1").equals("tr1")) {
    tr1.setTcSuccess(true);
  } else {
    tr1.appendTcDetail("Failed because decoded attribute name is not tr1 but "
        + PortletSessionUtil.decodeAttributeName("javax.portlet.p.id?tr1"));
  }
  tr1.writeTo(writer);

  /* TestCase: V2EnvironmentTests_PortletSessionUtil_ApiRender_decodeScope1 */
  /* Details: "Method decodeScope(String): Returns the decoded */
  /* attribute scope for the input encoded attribute name" */
  TestResult tr2 =
      tcd.getTestResultFailed(V2ENVIRONMENTTESTS_PORTLETSESSIONUTIL_APIRENDER_DECODESCOPE1);
  if (PortletSessionUtil.decodeScope("javax.portlet.p.id?tr0") == PortletSession.PORTLET_SCOPE) {
    tr2.setTcSuccess(true);
  }
  tr2.writeTo(writer);

  /* TestCase: V2EnvironmentTests_PortletSessionUtil_ApiRender_decodeScope2 */
  /* Details: "Method decodeScope(String): Returns */
  /* PortletSession.APPLICATION_SCOPE if the attribute name is in */
  /* APPLICATION_SCOPE" */
  TestResult tr3 =
      tcd.getTestResultFailed(V2ENVIRONMENTTESTS_PORTLETSESSIONUTIL_APIRENDER_DECODESCOPE2);
  if (PortletSessionUtil.decodeScope("tr1") == PortletSession.APPLICATION_SCOPE) {
    tr3.setTcSuccess(true);
  }
  tr3.writeTo(writer);

  /* TestCase: V2EnvironmentTests_PortletSessionUtil_ApiRender_decodeScope3 */
  /* Details: "Method decodeScope(String): Returns */
  /* PortletSession.PORTLET_SCOPE if the attribute name is in */
  /* PORTLET_SCOPE" */
  TestResult tr4 =
      tcd.getTestResultFailed(V2ENVIRONMENTTESTS_PORTLETSESSIONUTIL_APIRENDER_DECODESCOPE3);
  if (PortletSessionUtil.decodeScope("javax.portlet.p.id?tr0") == PortletSession.PORTLET_SCOPE) {
    tr4.setTcSuccess(true);
  }
  tr4.writeTo(writer);

}
 
Example 15
Source File: PortletSessionImpl.java    From portals-pluto with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the attribute of the specified name under the given scope.
 * 
 * @param name  the attribute name.
 * @param scope  the scope under which the attribute object is stored.
 * @return the attribute object.
 */
public Object getAttribute(String name, int scope) {
	ArgumentUtility.validateNotNull("attributeName", name);
	String key = (scope == PortletSession.APPLICATION_SCOPE)
			? name : createPortletScopedId(name);
	return httpSession.getAttribute(key);
}