Java 类javax.portlet.PortletMode 实例源码

项目:spring4-understanding    文件:Portlet20AnnotationControllerTests.java   
@Test
public void standardHandleMethod() throws Exception {
    DispatcherPortlet portlet = new DispatcherPortlet() {
        @Override
        protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
            GenericWebApplicationContext wac = new GenericWebApplicationContext();
            wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class));
            wac.refresh();
            return wac;
        }
    };
    portlet.init(new MockPortletConfig());

    MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
    MockRenderResponse response = new MockRenderResponse();
    portlet.render(request, response);
    assertEquals("test", response.getContentAsString());
}
项目:spring4-understanding    文件:PortletAnnotationControllerTests.java   
@Test
public void standardHandleMethod() throws Exception {
    DispatcherPortlet portlet = new DispatcherPortlet() {
        @Override
        protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
            GenericWebApplicationContext wac = new GenericWebApplicationContext();
            wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class));
            wac.refresh();
            return wac;
        }
    };
    portlet.init(new MockPortletConfig());

    MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
    MockRenderResponse response = new MockRenderResponse();
    portlet.render(request, response);
    assertEquals("test", response.getContentAsString());
}
项目:spring4-understanding    文件:PortletAnnotationControllerTests.java   
@Test
public void mavResolver() throws Exception {
    DispatcherPortlet portlet = new DispatcherPortlet() {
        @Override
        protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
            GenericWebApplicationContext wac = new GenericWebApplicationContext();
            wac.registerBeanDefinition("controller",
                    new RootBeanDefinition(ModelAndViewResolverController.class));
            RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
            adapterDef.getPropertyValues()
                    .add("customModelAndViewResolver", new MyModelAndViewResolver());
            wac.registerBeanDefinition("handlerAdapter", adapterDef);
            wac.refresh();
            return wac;
        }
    };
    portlet.init(new MockPortletConfig());

    MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
    MockRenderResponse response = new MockRenderResponse();
    portlet.render(request, response);
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletModeMappingViewRenderRequestWithUnauthorizedUserRole() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setPortletMode(PortletMode.VIEW);
    request.addUserRole("role3");
    request.setParameter("action", "not mapped");
    request.setParameter("myParam", "not mapped");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception) model.get("exception");
    assertNotNull(exception);
    assertTrue(exception.getClass().equals(PortletSecurityException.class));
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:sakai    文件:PortletStateTest.java   
public void testSerialization() throws IOException, ClassNotFoundException
{
    PortletState state = new PortletState("id");
    state.setPortletMode(PortletMode.VIEW);
    state.setWindowState(WindowState.MAXIMIZED);

    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bao);

    out.writeObject(state);

    ByteArrayInputStream bai = new ByteArrayInputStream(bao.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bai);
    PortletState alter = (PortletState) in.readObject();

    assertEquals(state, alter);

}
项目:sakai    文件:SimplePortletStateEncoderTest.java   
public void testEncodeDecode()
{
    PortletState state = new PortletState("id");
    state.setAction(true);
    state.setSecure(true);
    state.setWindowState(WindowState.MAXIMIZED);
    state.setPortletMode(PortletMode.EDIT);

    String uriSafe = encoder.encode(state);
    PortletState read = encoder.decode(uriSafe);
    assertEquals(state.getId(), read.getId());
    assertEquals(state.isAction(), read.isAction());
    assertEquals(state.isSecure(), read.isSecure());
    assertEquals(state.getWindowState(), read.getWindowState());
    assertEquals(state.getPortletMode(), read.getPortletMode());
}
项目:sakai    文件:SimpleRSSPortlet.java   
/**
 * Get the feed content
 * @param request
 * @param response
 * @return Map of params or null if any required data is missing
 */
