コード例 #1
0
  /**
   * Redefine method, we have to check stuff.
   *
   * @see de.ingrid.portal.portlets.admin.ContentPortlet#doActionSave(javax.portlet.ActionRequest)
   */
  protected void doActionSave(ActionRequest request) {
    AdminCMSForm af =
        (AdminCMSForm) Utils.getActionForm(request, AdminCMSForm.SESSION_KEY, AdminCMSForm.class);
    af.populate(request);
    af.validate();
    if (af.hasErrors()) {
      return;
    }

    IngridCMS cmsEntry = new IngridCMS();
    cmsEntry.setItemChanged(new Date());
    cmsEntry.setItemChangedBy(request.getUserPrincipal().getName());
    cmsEntry.setItemDescription(af.getInput(AdminCMSForm.FIELD_DESCRIPTION));
    cmsEntry.setItemKey(af.getInput(AdminCMSForm.FIELD_KEY));

    HashSet localizedItems = new HashSet();

    String[] languages = Utils.getLanguagesShortAsArray();
    for (String lang : languages) {
      IngridCMSItem item = new IngridCMSItem();
      item.setItemLang(lang);
      item.setItemTitle(af.getInput(AdminCMSForm.FIELD_TITLE + lang));
      item.setItemValue(af.getInput(AdminCMSForm.FIELD_VALUE + lang));
      item.setItemChanged(new Date());
      item.setItemChangedBy(request.getUserPrincipal().getName());
      localizedItems.add(item);
    }

    cmsEntry.setLocalizedItems(localizedItems);

    UtilsDB.saveDBObject(cmsEntry);

    af.addMessage("admin.cms.save.success");
  }
コード例 #2
0
 /**
  * @see de.ingrid.portal.portlets.admin.ContentPortlet#doActionDelete(javax.portlet.ActionRequest)
  */
 protected void doActionDelete(ActionRequest request) {
   Session session = HibernateUtil.currentSession();
   Long[] ids = ContentPortlet.convertIds(getIds(request));
   for (int i = 0; i < ids.length; i++) {
     IngridCMS cmsEntry = (IngridCMS) session.load(dbEntityClass, ids[i]);
     UtilsDB.deleteDBObject(cmsEntry);
   }
 }
コード例 #3
0
  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);
  }
コード例 #4
0
  /**
   * Redefine method, we have to check stuff.
   *
   * @see de.ingrid.portal.portlets.admin.ContentPortlet#doActionUpdate(javax.portlet.ActionRequest)
   */
  protected void doActionUpdate(ActionRequest request) {
    AdminCMSForm af =
        (AdminCMSForm) Utils.getActionForm(request, AdminCMSForm.SESSION_KEY, AdminCMSForm.class);
    af.populate(request);
    af.validate();
    if (af.hasErrors()) {
      return;
    }

    Session session = HibernateUtil.currentSession();
    IngridCMS cmsEntry =
        (IngridCMS) session.load(dbEntityClass, new Long(af.getInput(AdminCMSForm.PARAM_ID)));

    cmsEntry.setItemChanged(new Date());
    cmsEntry.setItemChangedBy(request.getUserPrincipal().getName());
    cmsEntry.setItemDescription(af.getInput(AdminCMSForm.FIELD_DESCRIPTION));
    cmsEntry.setItemKey(af.getInput(AdminCMSForm.FIELD_KEY));

    String[] languages = Utils.getLanguagesShortAsArray();
    for (String lang : languages) {
      IngridCMSItem item = cmsEntry.getLocalizedEntry(lang);
      if (item == null) {
        item = new IngridCMSItem();
        item.setItemLang(lang);
        cmsEntry.getLocalizedItems().add(item);
      }
      item.setItemTitle(af.getInput(AdminCMSForm.FIELD_TITLE + lang));
      item.setItemValue(af.getInput(AdminCMSForm.FIELD_VALUE + lang));
      item.setItemChanged(new Date());
      item.setItemChangedBy(request.getUserPrincipal().getName());
    }

    UtilsDB.updateDBObject(cmsEntry);

    af.addMessage("admin.cms.update.success");
  }
コード例 #5
0
  /** @see de.ingrid.portal.forms.ActionForm#validate() */
  public boolean validate() {
    boolean allOk = true;
    clearErrors();

    // check input
    try {
      String numEntities = getInput("numEntities");
      if (numEntities != null) {
        int intNumEntities = new Integer(numEntities).intValue();
        String fieldName = "";
        for (int i = 0; i < intNumEntities; i++) {

          fieldName = FIELD_DESCRIPTION + i;
          if (hasInput(fieldName)) {
            if (getInput(fieldName).length() > 1024)
              setError(fieldName, "admin.rss.error.description.too.long");
            allOk = false;
          }

          fieldName = FIELD_PROVIDER + i;
          if (!hasInput(fieldName)) {
            setError(fieldName, "admin.rss.error.missing.provider");
            allOk = false;
          }
          fieldName = FIELD_URL + i;
          if (!hasInput(fieldName)) {
            setError(fieldName, "admin.rss.error.missing.url");
            allOk = false;
          } else {
            // check database whether other record (other id) has
            // same ident (kuerzel)
            Long id = null;
            try {
              id = new Long(getInput(PARAM_ID + i));
            } catch (Exception ex) {
            }
            String url = getInput(fieldName);
            Session session = HibernateUtil.currentSession();
            Criteria crit =
                session.createCriteria(IngridRSSSource.class).add(Restrictions.eq(FIELD_URL, url));
            if (id != null) {
              crit.add(Restrictions.ne(PARAM_ID, id));
            }
            List foundURLs = UtilsDB.getValuesFromDB(crit, session, null, true);
            if (foundURLs != null && !foundURLs.isEmpty()) {
              setError(fieldName, "admin.rss.error.url.exists");
              allOk = false;
            }
          }
          fieldName = FIELD_LANGUAGE + i;
          if (!hasInput(fieldName)) {
            setError(fieldName, "admin.rss.error.missing.language");
            allOk = false;
          }
        }
      }
    } catch (Throwable t) {
      if (log.isErrorEnabled()) {
        log.error("Error validating input.", t);
      }
      allOk = false;
    } finally {
      HibernateUtil.closeSession();
    }

    return allOk;
  }