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);
}
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);
}
}
}
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";
}
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);
}
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);
}
}
Aggregations