Search in sources :

Example 46 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class AbstractHeaderProvider method isIncluded.

protected final boolean isIncluded(RenderRequest renderRequest, String preferenceName) {
    final PortletPreferences preferences = renderRequest.getPreferences();
    final String rslt = preferences.getValue(preferenceName, Boolean.FALSE.toString());
    return Boolean.valueOf(rslt);
}
Also used : PortletPreferences(javax.portlet.PortletPreferences)

Example 47 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class SoffitConnectorController method invokeService.

@RenderMapping
public void invokeService(final RenderRequest req, final RenderResponse res) {
    final PortletPreferences prefs = req.getPreferences();
    final String serviceUrl = prefs.getValue(SERVICE_URL_PREFERENCE, null);
    if (serviceUrl == null) {
        throw new IllegalStateException("Missing portlet prefernce value for " + SERVICE_URL_PREFERENCE);
    }
    // First look in cache for an existing response that applies to this request
    ResponseWrapper responseValue = fetchContentFromCacheIfAvailable(req, serviceUrl);
    if (responseValue != null) {
        logger.debug("Response value obtained from cache for serviceUrl '{}'", serviceUrl);
    } else {
        logger.debug("No applicable response in cache;  invoking serviceUrl '{}'", serviceUrl);
        final HttpGet getMethod = new HttpGet(serviceUrl);
        try (final CloseableHttpClient httpClient = httpClientBuilder.build()) {
            // Send the data model as encrypted JWT HTTP headers
            for (IHeaderProvider headerProvider : headerProviders) {
                final Header header = headerProvider.createHeader(req, res);
                if (header != null) {
                    getMethod.addHeader(header);
                }
            }
            // Send the request
            final HttpResponse httpResponse = httpClient.execute(getMethod);
            try {
                final int statusCode = httpResponse.getStatusLine().getStatusCode();
                logger.debug("HTTP response code for url '{}' was '{}'", serviceUrl, statusCode);
                if (statusCode == HttpStatus.SC_OK) {
                    responseValue = extractResponseAndCacheIfAppropriate(httpResponse, req, serviceUrl);
                } else {
                    logger.error("Failed to get content from remote service '{}';  HttpStatus={}", serviceUrl, statusCode);
                    res.getWriter().write("FAILED!  statusCode=" + // TODO:  Better message
                    statusCode);
                }
            } finally {
                if (null != httpResponse) {
                    // Ensures that the entity content is fully consumed and the content stream,
                    // if exists, is closed.
                    EntityUtils.consumeQuietly(httpResponse.getEntity());
                }
            }
        } catch (IOException e) {
            logger.error("Failed to invoke serviceUrl '{}'", serviceUrl, e);
        }
    }
    if (responseValue != null) {
        // Whether by cache or by fresh HTTP request, we have a response we can show...
        try {
            res.getPortletOutputStream().write(responseValue.getBytes());
        } catch (IOException e) {
            logger.error("Failed to write the response for serviceUrl '{}'", serviceUrl, e);
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) PortletPreferences(javax.portlet.PortletPreferences) IOException(java.io.IOException) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 48 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class ViewBackgroundPreferenceController method getView.

/**
 * Display the main user-facing view of the portlet.
 *
 * @param request
 * @return
 */
@RenderMapping
public String getView(RenderRequest req, Model model) {
    final String[] images = imageSetSelectionStrategy.getImageSet(req);
    model.addAttribute("images", images);
    final String[] thumbnailImages = imageSetSelectionStrategy.getImageThumbnailSet(req);
    model.addAttribute("thumbnailImages", thumbnailImages);
    final String[] imageCaptions = imageSetSelectionStrategy.getImageCaptions(req);
    model.addAttribute("imageCaptions", imageCaptions);
    final String preferredBackgroundImage = imageSetSelectionStrategy.getSelectedImage(req);
    model.addAttribute("backgroundImage", preferredBackgroundImage);
    final String backgroundContainerSelector = imageSetSelectionStrategy.getBackgroundContainerSelector(req);
    model.addAttribute("backgroundContainerSelector", backgroundContainerSelector);
    final PortletPreferences prefs = req.getPreferences();
    model.addAttribute("applyOpacityTo", prefs.getValue("applyOpacityTo", null));
    model.addAttribute("opacityCssValue", prefs.getValue("opacityCssValue", "1.0"));
    return "/jsp/BackgroundPreference/viewBackgroundPreference";
}
Also used : PortletPreferences(javax.portlet.PortletPreferences) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 49 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class ConfigurablePreferencesBasedTokenGenerator method generateToken.

/**
 * Returns a String hashcode of the values for the portlet preferences that are configurable by
 * the Dynamic Skin portlet. The hashcode is generated in a repeatable fashion by calculating it
 * based on sorted portlet preference names. Though hashcode does not guarantee uniqueness, from
 * a practical perspective we'll have so few different values we can reasonably assume
 * preference value combinations will be unique.
 *
 * @see DynamicSkinUniqueTokenGenerator#generateToken(DynamicSkinInstanceData)
 */
@Override
public String generateToken(final DynamicSkinInstanceData data) {
    final PortletPreferences preferences = data.getPortletRequest().getPreferences();
    int hash = 0;
    // Add the list of preference names to an ordered list so we can get reliable hashcode
    // calculations.
    final Map<String, String[]> prefs = preferences.getMap();
    final TreeSet<String> orderedNames = new TreeSet<String>(prefs.keySet());
    final Iterator<String> iterator = orderedNames.iterator();
    while (iterator.hasNext()) {
        final String preferenceName = iterator.next();
        if (preferenceName.startsWith(DynamicRespondrSkinConstants.CONFIGURABLE_PREFIX)) {
            hash = hash * 31 + preferences.getValue(preferenceName, "").trim().hashCode();
        }
    }
    return Integer.toString(hash);
}
Also used : TreeSet(java.util.TreeSet) PortletPreferences(javax.portlet.PortletPreferences)

Example 50 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class DynamicRespondrSkinViewController method displaySkinCssHeader.

/**
 * Display Skin CSS include based on skin's configuration values from portlet preferences.<br>
 * dynamic=false: load the pre-built css file from the skins directory and default skin name;
 * e.g. RELATIVE_ROOT/{defaultSkin}.css dynamic=true: Process the default skin less file if
 * needed at RELATIVE_ROOT/{defaultSkin}.less to create a customized skin css file
 * (RELATIVE_ROOT/skin-ID#.css to load.
 */
@RenderMapping
public ModelAndView displaySkinCssHeader(RenderRequest request, RenderResponse response, Model model) throws IOException {
    if (PortletRequest.RENDER_HEADERS.equals(request.getAttribute(PortletRequest.RENDER_PART))) {
        PortletPreferences prefs = request.getPreferences();
        Boolean enabled = Boolean.valueOf(prefs.getValue(DynamicRespondrSkinConstants.PREF_DYNAMIC, "false"));
        String skinName = prefs.getValue(DynamicRespondrSkinConstants.PREF_SKIN_NAME, DynamicRespondrSkinConstants.DEFAULT_SKIN_NAME);
        String cssUrl = enabled ? calculateDynamicSkinUrlPathToUse(request, skinName) : calculateDefaultSkinCssLocationInWebapp(skinName);
        model.addAttribute(DynamicRespondrSkinConstants.SKIN_CSS_URL_MODEL_ATTRIBUTE_NAME, cssUrl);
        return new ModelAndView("jsp/DynamicRespondrSkin/skinHeader");
    } else {
        // We need to know if this user can CONFIG this skin
        // Default
        boolean canAccessSkinConfig = false;
        final HttpServletRequest httpr = portalRequestUtils.getCurrentPortalRequest();
        final IPerson user = personManager.getPerson(httpr);
        final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
        final IPortletWindowId portletWindowId = portletWindowRegistry.getPortletWindowId(httpr, request.getWindowID());
        final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpr, portletWindowId);
        final IPortletEntity portletEntity = portletWindow.getPortletEntity();
        if (principal.canConfigure(portletEntity.getPortletDefinitionId().toString())) {
            canAccessSkinConfig = true;
        }
        // RENDER_MARKUP
        return new ModelAndView("jsp/DynamicRespondrSkin/skinBody", DynamicRespondrSkinConstants.CAN_ACCESS_SKIN_CONFIG_MODEL_NAME, canAccessSkinConfig);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) ModelAndView(org.springframework.web.portlet.ModelAndView) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortletPreferences(javax.portlet.PortletPreferences) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Aggregations

PortletPreferences (javax.portlet.PortletPreferences)59 HashMap (java.util.HashMap)12 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)10 ModelAndView (org.springframework.web.portlet.ModelAndView)9 List (java.util.List)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 PortletRequest (javax.portlet.PortletRequest)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPerson (org.apereo.portal.security.IPerson)5 ResourceMapping (org.springframework.web.portlet.bind.annotation.ResourceMapping)5 KBArticle (com.liferay.knowledgebase.model.KBArticle)4 Map (java.util.Map)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 AdminSubscriptionSender (com.liferay.knowledgebase.admin.util.AdminSubscriptionSender)2 KBFolder (com.liferay.knowledgebase.model.KBFolder)2 BaseUpgradePortletPreferences (com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences)2 Portlet (com.liferay.portal.model.Portlet)2 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)2