private SyndFeed getFeedContent(RenderRequest request, RenderResponse response) {

    SyndFeed feed;

    //check cache, otherwise get fresh
    //we use the feedUrl as the cacheKey
    String feedUrl = getConfiguredFeedUrl(request);
    if(StringUtils.isBlank(feedUrl)) {
        log.debug("No feed URL configured");
        doError("error.no.config", "error.heading.config", getPortletModeUrl(response, PortletMode.EDIT), request, response);
        return null;
    }

    String cacheKey = feedUrl;

    feed = feedCache.get(cacheKey);
    if(feed != null) {
        log.debug("Fetching data from feed cache for: " + cacheKey);
    } else {
        //get from remote
        feed = getRemoteFeed(feedUrl, request, response);
    }

    return feed;
}
项目:portals-pluto    文件:DriverPortletConfigImpl.java   
private HashSet<PortletMode> getPMList(String mimeType) {
   HashSet<PortletMode> pms = new HashSet<PortletMode>();

   pms.add(PortletMode.VIEW);       // all portlets support view

   // Add the portlet mode to the list 

   for (Supports s : portlet.getSupports()) {
      if (mimeType.equalsIgnoreCase(s.getMimeType())) {
         for (String pmname : s.getPortletModes()) {
            PortletMode pm = new PortletMode(pmname);
            pms.add(pm);
         }
      }
   }

   return pms;
}
项目:eterna    文件:RenderExecute.java   
public ModelExport execute(AppData data, Connection conn)
        throws ConfigurationException, SQLException, IOException
{
    WindowState state = data.renderRequest.getWindowState();
    if (!state.equals(WindowState.MINIMIZED))
    {
        PortletMode mode = data.renderRequest.getPortletMode();
        if (PortletMode.VIEW.equals(mode))
        {
            return this.view;
        }
        else if (PortletMode.EDIT.equals(mode))
        {
            return this.edit;
        }
        else if (PortletMode.HELP.equals(mode))
        {
            return this.help;
        }
        else
        {
            log.error("Unknown portlet mode: " + mode + ".");
        }
    }
    return null;
}
项目:class-guard    文件:Portlet20AnnotationControllerTests.java   
@Test
public void standardHandleMethod() throws Exception {
    DispatcherPortlet portlet = new DispatcherPortlet() {
        @Override
        protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
            GenericWebApplicationContext wac = new GenericWebApplicationContext();
            wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class));
            wac.refresh();
            return wac;
        }
    };
    portlet.init(new MockPortletConfig());

    MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
    MockRenderResponse response = new MockRenderResponse();
    portlet.render(request, response);
    assertEquals("test", response.getContentAsString());
}
项目:portals-pluto    文件:PortletURLTag168.java   
/**
 * Provides a list of all static PortletMode available in the specifications by using introspection
 * 
 * @return Hashtable
 */
private static Hashtable<String, Object> getDefinedPortletModes() {
   Hashtable<String, Object> portletModes = new Hashtable<String, Object>();
   Field[] f = PortletMode.class.getDeclaredFields();

   for (int i = 0; i < f.length; i++) {
      if (f[i].getType().isAssignableFrom(javax.portlet.PortletMode.class)) {
         try {
            portletModes.put(f[i].get(f[i]).toString().toUpperCase(), f[i].get(f[i]));
         } catch (IllegalAccessException e) {
         }
      }
   }

   return portletModes;
}
项目:sakai    文件:PortletStateTest.java   
public void testSerialization() throws IOException, ClassNotFoundException
{
    PortletState state = new PortletState("id");
    state.setPortletMode(PortletMode.VIEW);
    state.setWindowState(WindowState.MAXIMIZED);

    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bao);

    out.writeObject(state);

    ByteArrayInputStream bai = new ByteArrayInputStream(bao.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bai);
    PortletState alter = (PortletState) in.readObject();

    assertEquals(state, alter);

}
项目:portals-pluto    文件:InvokeHeaderTest.java   
@Test
public void invoke1b() throws Exception {
   meths.reset();
   PortletInvoker i = new PortletInvoker(ams, "portlet1");
   PortletMode mode = new PortletMode("CustomMode");
   req.setMode(mode);
   i.renderHeaders(req, resp);
   List<String> names = meths.getMethods();
   assertNotNull(names);
   assertEquals(3, names.size());
   List<String> soll = Arrays.asList(new String[] {
         Header1.class.getSimpleName() + "#header1a",
         Header1.class.getSimpleName() + "#header1b",
         Header1.class.getSimpleName() + "#header1c"
         });
   for (String name : names) {
      assertTrue(soll.contains(name));
   }
}
项目:sakai    文件:SimpleRSSPortlet.java   
/**
 * Get the feed content
 * @param request
 * @param response
 * @return Map of params or null if any required data is missing
 */
