Java 类javax.portlet.ResourceResponse 实例源码

项目:liferay-dummy-factory    文件:PageMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest request, ResourceResponse response)
        throws Exception {
    String cmd = ParamUtil.getString(request, Constants.CMD);
    String serializedJson = "";

    if(cmd.equals(CMD_PAGELIST)) {
        serializedJson = getPageLists(request,response );
    } else {
        _log.error("Unknown command is passed <" + cmd + ">");
    }

    HttpServletResponse servletResponse = _portal.getHttpServletResponse(
            response);

    servletResponse.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(servletResponse, serializedJson);     
}
项目:ch-inofix-timetracker    文件:ImportTaskRecordsMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);

    PortletRequestDispatcher portletRequestDispatcher = null;

    if (cmd.equals(Constants.IMPORT)) {
        portletRequestDispatcher = getPortletRequestDispatcher(resourceRequest, "/import/processes_list/view.jsp");
    } else {
        portletRequestDispatcher = getPortletRequestDispatcher(resourceRequest,
                "/import/new_import/import_task_records_resources.jsp");
    }

    portletRequestDispatcher.include(resourceRequest, resourceResponse);
}
项目:ch-inofix-contact-manager    文件:ImportContactsMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);

    PortletRequestDispatcher portletRequestDispatcher = null;

    if (cmd.equals(Constants.IMPORT)) {
        portletRequestDispatcher = getPortletRequestDispatcher(resourceRequest, "/import/processes_list/view.jsp");
    } else {
        portletRequestDispatcher = getPortletRequestDispatcher(resourceRequest,
                "/import/new_import/import_contacts_resources.jsp");
    }

    portletRequestDispatcher.include(resourceRequest, resourceResponse);
}
项目:liferay-gsearch    文件:GetHelpTextMVCResourceCommand.java   
@Override
protected void doServeResource(
    ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("GetHelpTextMVCResourceCommand.doServeResource()");
    }

    JSONObject helpObject = JSONFactoryUtil.createJSONObject();

    helpObject.put(GSearchWebKeys.HELP_TEXT, getHelpText(resourceRequest));

    JSONPortletResponseUtil.writeJSON(
        resourceRequest, resourceResponse, helpObject);
}
项目:liferay-dummy-factory    文件:RoleMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
    String serializedJson = "";

    if (cmd.equals(CMD_ROLELIST)) {
        serializedJson = getRoleLists(resourceRequest, resourceResponse);
    } else {
        _log.error("Unknown command is passed <" + cmd + ">");
    }

    HttpServletResponse response = _portal.getHttpServletResponse(resourceResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(response, serializedJson);
}
项目:liferay-dummy-factory    文件:ImageLinksMVCResourceCommand.java   
/**
 * Create Return json value 
 * 
 * @param resourceRequest
 * @param resourceResponse
 * @param urls URL string list
 * @return json URL strings
 */
protected String createReturnJson(ResourceRequest resourceRequest, ResourceResponse resourceResponse, List<String> urls) {

    JSONObject rootJSONObject = JSONFactoryUtil.createJSONObject();

    //Add plain text with line breaks for textarea
    rootJSONObject.put("urlstr", String.join(LDFPortletKeys.EOL, urls));

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    for ( String url : urls) {
        JSONObject curUserJSONObject = JSONFactoryUtil.createJSONObject();

        curUserJSONObject.put("url", url);
        jsonArray.put(curUserJSONObject);
    }
    rootJSONObject.put("urllist", jsonArray);

    return rootJSONObject.toJSONString();
}
项目:liferay-dummy-factory    文件:MBMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {
    String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
    String serializedJson = "";

    if(cmd.equals(CMD_THREAD_LIST)) {
        serializedJson = getThreadList(resourceRequest,resourceResponse );

    } else if (cmd.equals(CMD_CATEGORY_LIST)) {
        serializedJson = getCategoryList(resourceRequest,resourceResponse );

    } else {
        _log.error("Unknown command is passed <" + cmd + ">");
    }

    HttpServletResponse response = _portal.getHttpServletResponse(
            resourceResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(response, serializedJson);        
}
项目:ch-inofix-data-manager    文件:ImportMeasurementsMVCResourceCommand.java   
@Override
    protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
            throws Exception {

//        _log.info("doServeResource()");

        String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);

//        _log.info("cmd = " + cmd);

        PortletRequestDispatcher portletRequestDispatcher = null;

        if (cmd.equals(Constants.IMPORT)) {
            portletRequestDispatcher = getPortletRequestDispatcher(resourceRequest, "/import/processes_list/view.jsp");
        } else {
            portletRequestDispatcher = getPortletRequestDispatcher(resourceRequest,
                    "/import/new_import/import_measurements_resources.jsp");
        }

        portletRequestDispatcher.include(resourceRequest, resourceResponse);
    }
