当前位置: 首页>>代码示例>>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;未经允许,请勿转载。