Package org.jasig.portal

Examples of org.jasig.portal.ChannelManager


                            ((IPrivileged) this.targetChannel).setPortalControlStructures(this.portcs);
                        }
                       
                        this.targetChannel.setRuntimeData(crd);
                       
                        final ChannelManager cm = this.portcs.getChannelManager();
                        cm.setChannelInstance(channelSubscribeId, this.targetChannel);
                       
                        this.renderChannel(this.targetChannel, contentHandler, printWriter);

                        return;
                    }
                    catch (Exception e) {
                        // if any of the above didn't work, fall back to the error channel
                        resetCError(ErrorCode.SET_RUNTIME_DATA_EXCEPTION, e, channelSubscribeId, this.targetChannel, "Channel failed a refresh attempt.");
                    }
                }
                else if (chFate.equals("restart")) {
                    final ChannelManager cm = this.portcs.getChannelManager();

                    try {
                        //Clean things up for the channel
                        if (this.targetChannel instanceof IResetableChannel) {
                            if (this.targetChannel instanceof IPrivileged) {
                                ((IPrivileged) this.targetChannel).setPortalControlStructures(this.portcs);
                            }
                           
                            this.targetChannel.setRuntimeData(this.runtimeData);

                            ((IResetableChannel) this.targetChannel).prepareForReset();
                        }

                        final ChannelRuntimeData crd = (ChannelRuntimeData) this.runtimeData.clone();
                        crd.clear();
                       
                        if ((this.targetChannel = cm.instantiateChannel(this.portcs.getHttpServletRequest(), this.portcs.getHttpServletResponse(), channelSubscribeId)) == null) {
                            resetCError(ErrorCode.GENERAL_ERROR, null, channelSubscribeId, null, "Channel failed to reinstantiate!");
                        }
                        else {
                            try {
                                if (this.targetChannel instanceof IPrivileged) {
                                    ((IPrivileged) this.targetChannel).setPortalControlStructures(this.portcs);
                                }
                               
                                this.targetChannel.setRuntimeData(crd);
                               
                                this.renderChannel(this.targetChannel, contentHandler, printWriter);
                               
                                return;
                            }
                            catch (Exception e) {
                                // if any of the above didn't work, fall back to the error channel
                                resetCError(ErrorCode.SET_RUNTIME_DATA_EXCEPTION, e, channelSubscribeId, this.targetChannel, "Channel failed a reload attempt.");
                                cm.setChannelInstance(channelSubscribeId, this);
                                log.error("an error occurred during channel reinitialization.", e);
                            }
                        }
                    }
                    catch (Exception e) {
View Full Code Here


          }
          ulm.addNode(channel,ulm.getParentId(destinationElementId),siblingId);
      }

      // Make sure ChannelManager knows about the new channel
      final ChannelManager channelManager = pcs.getChannelManager();
      channelManager.instantiateChannel(pcs.getHttpServletRequest(), pcs.getHttpServletResponse(), channel.getId());
     
      ulm.saveUserLayout();
  }
View Full Code Here

    }
          ulm.addNode(channel,ulm.getParentId(destinationElementId),siblingId);
    }

      // Make sure ChannelManager knows about the new channel
      final ChannelManager channelManager = pcs.getChannelManager();
      channelManager.instantiateChannel(pcs.getHttpServletRequest(), pcs.getHttpServletResponse(), channel.getId());
      saveLayout(true);
  }
