/**
   * @see
   *     org.apache.portals.bridges.velocity.GenericVelocityPortlet#doView(javax.portlet.RenderRequest,
   *     javax.portlet.RenderResponse)
   */
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    Context context = getContext(request);
    IngridResourceBundle messages =
        new IngridResourceBundle(
            getPortletConfig().getResourceBundle(request.getLocale()), request.getLocale());
    context.put("MESSAGES", messages);

    // check for just logged in users
    HttpSession session =
        ((RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV))
            .getRequest()
            .getSession(true);
    String loginStarted = (String) session.getAttribute(Settings.SESSION_LOGIN_STARTED);
    if (loginStarted != null && loginStarted.equals("1")) {
      session.removeAttribute(Settings.SESSION_LOGIN_STARTED);
      // do something "after login" stuff

      // initialize the session preference with persistent data from
      // personalization
      IngridSessionPreferences sessionPrefs =
          Utils.getSessionPreferences(
              request, IngridSessionPreferences.SESSION_KEY, IngridSessionPreferences.class);
      if (sessionPrefs != null) {
        Principal principal = request.getUserPrincipal();
        if (principal != null) {
          HashMap persistentSearchSettings =
              (HashMap)
                  IngridPersistencePrefs.getPref(
                      principal.getName(), IngridPersistencePrefs.SEARCH_SETTINGS);
          if (persistentSearchSettings != null) {
            sessionPrefs.putAll(persistentSearchSettings);
          }
        }
      }
    }

    String userName = request.getUserPrincipal().getName();
    User user = null;
    try {
      user = userManager.getUser(userName);
    } catch (SecurityException e) {
      e.printStackTrace();
    }

    if (user != null) {
      context.put("userAttributes", user.getInfoMap());
    }

    super.doView(request, response);
  }
  /**
   * @see
   *     org.apache.portals.bridges.velocity.GenericVelocityPortlet#doView(javax.portlet.RenderRequest,
   *     javax.portlet.RenderResponse)
   */
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    Context context = getContext(request);

    IngridResourceBundle messages =
        new IngridResourceBundle(
            getPortletConfig().getResourceBundle(request.getLocale()), request.getLocale());
    context.put("MESSAGES", messages);

    PortletPreferences prefs = request.getPreferences();
    String titleKey = prefs.getValue("titleKey", "searchSettings.title.rankingAndGrouping");
    response.setTitle(messages.getString(titleKey));

    UtilsSearch.doViewForPartnerPortlet(request, context);

    Principal principal = request.getUserPrincipal();
    String partnerStr =
        (String)
            IngridPersistencePrefs.getPref(
                principal.getName(), IngridPersistencePrefs.SEARCH_PARTNER);

    if (partnerStr != null) {

      PortletSession session = request.getPortletSession();
      DisplayTreeNode partnerRoot = (DisplayTreeNode) session.getAttribute("partnerRoot");
      Iterator it = partnerRoot.getChildren().iterator();
      while (it.hasNext()) {
        DisplayTreeNode partnerNode = (DisplayTreeNode) it.next();
        if (partnerStr.indexOf(Settings.QFIELD_PARTNER.concat(":").concat(partnerNode.getId()))
                != -1
            || partnerNode.get("checked") != null) {
          partnerNode.put("checked", "true");
        } else {
          partnerNode.remove("checked");
        }
        Iterator it2 = partnerNode.getChildren().iterator();
        while (it2.hasNext()) {
          DisplayTreeNode providerNode = (DisplayTreeNode) it2.next();
          if (partnerStr.indexOf(Settings.QFIELD_PROVIDER.concat(":").concat(providerNode.getId()))
              != -1) {
            providerNode.put("checked", "true");
            partnerNode.setOpen(true);
          } else {
            providerNode.remove("checked");
          }
        }
      }
    }
    super.doView(request, response);
  }
  /**
   * @see
   *     org.apache.portals.bridges.velocity.GenericVelocityPortlet#doView(javax.portlet.RenderRequest,
   *     javax.portlet.RenderResponse)
   */
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    Context context = getContext(request);

    IngridResourceBundle messages =
        new IngridResourceBundle(
            getPortletConfig().getResourceBundle(request.getLocale()), request.getLocale());
    context.put("MESSAGES", messages);

    // set localized title for this page
    response.setTitle(messages.getString("admin.statistics.headline"));

    context.put(
        "apacheStatisticsURL",
        PortalConfig.getInstance().getString(PortalConfig.APACHE_STATISTICS_URL, ""));

    super.doView(request, response);
  }
  public void doView(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response)
      throws PortletException, IOException {
    Context context = getContext(request);
    IngridResourceBundle messages =
        new IngridResourceBundle(
            getPortletConfig().getResourceBundle(request.getLocale()), request.getLocale());
    context.put("MESSAGES", messages);

    // enable/disable providers drop down
    String selectedDS =
        SearchState.getSearchStateObjectAsString(request, Settings.PARAM_DATASOURCE);
    if (PortalConfig.getInstance().getBoolean(PortalConfig.PORTAL_SEARCH_DISPLAY_PROVIDERS)
        || selectedDS.equals(Settings.PARAMV_DATASOURCE_ENVINFO)
            && PortalConfig.getInstance()
                .getBoolean(PortalConfig.PORTAL_SEARCH_DISPLAY_PROVIDERS_ENVINFO)) {
      String partner =
          PortalConfig.getInstance().getString(PortalConfig.PORTAL_SEARCH_RESTRICT_PARTNER);
      List providers;
      if (partner == null || partner.length() == 0) {
        providers = UtilsDB.getProviders();
      } else {
        providers = UtilsDB.getProvidersFromPartnerKey(partner);
      }
      context.put("displayProviders", Boolean.TRUE);
      context.put("providers", providers);
      context.put("UtilsString", new UtilsString());

      // get selected provider
      IngridSessionPreferences sessionPrefs =
          Utils.getSessionPreferences(
              request, IngridSessionPreferences.SESSION_KEY, IngridSessionPreferences.class);
      String provider = request.getParameter(Settings.PARAM_PROVIDER);
      if (provider != null) {
        sessionPrefs.put(IngridSessionPreferences.RESTRICTING_PROVIDER, provider);
      }
      context.put(
          "selectedProviderIdent", sessionPrefs.get(IngridSessionPreferences.RESTRICTING_PROVIDER));
    }

    super.doView(request, response);
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    ItemSelectorRendering itemSelectorRendering =
        _itemSelector.getItemSelectorRendering(renderRequest, renderResponse);

    LocalizedItemSelectorRendering localizedItemSelectorRendering =
        new LocalizedItemSelectorRendering(renderRequest.getLocale(), itemSelectorRendering);

    localizedItemSelectorRendering.store(renderRequest);

    super.render(renderRequest, renderResponse);
  }
  /**
   * @see
   *     de.ingrid.portal.portlets.admin.ContentPortlet#doViewAfterUpdate(javax.portlet.RenderRequest)
   */
  protected boolean doViewAfterUpdate(RenderRequest request) {
    ActionForm af =
        (AdminCMSForm) Utils.getActionForm(request, AdminCMSForm.SESSION_KEY, AdminCMSForm.class);
    setDefaultViewPage(viewEdit);
    Context context = getContext(request);
    context.put("actionForm", af);
    context.put(CONTEXT_MODE, CONTEXTV_MODE_EDIT);
    String lang = Utils.checkSupportedLanguage(request.getLocale().getLanguage());

    // add the velocity tool to access arrays
    ListTool listTool = new ListTool();
    context.put("ListTool", listTool);
    context.put("languagesNames", Utils.getLanguagesFullAsArray(lang));
    context.put("languagesShort", Utils.getLanguagesShortAsArray());

    Object[] entities = getDBEntities(request);
    context.put(CONTEXT_ENTITIES, entities);
    return false;
  }
  @SuppressWarnings("unchecked")
  @RenderMode(name = "VIEW")
  public void showBooks(RenderRequest request, RenderResponse response)
      throws IOException, PortletException {
    logger.info("Entering showBooks method");
    PortalContext context = request.getPortalContext();
    printSupportedPortletModes(context);
    printSupportedWindowStates(context);

    // --get user attributes user.name.given and user.name.family
    Map<String, Object> userAttributeMap =
        (Map<String, Object>) request.getAttribute(PortletRequest.USER_INFO);
    String firstName = "";
    String lastName = "";
    if (userAttributeMap != null) {
      firstName = (String) userAttributeMap.get("user.name.given");
      lastName = (String) userAttributeMap.get("user.name.family");
      request.setAttribute("firstName", firstName);
      request.setAttribute("lastName", lastName);
    }

    String portalInfo = context.getPortalInfo();
    request.setAttribute("portalInfo", portalInfo);

    // --generate all the URLs that will be used by the portlet
    generateUrls(request, response);

    String myaction = request.getParameter("myaction");
    if (myaction != null) {
      logger.info("myaction parameter is not null. Value is " + myaction);
      request.getPortletSession().setAttribute("myaction", myaction, PortletSession.PORTLET_SCOPE);
    } else {
      // -- if myaction is NULL then show the home page of Book
      // catalog
      // page
      request
          .getPortletSession()
          .setAttribute("myaction", "showCatalog", PortletSession.PORTLET_SCOPE);
    }

    // -- send myaction as a request attribute to the BookServlet.
    request.setAttribute("myaction", request.getPortletSession().getAttribute("myaction"));

    // --dynamically obtain the title for the portlet, based on myaction
    String titleKey =
        "portlet.title." + (String) request.getPortletSession().getAttribute("myaction");
    response.setTitle(getResourceBundle(request.getLocale()).getString(titleKey));

    // --if the action is uploadTocForm then store the ISBN number of
    // the
    // --book for which the TOC is being uploaded. The upload action
    // will use the ISBN number to create file name -- refer home.jsp
    // page
    if (((String) request.getAttribute("myaction")).equalsIgnoreCase("uploadTocForm")) {
      request.getPortletSession().setAttribute("isbnNumber", request.getParameter("isbnNumber"));
    }

    if (((String) request.getPortletSession().getAttribute("myaction"))
        .equalsIgnoreCase("showSearchResults")) {
      request.setAttribute(
          "matchingBooks", request.getPortletSession().getAttribute("matchingBooks"));
    }

    // its important to encode URLs
    PortletRequestDispatcher dispatcher =
        request
            .getPortletSession()
            .getPortletContext()
            .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet"));
    dispatcher.include(request, response);
  }