private SyndFeed getFeedContent(RenderRequest request, RenderResponse response) {

    SyndFeed feed;

    //check cache, otherwise get fresh
    //we use the feedUrl as the cacheKey
    String feedUrl = getConfiguredFeedUrl(request);
    if(StringUtils.isBlank(feedUrl)) {
        log.debug("No feed URL configured");
        doError("error.no.config", "error.heading.config", getPortletModeUrl(response, PortletMode.EDIT), request, response);
        return null;
    }

    String cacheKey = feedUrl;

    feed = feedCache.get(cacheKey);
    if(feed != null) {
        log.debug("Fetching data from feed cache for: " + cacheKey);
    } else {
        //get from remote
        feed = getRemoteFeed(feedUrl, request, response);
    }

    return feed;
}
项目:sakai    文件:SimplePortletStateEncoderTest.java   
public void testEncodeDecode()
{
    PortletState state = new PortletState("id");
    state.setAction(true);
    state.setSecure(true);
    state.setWindowState(WindowState.MAXIMIZED);
    state.setPortletMode(PortletMode.EDIT);

    String uriSafe = encoder.encode(state);
    PortletState read = encoder.decode(uriSafe);
    assertEquals(state.getId(), read.getId());
    assertEquals(state.isAction(), read.isAction());
    assertEquals(state.isSecure(), read.isSecure());
    assertEquals(state.getWindowState(), read.getWindowState());
    assertEquals(state.getPortletMode(), read.getPortletMode());
}
项目:reverse-web-proxy-portlet    文件:ReverseProxyIFramePortlet.java   
@Override
public void processAction(ActionRequest request, ActionResponse response)
        throws IOException, PortletException {

  String action = request.getParameter("action");

  if ("editPrefs".equals(action)) {
    PortletPreferences prefs = request.getPreferences();
    for (String key : prefs.getMap().keySet()) {
      String value = request.getParameter(key);
      prefs.setValue(key, value);
    }
    prefs.store();

  } else {
    String url = request.getParameter("URL");
    if (!StringUtils.isBlank(url)) {
      PortletMessaging.publish(request, IFrameGenericPortlet.IFRAME_SRC_URL, url.trim());
    }
  }

  response.setPortletMode(PortletMode.VIEW);
}
项目:flashlight-search    文件:SearchUrlAction.java   
/**
 * Returns a list of search URLs to be put in the request attributes
 *
 * @param themeDisplay The theme display
 * @param layout The current page
 * @return A list of search URLs to be put in the request attributes
 */