项目:spring4-understanding    文件:AnnotationMethodHandlerAdapter.java   
private String determineDefaultPhase(Method handlerMethod) {
    if (void.class != handlerMethod.getReturnType()) {
        return PortletRequest.RENDER_PHASE;
    }
    for (Class<?> argType : handlerMethod.getParameterTypes()) {
        if (ActionRequest.class.isAssignableFrom(argType) || ActionResponse.class.isAssignableFrom(argType) ||
                InputStream.class.isAssignableFrom(argType) || Reader.class.isAssignableFrom(argType)) {
            return PortletRequest.ACTION_PHASE;
        }
        else if (RenderRequest.class.isAssignableFrom(argType) || RenderResponse.class.isAssignableFrom(argType) ||
                OutputStream.class.isAssignableFrom(argType) || Writer.class.isAssignableFrom(argType)) {
            return PortletRequest.RENDER_PHASE;
        }
        else if (ResourceRequest.class.isAssignableFrom(argType) || ResourceResponse.class.isAssignableFrom(argType)) {
            return PortletRequest.RESOURCE_PHASE;
        }
        else if (EventRequest.class.isAssignableFrom(argType) || EventResponse.class.isAssignableFrom(argType)) {
            return PortletRequest.EVENT_PHASE;
        }
    }
    return "";
}
项目:spring4-understanding    文件:DispatcherPortlet.java   
/**
 * Determine an error ModelAndView via the registered HandlerExceptionResolvers.
 * @param request current portlet request
 * @param response current portlet response
 * @param handler the executed handler, or null if none chosen at the time of
 * the exception (for example, if multipart resolution failed)
 * @param ex the exception that got thrown during handler execution
 * @return a corresponding ModelAndView to forward to
 * @throws Exception if no error ModelAndView found
 */
protected ModelAndView processHandlerException(
        ResourceRequest request, ResourceResponse response, Object handler, Exception ex)
        throws Exception {

    ModelAndView exMv = null;
    for (Iterator<HandlerExceptionResolver> it = this.handlerExceptionResolvers.iterator(); exMv == null && it.hasNext();) {
        HandlerExceptionResolver resolver = it.next();
        exMv = resolver.resolveException(request, response, handler, ex);
    }
    if (exMv != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("HandlerExceptionResolver returned ModelAndView [" + exMv + "] for exception");
        }
        logger.warn("Handler execution resulted in exception - forwarding to resolved error view", ex);
        return exMv;
    }
    else {
        throw ex;
    }
}
项目:spring4-understanding    文件:DispatcherPortlet.java   
/**
 * Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 * Will just invoke afterCompletion for all interceptors whose preHandle
 * invocation has successfully completed and returned true.
 * @param mappedHandler the mapped HandlerExecutionChain
 * @param interceptorIndex index of last interceptor that successfully completed
 * @param ex Exception thrown on handler execution, or null if none
 * @see HandlerInterceptor#afterRenderCompletion
 */
private void triggerAfterResourceCompletion(HandlerExecutionChain mappedHandler, int interceptorIndex,
        ResourceRequest request, ResourceResponse response, Exception ex)
        throws Exception {

    // Apply afterCompletion methods of registered interceptors.
    if (mappedHandler != null) {
        HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
        if (interceptors != null) {
            for (int i = interceptorIndex; i >= 0; i--) {
                HandlerInterceptor interceptor = interceptors[i];
                try {
                    interceptor.afterResourceCompletion(request, response, mappedHandler.getHandler(), ex);
                }
                catch (Throwable ex2) {
                    logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
                }
            }
        }
    }
}
项目:spring4-understanding    文件:PortletUtils.java   
/**
 * Serve the resource as specified in the given request to the given response,
 * using the PortletContext's request dispatcher.
 * <p>This is roughly equivalent to Portlet 2.0 GenericPortlet.
 * @param request the current resource request
 * @param response the current resource response
 * @param context the current Portlet's PortletContext
 * @throws PortletException propagated from Portlet API's forward method
 * @throws IOException propagated from Portlet API's forward method
 */
