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


Java ResourceResponse.setContentType方法代码示例

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


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

示例1: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
		throws PortletException, IOException {
	response.setContentType("text/html");
	JSONArray array = JSONFactoryUtil.createJSONArray();
	String themeId = request.getParameter(PARAM_SELECTED_THEME_ID);
	ThemeDisplay themeDisplay = (ThemeDisplay) request
			.getAttribute(WebKeys.THEME_DISPLAY);

	Theme themeObject = ThemeLocalServiceUtil.fetchTheme(
			themeDisplay.getCompanyId(), themeId);
	if (Validator.isNotNull(themeObject)) {
		Map<String, ColorScheme> colorSchemeMap = themeObject
				.getColorSchemesMap();
		for (String colorSchemeId : colorSchemeMap.keySet()) {
			JSONObject colorScheme = JSONFactoryUtil.createJSONObject();
			colorScheme.put("colorSchemeId", colorSchemeId);
			colorScheme.put("colorSchemeName",
					colorSchemeMap.get(colorSchemeId).getName());
			array.put(colorScheme);
		}
	}
	PrintWriter writer = response.getWriter();
	writer.write(array.toString());
}
 
开发者ID:knowarth-technologies,项目名称:theme-personalizer,代码行数:26,代码来源:ThemePersonalizerPortlet.java

示例2: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest resourceRequest,
        ResourceResponse resourceResponse) throws IOException,
        PortletException {
    System.out.println("#############AJAX CALL####################");
    String diagram = ParamUtil.getString(resourceRequest, "diagram");
    
    JSONObject diagramJSON = new JSONObject(diagram);
    //System.out.println(diagram);
    System.out.println(diagramJSON.get("nodes"));
    JSONArray arrDiagram = diagramJSON.getJSONArray("nodes");
    for (int i = 0; i < arrDiagram.length(); i++) {
    	
    }
    resourceResponse.setContentType("text/html");
    PrintWriter writer = resourceResponse.getWriter();
    writer.print(diagram);
    writer.write("Hello");
    writer.flush();
    writer.close();
    super.serveResource(resourceRequest, resourceResponse);
}
 
开发者ID:openegovplatform,项目名称:OEPv2,代码行数:23,代码来源:ProcessDesignerPortlet.java

示例3: uploadPHPFile

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
private void uploadPHPFile(ResourceRequest resourceRequest,
          ResourceResponse resourceResponse) throws IOException {
      UploadRequest uploadRequest = PortalUtil.getUploadPortletRequest(resourceRequest);
      File objFile = uploadRequest.getFile("PHPFILE");
      String objFileName = uploadRequest.getFileName("PHPFILE");
      _log.info("objFile: [" + objFile + "], objFileName: [" + objFileName + "]");        

      InputStream is = new FileInputStream(objFile);
          
      byte[] buff = new byte[is.available()];
      is.read(buff);
      is.close();
      String publicKeyStr = new String(buff);
resourceResponse.setContentType("text/html");
      PrintWriter writer = resourceResponse.getWriter();
      JSONObject jsonObject =  JSONFactoryUtil.createJSONObject();
      String[] arrStr = publicKeyStr.split("-----BEGIN PUBLIC KEY-----");
      publicKeyStr = arrStr[1];
      arrStr = publicKeyStr.split("-----END PUBLIC KEY-----");
      jsonObject.put("publicKey", arrStr[0]);
      phpPublicKey = arrStr[0];
      writer.print(jsonObject.toString());
      writer.flush();
      writer.close();
  }
 
开发者ID:openegovplatform,项目名称:OEPv2,代码行数:26,代码来源:RSAToolPortlet.java

示例4: 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

示例5: 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();
	
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Liferay,代码行数:18,代码来源:AsposeIconAction.java

示例6: 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

