当前位置: 首页>>代码示例>>Java>>正文


Java ResourceResponse.setCharacterEncoding方法代码示例

本文整理汇总了Java中javax.portlet.ResourceResponse.setCharacterEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceResponse.setCharacterEncoding方法的具体用法?Java ResourceResponse.setCharacterEncoding怎么用?Java ResourceResponse.setCharacterEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.portlet.ResourceResponse的用法示例。


在下文中一共展示了ResourceResponse.setCharacterEncoding方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initCsv

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
private CSVWriter initCsv(ResourceResponse resourceResponse)
		throws IOException, UnsupportedEncodingException {
	//Necesario para crear el fichero csv.
	resourceResponse.setCharacterEncoding(StringPool.UTF8);
	resourceResponse.setContentType(ContentTypes.TEXT_CSV_UTF8);
	resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"attachment; fileName=Statistics.csv");
	byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF};
	
	resourceResponse.getPortletOutputStream().write(b);
	
	CSVWriter writer = new CSVWriter(new OutputStreamWriter(resourceResponse.getPortletOutputStream(),StringPool.UTF8),CharPool.SEMICOLON);
	return writer;
}
 
开发者ID:TelefonicaED,项目名称:liferaylms-portlet,代码行数:14,代码来源:CourseStats.java

示例2: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
/**
 * Fornece o arquivo CSV
 */
@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException,
		PortletException {

	if (hasPermission(resourceRequest)) {

		resourceResponse.setContentType("text/csv; charset=ISO-8859-1");
		resourceResponse.setCharacterEncoding("ISO-8859-1");
		resourceResponse.setProperty("content-disposition", "attachment;filename=contadores.csv");

		OutputStream os = resourceResponse.getPortletOutputStream();
		Writer writer = new OutputStreamWriter(os, Charset.forName(resourceResponse.getCharacterEncoding()));

		long companyId = PortalUtil.getCompanyId(resourceRequest);
		try {
			writer.write(ContadorAcessoLocalServiceUtil.getCSV(companyId));
		} catch (SystemException e) {
			throw new PortletException(e);
		}
		writer.flush();
	} else {
		super.serveResource(resourceRequest, resourceResponse);
	}

}
 
开发者ID:camaradosdeputadosoficial,项目名称:edemocracia,代码行数:29,代码来源:ContadoresPortlet.java

示例3: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
   
   String testcase = request.getRenderParameters().getValue("testcase");
   response.setCharacterEncoding("UTF-8");
   response.setContentType("text/plain");
   response.getWriter().write("OK " + testcase);

}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:10,代码来源:PortletHubTests_SPEC_23_JSPA.java

示例4: doLoadMore

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
/**
 * Performs the "load more" AJAX request
 *
 * @param request The resource request
 * @param response The resource response
 *
 * @throws PortletException If something goes wrong
 * @throws IOException If something goes wrong
 */
public void doLoadMore(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    response.setContentType(ContentTypes.APPLICATION_JSON);
    response.setCharacterEncoding(StandardCharsets.UTF_8.name());
    response.setProperty(HTTP_HEADER_CACHE_CONTROL, CACHE_CONTROL_NO_CACHE);
    response.setProperty(ResourceResponse.EXPIRATION_CACHE, ZERO);

    String tabId = ParamUtil.get(request, PortletRequestParameter.TAB_ID.getName(), StringPool.BLANK);
    int offset = ParamUtil.getInteger(request, PortletRequestParameter.PAGE_OFFSET.getName(), 0);
    if(offset < 0) {
        offset = 0;
    }

    FlashlightSearchConfiguration config = this.searchService.readConfiguration(request.getPreferences());
    Map<String, FlashlightSearchConfigurationTab> tabs = config.getTabs();

    if(tabs.containsKey(tabId)) {
        try {
            SearchResultsContainer container = this.searchService.search(request, response, tabId, offset, true);
            JSONPayloadFactory jsonPayloadFactory = new JSONPayloadFactory(this.jsonFactory);
            if(container.hasSearchResults(tabId)) {
                FlashlightSearchConfigurationTab tab = tabs.get(tabId);
                SearchPage page = container.getSearchPage(tabId);

                ResourceURL loadMoreUrl = response.createResourceURL();
                loadMoreUrl.setResourceID(PortletResource.LOAD_MORE.getResourceId());
                loadMoreUrl.setParameter(PortletRequestParameter.TAB_ID.getName(), tabId);
                loadMoreUrl.setParameter(PortletRequestParameter.KEYWORDS.getName(), ParamUtil.get(request, PortletRequestParameter.KEYWORDS.getName(), StringPool.BLANK));
                loadMoreUrl.setParameter(PortletRequestParameter.PAGE_OFFSET.getName(), Integer.toString(offset + 1));
                loadMoreUrl.setParameter(PortletRequestParameter.RANDOM_CACHE.getName(), randomCacheParamValue());

                JSONObject payload = jsonPayloadFactory.createJSONPayload(tab, page, offset, loadMoreUrl.toString());
                response.getWriter().print(payload.toJSONString());
            } else {
                // No search results with the given tab
                LOG.debug("A search tab was found, but no pages were returned");
                response.setProperty(ResourceResponse.HTTP_STATUS_CODE, STATUS_CODE_NOT_FOUND);
            }
        } catch (SearchException e) {
            // Cannot perform search, return a 500 error
            LOG.error("Cannot perform search", e);
            response.setProperty(ResourceResponse.HTTP_STATUS_CODE, STATUS_CODE_INTERNAL_ERROR);
        }
    } else {
        // No tab with given ID. Return 404
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, STATUS_CODE_NOT_FOUND);
    }
}
 
