コード例 #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
  /**
   * 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");
  }