public static void serveResource(ResourceRequest request, ResourceResponse response, PortletContext context)
        throws PortletException, IOException {

    String id = request.getResourceID();
    if (id != null) {
        if (!PortletUtils.isProtectedResource(id)) {
            PortletRequestDispatcher rd = context.getRequestDispatcher(id);
            if (rd != null) {
                rd.forward(request, response);
                return;
            }
        }
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "404");
    }
}
项目:liferay-blade-samples    文件:CustomMVCResourceCommand.java   
@Override
public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws PortletException {

    final String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);

    if (cmd.equals("BOOKMARK_ORDERABLE")) {
        serveOlderUserBookmarks(resourceRequest, resourceResponse);
    }
    else {
        _editFolderMVCResourceCommand.serveResource(
            resourceRequest, resourceResponse);
    }

    return true;
}
项目:liferay-blade-samples    文件:CaptchaMVCResourceCommand.java   
@Override
public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws PortletException {

    if (_log.isInfoEnabled()) {
        _log.info("get captcha resource ");
    }

    try {
        CaptchaUtil.serveImage(resourceRequest, resourceResponse);

        return false;
    }
    catch (Exception e) {
        _log.error(e, e);

        return true;
    }
}
项目:liferay-blade-samples    文件:CustomMVCResourceCommand.java   
@Override
public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws PortletException {

    final String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);

    if (cmd.equals("BOOKMARK_ORDERABLE")) {
        serveOlderUserBookmarks(resourceRequest, resourceResponse);
    }
    else {
        _editFolderMVCResourceCommand.serveResource(
            resourceRequest, resourceResponse);
    }

    return true;
}
项目:liferay-blade-samples    文件:CaptchaMVCResourceCommand.java   
@Override
public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws PortletException {

    if (_log.isInfoEnabled()) {
        _log.info("get captcha resource ");
    }

    try {
        CaptchaUtil.serveImage(resourceRequest, resourceResponse);

        return false;
    }
    catch (Exception e) {
        _log.error(e, e);

        return true;
    }
}
项目:liferay-blade-samples    文件:CustomMVCResourceCommand.java   
@Override
public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws PortletException {

    final String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);

    if (cmd.equals("BOOKMARK_ORDERABLE")) {
        serveOlderUserBookmarks(resourceRequest, resourceResponse);
    }
    else {
        _editFolderMVCResourceCommand.serveResource(
            resourceRequest, resourceResponse);
    }

    return true;
}
项目:liferay-blade-samples    文件:CaptchaMVCResourceCommand.java   
@Override
public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws PortletException {

    if (_log.isInfoEnabled()) {
        _log.info("get captcha resource ");
    }

    try {
        CaptchaUtil.serveImage(resourceRequest, resourceResponse);

        return false;
    }
    catch (Exception e) {
        _log.error(e, e);

        return true;
    }
}
项目:OEPv2    文件:ProcessDesignerPortlet.java   
@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);
}
项目:OEPv2    文件:DossierProcPortlet.java   
@Override
public void serveResource(ResourceRequest resourceRequest,
        ResourceResponse resourceResponse) throws IOException,
        PortletException {
    System.out.println("=====serveResource=======");
    String domainNo = ParamUtil.getString(resourceRequest, "domainNo");
    String administrationNo = ParamUtil.getString(resourceRequest,
            "administrationNo");
    PrintWriter pw = resourceResponse.getWriter();
    JSONObject juser = JSONFactoryUtil.createJSONObject();

    juser.put("domainNo", domainNo);
    juser.put("administrationNo", administrationNo);
    pw.println(juser.toString());
    PortletSession session = resourceRequest.getPortletSession();
    // PortletMode portletMode= resourceRequest.getPortletMode();
    // portletMode.s
    session.setAttribute("domainNo", domainNo);
    System.out.println(juser.toString());
}
项目:OEPv2    文件:MenuListDomain.java   
@Override
public void serveResource(ResourceRequest resourceRequest,
        ResourceResponse resourceResponse) throws IOException,
        PortletException {
    System.out.println("=====serveResource=======");
    String domainNo = ParamUtil.getString(resourceRequest, "domainNo");
    String administrationNo = ParamUtil.getString(resourceRequest,
            "administrationNo");
    PrintWriter pw = resourceResponse.getWriter();
    JSONObject juser = JSONFactoryUtil.createJSONObject();

    juser.put("domainNo", domainNo);
    juser.put("administrationNo", administrationNo);
    pw.println(juser.toString());
    PortletSession session = resourceRequest.getPortletSession();
    session.setAttribute("domainNo", domainNo);
}
项目:OEPv2    文件:RSAToolPortlet.java   
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();
  }
