本文整理汇总了Java中javax.portlet.ResourceResponse.getPortletOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceResponse.getPortletOutputStream方法的具体用法?Java ResourceResponse.getPortletOutputStream怎么用?Java ResourceResponse.getPortletOutputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.portlet.ResourceResponse
的用法示例。
在下文中一共展示了ResourceResponse.getPortletOutputStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: serveResource
import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, ResourceRequest resourceRequest,
ResourceResponse resourceResponse) throws Exception {
resourceResponse.setContentType("image/png");
resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL,
"max-age=5, must-revalidate");
OutputStream out = resourceResponse.getPortletOutputStream();
InputStream is=getClass().getClassLoader().getResourceAsStream("asposeicon/aspose.png");
byte[] bytes = IOUtils.toByteArray(is);
out.write(bytes, 0, bytes.length);
out.close();
}
示例3: 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);
}
}
示例4: serveResource
import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
public void serveResource(ResourceRequest request, ResourceResponse response)
throws IOException, PortletException {
String prettyProperties = prettify(request);
OutputStream out = response.getPortletOutputStream();
IOUtils.copy(new StringReader(prettyProperties), out);
IOUtils.closeQuietly(out);
}
开发者ID:tmoreira2020,项目名称:portal-properties-prettier-app,代码行数:10,代码来源:PortalPropertiesPrettierPortlet.java
示例5: serveImage
import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@ServeResourceMethod(portletNames="MultipartPortlet")
public void serveImage(ResourceRequest req, ResourceResponse resp) throws IOException {
String fn = req.getRenderParameters().getValue("fn");
String ct = req.getRenderParameters().getValue("ct");
resp.setContentType(ct);
String path = req.getPortletContext().getRealPath(fn);
File file = new File(path);
OutputStream os = resp.getPortletOutputStream();
Files.copy(file.toPath(), os);
os.flush();
}
示例6: 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();
}
}
}
示例7: 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)
{
}
}
}