开发者ID:savoirfairelinux,项目名称:flashlight-search,代码行数:57,代码来源:FlashlightSearchPortlet.java

示例5: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest resourceRequest,
		ResourceResponse resourceResponse) throws IOException,
		PortletException {
	ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
	String action = ParamUtil.getString(resourceRequest, "action");
	long actId = ParamUtil.getLong(resourceRequest, "actId",0);


	if(action.equals("export")){

		try {

			CalificationType ct = new CalificationTypeRegistry().getCalificationType(CourseLocalServiceUtil.getCourseByGroupCreatedId(themeDisplay.getScopeGroupId()).getCalificationType());

			//Necesario para crear el fichero csv.
			resourceResponse.setCharacterEncoding(StringPool.UTF8);
			resourceResponse.setContentType(ContentTypes.TEXT_CSV_UTF8);
			resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"attachment; fileName=data.csv");
			byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF};

			resourceResponse.getPortletOutputStream().write(b);

			CSVWriter writer = new CSVWriter(new OutputStreamWriter(resourceResponse.getPortletOutputStream(),StringPool.UTF8),CharPool.SEMICOLON);
			String[] cabeceras = new String[4];


			//En esta columna vamos a tener el nombre del usuario.
			cabeceras[0]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.user");
			cabeceras[1]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.date");
			cabeceras[2]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.result");
			cabeceras[3]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.comment");

			writer.writeNext(cabeceras);
			DynamicQuery dq=DynamicQueryFactoryUtil.forClass(LearningActivityResult.class);
			Criterion criterion=PropertyFactoryUtil.forName("actId").eq(actId);
			dq.add(criterion);

			//Partiremos del usuario para crear el csv para que sea más facil ver los intentos.
			List<LearningActivityResult> listresult = LearningActivityResultLocalServiceUtil.dynamicQuery(dq);
			for(LearningActivityResult learningActivityResult:listresult){
				//Array con los resultados de los intentos.
				String[] resultados = new String[4];
				//En la primera columna del csv introducidos el nombre del estudiante.
				resultados[0] = UserLocalServiceUtil.getUser(learningActivityResult.getUserId()).getScreenName();
				resultados[1] = _dateFormat.format(learningActivityResult.getEndDate());
				resultados[2] = ct.translate(themeDisplay.getLocale(), themeDisplay.getScopeGroupId(), learningActivityResult.getResult());
				resultados[3] = learningActivityResult.getComments()!=null?learningActivityResult.getComments():"";

				//Escribimos las respuestas obtenidas para el intento en el csv.
				writer.writeNext(resultados);
			}
			writer.flush();
			writer.close();
			resourceResponse.getPortletOutputStream().flush();
			resourceResponse.getPortletOutputStream().close();

		} catch (NestableException e) {

		}finally{
			resourceResponse.getPortletOutputStream().flush();
			resourceResponse.getPortletOutputStream().close();
		}
	} 
}
 
开发者ID:TelefonicaED,项目名称:liferaylms-portlet,代码行数:66,代码来源:OfflineActivity.java