项目:liferaylms-portlet    文件:CatalogCourses.java   
public void serveResource(ResourceRequest request, ResourceResponse response)throws PortletException, IOException {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String action = ParamUtil.getString(request, "action");

    if(action.equals("getCourses")){
        JSONArray usersJSONArray = JSONFactoryUtil.createJSONArray();

        String freeText = ParamUtil.getString(request, "courseTitle");

        List<Course> listCourse = CourseLocalServiceUtil.getCoursesCatalogByTitleCategoriesTags(freeText, null, null, themeDisplay.getCompanyId(), 
                                        themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), themeDisplay.getLanguageId(), -1, -1);

        JSONObject userJSON = null;

        for (Course course : listCourse) {
            userJSON = JSONFactoryUtil.createJSONObject();
            userJSON.put("courseTitle", course.getTitle(themeDisplay.getLocale()));
            userJSON.put("courseDescription", course.getDescription(themeDisplay.getLocale()));
            usersJSONArray.put(userJSON);
        }

        PrintWriter out = response.getWriter();
        out.println(usersJSONArray.toString());
    }
}
项目:liferaylms-portlet    文件:CourseStats.java   
@Override
public void serveResource(ResourceRequest resourceRequest,
                          ResourceResponse resourceResponse) 
                throws IOException, PortletException {
    String action = ParamUtil.getString(resourceRequest, "action");
    ThemeDisplay themeDisplay  =(ThemeDisplay)resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long teamId   = ParamUtil.getLong(resourceRequest, "teamId", 0);

    if("export".equals(action)){
        long courseId = ParamUtil.getLong(resourceRequest, "courseId",0);
        exportCourse(resourceResponse, courseId, teamId, themeDisplay);
    } else if("exportModule".equals(action)){
        long moduleId = ParamUtil.getLong(resourceRequest, "moduleId",0);
        exportModule(resourceResponse, moduleId, teamId, themeDisplay, resourceRequest);
    }
}
项目:Aspose_for_Liferay    文件:AsposeIconAction.java   
@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();

}
项目:edemocracia    文件:ChatRoomPortlet.java   
@Override
public final void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    String id = request.getResourceID();
    PrintWriter out = response.getWriter();
    if (id.equalsIgnoreCase("cdchatupdate")) {
        getAjaxChatUpdate(request, out);
    } else if (id.equalsIgnoreCase("cdchatpostmsg")) {
        postAjaxMessage(request, out);
    } else if (id.equalsIgnoreCase("cdchatbanuser")) {
        ajaxBanUser(request, out, true);
    } else if (id.equalsIgnoreCase("cdchatunbanuser")) {
        ajaxBanUser(request, out, false);
    } else if (id.equalsIgnoreCase("cdchatapprovemsg")) {
        ajaxApproveMsg(request, out, true);
    } else if (id.equalsIgnoreCase("cdchatrejectmsg")) {
        ajaxApproveMsg(request, out, false);
    } else if (id.equalsIgnoreCase("cdchatopenroom")) {
        ajaxOpenRoom(request, out);
    } else if (id.equalsIgnoreCase("cdchatcloseroom")) {
        ajaxCloseRoom(request, out);
    } else if (id.equalsIgnoreCase("cdchatexport")) {
        exportMessages(request, response);
    }
}
项目:edemocracia    文件:ContadoresPortlet.java   
/**
 * 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);
    }

}
项目:portals-pluto    文件:DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceRequest.java   
@Override
public void serveResource(ResourceRequest portletReq, ResourceResponse portletResp)
      throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   // Prereq for: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceRequest_getAttribute
   portletReq.setAttribute(ATTR_PREFIX +"V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceRequest_getAttribute", "Value1");

   // Prereq for: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceRequest_getAttributeNames
   portletReq.setAttribute(ATTR_PREFIX + "V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceRequest_getAttributeNames", "Value1");

   // Now do the actual dispatch
   String target = SERVLET_PREFIX + "DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceRequest_servlet" + SERVLET_SUFFIX + "?" + QUERY_STRING;
   PortletRequestDispatcher rd = portletConfig.getPortletContext()
         .getRequestDispatcher(target);
   rd.include(portletReq, portletResp);
}
项目:portals-pluto    文件:AsyncFilter.java   
@Override
public void doFilter(ResourceRequest resourceRequest, ResourceResponse resourceResponse, FilterChain chain) throws IOException,
      PortletException {

   DispatcherType dispatcherType = resourceRequest.getDispatcherType();

   StringBuilder txt = new StringBuilder(128);
   txt.append("Entering request. DispatcherType: ").append(dispatcherType);
   txt.append(", request #: ").append(reqnum.getRandomNumber());
   LOGGER.fine(txt.toString());

   if (asyncDialogBean.isShowFilter()) {
      txt.setLength(0);
      txt.append("<div class='msgbox'>");
      txt.append("Filter: Request number: ").append(reqnum.getRandomNumber());
      txt.append(", DispatcherType: ").append(resourceRequest.getDispatcherType());
      txt.append("</div>");
      resourceResponse.getWriter().write(txt.toString());
   }

   chain.doFilter(resourceRequest, resourceResponse);

   LOGGER.fine("Exiting request. DispatcherType: " + resourceRequest.getDispatcherType());

}
项目:portals-pluto    文件:PortletTests_ResourceServingPortlet_ApiResource.java   
@Override
public void serveResource(ResourceRequest portletReq,
      ResourceResponse portletResp) throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   JSR286ApiTestCaseDetails tcd = new JSR286ApiTestCaseDetails();

   // Create result objects for the tests

   /*
    * TestCase:
    * V2PortletTests_ResourceServingPortlet_ApiResource_serveResource
    */
   /* Details: "Method serveResource(ResourceRequest, ResourceResponse): */
   /* is called to allow the portlet to generate resource content " */
   TestResult tr0 = tcd.getTestResultFailed(
         V2PORTLETTESTS_RESOURCESERVINGPORTLET_APIRESOURCE_SERVERESOURCE);

   tr0.setTcSuccess(true);

   tr0.writeTo(writer);
}
项目:flashlight-search    文件:FlashlightSearchPortlet.java   
/**
 * Routes between portlet resources
 *
 * @param request  The request
 * @param response The response
 *
 * @throws PortletException If something goes wrong
 * @throws IOException      If something goes wrong
 */
