本文整理汇总了Java中com.liferay.portal.util.PortalUtil.getHttpServletRequest方法的典型用法代码示例。如果您正苦于以下问题:Java PortalUtil.getHttpServletRequest方法的具体用法?Java PortalUtil.getHttpServletRequest怎么用?Java PortalUtil.getHttpServletRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.liferay.portal.util.PortalUtil
的用法示例。
在下文中一共展示了PortalUtil.getHttpServletRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendFile
import com.liferay.portal.util.PortalUtil; //导入方法依赖的package包/类
/**
* Send file.
*
* @param name the name
* @param mimeType the mime type
* @param contents the contents
* @param request the request
* @param response the response
*/
protected void sendFile(final String name, final String mimeType,
final byte[] contents, final ActionRequest request,
final ActionResponse response) {
try {
if (name != null && mimeType != null && contents != null) {
final HttpServletRequest httpServletRequest = PortalUtil
.getHttpServletRequest(request);
final HttpServletResponse httpServletResponse = PortalUtil
.getHttpServletResponse(response);
httpServletResponse.setContentType(mimeType);
httpServletResponse.setHeader("Expires", "0");
httpServletResponse.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
httpServletResponse.setHeader("Pragma", "public");
httpServletResponse.setContentLength(contents.length);
ServletResponseUtil.sendFile(httpServletRequest,
httpServletResponse, name, contents);
}
} catch (final Throwable t) {
t.printStackTrace();
}
}
示例2: exportAction
import com.liferay.portal.util.PortalUtil; //导入方法依赖的package包/类
@ProcessAction(name = "exportAction")
public void exportAction(ActionRequest request, ActionResponse response) {
try {
long userId = com.liferay.portal.util.PortalUtil.getUserId(request);
long companyId = com.liferay.portal.util.PortalUtil
.getCompanyId(request);
List<Application> applicationsPerUser = ApplicationLocalServiceUtil
.getDeveloperApplications(companyId, userId);
GovAppsExport export = new GovAppsExport();
for (Application _application : applicationsPerUser) {
// add application
ApplicationType xml = exportApp(_application);
if (xml != null)
export.getAppplications().add(xml);
}
JAXBContext jctx = JAXBContext
.newInstance("de.fraunhofer.fokus.oefit.schemagen");
Marshaller m = jctx.createMarshaller();
StringWriter sw = new StringWriter();
m.marshal(export, sw);
HttpServletRequest httpServletRequest = (HttpServletRequest) PortalUtil
.getHttpServletRequest(request);
HttpServletResponse httpServletResponse = (HttpServletResponse) PortalUtil
.getHttpServletResponse(response);
httpServletResponse.setHeader("Expires", "0");
httpServletResponse.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
httpServletResponse.setHeader("Pragma", "public");
// setting the content type
sw.flush();
String content = sw.toString();
sw.close();
httpServletResponse.setContentLength(content.length());
com.liferay.portal.kernel.servlet.ServletResponseUtil.sendFile(
httpServletRequest, httpServletResponse, "export.xml",
content.getBytes("UTF-8"));
} catch (Throwable t) {
request.setAttribute("errorMsg", t.getMessage());
response.setRenderParameter("jspPage", errorJSP);
}
}