* @return The context
* @throws ProcessingException If the context is not available.
*/
public SessionContext getSessionContext(String name)
throws ProcessingException {
ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel();
SessionContext context = this.getContext( objectModel, name );
if (name.equals(PortalConstants.SESSION_CONTEXT_NAME) && context == null) {
Request req = ObjectModelHelper.getRequest(objectModel);
Session session = req.getSession(false);
if (session != null) {
PortalManager portal = null;
try {
portal = (PortalManager)manager.lookup(PortalManager.ROLE);
// is this an external resource which wants access to a coplet?
String value = req.getParameter("portalcontext");
if (value != null) {
int sepOne, sepTwo;
sepOne = value.indexOf('_');
if (sepOne != -1) {
sepTwo = value.indexOf('_', sepOne+1);
if (sepTwo != -1) {
String copletIdentifier = value.substring(0, sepOne);
String copletID = value.substring(sepOne+1, sepTwo);
String copletNumber = value.substring(sepTwo+1);
if (copletIdentifier.equals("coplet")) {
Map info = new HashMap(3);
SessionContextImpl.copletInfo.set(info);
SourceParameters pars = new SourceParameters();
info.put(PortalConstants.COPLETINFO_PARAMETERS, pars);
pars.setSingleParameterValue(PortalConstants.PARAMETER_ID, copletID);
pars.setSingleParameterValue(PortalConstants.PARAMETER_NUMBER, copletNumber);
pars.setSingleParameterValue(PortalConstants.PARAMETER_MEDIA, portal.getMediaType());
info.put(PortalConstants.COPLETINFO_STATUSPROFILE, portal.getStatusProfile());
info.put(PortalConstants.COPLETINFO_PORTALURI, req.getRequestURI());
}
}
}
} else {
if (SessionContextImpl.copletInfo.get() == null) {
throw new ProcessingException("Portal context not available outside a coplet.");
}
}
context = new SessionContextImpl(name, objectModel, portal);
objectModel.put(this.getClass().getName()+name, context);
} catch (SAXException se) {
throw new ProcessingException("SAXException", se);
} catch (IOException ioe) {
throw new ProcessingException("IOException", ioe);
} catch (ComponentException ce) {
throw new ProcessingException("Unable to lookup portal.", ce);
} finally {
manager.release(portal);
}
}
}
return context;
}