@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    PortletResource resource = PortletResource.getResource(request);

    switch(resource) {
        case LOAD_MORE:
            this.doLoadMore(request, response);
        break;
        default:
            response.setProperty(ResourceResponse.HTTP_STATUS_CODE, STATUS_CODE_NOT_FOUND);
        break;
    }
}
项目:myfaces-trinidad    文件:XmlHttpPortletExternalContext.java   
@Override
public void redirect(String url)
  throws IOException
{
  PrintWriter writer = ((ResourceResponse)_ec.getResponse()).getWriter();
  XmlHttpConfigurator.sendXmlRedirect(writer, url);
}
项目:myfaces-trinidad    文件:XmlHttpResourceResponse.java   
public XmlHttpResourceResponse(ExternalContext ec)
{
  super((ResourceResponse) ec.getResponse());

  _contentType = "text/xml;charset=utf-8";

  // must set contentType here since
  // setContentType is ignored when inside an included page (bug 5591124)
  super.setContentType(_contentType);
}
项目:liferay-gsearch    文件:GetSuggestionsMVCResourceCommand.java   
@Override
protected void doServeResource(
    ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("GetSuggestionsMVCResourceCommand.doServeResource()");
    }

    JSONArray response = null;

    try {
        response = _gSearchSuggester.getSuggestions(
            resourceRequest);
    }
    catch (Exception e) {

        _log.error(e, e);

        return;
    }

    // Write response to the output stream.

    JSONPortletResponseUtil.writeJSON(
        resourceRequest, resourceResponse, response);
}
项目:liferay-gsearch    文件:GetSuggestionsMVCResourceCommand.java   
@Override
protected void doServeResource(
    ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("GetSuggestionsMVCResourceCommand.doServeResource()");
    }

    JSONArray response = null;

    try {
        response = _gSearchSuggester.getSuggestions(
            resourceRequest);
    }
    catch (Exception e) {

        _log.error(e, e);

        return;
    }

    // Write response to the output stream.

    JSONPortletResponseUtil.writeJSON(
        resourceRequest, resourceResponse, response);
}
项目:liferay-dummy-factory    文件:PageMVCResourceCommand.java   
/**
 * Get Page lists
 * 
 * Depending on the passed site groupd id, 
 * fetch all pages in the site and return JSON object list.
 * 
 * @param request
 * @param response
 * @return
 */
