當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestContextUtils.getLocale方法代碼示例

本文整理匯總了Java中org.springframework.web.servlet.support.RequestContextUtils.getLocale方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestContextUtils.getLocale方法的具體用法?Java RequestContextUtils.getLocale怎麽用?Java RequestContextUtils.getLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.servlet.support.RequestContextUtils的用法示例。


在下文中一共展示了RequestContextUtils.getLocale方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onSubmit

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.POST)
protected String onSubmit(final HttpServletRequest request,
                                                         final TrackCommand command,
                                                         final Map<String, Object> model,
                                                         final BindingResult bindingResult) {
    new TrackCommandValidator().validate(command, bindingResult);

    final TrackingId trackingId = new TrackingId(command.getTrackingId());
    final Cargo cargo = cargoRepository.find(trackingId);

    if (cargo != null) {
        final Locale locale = RequestContextUtils.getLocale(request);
        final List<HandlingEvent> handlingEvents = handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId).distinctEventsByCompletionTime();
        model.put("cargo", new CargoTrackingViewAdapter(cargo, messageSource, locale, handlingEvents));
    } else {
        bindingResult.rejectValue("trackingId", "cargo.unknown_id", new Object[]{command.getTrackingId()}, "Unknown tracking id");
    }
    return "track";
}
 
開發者ID:citerus,項目名稱:dddsample-core,代碼行數:20,代碼來源:CargoTrackingController.java

示例2: getInfo

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
public AppstoreHit getInfo(String appId, CatalogEntryType appType) {
    Locale locale = RequestContextUtils.getLocale(request);

    CatalogEntry entry;
    if (CatalogEntryType.APPLICATION.equals(appType)) {
        entry = catalogStore.findApplication(appId);
    } else if (CatalogEntryType.SERVICE.equals(appType)) {
        entry = catalogStore.findService(appId);
    } else {
        logger.warn("Getting information about something that isn't an application or a service: {}", appType);
        throw new IllegalArgumentException("getInfo supports only applications and services");
    }

    String providerName = getOrganizationName(entry);

    return new AppstoreHit(locale, entry, imageService.getImageForURL(entry.getIcon(locale), ImageFormat.PNG_64BY64, false), providerName, getInstallationOption(entry));

}
 
開發者ID:ozwillo,項目名稱:ozwillo-portal,代碼行數:19,代碼來源:PortalAppstoreService.java

示例3: getLanguage

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
public String getLanguage(HttpServletRequest request) {
   Locale locale = RequestContextUtils.getLocale(request);
   String language = locale.getLanguage();
   if(!supportedLanguages.contains(language)){
      language = "en";
   }

   return language;
}
 
開發者ID:chen0040,項目名稱:spring-boot-slingshot,代碼行數:10,代碼來源:SpringRequestHelper.java

示例4: doEndTag

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
public int doEndTag() throws JspException {
    Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest());
    String result = StringUtil.formatBytes(bytes, locale);

    try {
        pageContext.getOut().print(result);
    } catch (IOException x) {
        throw new JspTagException(x);
    }
    return EVAL_PAGE;
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:12,代碼來源:FormatBytesTag.java

