Package com.dotcms.repackage.org.apache.struts.action

Examples of com.dotcms.repackage.org.apache.struts.action.ActionMessage


      _populateContent(req, res, config, form, user, currentContentlet);
      //http://jira.dotmarketing.net/browse/DOTCMS-1450
      //The form doesn't have the identifier in it. so the populate content was setting it to 0
      currentContentlet.setIdentifier(currentContentident);
    }catch (DotContentletValidationException ve) {
      ae.add(Globals.ERROR_KEY, new ActionMessage("message.contentlet.invalid.form"));
      req.setAttribute(Globals.ERROR_KEY, ae);
      throw new DotContentletValidationException(ve.getMessage());
    }

    //Saving interval review properties
    if (contentletForm.isReviewContent()) {
      currentContentlet.setReviewInterval(contentletForm.getReviewIntervalNum() + contentletForm.getReviewIntervalSelect());
    } else {
      currentContentlet.setReviewInterval(null);
    }

    // saving the review dates
    currentContentlet.setLastReview(new Date ());
    if (currentContentlet.getReviewInterval() != null) {
      currentContentlet.setNextReview(conAPI.getNextReview(currentContentlet, user, false));
    }

    ArrayList<Category> cats = new ArrayList<Category>();
    // Getting categories that come from the entity
    String[] arr = req.getParameterValues("categories") == null?new String[0]:req.getParameterValues("categories");
    if (arr != null && arr.length > 0) {
      for (int i = 0; i < arr.length; i++) {
        Category category = catAPI.find(arr[i], user, false);
        if(!cats.contains(category))
        {
          cats.add(category);
        }

      }
    }


    try{

      currentContentlet.setInode(null);
      ContentletRelationships contRel = retrieveRelationshipsData(currentContentlet,user, req );

      // http://jira.dotmarketing.net/browse/DOTCMS-65
      // Coming from other contentlet to relate it automatically
      String relateWith = req.getParameter("relwith");
      String relationType = req.getParameter("reltype");
      String relationHasParent = req.getParameter("relisparent");
      if(relateWith != null){
        try {

          List<ContentletRelationshipRecords> recordsList = contRel.getRelationshipsRecords();
          for(ContentletRelationshipRecords records : recordsList) {
            if(!records.getRelationship().getRelationTypeValue().equals(relationType))
              continue;
            if(RelationshipFactory.isSameStructureRelationship(records.getRelationship()) &&
                ((!records.isHasParent() && relationHasParent.equals("no")) ||
                    (records.isHasParent() && relationHasParent.equals("yes"))))
              continue;
            records.getRecords().add(conAPI.find(relateWith, user, false));

          }


        } catch (Exception e) {
          Logger.error(this,"Contentlet failed while creating new relationship",e);
        }

      }

      //Checkin in the content
      currentContentlet = conAPI.checkin(currentContentlet, contRel, cats, _getSelectedPermissions(req, currentContentlet), user, false);

          if ((subcmd != null) && subcmd.equals(com.dotmarketing.util.Constants.PUBLISH)) {
              Logger.debug(this, "publishing after checkin");
              ActivityLogger.logInfo(this.getClass(), "Publishing Contentlet "," User "+user.getFirstName()+" published content titled '"+currentContentlet.getTitle(), HostUtil.hostNameUtil(req, user));
              APILocator.getVersionableAPI().setLive(currentContentlet);
          }

    }catch(DotContentletValidationException ve) {
      if(ve.hasRequiredErrors()){
        List<Field> reqs = ve.getNotValidFields().get(DotContentletValidationException.VALIDATION_FAILED_REQUIRED);
        for (Field field : reqs) {
          ae.add(Globals.ERROR_KEY, new ActionMessage("message.contentlet.required", field.getFieldName()));
        }
      }
      if(ve.hasLengthErrors()){
        List<Field> reqs = ve.getNotValidFields().get(DotContentletValidationException.VALIDATION_FAILED_MAXLENGTH);
        for (Field field : reqs) {
          ae.add(Globals.ERROR_KEY, new ActionMessage("message.contentlet.maxlength", field.getFieldName(),"255"));
        }
      }
      if(ve.hasPatternErrors()){
        List<Field> reqs = ve.getNotValidFields().get(DotContentletValidationException.VALIDATION_FAILED_PATTERN);
        for (Field field : reqs) {
          ae.add(Globals.ERROR_KEY, new ActionMessage("message.contentlet.format", field.getFieldName()));
        }
      }
      if(ve.hasRelationshipErrors()){
        StringBuffer sb = new StringBuffer("<br>");
        Map<String,Map<Relationship,List<Contentlet>>> notValidRelationships = ve.getNotValidRelationship();
        Set<String> auxKeys = notValidRelationships.keySet();
        for(String key : auxKeys)
        {
          String errorMessage = "";
          if(key.equals(DotContentletValidationException.VALIDATION_FAILED_REQUIRED_REL))
          {
            errorMessage = "<b>Required Relationship</b>";
          }
          else if(key.equals(DotContentletValidationException.VALIDATION_FAILED_INVALID_REL_CONTENT))
          {
            errorMessage = "<b>Invalid Relationship-Contentlet</b>";
          }
          else if(key.equals(DotContentletValidationException.VALIDATION_FAILED_BAD_REL))
          {
            errorMessage = "<b>Bad Relationship</b>";
          }

          sb.append(errorMessage + ":<br>");
          Map<Relationship,List<Contentlet>> relationshipContentlets = notValidRelationships.get(key);
          for(Entry<Relationship,List<Contentlet>> relationship : relationshipContentlets.entrySet())
          {
            sb.append(relationship.getKey().getRelationTypeValue() + ", ");
          }
          sb.append("<br>");
        }
        sb.append("<br>");

        //need to update message to support multiple relationship validation errors
        ae.add(Globals.ERROR_KEY, new ActionMessage("message.relationship.required_ext",sb.toString()));
      }



      if(ve.hasUniqueErrors()){
        List<Field> reqs = ve.getNotValidFields().get(DotContentletValidationException.VALIDATION_FAILED_UNIQUE);
        for (Field field : reqs) {
          ae.add(Globals.ERROR_KEY, new ActionMessage("message.contentlet.unique", field.getFieldName()));
        }
      }

      req.setAttribute(com.dotmarketing.util.WebKeys.CONTENTLET_RELATIONSHIPS_EDIT, getCurrentContentletRelationships(req, user));

      throw ve;
    }catch (Exception e) {

      ae.add(Globals.ERROR_KEY, new ActionMessage("message.contentlet.save.error"));
      Logger.error(this,"Contentlet failed during checkin",e);
      throw e;
    }finally{
      if (ae != null && ae.size() > 0){
        req.setAttribute(Globals.ERROR_KEY, ae);
View Full Code Here


        String message;
        while (reports.hasNext())
        {
            message = null;
            ActionMessage report = (ActionMessage)reports.next();
            if (resources != null) //&& report.isResource() DOTCMS-4819
            {
                message = resources.getMessage(locale,
                                               report.getKey(),
                                               report.getValues());
            }

            results.append(prefix);

            if (message != null)
            {
                results.append(message);
            }
            else
            {
                results.append(report.getKey());
            }

            results.append(suffix);
            results.append("\r\n");
        }
View Full Code Here

        MessageResources res = getResources(bundle);
        List list = new ArrayList();
        
        while (msgs.hasNext())
        {
            ActionMessage msg = (ActionMessage)msgs.next();

            String message = null;
            if (res != null ) //&& msg.isResource() DOTCMS-4819
            {
                message =
                    res.getMessage(this.locale, msg.getKey(), msg.getValues());

                if (message == null)
                {
                    LOG.warn("Message for key " + msg.getKey() +
                             " could not be found in message resources.");
                }
            }

            if (message == null)
            {
                // if the resource bundle wasn't found or
                // ActionMessage.isResource() returned false or the key
                // wasn't found in the resources, then use the key
                message = msg.getKey();
            }
            list.add(message);
        }
        return list;
    }
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.org.apache.struts.action.ActionMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.