示例7: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void serveResource(ResourceRequest req, ResourceResponse resp)
      throws PortletException, IOException {
   
   resp.setContentType("text/html");
   PrintWriter writer = resp.getWriter();

   ArrayList<String> msgs = (ArrayList<String>) req.getPortletSession().getAttribute(ATTRIB_MSGS);
   if (msgs == null) {
      msgs = new ArrayList<String>();
      
      StringBuffer sb = new StringBuffer();
      sb.append("<p style='margin:0px 5px 0px 5px; color:#00D;"
            + " background-color:#FFA;'>");
      sb.append("No messages.");
      sb.append("</p>");
      msgs.add(sb.toString());
   }

   for (String msg : msgs) {
      writer.write(msg);
   }

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

示例8: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void serveResource(ResourceRequest req, ResourceResponse resp)
      throws PortletException, IOException {
   
   resp.setContentType("text/html");
   PrintWriter writer = resp.getWriter();

   ArrayList<String> msgs = (ArrayList<String>) req.getPortletSession().getAttribute(ATTRIB_MSGS);
   if (msgs == null) {
      msgs = new ArrayList<String>();
      
      StringBuffer sb = new StringBuffer();
      sb.append("<p style='margin:0px 5px 0px 5px; color:#00D;"
            + " background-color:#FFA;'>");
      sb.append("No messages.");
      sb.append("</p>");
      msgs.add(sb.toString());
   }

   for (String msg : msgs) {
      writer.write(msg);
   }

   int n = msgs.size();
   logger.fine("Served messages. latest message: " + (n > 0 ? msgs.get(n-1) : "null"));
}
 
开发者ID:msnicklous,项目名称:SinglePageAppPortlets,代码行数:28,代码来源:MessageBoxPortlet.java

示例9: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    String testId = getTestId(request);
    PortletTest test = (PortletTest) tests.get(testId);
    if (test != null) {
        TestResults results = test.doTest(getPortletConfig(),
                                          getPortletContext(),
                                          request,
                                          response);
        PortletSession session = request.getPortletSession();
        TestResults existing = (TestResults) session.getAttribute(
                test.getClass().getName());
        if (existing != null) {
            for (TestResult result : results.getCollection()) {
                existing.add(result);
            }
            request.setAttribute("results", existing);
            session.setAttribute(test.getClass().getName(), null);
        } else {
            request.setAttribute("results", results);
        }
    }
    if (test.getConfig().getDisplayURI().indexOf("load_resource_test") > -1) {
        response.setContentType("text/html");
        getPortletContext().getRequestDispatcher("/jsp/test_results.jsp")
            .include(request, response);
    }
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:29,代码来源:TestPortlet.java

示例10: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void serveResource(ResourceRequest req, ResourceResponse resp)
      throws PortletException, IOException {
   
   resp.setContentType("text/html");
   PrintWriter writer = resp.getWriter();

   String num = req.getParameter(PARAM_NUM_ACTIONS);
   num = (num == null) ? "error" : num;
   
   writer.write("<p>Partial Action has been executed " + num + " times.</p>\n");
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:14,代码来源:PartialActionPortlet.java

示例11: 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

示例12: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest req, ResourceResponse resp)
      throws PortletException, IOException {

   resp.setContentType("text/html");
   PrintWriter writer = resp.getWriter();

   StringBuilder txt = new StringBuilder();
   
   String scText = req.getRenderParameters().getValue(PARAM_STATUSCODE);
   if (scText != null && scText.matches("\\d+")) {
      int sc = Integer.parseInt(scText);
      if (isDebug) {
         logger.fine("Setting HTTP status code to: " + sc);
      }
      resp.setStatus(sc);
   }
   
   txt.append("<p>serveResource</p>");
   txt.append("<p>Status code: ").append(scText);
   txt.append("<br>Status code from getStatus(): ").append(resp.getStatus());
   txt.append("<br>Content length: ");
   int len = txt.length() + "</p>".length() + 3;
   txt.append(String.format("%3d", len));
   txt.append("</p>");
   
   resp.setContentLengthLong(txt.length());
   writer.write(txt.toString());
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:30,代码来源:AuthSCPortlet.java

示例13: 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();
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:14,代码来源:MultipartPortlet.java

示例14: 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

示例15: serveResource

import javax.portlet.ResourceResponse; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest req, ResourceResponse resp)
      throws PortletException, IOException {

   String key = req.getParameter(PARAM_IMGNAME);
   String imgDir = DEFAULT_IMAGE;
   if ((key != null) && imgMap.containsKey(key)) {
      imgDir = imgMap.get(key);
   }
   
   String bc = req.getParameter(PARAM_BORDER_COLOR);
   String imgStyle = "";
   if (bc != null) {
      imgStyle = " style='border:1px solid " + bc + ";' ";
   }
   
   String ctx = req.getContextPath();
   String ca = req.getCacheability();
   
   resp.setContentType("text/html");
   PrintWriter writer = resp.getWriter();
   
   String clr = req.getParameter(PARAM_COLOR);
   clr = (clr == null) ? "#FFFFFF" : clr;

   // add action button if cacheability allows -
   PortletURL aurl = null;
   String bmu = "<p>Action URL could not be created.</p>";
   try {
      aurl = resp.createActionURL();
   } catch (Exception e) {}
   if (aurl != null) {
      bmu = "<form  onsubmit='return false;' METHOD='POST' ACTION='" + aurl + "'><input id='<portlet:namespace/>-clear' type='submit' name='action' value='Action' /></form>";
   }

   writer.write("<div style='background-color:" + clr + ";'>\n");
   writer.write("   <table style='background-color:" + clr + ";'>");
   writer.write("   <tr><td align='center' style='background-color:" + clr + ";'>");
   writer.write("   <img src='" + ctx + imgDir + "'" + imgStyle + ">\n");
   writer.write("   </td><td style='background-color:" + clr + ";'>");
   writer.write("   <p>" + bmu + "</p>");
   writer.write("   <p>Cacheability: " + ca + "</p>");
   writer.write("   </td></tr>");
   writer.write("   </table>");
   writer.write("</div>\n");


}
 
开发者ID:msnicklous,项目名称:SinglePageAppPortlets,代码行数:49,代码来源:ResourcePortlet.java


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