示例5: convert

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
private PlayQueueInfo convert(HttpServletRequest request, Player player, boolean serverSidePlaylist, int offset) throws Exception {
    String url = NetworkService.getBaseUrl(request);

    /* if (serverSidePlaylist && player.isJukebox()) {
        updateJukebox(player, offset);
    } */
    boolean isCurrentPlayer = player.getIpAddress() != null && player.getIpAddress().equals(request.getRemoteAddr());

    boolean m3uSupported = player.isExternal() || player.isExternalWithPlaylist();
    serverSidePlaylist = player.isAutoControlEnabled() && m3uSupported && isCurrentPlayer && serverSidePlaylist;
    Locale locale = RequestContextUtils.getLocale(request);

    List<PlayQueueInfo.Entry> entries = new ArrayList<PlayQueueInfo.Entry>();
    PlayQueue playQueue = player.getPlayQueue();

    for (MediaFile file : playQueue.getFiles()) {

        String albumUrl = url + "main.view?id=" + file.getId();
        String streamUrl = url + "stream?player=" + player.getId() + "&id=" + file.getId();
        String coverArtUrl = url + "coverArt.view?id=" + file.getId();

        String remoteStreamUrl = jwtSecurityService.addJWTToken(url + "ext/stream?player=" + player.getId() + "&id=" + file.getId());
        String remoteCoverArtUrl = jwtSecurityService.addJWTToken(url + "ext/coverArt.view?id=" + file.getId());

        String format = formatFormat(player, file);
        String username = securityService.getCurrentUsername(request);
        boolean starred = mediaFileService.getMediaFileStarredDate(file.getId(), username) != null;
        entries.add(new PlayQueueInfo.Entry(file.getId(), file.getTrackNumber(), file.getTitle(), file.getArtist(),
                file.getAlbumName(), file.getGenre(), file.getYear(), formatBitRate(file),
                file.getDurationSeconds(), file.getDurationString(), format, formatContentType(format),
                formatFileSize(file.getFileSize(), locale), starred, albumUrl, streamUrl, remoteStreamUrl,
                coverArtUrl, remoteCoverArtUrl));
    }
    boolean isStopEnabled = playQueue.getStatus() == PlayQueue.Status.PLAYING && !player.isExternalWithPlaylist();

    float gain = 0.0f;
    gain = jukeboxService.getGain(player);

    return new PlayQueueInfo(entries, isStopEnabled, playQueue.isRepeatEnabled(), playQueue.isRadioEnabled(), serverSidePlaylist, gain);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:41,代碼來源:PlayQueueService.java

示例6: handleRequestInternal

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();

    List<TransferStatus> streamStatuses = statusService.getAllStreamStatuses();
    List<TransferStatus> downloadStatuses = statusService.getAllDownloadStatuses();
    List<TransferStatus> uploadStatuses = statusService.getAllUploadStatuses();

    Locale locale = RequestContextUtils.getLocale(request);
    List<TransferStatusHolder> transferStatuses = new ArrayList<>();

    for (int i = 0; i < streamStatuses.size(); i++) {
        long minutesAgo = streamStatuses.get(i).getMillisSinceLastUpdate() / 1000L / 60L;
        if (minutesAgo < 60L) {
            transferStatuses.add(new TransferStatusHolder(streamStatuses.get(i), true, false, false, i, locale));
        }
    }
    for (int i = 0; i < downloadStatuses.size(); i++) {
        transferStatuses.add(new TransferStatusHolder(downloadStatuses.get(i), false, true, false, i, locale));
    }
    for (int i = 0; i < uploadStatuses.size(); i++) {
        transferStatuses.add(new TransferStatusHolder(uploadStatuses.get(i), false, false, true, i, locale));
    }

    map.put("transferStatuses", transferStatuses);
    map.put("chartWidth", StatusChartController.IMAGE_WIDTH);
    map.put("chartHeight", StatusChartController.IMAGE_HEIGHT);

    return new ModelAndView("status","model",map);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:31,代碼來源:StatusController.java

示例7: getTemplateSource

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
protected Workbook getTemplateSource(String url, HttpServletRequest request) throws Exception {
	LocalizedResourceHelper helper = new LocalizedResourceHelper(getApplicationContext());
	Locale userLocale = RequestContextUtils.getLocale(request);
	Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale);

	// Create the Excel document from the source.
	if (logger.isDebugEnabled()) {
		logger.debug("Loading Excel workbook from " + inputFile);
	}
	//POIFSFileSystem fs = new POIFSFileSystem(inputFile.getInputStream());
	return new XSSFWorkbook(inputFile.getInputStream());
}
 
開發者ID:PacktPublishing,項目名稱:Spring-MVC-Blueprints,代碼行數:13,代碼來源:AbstractExcelView.java

示例8: createTilesRequest

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * Create a Tiles {@link Request}.
 * <p>This implementation creates a {@link ServletRequest}.
 * @param request the current request
 * @param response the current response
 * @return the Tiles request
 */