private List<SearchUrl> generateSearchUrl(HttpServletRequest request, ThemeDisplay themeDisplay, Layout layout) {
    LayoutTypePortlet layoutType = (LayoutTypePortlet) layout.getLayoutType();
    UnicodeProperties props = layoutType.getTypeSettingsProperties();

    return layoutType.getPortlets().stream()
        .filter(portlet -> portlet.getPortletName().equals(FlashlightSearchPortletKeys.PORTLET_NAME))
        .map(portletInstance -> {

            String columnId = StringPool.BLANK;
            for(Entry<String, String> entry : props.entrySet()) {
                if(entry.getValue().equals(portletInstance.getPortletId())) {
                    columnId = entry.getKey();
                    break;
                }
            }

            String portletUrl;

            try {
                portletUrl = this.portal.getLayoutFriendlyURL(layout, themeDisplay);
            } catch (PortalException e) {
                portletUrl = StringPool.BLANK;
                LOG.error(e);
            }

            SearchUrlRequestParameter[] params = new SearchUrlRequestParameter[] {
                new SearchUrlRequestParameter(PARAM_PORTLET_ID, portletInstance.getPortletId()),
                new SearchUrlRequestParameter(PARAM_PORTLET_LIFECYCLE, LIFECYCLE_RENDER),
                new SearchUrlRequestParameter(PARAM_PORTLET_MODE, PortletMode.VIEW.toString()),
                new SearchUrlRequestParameter(PARAM_PORTLET_COLUMN_ID, columnId),
                new SearchUrlRequestParameter(PARAM_PORTLET_COLUMN_COUNT, Integer.toString(layoutType.getNumOfColumns()))
            };

            String portletNamespace = this.portal.getPortletNamespace(portletInstance.getPortletId());

            return new SearchUrl(layout, portletUrl, params, portletNamespace);
        })
        .collect(Collectors.toList());
}
项目:opencps-v2    文件:LookupDossierResult.java   
@Override
public void render(
    RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL dossierInfoURL = PortletURLFactoryUtil.create(
        renderRequest, portletId, themeDisplay.getPlid(),
        PortletRequest.RENDER_PHASE);

    dossierInfoURL.setPortletMode(PortletMode.VIEW);
    dossierInfoURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    dossierInfoURL.setParameter(
        "mvcPath", "/templates/lookup_dossier/dossierinfo.ftl");

    urlObject.put("dossierinfo", dossierInfoURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put(
        "portletNamespace",
        themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:opencps-v2    文件:RegisterPorltet.java   
@Override
public void render(
    RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL registerResultURL = PortletURLFactoryUtil.create(
        renderRequest, portletId, themeDisplay.getPlid(),
        PortletRequest.RENDER_PHASE);

    registerResultURL.setPortletMode(PortletMode.VIEW);
    registerResultURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    registerResultURL.setParameter(
        "mvcPath", "/templates/applicant/register_result.ftl");

    urlObject.put("register_result", registerResultURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put(
        "portletNamespace",
        themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:opencps-v2    文件:ForgottenAccount.java   
@Override
public void render(
    RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL confirmPasswordURL = PortletURLFactoryUtil.create(
        renderRequest, portletId, themeDisplay.getPlid(),
        PortletRequest.RENDER_PHASE);

    confirmPasswordURL.setPortletMode(PortletMode.VIEW);
    confirmPasswordURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    confirmPasswordURL.setParameter(
        "mvcPath", "/templates/applicant/confirm_password.ftl");

    urlObject.put("confirm_password", confirmPasswordURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put(
        "portletNamespace",
        themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:opencps-v2    文件:ServiceInfoLookup.java   
@Override
public void render(
    RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL serviceInfoLookupURL = PortletURLFactoryUtil.create(
        renderRequest, portletId, themeDisplay.getPlid(),
        PortletRequest.RENDER_PHASE);

    serviceInfoLookupURL.setPortletMode(PortletMode.VIEW);
    serviceInfoLookupURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    serviceInfoLookupURL.setParameter(
        "mvcPath", "/templates/homepage/serviceinfo_lookup.ftl");

    urlObject.put("serviceinfo_lookup", serviceInfoLookupURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put(
        "portletNamespace",
        themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:opencps-v2    文件:ConfirmAccountPortlet.java   
@Override
public void render(
    RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL registerResultURL = PortletURLFactoryUtil.create(
        renderRequest, portletId, themeDisplay.getPlid(),
        PortletRequest.RENDER_PHASE);

    registerResultURL.setPortletMode(PortletMode.VIEW);
    registerResultURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    registerResultURL.setParameter(
        "mvcPath", "/templates/applicant/register_result.ftl");

    urlObject.put("register_result", registerResultURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put(
        "portletNamespace",
        themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:opencps-v2    文件:DossierLookup.java   
@Override
public void render(
    RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL dossierLookupURL = PortletURLFactoryUtil.create(
        renderRequest, portletId, themeDisplay.getPlid(),
        PortletRequest.RENDER_PHASE);

    dossierLookupURL.setPortletMode(PortletMode.VIEW);
    dossierLookupURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    dossierLookupURL.setParameter(
        "mvcPath", "/templates/homepage/dossier_lookup.ftl");

    urlObject.put("dossier_lookup", dossierLookupURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put(
        "portletNamespace",
        themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:opencps-v2    文件:ServiceSearchPortlet.java   
public void render(RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL dossierLookupURL = PortletURLFactoryUtil.create(renderRequest, portletId, themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    dossierLookupURL.setPortletMode(PortletMode.VIEW);
    dossierLookupURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    dossierLookupURL.setParameter("mvcPath", "/templates/homepage/search_serviceinfo.ftl");

    urlObject.put("dossier_lookup", dossierLookupURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put("portletNamespace", themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:opencps-v2    文件:DossierLookupPortlet.java   
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();

    JSONObject urlObject = JSONFactoryUtil.createJSONObject();
    JSONObject apiObject = JSONFactoryUtil.createJSONObject();

    // url
    PortletURL dossierLookupURL = PortletURLFactoryUtil.create(renderRequest, portletId, themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    dossierLookupURL.setPortletMode(PortletMode.VIEW);
    dossierLookupURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    dossierLookupURL.setParameter("mvcPath", "/templates/homepage/dossier_lookup.ftl");

    urlObject.put("dossier_lookup", dossierLookupURL.toString());

    // api
    apiObject.put("server", themeDisplay.getPortalURL() + "/o/rest/v2");
    apiObject.put("portletNamespace", themeDisplay.getPortletDisplay().getNamespace());

    // set varible
    renderRequest.setAttribute("ajax", urlObject);
    renderRequest.setAttribute("api", apiObject);

    super.render(renderRequest, renderResponse);

}
项目:spring4-understanding    文件:AnnotationMethodHandlerAdapter.java   
public void initStandardMapping(String[] modes, RequestMethod[] methods, String[] params, String[] headers) {
    for (String mode : modes) {
        this.modes.add(new PortletMode(mode));
    }
    for (RequestMethod method : methods) {
        this.methods.add(method.name());
    }
    this.params = StringUtils.mergeStringArrays(this.params, params);
    this.headers = StringUtils.mergeStringArrays(this.headers, headers);
}
项目:spring4-understanding    文件:DefaultAnnotationHandlerMapping.java   
/**
 * Register all handlers specified in the Portlet mode map for the corresponding modes.
 * @throws org.springframework.beans.BeansException if the handler couldn't be registered
 */
protected void detectHandlers() throws BeansException {
    ApplicationContext context = getApplicationContext();
    String[] beanNames = context.getBeanNamesForType(Object.class);
    for (String beanName : beanNames) {
        Class<?> handlerType = context.getType(beanName);
        RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class);
        if (mapping != null) {
            // @RequestMapping found at type level
            String[] modeKeys = mapping.value();
            String[] params = mapping.params();
            boolean registerHandlerType = true;
            if (modeKeys.length == 0 || params.length == 0) {
                registerHandlerType = !detectHandlerMethods(handlerType, beanName, mapping);
            }
            if (registerHandlerType) {
                AbstractParameterMappingPredicate predicate = new TypeLevelMappingPredicate(
                        params, mapping.headers(), mapping.method());
                for (String modeKey : modeKeys) {
                    registerHandler(new PortletMode(modeKey), beanName, predicate);
                }
            }
        }
        else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) {
            detectHandlerMethods(handlerType, beanName, mapping);
        }
    }
}
项目:spring4-understanding    文件:PortletModeParameterHandlerMapping.java   
/**
 * Register all handlers specified in the Portlet mode map for the corresponding modes.
 * @param portletModeParameterMap Map with mode names as keys and parameter Maps as values
 */
protected void registerHandlersByModeAndParameter(Map<String, Map<String, ?>> portletModeParameterMap) {
    Assert.notNull(portletModeParameterMap, "'portletModeParameterMap' must not be null");
    for (Map.Entry<String, Map<String, ?>> entry : portletModeParameterMap.entrySet()) {
        PortletMode mode = new PortletMode(entry.getKey());
        registerHandler(mode, entry.getValue());
    }
}
项目:spring4-understanding    文件:PortletModeParameterHandlerMapping.java   
/**
 * Register the given handler instance for the given PortletMode and parameter value,
 * under an appropriate lookup key.
 * @param mode the PortletMode for which this mapping is valid
 * @param parameter the parameter value to which this handler is mapped
 * @param handler the handler instance bean
 * @throws BeansException if the handler couldn't be registered
 * @throws IllegalStateException if there is a conflicting handler registered
 * @see #registerHandler(Object, Object)
 */
protected void registerHandler(PortletMode mode, String parameter, Object handler)
        throws BeansException, IllegalStateException {

    // Check for duplicate parameter values across all portlet modes.
    if (!this.allowDuplicateParameters && this.parametersUsed.contains(parameter)) {
        throw new IllegalStateException(
                "Duplicate entries for parameter [" + parameter + "] in different Portlet modes");
    }
    this.parametersUsed.add(parameter);

    registerHandler(new PortletModeParameterLookupKey(mode, parameter), handler);
}
项目:spring4-understanding    文件:PortletModeParameterHandlerMapping.java   
/**
 * Returns a lookup key that combines the current PortletMode and the current
 * value of the specified parameter.
 * @see javax.portlet.PortletRequest#getPortletMode()
 * @see #setParameterName
 */
@Override
protected PortletModeParameterLookupKey getLookupKey(PortletRequest request) throws Exception {
    PortletMode mode = request.getPortletMode();
    String parameter = request.getParameter(this.parameterName);
    return new PortletModeParameterLookupKey(mode, parameter);
}
项目:spring4-understanding    文件:PortletModeHandlerMapping.java   
/**
 * Register all handlers specified in the Portlet mode map for the corresponding modes.
 * @param portletModeMap Map with mode names as keys and handler beans or bean names as values
 */
protected void registerHandlersByMode(Map<String, Object> portletModeMap) {
    Assert.notNull(portletModeMap, "'portletModeMap' must not be null");
    for (Map.Entry<String, Object> entry : portletModeMap.entrySet()) {
        registerHandler(new PortletMode(entry.getKey()), entry.getValue());
    }
}
项目:spring4-understanding    文件:PortletModeHandlerMappingTests.java   
@Test
public void portletModeView() throws Exception {
    request.setPortletMode(PortletMode.VIEW);

    Object handler = hm.getHandler(request).getHandler();
    assertEquals(pac.getBean("viewHandler"), handler);
}
项目:spring4-understanding    文件:PortletModeHandlerMappingTests.java   
@Test
public void portletModeEdit() throws Exception {
    request.setPortletMode(PortletMode.EDIT);

    Object handler = hm.getHandler(request).getHandler();
    assertEquals(pac.getBean("editHandler"), handler);
}
项目:spring4-understanding    文件:PortletModeHandlerMappingTests.java   
@Test
public void portletModeHelp() throws Exception {
    request.setPortletMode(PortletMode.HELP);

    Object handler = hm.getHandler(request).getHandler();
    assertEquals(pac.getBean("helpHandler"), handler);
}
项目:spring4-understanding    文件:PortletModeParameterHandlerMappingTests.java   
@Test
public void portletModeViewWithParameter() throws Exception {
    MockPortletRequest addRequest = request;
    addRequest.setPortletMode(PortletMode.VIEW);
    addRequest.setParameter("action", "add");
    Object addHandler = hm.getHandler(addRequest).getHandler();
    assertEquals(pac.getBean("addItemHandler"), addHandler);

    MockPortletRequest removeRequest = new MockPortletRequest();
    removeRequest.setPortletMode(PortletMode.VIEW);
    removeRequest.setParameter("action", "remove");
    Object removeHandler = hm.getHandler(removeRequest).getHandler();
    assertEquals(pac.getBean("removeItemHandler"), removeHandler);
}
项目:spring4-understanding    文件:PortletModeParameterHandlerMappingTests.java   
@Test
public void portletModeEditWithParameter() throws Exception {
    request.setPortletMode(PortletMode.EDIT);
    request.setParameter("action", "prefs");

    Object handler = hm.getHandler(request).getHandler();
    assertEquals(pac.getBean("preferencesHandler"), handler);
}
项目:spring4-understanding    文件:PortletModeParameterHandlerMappingTests.java   
@Test
public void allowDuplicateMappingInDifferentPortletMode() throws Exception {
    hm.setAllowDuplicateParameters(true);

    Object editRemoveHandler = new Object();
    hm.registerHandler(PortletMode.EDIT, "remove", editRemoveHandler);

    request.setPortletMode(PortletMode.EDIT);
    request.setParameter("action", "remove");

    Object handler = hm.getHandler(request).getHandler();
    assertEquals(editRemoveHandler, handler);
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletModeParameterMappingHelp1() throws Exception {
    MockActionRequest request = new MockActionRequest();
    MockActionResponse response = new MockActionResponse();
    request.setPortletMode(PortletMode.HELP);
    request.setParameter("action", "help1");
    complexDispatcherPortlet.processAction(request, response);
    String param = response.getRenderParameter("param");
    assertEquals("help1 was here", param);
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletModeParameterMappingHelp2() throws Exception {
    MockActionRequest request = new MockActionRequest();
    MockActionResponse response = new MockActionResponse();
    request.setPortletMode(PortletMode.HELP);
    request.setParameter("action", "help2");
    complexDispatcherPortlet.processAction(request, response);
    String param = response.getRenderParameter("param");
    assertEquals("help2 was here", param);
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletModeParameterMappingInvalidHelpActionRequest() throws Exception {
    MockActionRequest request = new MockActionRequest();
    MockActionResponse response = new MockActionResponse();
    request.setPortletMode(PortletMode.HELP);
    request.setParameter("action", "help3");
    complexDispatcherPortlet.processAction(request, response);
    String exceptionParam = response.getRenderParameter(DispatcherPortlet.ACTION_EXCEPTION_RENDER_PARAMETER);
    assertNotNull(exceptionParam);
    assertTrue(exceptionParam.startsWith(NoHandlerFoundException.class.getName()));
}