View Full Code Here

     */
    public void renderState(HttpServletRequest req, HttpServletResponse res, IUserInstance userInstance) throws PortalException {
        final IPerson person = userInstance.getPerson();
        final LocaleManager localeManager = userInstance.getLocaleManager();
        final IUserPreferencesManager uPreferencesManager = userInstance.getPreferencesManager();
        final ChannelManager channelManager = userInstance.getChannelManager();
        final Object renderingLock = userInstance.getRenderingLock();
       
        UPFileSpec upfs = new UPFileSpec(req);
        String rootNodeId = upfs.getMethodNodeId();
        if (rootNodeId == null) {
            rootNodeId = UPFileSpec.USER_LAYOUT_ROOT_NODE;
        }
       
        // see if a new root target has been specified
        String newRootNodeId = req.getParameter("uP_detach_target");

        // set optimistic uPElement value
        UPFileSpec uPElement = new UPFileSpec(UPFileSpec.RENDER_METHOD, rootNodeId, null, null);

        if (newRootNodeId != null) {
            // set a new root
            uPElement.setMethodNodeId(newRootNodeId);
        }
       
        channelManager.setUPElement(uPElement);

        // proccess possible portlet action
        final IPortletWindowId targetedPortletWindowId = this.portletRequestParameterManager.getTargetedPortletWindowId(req);
        if (targetedPortletWindowId != null) {
            final PortletUrl portletUrl = this.portletRequestParameterManager.getPortletRequestInfo(req, targetedPortletWindowId);
           
            if (RequestType.ACTION.equals(portletUrl.getRequestType())) {
                final IPortletEntity targetedPortletEntity = this.portletWindowRegistry.getParentPortletEntity(req, targetedPortletWindowId);
                if (targetedPortletEntity != null) {
                    final String channelSubscribeId = targetedPortletEntity.getChannelSubscribeId();
                    final boolean actionExecuted = channelManager.doChannelAction(req, res, channelSubscribeId, false);
                   
                    if (actionExecuted) {
                        // The action completed, return immediately
                        return;
                    }
   
                    // The action didn't execute, continue and try to render normally
                }
            }
        }
       
        // process possible worker dispatch
        final boolean workerDispatched = this.processWorkerDispatchIfNecessary(req, res, uPreferencesManager, channelManager);
        if (workerDispatched) {
            //If a worker was dispatched to return immediately
            return;
        }
       
        //Set a larger buffer to allow for explicit flushing
        res.setBufferSize(16 * 1024);
       
        final long startTime = System.currentTimeMillis();
        synchronized (renderingLock) {
            // This function does ALL the content gathering/presentation work.
            // The following filter sequence is processed:
            //        userLayoutXML (in UserPreferencesManager)
            //              |
            //        incorporate StructureAttributes
            //              |
            //        Structure transformation
            //              + (buffering step)
            //        ChannelRendering Buffer
            //              |
            //        ThemeAttributesIncorporation Filter
            //              |
            //        Theme Transformatio
            //              |
            //        ChannelIncorporation filter
            //              |
            //        Serializer (XHTML/WML/HTML/etc.)
            //              |
            //        JspWriter
            //

            try {

                // determine uPElement (optimistic prediction) --begin
                // We need uPElement for ChannelManager.setReqNRes() call. That call will distribute uPElement
                // to Privileged channels. We assume that Privileged channels are smart enough not to delete
                // themselves in the detach mode !

                // In general transformations will start at the userLayoutRoot node, unless
                // we are rendering something in a detach mode.
                IUserLayoutNodeDescription rElement = null;
                // see if an old detach target exists in the servlet path

                // give channels the current locale manager
                channelManager.setLocaleManager(localeManager);

                IUserLayoutManager ulm = uPreferencesManager.getUserLayoutManager();

                // determine uPElement (optimistic prediction) --end

                // set up the channel manager

                channelManager.startRenderingCycle(req, res, uPElement);

                // after this point the layout is determined

                UserPreferences userPreferences = uPreferencesManager.getUserPreferences();
                StructureStylesheetDescription ssd = uPreferencesManager.getStructureStylesheetDescription();
                ThemeStylesheetDescription tsd = uPreferencesManager.getThemeStylesheetDescription();

                // verify upElement and determine rendering root --begin
                if (newRootNodeId != null && (!newRootNodeId.equals(rootNodeId))) {
                    // see if the new detach traget is valid
                    try {
                        rElement = ulm.getNode(newRootNodeId);
                    }
                    catch (PortalException e) {
                        rElement = null;
                    }

                    if (rElement != null) {
                        // valid new root id was specified. need to redirect
                        // peterk: should we worry about forwarding
                        // parameters here ? or those passed with detach
                        // always get sacked ?
                        // Andreas: Forwarding parameters with detach
                        // are not lost anymore with the URLUtil class.

                        // Skip the uP_detach_target parameter since
                        // it has already been processed
                        String[] skipParams = new String[] { "uP_detach_target" };

                        try {
                            URLUtil.redirect(req, res, newRootNodeId, true, skipParams, CHARACTER_SET);
                        }
                        catch (PortalException pe) {
                            log.error("PortalException occurred while redirecting",
                                    pe);
                        }
                        return;
                    }
                }

                // LogService.log(LogService.DEBUG,"uP_detach_target=\""+rootNodeId+"\".");
                try {
                    rElement = ulm.getNode(rootNodeId);
                }
                catch (PortalException e) {
                    rElement = null;
                }
                // if we haven't found root node so far, set it to the userLayoutRoot
                if (rElement == null) {
                    rootNodeId = UPFileSpec.USER_LAYOUT_ROOT_NODE;
                }

                // update the render target
                uPElement.setMethodNodeId(rootNodeId);

                // inform channel manager about the new uPElement value
                channelManager.setUPElement(uPElement);
                // verify upElement and determine rendering root --begin
               
                // Increase output buffer size, buffer will be flushed before and after every <channel>
                res.setBufferSize(16 * 1024);

                // Disable page caching
                res.setHeader("pragma", "no-cache");
                res.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
                res.setDateHeader("Expires", 0);
                // set the response mime type
                res.setContentType(tsd.getMimeType() + "; charset=" + CHARACTER_SET);
                // obtain the writer - res.getWriter() must occur after res.setContentType()
                Writer out = new BufferedWriter(res.getWriter(), 1024);
                // get a serializer appropriate for the target media
                BaseMarkupSerializer markupSerializer =
                    MEDIA_MANAGER.getSerializerByName(tsd.getSerializerName(),
                        new ChannelTitleIncorporationWiterFilter(out, channelManager, ulm));
                // set up the serializer
                markupSerializer.asContentHandler();
                // see if we can use character caching
                boolean ccaching = (CHARACTER_CACHE_ENABLED && (markupSerializer instanceof CachingSerializer));
                channelManager.setCharacterCaching(ccaching);
                // pass along the serializer name
                channelManager.setSerializerName(tsd.getSerializerName());
                // initialize ChannelIncorporationFilter
                CharacterCachingChannelIncorporationFilter cif = new CharacterCachingChannelIncorporationFilter(markupSerializer, channelManager, CACHE_ENABLED && CHARACTER_CACHE_ENABLED, req, res);

                String cacheKey = null;
                boolean output_produced = false;
                if (CACHE_ENABLED) {
                    boolean ccache_exists = false;
                    // obtain the cache key
                    cacheKey = constructCacheKey(uPreferencesManager, rootNodeId);
                    if (ccaching) {
                        // obtain character cache
                        List<CacheEntry> cacheEntries = systemCharacterCache.get(cacheKey);
                        if(cacheEntries!=null && cacheEntries.size()>0) {
                            ccache_exists = true;
                            if (log.isDebugEnabled())
                                log
                                        .debug("retreived transformation character block cache for a key \""
                                                + cacheKey + "\"");
                            // start channel threads
                            for(int i=0;i<cacheEntries.size();i++) {
                                CacheEntry ce = cacheEntries.get(i);
                                if (ce.getCacheType().equals(CacheType.CHANNEL_CONTENT)) {
                                    String channelSubscribeId = ((ChannelContentCacheEntry)ce).getChannelId();
                                    if(channelSubscribeId!=null) {
                                        try {
                                            channelManager.startChannelRendering(req, res, channelSubscribeId);
                                        } catch (PortalException e) {
                                            log.error("UserInstance::renderState() : unable to start rendering channel (subscribeId=\""+channelSubscribeId+"\", user="+person.getID()+" layoutId="+uPreferencesManager.getCurrentProfile().getLayoutId(),e);
                                        }
                                    } else {
                                        log.error("channel entry " + Integer.toString(i)
                                            + " in character cache is invalid (user=" + person.getID() + ")!");
                                    }
                                }
                            }
                            channelManager.commitToRenderingChannelSet();

                            // go through the output loop
                            CachingSerializer cSerializer = (CachingSerializer) markupSerializer;
                            cSerializer.setDocumentStarted(true);

                            for(int sb=0; sb<cacheEntries.size();sb++) {
                                CacheEntry ce = cacheEntries.get(sb);
                                if (log.isDebugEnabled()) {
                                    DebugCachingSerializer dcs = new DebugCachingSerializer();
                                    log.debug("----------printing " + ce.getCacheType() + " cache block "+Integer.toString(sb));
                                    ce.replayCache(dcs, channelManager, req, res);
                                    log.debug(dcs.getCache());
                                }

                                // get cache block output
                                ce.replayCache(cSerializer, channelManager, req, res);
                            }

                            cSerializer.flush();
                            output_produced = true;
                        }
                    }
                    // if this failed, try XSLT cache
                    if ((!ccaching) || (!ccache_exists)) {
                        // obtain XSLT cache

                        SAX2BufferImpl cachedBuffer = systemCache.get(cacheKey);
                        if (cachedBuffer != null) {
                            // replay the buffer to channel incorporation filter
                            if (log.isDebugEnabled()) {
                                log.debug("retreived XSLT transformation cache for a key '" + cacheKey + "'");
                            }
                           
                            // attach rendering buffer downstream of the cached buffer
                            ChannelRenderingBuffer crb = new ChannelRenderingBuffer(cachedBuffer, channelManager, ccaching, req, res);
                           
                            // attach channel incorporation filter downstream of the channel rendering buffer
                            cif.setParent(crb);
                            crb.setOutputAtDocumentEnd(true);
                            cachedBuffer.outputBuffer(crb);

                            output_produced = true;
                        }
                    }
                }
                // fallback on the regular rendering procedure
                if (!output_produced) {

                    // obtain transformer handlers for both structure and theme stylesheets
                    TransformerHandler ssth = XSLT.getTransformerHandler(ResourceLoader.getResourceAsURL(this.getClass(), ssd.getStylesheetURI()).toString());
                    TransformerHandler tsth = XSLT.getTransformerHandler(tsd.getStylesheetURI(), localeManager
                            .getLocales(), this);

                    // obtain transformer references from the handlers
                    Transformer sst = ssth.getTransformer();
                    sst.setErrorListener(cErrListener);
                    Transformer tst = tsth.getTransformer();
                    tst.setErrorListener(cErrListener);
                   
                    // pass resourcesDao into transformer
                    tst.setParameter(ResourcesXalanElements.SKIN_RESOURCESDAO_PARAMETER_NAME, resourcesElementsProvider);
                    tst.setParameter(ResourcesXalanElements.CURRENT_REQUEST, req);

                    // initialize ChannelRenderingBuffer and attach it downstream of the structure transformer
                    ChannelRenderingBuffer crb = new ChannelRenderingBuffer(channelManager, ccaching, req, res);
                    ssth.setResult(new SAXResult(crb));

                    // determine and set the stylesheet params
                    // prepare .uP element and detach flag to be passed to the stylesheets
                    // Including the context path in front of uPElement is necessary for phone.com browsers to work
                    sst.setParameter("baseActionURL", uPElement.getUPFile());
                    // construct idempotent version of the uPElement
                    UPFileSpec uPIdempotentElement = new UPFileSpec(uPElement);
                    sst.setParameter("baseIdempotentActionURL", uPElement.getUPFile());

                    Hashtable<String, String> supTable = userPreferences.getStructureStylesheetUserPreferences()
                            .getParameterValues();
                    for (Map.Entry<String, String> param : supTable.entrySet()) {
                        String pName = param.getKey();
                        String pValue = param.getValue();
                        if (log.isDebugEnabled())
                            log.debug("setting sparam \"" + pName + "\"=\"" + pValue
                                    + "\".");
                        sst.setParameter(pName, pValue);
                    }

                    // all the parameters are set up, fire up structure transformation

                    // filter to fill in channel/folder attributes for the "structure" transformation.
                    StructureAttributesIncorporationFilter saif = new StructureAttributesIncorporationFilter(ssth,
                            userPreferences.getStructureStylesheetUserPreferences());

                    // This is a debug statement that will print out XML incoming to the
                    // structure transformation to a log file serializer to a printstream
                    StringWriter dbwr1 = null;
                    OutputFormat outputFormat = null;
                    if (logXMLBeforeStructureTransformation && log.isDebugEnabled()) {
                        dbwr1 = new StringWriter();
                        outputFormat = new OutputFormat();
                        outputFormat.setIndenting(true);
                        XMLSerializer dbser1 = new XMLSerializer(dbwr1, outputFormat);
                        SAX2DuplicatingFilterImpl dupl1 = new SAX2DuplicatingFilterImpl(ssth, dbser1);
                        dupl1.setParent(saif);
                    }

                    // if operating in the detach mode, need wrap everything
                    // in a document node and a <layout_fragment> node
                    boolean detachMode = !rootNodeId.equals(UPFileSpec.USER_LAYOUT_ROOT_NODE);
                    if (detachMode) {
                        saif.startDocument();
                        saif.startElement("",
                                "layout_fragment",
                                "layout_fragment",
                                new org.xml.sax.helpers.AttributesImpl());

                        //                            emptyt.transform(new DOMSource(rElement),new SAXResult(new ChannelSAXStreamFilter((ContentHandler)saif)));
                        if (rElement == null) {
                            ulm.getUserLayout(new ChannelSAXStreamFilter((ContentHandler) saif));
                        }
                        else {
                            ulm.getUserLayout(rElement.getId(), new ChannelSAXStreamFilter((ContentHandler) saif));
                        }

                        saif.endElement("", "layout_fragment", "layout_fragment");
                        saif.endDocument();
                    }
                    else {
                        if (rElement == null) {
                            ulm.getUserLayout(saif);
                        }
                        else {
                            ulm.getUserLayout(rElement.getId(), saif);
                        }
                        //                            emptyt.transform(new DOMSource(rElement),new SAXResult((ContentHandler)saif));
                    }
                    // all channels should be rendering now

                    // Debug piece to print out the recorded pre-structure transformation XML
                    if (logXMLBeforeStructureTransformation && log.isDebugEnabled()) {
                            log.debug("XML incoming to the structure transformation :\n\n"
                                            + dbwr1.toString() + "\n\n");
                    }

                    // prepare for the theme transformation

                    // set up of the parameters
                    tst.setParameter("baseActionURL", uPElement.getUPFile());
                    tst.setParameter("baseIdempotentActionURL", uPIdempotentElement.getUPFile());
                    if (externalLoginUrl != null) {
                        tst.setParameter("EXTERNAL_LOGIN_URL", externalLoginUrl);
                    }

                    Hashtable<String, String> tupTable = userPreferences.getThemeStylesheetUserPreferences()
                            .getParameterValues();
                    for (Map.Entry<String, String> param : tupTable.entrySet()) {
                        String pName = param.getKey();
                        String pValue = param.getValue();
                        if (log.isDebugEnabled())
                            log.debug("setting tparam \"" + pName + "\"=\"" + pValue
                                    + "\".");
                        tst.setParameter(pName, pValue);
                    }

                    VersionsManager versionsManager = VersionsManager.getInstance();
                    Version[] versions = versionsManager.getVersions();

                    for (Version version : versions) {
                        String paramName = "version-" + version.getFname();
                        tst.setParameter(paramName, version.dottedTriple());
                    }

                    // the uP_productAndVersion stylesheet parameter is deprecated
                    // instead use the more generic "version-UP_VERSION" generated from the
                    // framework's functional name when all versions are pulled immediately
                    // above.
                    Version uPortalVersion = versionsManager.getVersion(IPermission.PORTAL_FRAMEWORK);
                    tst.setParameter("uP_productAndVersion", "uPortal " + uPortalVersion.dottedTriple());

                    final Locale[] locales = localeManager.getLocales();
                    if (locales != null && locales.length > 0 && locales[0] != null) {
                        tst.setParameter("USER_LANG", locales[0].toString().replace('_', '-'));
                    }

                    // initialize a filter to fill in channel attributes for the "theme" (second) transformation.
                    // attach it downstream of the channel rendering buffer
                    ThemeAttributesIncorporationFilter taif = new ThemeAttributesIncorporationFilter(
                            (XMLReader) crb, userPreferences.getThemeStylesheetUserPreferences());
                    // attach theme transformation downstream of the theme attribute incorporation filter
                    taif.setAllHandlers(tsth);

                    // This is a debug statement that will print out XML incoming to the
                    // theme transformation to a log file serializer to a printstream
                    StringWriter dbwr2 = null;
                    if (logXMLBeforeThemeTransformation && log.isDebugEnabled()) {
                        dbwr2 = new StringWriter();
                        XMLSerializer dbser2 = new XMLSerializer(dbwr2, outputFormat);
                        SAX2DuplicatingFilterImpl dupl2 = new SAX2DuplicatingFilterImpl(tsth, dbser2);
                        dupl2.setParent(taif);
                    }

                    if (CACHE_ENABLED && !ccaching) {
                        // record cache
                        // attach caching buffer downstream of the theme transformer
                        SAX2BufferImpl newCache = new SAX2BufferImpl();
                        tsth.setResult(new SAXResult(newCache));

                        // attach channel incorporation filter downstream of the caching buffer
                        cif.setParent(newCache);

                        systemCache.put(cacheKey, newCache);
                        newCache.setOutputAtDocumentEnd(true);
                        if (log.isDebugEnabled())
                            log.debug("recorded transformation cache with key \""
                                    + cacheKey + "\"");
                    }
                    else {
                        // attach channel incorporation filter downstream of the theme transformer
                        tsth.setResult(new SAXResult(cif));
                    }
                    // fire up theme transformation
                    crb.stopBuffering();
                    crb.outputBuffer();
                    crb.clearBuffer();

                    // Debug piece to print out the recorded pre-theme transformation XML
                    if (logXMLBeforeThemeTransformation && log.isDebugEnabled()) {
                        log.debug("XML incoming to the theme transformation :\n\n"
                                + dbwr2.toString() + "\n\n");
                    }

                    if (CACHE_ENABLED && ccaching) {
                        // save character block cache
                        List<CacheEntry> cacheBlocks = cif.getCacheBlocks();
                        if(cacheBlocks == null) {
                            log
                                    .error("CharacterCachingChannelIncorporationFilter returned invalid cache entries!");
                        }
                        else {
                            // record cache
                            systemCharacterCache.put(cacheKey, cacheBlocks);
                            if (log.isDebugEnabled()) {
                                log
                                        .debug("recorded transformation character block cache with key \""
                                                + cacheKey + "\"");

                                log.debug("Printing transformation cache blocks:");
                                for (int i=0; i<cacheBlocks.size(); i++) {
                                    CacheEntry ce = cacheBlocks.get(i);
                                    if (ce.getCacheType().equals(CacheType.CHARACTERS)) {
                                        log.debug("----------piece "+Integer.toString(i));
                                    } else if (ce.getCacheType().equals(CacheType.CHANNEL_CONTENT)) {
                                        log.debug("----------channel content entry "+Integer.toString(i));
                                    }
                                    DebugCachingSerializer dcs = new DebugCachingSerializer();
                                    ce.replayCache(dcs, channelManager, req, res);
                                    log.debug(dcs.getCache());
                                }
                            }
                        }
                    }

                }
                // signal the end of the rendering round
                channelManager.finishedRenderingCycle();
            }
            catch (PortalException pe) {
                throw pe;
            }
            catch (Exception e) {
View Full Code Here

    String nodeId = node.getId();

    // instantiate the channel in the user's layout
    final HttpSession session = request.getSession(false);
        ChannelManager cm = new ChannelManager(upm, session);
    cm.instantiateChannel(new PortalHttpServletRequestWrapper(request, response, userInstanceManager), response, channel.getId());

    try {
      // save the user's layout
      saveUserLayoutPreservingTab(ulm, upm, per);
    } catch (Exception e) {
View Full Code Here

        this.userInstanceManager = userInstanceManager;
    }

    public boolean processParameters(IWritableHttpServletRequest request, HttpServletResponse response) {
        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
        final ChannelManager channelManager = userInstance.getChannelManager();
       
        this.parseMultiTargetEvent(request, response, "uP_help_target", PortalEvent.HELP_BUTTON, channelManager);
        this.parseMultiTargetEvent(request, response, "uP_about_target", PortalEvent.ABOUT_BUTTON, channelManager);
        this.parseMultiTargetEvent(request, response, "uP_edit_target", PortalEvent.EDIT_BUTTON, channelManager);

        this.parseSingleTargetEvent(request, response, "uP_detach_target", PortalEvent.DETACH_BUTTON, channelManager);


        final IPerson person = userInstance.getPerson();
        final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
        final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
        final UserPreferences userPreferences = preferencesManager.getUserPreferences();

       
        final StructureStylesheetUserPreferences structureStylesheetUserPreferences = userPreferences.getStructureStylesheetUserPreferences();
        final ThemeStylesheetUserPreferences themeStylesheetUserPreferences = userPreferences.getThemeStylesheetUserPreferences();
       
        String root = request.getParameter("uP_root");
        if (root != null) {
            // If a channel specifies "me" as its root, set the root
            // to the channel's subscribe Id
            if (root.equals("me")) {
                // get uPFile spec and search for "channel" clause
                //TODO get UPFileSpec for original request and store it as a request attribute
                final UPFileSpec upfs = new UPFileSpec(request);
                root = upfs.getTargetNodeId();
            }

            if (IUserLayout.ROOT_NODE_NAME.equals(root)) {
                final String oldChannelId = structureStylesheetUserPreferences.getParameterValue("userLayoutRoot");
               
                if (oldChannelId != null && !IUserLayout.ROOT_NODE_NAME.equals(oldChannelId)) {
                    //Tell the previously maximized channel it is going back to normal
                    if (logger.isDebugEnabled()) {
                        logger.debug("Sending window state event '" + PortalEvent.NORMAL + "' to '" + root + "'.");
                    }
                    channelManager.passPortalEvent(request, response, oldChannelId, PortalEvent.NORMAL);
                }
            }
            else {
                //Make sure that the focused channel isn't rendered minimized
                themeStylesheetUserPreferences.setChannelAttributeValue(root, "minimized", "false");
               
                //Tell the channel it is being maximized
                if (logger.isDebugEnabled()) {
                    logger.debug("Sending window state event '" + PortalEvent.MAXIMIZE + "' to '" + root + "'.");
                }
                channelManager.passPortalEvent(request, response, root, PortalEvent.MAXIMIZE);
            }
           
            structureStylesheetUserPreferences.putParameterValue("userLayoutRoot", root);
        }
       
        // fname and root are mutually exclusive and
        // should not be used in the same request,
        // as an fname is treated as the root target.
        final String fname = request.getParameter(Constants.FNAME_PARAM);
        if (fname != null) {
            // get a subscribe id for the fname
            String subId = null;
            try {
                subId = userLayoutManager.getSubscribeId(fname);
            }
            catch (PortalException pe) {
                logger.warn("Unable to get subscribe ID for fname='" + fname + "'", pe);
            }

            if (subId != null) {
                if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
                    // get wrapper implementation for focusing
                    final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
                    // .. and now set it as the focused id
                    transientUserLayoutManagerWrapper.setFocusedId(subId);
                }
   
                structureStylesheetUserPreferences.putParameterValue("userLayoutRoot", subId);
                if (logger.isDebugEnabled()) {
                    logger.debug("setting structure preference 'userLayoutRoot'='" + subId + "'");
                }
            }
        }
       
        // other params
        final String[] structParamNames = request.getParameterValues("uP_sparam");
        if (structParamNames != null) {
            for (final String structParamName : structParamNames) {
                final String structParamValue = request.getParameter(structParamName);
               
                structureStylesheetUserPreferences.putParameterValue(structParamName, structParamValue);
                if (logger.isDebugEnabled()) {
                    logger.debug("set structure parameter '" + structParamName + "'='" + structParamValue + "'.");
                }
            }
        }

        final String[] themeParamNames = request.getParameterValues("uP_tparam");
        if (themeParamNames != null) {
            for (final String themeParamName : themeParamNames) {
                final String themeParamValue = request.getParameter(themeParamName);
               
                themeStylesheetUserPreferences.putParameterValue(themeParamName, themeParamValue);
                if (logger.isDebugEnabled()) {
                    logger.debug("set theme parameter '" + themeParamName + "'='" + themeParamValue + "'.");
                }
            }
        }
       
        // attribute processing
        // structure transformation
        final String[] structFolderAttrNames = request.getParameterValues("uP_sfattr");
        if (structFolderAttrNames != null) {
            for (final String structFolderAttrName : structFolderAttrNames) {
                final String[] folderIds = request.getParameterValues(structFolderAttrName + "_folderId");
               
                if (folderIds != null) {
                    for (final String folderId : folderIds) {
                        final String structFolderAttrValue = request.getParameter(structFolderAttrName + "_" + folderId + "_value");
                        structureStylesheetUserPreferences.setFolderAttributeValue(folderId, structFolderAttrName, structFolderAttrValue);
                       
                        if (logger.isDebugEnabled()) {
                            logger.debug("set structure folder attribute '" + structFolderAttrName + "'='" + structFolderAttrValue + "' on folder '" + folderId + "'.");
                        }
                    }
                }
            }
        }
           
        final String[] structChannelAttrNames = request.getParameterValues("uP_scattr");
        if (structChannelAttrNames != null) {
            for (final String structChannelAttrName : structChannelAttrNames) {
                final String[] channelIds = request.getParameterValues(structChannelAttrName + "_channelId");
               
                if (channelIds != null) {
                    for (final String channelId : channelIds) {
                        final String structChannelAttrValue = request.getParameter(structChannelAttrName + "_" + channelId + "_value");
                        structureStylesheetUserPreferences.setChannelAttributeValue(channelId, structChannelAttrName, structChannelAttrValue);
                       
                        if (logger.isDebugEnabled()) {
                            logger.debug("set structure channel attribute '" + structChannelAttrName + "'='" + structChannelAttrValue + "' on folder '" + channelId + "'.");
                        }
                    }
                }
            }
        }
       
        // theme stylesheet attributes
        final String[] themeChannelAttrNames = request.getParameterValues("uP_tcattr");
        if (themeChannelAttrNames != null) {
            for (final String themeChannelAttrName : themeChannelAttrNames) {
                final String[] channelIds = request.getParameterValues(themeChannelAttrName + "_channelId");
               
                if (channelIds != null) {
                    for (final String channelId : channelIds) {
                        final String themeChannelAttrValue = request.getParameter(themeChannelAttrName + "_" + channelId + "_value");
                        themeStylesheetUserPreferences.setChannelAttributeValue(channelId, themeChannelAttrName, themeChannelAttrValue);
                       
                        if (logger.isDebugEnabled()) {
                            logger.debug("set theme channel attribute '" + themeChannelAttrName + "'='" + themeChannelAttrValue + "' on folder '" + channelId + "'.");
                        }
                       
                        if ("minimized".equals(themeChannelAttrName)) {
                            final Element channel = userLayoutManager.getUserLayoutDOM().getElementById(channelId);
                            try {
                                UserPrefsHandler.setUserPreference(channel, themeChannelAttrName, person);
                            }
                            catch (Exception e) {
                                logger.warn("Failed to set 'minimized' attribute on channel '" + channelId + "' with element: " + channel, e);
                            }
                           
                            final PortalEvent event;
                            if ("true".equals(themeChannelAttrValue)) {
                                event = PortalEvent.MINIMIZE;
                            }
                            else {
                                event = PortalEvent.NORMAL;
                            }
       
                            channelManager.passPortalEvent(request, response, channelId, event);
                            if (logger.isDebugEnabled()) {
                                logger.debug("Sent window state event '" + event + "' to '" + channelId + "'.");
                            }
                        }
                    }
View Full Code Here

                    try {
                        if (this.the_channel instanceof IPrivilegedChannel)
                            ((IPrivilegedChannel) this.the_channel)
                                    .setPortalControlStructures(this.portcs);
                        this.the_channel.setRuntimeData(crd);
                        ChannelManager cm = this.portcs.getChannelManager();
                        cm.setChannelInstance(channelSubscribeId,
                                this.the_channel);
                        this.the_channel.renderXML(out);
                        return;
                    } catch (Exception e) {
                        // if any of the above didn't work, fall back to the
                        // error channel
                        resetCError(ErrorCode.SET_RUNTIME_DATA_EXCEPTION, e,
                                channelSubscribeId, this.the_channel,
                                "Channel failed a refresh attempt.");
                    }
                } else if (chFate.equals("restart")) {

                    ChannelManager cm = this.portcs.getChannelManager();

                    ChannelRuntimeData crd =
                        (ChannelRuntimeData) this.runtimeData.clone();
                    crd.clear();
                    try {
                        if ((this.the_channel = cm
                                .instantiateChannel(channelSubscribeId)) == null) {
                            resetCError(ErrorCode.GENERAL_ERROR, null,
                                    channelSubscribeId, null,
                                    "Channel failed to reinstantiate!");
                        } else {
                            try {
                                if (this.the_channel instanceof IPrivilegedChannel) {
                                    ((IPrivilegedChannel) this.the_channel)
                                            .setPortalControlStructures(this.portcs);
                                }
                                this.the_channel.setRuntimeData(crd);
                                this.the_channel.renderXML(out);
                                return;
                            } catch (Exception e) {
                                // if any of the above didn't work, fall back to
                                // the error channel
                                resetCError(ErrorCode.SET_RUNTIME_DATA_EXCEPTION,
                                        e, channelSubscribeId,
                                        this.the_channel,
                                        "Channel failed a reload attempt.");
                                cm.setChannelInstance(
                                        channelSubscribeId, this);
                                log.error("CError::setRuntimeData() : " +
                                        "an error occurred during channel reinitialization. ", e);
                            }
                        }
View Full Code Here

                    try {
                        if (this.the_channel instanceof IPrivilegedChannel)
                            ((IPrivilegedChannel) this.the_channel)
                                    .setPortalControlStructures(this.portcs);
                        this.the_channel.setRuntimeData(crd);
                        ChannelManager cm = this.portcs.getChannelManager();
                        cm.setChannelInstance(channelSubscribeId,
                                this.the_channel);
                        if (this.the_channel instanceof ICharacterChannel) {
                            ((ICharacterChannel) this.the_channel)
                                    .renderCharacters(out);
                        } else {
                            ThemeStylesheetDescription tsd = this.portcs
                                    .getUserPreferencesManager()
                                    .getThemeStylesheetDescription();
                            BaseMarkupSerializer serOut = MEDIAMANAGER
                                    .getSerializerByName(tsd
                                            .getSerializerName(), out);
                            this.the_channel.renderXML(serOut);
                        }
                        return;
                    } catch (Exception e) {
                        // if any of the above didn't work, fall back to the
                        // error channel
                        resetCError(ErrorCode.SET_RUNTIME_DATA_EXCEPTION, e,
                                channelSubscribeId, this.the_channel,
                                "Channel failed a refresh attempt.");
                    }
                } else if (chFate.equals("restart")) {
                    log
                            .debug("CError:renderCharacters() : going for reinstantiation");

                    ChannelManager cm = this.portcs.getChannelManager();

                    ChannelRuntimeData crd = (ChannelRuntimeData) this.runtimeData
                            .clone();
                    crd.clear();
                    try {
                        this.the_channel = cm
                        .instantiateChannel(channelSubscribeId);
                        if (this.the_channel == null) {
                            resetCError(ErrorCode.GENERAL_ERROR, null,
                                    channelSubscribeId, null,
                                    "Channel failed to reinstantiate!");
                        } else {
                            try {
                                if (this.the_channel instanceof IPrivilegedChannel) {
                                    ((IPrivilegedChannel) this.the_channel)
                                            .setPortalControlStructures(this.portcs);
                                }
                                this.the_channel.setRuntimeData(crd);
                                if (this.the_channel instanceof ICharacterChannel) {
                                    ((ICharacterChannel) this.the_channel)
                                            .renderCharacters(out);
                                } else {
                                    ThemeStylesheetDescription tsd = this.portcs
                                            .getUserPreferencesManager()
                                            .getThemeStylesheetDescription();
                                    BaseMarkupSerializer serOut = MEDIAMANAGER
                                            .getSerializerByName(tsd
                                                    .getSerializerName(), out);
                                    this.the_channel.renderXML(serOut);
                                }
                                return;
                            } catch (Exception e) {
                                // if any of the above didn't work, fall back to
                                // the error channel
                                resetCError(ErrorCode.SET_RUNTIME_DATA_EXCEPTION,
                                        e, channelSubscribeId,
                                        this.the_channel,
                                        "Channel failed a reload attempt.");
                                cm.setChannelInstance(
                                         channelSubscribeId, this);
                                log.error( "CError::renderCharacters() : an error occurred " +
                                        "during channel reinitialization.", e);
                            }
                        }
View Full Code Here

TOP

Related Classes of org.jasig.portal.ChannelManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.