protected String getPageLists(ResourceRequest request, ResourceResponse response) {
    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
            WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
    long siteGroupId = ParamUtil.getLong(request, "siteGroupId", themeDisplay.getSiteGroupId());

    List<Layout> layouts = _layoutLocalService.getLayouts(
            siteGroupId, 
            false, 
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 
            false, 
            QueryUtil.ALL_POS, 
            QueryUtil.ALL_POS);

    for(Layout layout : layouts ) {
        JSONObject curUserJSONObject = JSONFactoryUtil.createJSONObject();

        if(_log.isDebugEnabled()) {
            _log.debug("layout <" + layout.getName(themeDisplay.getLocale()) + ">");
            _log.debug(layout.toString());
            _log.debug("----------");
        }

        curUserJSONObject.put("name" , layout.getName(themeDisplay.getLocale()));
        curUserJSONObject.put("parentLayoutId" , layout.getLayoutId());

        jsonArray.put(curUserJSONObject);
    }

    return jsonArray.toJSONString();
}
项目:liferay-dummy-factory    文件:ImageLinksMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {
    int numberOfCrawlers = ParamUtil.getInteger(resourceRequest, "numberOfCrawlers", -1);
    int maxDepthOfCrawling = ParamUtil.getInteger(resourceRequest, "maxDepthOfCrawling", -1);
    int maxPagesToFetch = ParamUtil.getInteger(resourceRequest, "maxPagesToFetch", -1);
    String tmpUrls = ParamUtil.getString(resourceRequest, "urls", "https://www.shutterstock.com/photos");
    String[] strArray = tmpUrls.split(",");
    List<String> urls = new ArrayList<>(Arrays.asList(strArray));
    List<String> result = Lists.newArrayList();

    if(_log.isDebugEnabled()) {
        _log.debug("numberOfCrawlers : " + String.valueOf(numberOfCrawlers));
        _log.debug("maxDepthOfCrawling : " + String.valueOf(maxDepthOfCrawling));
        _log.debug("maxPagesToFetch : " + String.valueOf(maxPagesToFetch));
    }

    if( numberOfCrawlers >= 0 && 
        maxDepthOfCrawling >= 0 && 
        maxPagesToFetch >= 0 ) {

        // Run image links crawler
        result = run(numberOfCrawlers, maxDepthOfCrawling, maxPagesToFetch, urls);
    }

    HttpServletResponse response = _portal.getHttpServletResponse(resourceResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    String serializedJson = createReturnJson(resourceRequest, resourceResponse, result);

    ServletResponseUtil.write(response, serializedJson);        
}
项目:liferay-dummy-factory    文件:MBMVCResourceCommand.java   
/**
 * Get Category list
 * 
 * @param resourceRequest
 * @param resourceResponse
 * @return
 * @throws PortalException 
 */
private String getCategoryList(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    String[] groupsStrIds = ParamUtil.getStringValues(resourceRequest, "groupIds",
            new String[] { String.valueOf(themeDisplay.getScopeGroupId()) });
    long[] groupIds = CommonUtil.convertStringToLongArray(groupsStrIds);        
    long siteGroupId = groupIds[0];

    if(_log.isDebugEnabled()) {
        _log.debug("SiteGroup Id <" + String.valueOf(siteGroupId) + ">");
    }

    List<MBCategory> categories = _mbCategoryLocalService.getCategories(
            siteGroupId, 
            MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, 
            WorkflowConstants.STATUS_APPROVED, 
            QueryUtil.ALL_POS, 
            QueryUtil.ALL_POS);

    for(MBCategory category : categories ) {
        JSONObject curUserJSONObject = JSONFactoryUtil.createJSONObject();

        if(_log.isDebugEnabled()) {
            _log.debug("Category name <" + category.getName() + ">");
            _log.debug(category.toString());
            _log.debug("----------");
        }

        curUserJSONObject.put("categoryId" , category.getCategoryId());
        curUserJSONObject.put("categoryName" , category.getName());

        jsonArray.put(curUserJSONObject);
    }

    return jsonArray.toJSONString();
}
项目:liferay-dummy-factory    文件:MBMVCResourceCommand.java   
/**
 * Get Thread list
 * 
 * Depending on the passed site groupd id, fetch all pages in the site and return JSON object list.
 * 
 * @param resourceRequest
 * @param resourceResponse
 * @return
 * @throws PortalException 
 */
protected String getThreadList(ResourceRequest resourceRequest, ResourceResponse resourceResponse) 
        throws PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
    long siteGroupId = ParamUtil.getLong(resourceRequest, "siteGroupId", themeDisplay.getSiteGroupId());

    if(_log.isDebugEnabled()) {
        _log.debug("SiteGroup Id <" + String.valueOf(siteGroupId) + ">");
    }

    List<MBThread> threads = _mbThreadLocalService.getThreads(
            siteGroupId, 
            MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, 
            WorkflowConstants.STATUS_APPROVED, 
            QueryUtil.ALL_POS, 
            QueryUtil.ALL_POS);

    for(MBThread thread : threads ) {
        JSONObject curUserJSONObject = JSONFactoryUtil.createJSONObject();

        MBMessage message = _mbMessageLocalService.getMessage(thread.getRootMessageId());

        if(_log.isDebugEnabled()) {
            _log.debug("Root message <" + message.getSubject() + ">");
            _log.debug(thread.toString());
            _log.debug("----------");
        }

        curUserJSONObject.put("rootMessageSubject" , message.getSubject());
        curUserJSONObject.put("threadId" , thread.getThreadId());
        curUserJSONObject.put("rootMessageId" , thread.getRootMessageId());

        jsonArray.put(curUserJSONObject);
    }

    return jsonArray.toJSONString();
}
项目:liferay-dummy-factory    文件:CategoryMVCResourceCommand.java   
/**
 * Get Category list
 * 
 * @param resourceRequest
 * @param resourceResponse
 * @return
 * @throws PortalException
 */
private String getCategoryList(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws PortalException {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    long vocabularyId = ParamUtil.getLong(resourceRequest, "vocabularyId",0);

    if (_log.isDebugEnabled()) {
        _log.debug("Vocabulary Id <" + String.valueOf(vocabularyId) + ">");
    }

    List<AssetCategory> categories = 
        _assetCategoryLocalService.getVocabularyCategories(
            vocabularyId,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            null
        );

    for (AssetCategory category : categories) {
        JSONObject curUserJSONObject = JSONFactoryUtil.createJSONObject();

        if (_log.isDebugEnabled()) {
            _log.debug("Category name <" + category.getName() + ">");
            _log.debug(category.toString());
            _log.debug("----------");
        }

        curUserJSONObject.put("categoryId", category.getCategoryId());
        curUserJSONObject.put("categoryName", category.getName());

        jsonArray.put(curUserJSONObject);
    }

    return jsonArray.toJSONString();
}