Java Code Examples for javax.portlet.PortletSession#PORTLET_SCOPE

The following examples show how to use javax.portlet.PortletSession#PORTLET_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: 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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: PortletSessionScopedConfig.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a portlet session scoped bean summary for display
 * 
 * @return  The configuration summary string
 * 
 */
public String getConfigAsString() {
   StringBuilder txt = new StringBuilder(128);
   for (Class<?> c : class2Anno.keySet()) {
      txt.append("\n\tClass: ").append(c.getCanonicalName());
      boolean ps = (class2Anno.get(c).value() == PortletSession.PORTLET_SCOPE);
      txt.append(", Portlet scoped: ").append(ps);
   }
   return txt.toString();
}
 
Example 12
Source File: PortletSessionScopedConfig.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the given bean class is portlet or application scoped.
 * 
 * @param bean    The bean class
 * @return        <code>true</code> if the bean is portlet scoped
 */
public Boolean isPortletScoped(Class<?> beanClass) {
   Boolean ps = null;
   for (Contextual<?> b : context2Anno.keySet()) {
      if (b instanceof Bean) {
         Bean<?> bean = (Bean<?>)b;
         if (beanClass.isAssignableFrom(bean.getBeanClass())) {
            ps = (context2Anno.get(b).value() == PortletSession.PORTLET_SCOPE);
            break;
         }
      }
   }
   return ps;
}
 
Example 13
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);

}