protected Request createTilesRequest(final HttpServletRequest request, HttpServletResponse response) {
	return new ServletRequest(this.applicationContext, request, response) {
		@Override
		public Locale getRequestLocale() {
			return RequestContextUtils.getLocale(request);
		}
	};
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:TilesView.java

示例9: resolveLocale

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@Override
public Locale resolveLocale(Request request) {
	try {
		HttpServletRequest servletRequest = ServletUtil.getServletRequest(request).getRequest();
		if (servletRequest != null) {
			return RequestContextUtils.getLocale(servletRequest);
		}
	}
	catch (NotAServletEnvironmentException e) {
		// Ignore
	}
	return super.resolveLocale(request);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:SpringLocaleResolver.java

示例10: getTemplateSource

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * Create the workbook from an existing XLS document.
 * @param url the URL of the Excel template without localization part nor extension
 * @param request current HTTP request
 * @return the template workbook
 * @throws Exception in case of failure
 */
protected Workbook getTemplateSource(String url, HttpServletRequest request) throws Exception {
	LocalizedResourceHelper helper = new LocalizedResourceHelper(getApplicationContext());
	Locale userLocale = RequestContextUtils.getLocale(request);
	Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale);

	// Create the Excel document from the source.
	if (logger.isDebugEnabled()) {
		logger.debug("Loading Excel workbook from " + inputFile);
	}
	return Workbook.getWorkbook(inputFile.getInputStream());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AbstractJExcelView.java

示例11: getTemplateSource

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
/**
 * Creates the workbook from an existing XLS document.
 * @param url the URL of the Excel template without localization part nor extension
 * @param request current HTTP request
 * @return the HSSFWorkbook
 * @throws Exception in case of failure
 */
protected HSSFWorkbook getTemplateSource(String url, HttpServletRequest request) throws Exception {
	LocalizedResourceHelper helper = new LocalizedResourceHelper(getApplicationContext());
	Locale userLocale = RequestContextUtils.getLocale(request);
	Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale);

	// Create the Excel document from the source.
	if (logger.isDebugEnabled()) {
		logger.debug("Loading Excel workbook from " + inputFile);
	}
	return new HSSFWorkbook(inputFile.getInputStream());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AbstractExcelView.java

示例12: resolveLocale

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@Override
public Locale resolveLocale(TilesRequestContext context) {
	if (context instanceof JspTilesRequestContext) {
		PageContext pc = ((JspTilesRequestContext) context).getPageContext();
		return RequestContextUtils.getLocale((HttpServletRequest) pc.getRequest());
	}
	else if (context instanceof ServletTilesRequestContext) {
		HttpServletRequest request = ((ServletTilesRequestContext) context).getRequest();
		if (request != null) {
			return RequestContextUtils.getLocale(request);
		}
	}
	return super.resolveLocale(context);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:SpringLocaleResolver.java

示例13: evaluateTemplate

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
private void evaluateTemplate(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws IOException, PebbleException {
  Locale locale = RequestContextUtils.getLocale(request);

  Writer writer = response.getWriter();
  try {
    PebbleTemplate template = this.pebbleEngine.getTemplate(this.templateName);
    template.evaluate(writer, model, locale);
  } finally {
    writer.flush();
  }
}
 
開發者ID:PebbleTemplates,項目名稱:pebble-spring4,代碼行數:12,代碼來源:PebbleView.java

示例14: logElapsedTime

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
private void logElapsedTime(long startNanoTime, HttpServletRequest request) {
  if (TIMER_LOGGER.isDebugEnabled()) {
    Locale locale = RequestContextUtils.getLocale(request);
    long endNanoTime = System.nanoTime();

    long elapsed = endNanoTime - startNanoTime;
    long elapsedMs = elapsed / NANO_PER_SECOND;
    TIMER_LOGGER.debug("Pebble template \"{}\" with locale {} processed in {} nanoseconds (approx. {}ms)",
            this.templateName, locale, elapsed, elapsedMs);
  }
}
 
開發者ID:PebbleTemplates,項目名稱:pebble-spring4,代碼行數:12,代碼來源:PebbleView.java

示例15: preHandle

import org.springframework.web.servlet.support.RequestContextUtils; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
	logger.debug("info");

    Locale locale = RequestContextUtils.getLocale(request);
    logger.debug("info: " + locale);
    
    request.setAttribute("locale", locale);

    return true;
}
 
開發者ID:elimu-ai,項目名稱:webapp,代碼行數:12,代碼來源:LocaleChangeInterceptor.java


注:本文中的org.springframework.web.servlet.support.RequestContextUtils.getLocale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。