示例6: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest resourceRequest,
		ResourceResponse resourceResponse) throws IOException,
		PortletException {
	String action = ParamUtil.getString(resourceRequest, "action");
	long[] courseIds=ParamUtil.getLongValues(resourceRequest, "courseIds");
	ThemeDisplay themeDisplay  =(ThemeDisplay)resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
	if(action.equals("export")){
		try
		{
		String charset = LanguageUtil.getCharset(themeDisplay.getLocale());
		if (Validator.isNull(charset)) {
			charset = LanguageUtil.getCharset(LocaleUtil.getDefault());
		}
		charset = StringPool.UTF8;
		resourceResponse.setCharacterEncoding(charset);
		resourceResponse.setContentType("text/csv;charset="+charset);
		resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"attachment; fileName=generalstats."+Long.toString(System.currentTimeMillis())+".csv");
		if (StringPool.UTF8.equals(charset)) {
	        byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF};
	        resourceResponse.getPortletOutputStream().write(b);
		}
        CSVWriter writer = new CSVWriter(new OutputStreamWriter(resourceResponse.getPortletOutputStream(),charset),';');
        String[] linea=new String[8];
        linea[0]=LanguageUtil.get(themeDisplay.getLocale(),"coursestats.name");
        linea[1]=LanguageUtil.get(themeDisplay.getLocale(),"coursestats.registered");
        linea[2]=LanguageUtil.get(themeDisplay.getLocale(),"coursestats.starts.course");
        linea[3]=LanguageUtil.get(themeDisplay.getLocale(),"coursestats.ends.course");
        linea[4]=LanguageUtil.get(themeDisplay.getLocale(),"closed");
        linea[5]=LanguageUtil.get(themeDisplay.getLocale(),"coursestats.modulestats.marks.average");
        linea[6]=LanguageUtil.get(themeDisplay.getLocale(),"coursestats.modulecounter");
        linea[7]=LanguageUtil.get(themeDisplay.getLocale(),"coursestats.activitiescounter");
        writer.writeNext(linea);
        long[] userExcludedIds = null;
        for(long courseId:courseIds)
        {
        	Course course=CourseLocalServiceUtil.getCourse(courseId);
        	userExcludedIds = CourseLocalServiceUtil.getTeachersAndEditorsIdsFromCourse(course);
	        linea=new String[8];
	        linea[0]=course.getTitle(themeDisplay.getLocale());
	        		        
			long registered=CourseLocalServiceUtil.countStudents(courseId, themeDisplay.getCompanyId(), null, null, null, null, false);
			long iniciados = (registered > 0) ? CourseResultLocalServiceUtil.countStudentsByCourseIdUserExcludedIdsStarted(courseId, userExcludedIds) : 0;
			long finalizados = (registered > 0) ? CourseResultLocalServiceUtil.countStudentsByCourseIdUserExcludedIdsFinished(courseId, userExcludedIds) : 0;
			double avgResult=0;
			if(finalizados>0){
				avgResult=CourseResultLocalServiceUtil.avgResultByCourseIdUserExcludedIds(course.getCourseId(), true, userExcludedIds);
			}
			long activitiesCount=LearningActivityLocalServiceUtil.countLearningActivitiesOfGroup(course.getGroupCreatedId());
			long modulesCount=ModuleLocalServiceUtil.countByGroupId(course.getGroupCreatedId());
			String closed=course.getClosed()?LanguageUtil.get(themeDisplay.getLocale(),"yes"):LanguageUtil.get(themeDisplay.getLocale(),"no");
			
			linea[1]=Long.toString(registered);
			linea[2]=Long.toString(iniciados);
			linea[3]=Long.toString(finalizados);
			DecimalFormat df = new DecimalFormat("#.#");
			linea[4]=closed;
			linea[5]=df.format(avgResult);
			linea[6]=Long.toString(modulesCount);
			linea[7]=Long.toString(activitiesCount);
	        writer.writeNext(linea);
	        //resourceResponse.getPortletOutputStream().write(b);
        }
        writer.flush();
		writer.close();
		resourceResponse.getPortletOutputStream().flush();
		resourceResponse.getPortletOutputStream().close();
		
		}
		catch(Exception e)
		{
			
		}
	}
}
 
开发者ID:TelefonicaED,项目名称:liferaylms-portlet,代码行数:76,代码来源:GeneralStats.java


注:本文中的javax.portlet.ResourceResponse.setCharacterEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。