List of usage examples for org.springframework.web.servlet.support RequestContextUtils getLocale
public static Locale getLocale(HttpServletRequest request)
From source file:org.gbif.portal.web.tag.SmallTaxonomyBrowserTag.java
/** * Render a special tree node.// w w w. j a v a 2 s . c om * * @param specialTreeNode * @param sb * @param contextPath */ protected void addElement(SpecialTreeNode specialTreeNode, StringBuffer sb, String contextPath) { Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest()); sb.append("<p class=\"specialConcept\">"); String link = getLink(contextPath, specialTreeNode); if (link != null) { sb.append("<a href=\""); sb.append(link); sb.append("\" class=\"treeNodeLink\">"); } sb.append("<span class=\"conceptLink\"> </span><span id=\""); sb.append(specialTreeNode.getExpandRequestParameter()); sb.append("\">"); sb.append(messageSource.getMessage(specialTreeNode.getDisplayName(), null, locale)); sb.append("</span>"); if (link != null) sb.append("</a>"); if (specialTreeNode.isShowChildren()) { sb.append("<div class=\"list\">"); for (BriefTaxonConceptDTO child : specialTreeNode.getChildren()) addElement(child, sb, contextPath); sb.append("</div>"); } sb.append("</p>"); }
From source file:org.gbif.portal.web.tag.SmallTaxonomyBrowserTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport#doEndTag() *//*ww w . jav a2s . c o m*/ @Override public int doEndTag() throws JspException { Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest()); if (concepts == null || concepts.size() == 0) return super.doEndTag(); StringBuffer sb = new StringBuffer(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String contextPath = request.getContextPath(); sb.append("<div><p id=\"smtFirstLevel\""); if (selectedConcept == null) { sb.append(" class=\"selected\">"); } else { sb.append("><a href=\""); String rootLink = getRootLink(contextPath); sb.append(rootLink); sb.append("\">"); } if (StringUtils.isEmpty(highestRank)) { sb.append(messageSource.getMessage(rootConceptsLinkMessageKey, null, locale)); } else { sb.append(messageSource.getMessage("taxonomy.browser.all." + highestRank, null, locale)); } if (selectedConcept != null) sb.append("</a>"); sb.append("</p>"); addConcepts(sb, pageContext, contextPath); sb.append("</div>"); try { pageContext.getOut().write(sb.toString()); } catch (IOException e) { logger.error(e.getMessage(), e); } return super.doEndTag(); }
From source file:org.gbif.portal.web.view.search.SearchWidgetController.java
/** * Adds content for the taxon name search widget. The ordering should be like so: * /*from ww w . j a va 2 s . com*/ * 1. Exact scientific name match * 2. Exact specific epithet matches * 3. Other scientific name matches * * TODO Add Scientific name parsing * * @param request * @param response * @throws Exception */ public void addTaxa(HttpServletRequest request, HttpServletResponse response) throws Exception { String searchString = getSearchString(request); TaxonomyManager taxonomyManager = (TaxonomyManager) getWebAppContext(request).getBean("taxonomyManager"); DataResourceManager dataResourceManager = (DataResourceManager) getWebAppContext(request) .getBean("dataResourceManager"); //use the nub provider DataProviderDTO nubProvider = dataResourceManager.getNubDataProvider(); //use the nub resource DataResourceDTO nubResource = dataResourceManager.getNubDataResource(); String providerKey = null; String resourceKey = null; if (nubProvider != null && nubProvider.getKey() != null) providerKey = nubProvider.getKey(); if (nubResource != null && nubResource.getKey() != null) resourceKey = nubResource.getKey(); //exact scientific name matches SearchResultsDTO exactTaxonMatches = taxonomyManager.findTaxonConcepts(searchString, false, null, null, resourceKey, null, null, RequestContextUtils.getLocale(request).getLanguage(), null, allowUnconfirmedNames, false, new SearchConstraints(0, 100)); request.setAttribute("exactTaxonMatches", exactTaxonMatches); //exact specific epithet matches SearchResultsDTO exactEpithetMatches = taxonomyManager.findSpeciesConcepts(null, searchString, false, null, resourceKey, null, new SearchConstraints(0, 100)); request.setAttribute("exactEpithetMatches", exactEpithetMatches); int matchesTotal = exactTaxonMatches.size() + exactEpithetMatches.size(); boolean hasMore = false; //shall we provide a paging link SearchConstraints searchConstraints = getSearchConstraints(request); if (matchesTotal <= DEFAULT_MAX_RESULTS) { boolean sortAlpha = false; if (searchString != null && searchString.length() > minLengthToSort) { sortAlpha = true; } //exact scientific name matches SearchResultsDTO fuzzyTaxonMatches = taxonomyManager.findTaxonConcepts(searchString, true, null, null, resourceKey, null, null, RequestContextUtils.getLocale(request).getLanguage(), null, allowUnconfirmedNames, sortAlpha, searchConstraints); //remove the exact matches for (Object exactMatch : exactTaxonMatches) { if (fuzzyTaxonMatches.contains(exactMatch)) fuzzyTaxonMatches.remove(exactMatch); } request.setAttribute("fuzzyTaxonMatches", fuzzyTaxonMatches); matchesTotal += fuzzyTaxonMatches.size(); hasMore = fuzzyTaxonMatches.hasMoreResults(); } else { hasMore = true; } // if there are still no results, then try a soundex if (matchesTotal == 0) { logger.debug("No names found, trying the SoundEx search"); SearchResultsDTO soundExMatches = taxonomyManager.findMatchingScientificNames(searchString, true, null, null, true, null, resourceKey, true, new SearchConstraints(0, DEFAULT_MAX_RESULTS)); request.setAttribute("soundexNameMatches", soundExMatches); matchesTotal = soundExMatches.size(); // it's just a suggestion list so no need for paging hasMore = false; } if (matchesTotal == 0) { //match on remote concept ids List<TaxonConceptDTO> taxonConcepts = taxonomyManager.getTaxonConceptForRemoteId(searchString); request.setAttribute("remoteConceptMatches", taxonConcepts); } request.setAttribute("moreTaxaMatches", hasMore); }
From source file:org.gbif.portal.web.view.search.SearchWidgetController.java
/** * Adds the content for the countries widget. * //from w ww .j av a 2s . c om * @param request * @param response * @throws Exception */ public void addCountries(HttpServletRequest request, HttpServletResponse response) throws Exception { String searchString = getSearchString(request); GeospatialManager geospatialManager = (GeospatialManager) getWebAppContext(request) .getBean("geospatialManager"); Locale locale = RequestContextUtils.getLocale(request); SearchResultsDTO geospatialMatches = geospatialManager.findCountries(searchString, true, true, false, locale, getSearchConstraints(request)); request.setAttribute("countryMatches", geospatialMatches); request.setAttribute("moreCountryMatches", geospatialMatches.hasMoreResults()); }
From source file:org.jasig.portal.portlet.container.cache.PortletCacheControlServiceImpl.java
@Override public CachedPortletData getCachedPortletRenderOutput(IPortletWindowId portletWindowId, HttpServletRequest httpRequest) { final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId);/*from w w w.j av a2s . com*/ final IPortletEntityId entityId = portletWindow.getPortletEntityId(); final IPortletEntity entity = this.portletEntityRegistry.getPortletEntity(httpRequest, entityId); final IPortletDefinitionId definitionId = entity.getPortletDefinitionId(); Serializable publicCacheKey = generatePublicScopePortletDataCacheKey(definitionId, portletWindow.getRenderParameters(), portletWindow.getPublicRenderParameters(), RequestContextUtils.getLocale(httpRequest)); Element publicCacheElement = this.publicScopePortletRenderOutputCache.get(publicCacheKey); if (publicCacheElement != null) { if (publicCacheElement.isExpired()) { this.publicScopePortletRenderOutputCache.remove(publicCacheKey); return null; } else { return (CachedPortletData) publicCacheElement.getValue(); } } else { // public cache contained no content, check private Serializable privateCacheKey = generatePrivateScopePortletDataCacheKey(httpRequest, portletWindowId, entityId, definitionId, portletWindow.getRenderParameters()); Element privateCacheElement = this.privateScopePortletRenderOutputCache.get(privateCacheKey); if (privateCacheElement != null) { if (privateCacheElement.isExpired()) { this.privateScopePortletRenderOutputCache.remove(privateCacheKey); return null; } else { return (CachedPortletData) privateCacheElement.getValue(); } } } return null; }
From source file:org.jasig.portal.portlet.container.cache.PortletCacheControlServiceImpl.java
@Override public CachedPortletData getCachedPortletResourceOutput(IPortletWindowId portletWindowId, HttpServletRequest httpRequest) { final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId);//from www . j a v a2 s. co m final IPortletEntityId entityId = portletWindow.getPortletEntityId(); final IPortletEntity entity = this.portletEntityRegistry.getPortletEntity(httpRequest, entityId); final IPortletDefinitionId definitionId = entity.getPortletDefinitionId(); Serializable publicCacheKey = generatePublicScopePortletDataCacheKey(definitionId, portletWindow.getRenderParameters(), portletWindow.getPublicRenderParameters(), RequestContextUtils.getLocale(httpRequest)); Element publicCacheElement = this.publicScopePortletResourceOutputCache.get(publicCacheKey); if (publicCacheElement != null) { CachedPortletData cachedPortletData = (CachedPortletData) publicCacheElement.getValue(); // only remove from cache if not using validation method if (publicCacheElement.isExpired() && StringUtils.isBlank(cachedPortletData.getEtag())) { this.publicScopePortletResourceOutputCache.remove(publicCacheKey); return null; } return cachedPortletData; } else { // public cache contained no content, check private Serializable privateCacheKey = generatePrivateScopePortletDataCacheKey(httpRequest, portletWindowId, entityId, definitionId, portletWindow.getRenderParameters()); Element privateCacheElement = this.privateScopePortletResourceOutputCache.get(privateCacheKey); if (privateCacheElement != null) { CachedPortletData cachedPortletData = (CachedPortletData) privateCacheElement.getValue(); if (privateCacheElement.isExpired() && StringUtils.isBlank(cachedPortletData.getEtag())) { this.privateScopePortletResourceOutputCache.remove(privateCacheKey); return null; } return cachedPortletData; } } return null; }
From source file:org.jasig.portal.portlet.container.cache.PortletCacheControlServiceImpl.java
@Override public void cachePortletRenderOutput(IPortletWindowId portletWindowId, HttpServletRequest httpRequest, String content, CacheControl cacheControl) { final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId);//from ww w . java2 s. com final IPortletEntityId entityId = portletWindow.getPortletEntityId(); final IPortletEntity entity = this.portletEntityRegistry.getPortletEntity(httpRequest, entityId); final IPortletDefinitionId definitionId = entity.getPortletDefinitionId(); final int expirationTime = cacheControl.getExpirationTime(); CachedPortletData newData = new CachedPortletData(); newData.setExpirationTimeSeconds(expirationTime); newData.setTimeStored(new Date()); newData.setStringData(content); newData.setEtag(cacheControl.getETag()); if (cacheControl.isPublicScope()) { newData.setCacheConfigurationMaxTTL( new Long(publicScopePortletRenderOutputCache.getCacheConfiguration().getTimeToLiveSeconds()) .intValue()); Serializable publicCacheKey = generatePublicScopePortletDataCacheKey(definitionId, portletWindow.getRenderParameters(), portletWindow.getPublicRenderParameters(), RequestContextUtils.getLocale(httpRequest)); Element publicCacheElement = constructCacheElement(publicCacheKey, newData, publicScopePortletRenderOutputCache.getCacheConfiguration(), cacheControl); this.publicScopePortletRenderOutputCache.put(publicCacheElement); } else { newData.setCacheConfigurationMaxTTL( new Long(privateScopePortletRenderOutputCache.getCacheConfiguration().getTimeToLiveSeconds()) .intValue()); Serializable privateCacheKey = generatePrivateScopePortletDataCacheKey(httpRequest, portletWindowId, entityId, definitionId, portletWindow.getRenderParameters()); Element privateCacheElement = constructCacheElement(privateCacheKey, newData, privateScopePortletRenderOutputCache.getCacheConfiguration(), cacheControl); this.privateScopePortletRenderOutputCache.put(privateCacheElement); } }
From source file:org.jasig.portal.portlet.container.cache.PortletCacheControlServiceImpl.java
@Override public void cachePortletResourceOutput(IPortletWindowId portletWindowId, HttpServletRequest httpRequest, CachedPortletData cachedPortletData, CacheControl cacheControl) { final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId);/*from www .ja v a 2 s . c o m*/ final IPortletEntityId entityId = portletWindow.getPortletEntityId(); final IPortletEntity entity = this.portletEntityRegistry.getPortletEntity(httpRequest, entityId); final IPortletDefinitionId definitionId = entity.getPortletDefinitionId(); final int expirationTime = cacheControl.getExpirationTime(); cachedPortletData.setEtag(cacheControl.getETag()); cachedPortletData.setExpirationTimeSeconds(expirationTime); cachedPortletData.setTimeStored(new Date()); if (cacheControl.isPublicScope()) { cachedPortletData.setCacheConfigurationMaxTTL( new Long(publicScopePortletResourceOutputCache.getCacheConfiguration().getTimeToLiveSeconds()) .intValue()); Serializable publicCacheKey = generatePublicScopePortletDataCacheKey(definitionId, portletWindow.getRenderParameters(), portletWindow.getPublicRenderParameters(), RequestContextUtils.getLocale(httpRequest)); Element publicCacheElement = constructCacheElement(publicCacheKey, cachedPortletData, publicScopePortletResourceOutputCache.getCacheConfiguration(), cacheControl); this.publicScopePortletResourceOutputCache.put(publicCacheElement); } else { cachedPortletData.setCacheConfigurationMaxTTL( new Long(privateScopePortletResourceOutputCache.getCacheConfiguration().getTimeToLiveSeconds()) .intValue()); Serializable privateCacheKey = generatePrivateScopePortletDataCacheKey(httpRequest, portletWindowId, entityId, definitionId, portletWindow.getRenderParameters()); Element privateCacheElement = constructCacheElement(privateCacheKey, cachedPortletData, privateScopePortletResourceOutputCache.getCacheConfiguration(), cacheControl); this.privateScopePortletResourceOutputCache.put(privateCacheElement); } }
From source file:org.jasig.portal.portlet.container.cache.PortletCacheControlServiceImpl.java
@Override public boolean purgeCachedPortletData(IPortletWindowId portletWindowId, HttpServletRequest httpRequest, CacheControl cacheControl) {//w w w .j a v a 2 s.c o m final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId); final IPortletEntityId entityId = portletWindow.getPortletEntityId(); final IPortletEntity entity = this.portletEntityRegistry.getPortletEntity(httpRequest, entityId); final IPortletDefinitionId definitionId = entity.getPortletDefinitionId(); if (cacheControl.isPublicScope()) { Serializable publicCacheKey = generatePublicScopePortletDataCacheKey(definitionId, portletWindow.getRenderParameters(), portletWindow.getPublicRenderParameters(), RequestContextUtils.getLocale(httpRequest)); boolean renderPurged = this.publicScopePortletRenderOutputCache.remove(publicCacheKey); return this.publicScopePortletResourceOutputCache.remove(publicCacheKey) || renderPurged; } else { Serializable privateCacheKey = generatePrivateScopePortletDataCacheKey(httpRequest, portletWindowId, entityId, definitionId, portletWindow.getRenderParameters()); boolean renderPurged = this.privateScopePortletRenderOutputCache.remove(privateCacheKey); return this.privateScopePortletResourceOutputCache.remove(privateCacheKey) || renderPurged; } }
From source file:org.jasig.portal.portlet.container.cache.PortletCacheControlServiceImpl.java
/** * Generate a cache key for the private scope Cache. * /*from www . j a v a2 s. c o m*/ * sessionId + windowId + entityId + definitionId + renderParameters * * Internally uses {@link ArrayList} as it implements {@link Serializable} and an appropriate equals/hashCode. * * @param request * @param windowId * @param entityId * @param definitionId * @param renderParameters * @return */ protected Serializable generatePrivateScopePortletDataCacheKey(HttpServletRequest request, IPortletWindowId windowId, IPortletEntityId entityId, IPortletDefinitionId definitionId, Map<String, String[]> renderParameters) { ArrayList<Object> key = new ArrayList<Object>(); final String sessionId = request.getSession().getId(); key.add(sessionId); key.add(windowId); key.add(entityId); key.add(definitionId); key.add(renderParameters); final Locale locale = RequestContextUtils.getLocale(request); key.add(locale); return key; }