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

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


  public void setSortOrder(int sortOrder) {
    this.sortOrder = sortOrder;
  }

  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = super.validate(mapping, request);
        if (errors == null) errors = new ActionErrors ();

        if(request.getParameter("cmd")!=null && request.getParameter("cmd").equals(Constants.ADD)) {
            if (maxContentlets > 0) {
                if (dynamic && !UtilMethods.isSet(luceneQuery)) {
                    errors.add("luceneQuery", new ActionMessage("error.containers.query.required"));
                }
            }
            if (!dynamic || maxContentlets == 0) {
                dynamic = false;
                luceneQuery = "";
View Full Code Here


  public void setUnique(boolean unique) {
    this.unique = unique;
  }

    public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
    ActionErrors ae = new ActionErrors()
    ae = super.validate(arg0,arg1);
    if(!isFixed() && !isReadOnly() && !(fieldType == null) && !(fieldType.equals("line_divider") || fieldType.equals("tab_divider"))){
        if(fieldType.equals("select") || fieldType.equals("radio") || fieldType.equals("checkbox") || fieldType.equals("javascript")) {
            if (!UtilMethods.isSet(values)) {
                ae.add(Globals.ERROR_KEY,new ActionMessage("message.field.values"));
            }
        }
        if( !fieldType.equals("host or folder" )&& !fieldType.equals("relationships_tab") && !fieldType.equals("permissions_tab") && !fieldType.equals("categories_tab") && !fieldType.equals("image") && !fieldType.equals("link") && !fieldType.equals("file") && !element.equals(FieldAPI.ELEMENT_CONSTANT) && !fieldType.equals("hidden")) {
            if (!UtilMethods.isSet(dataType)) {
                ae.add(Globals.ERROR_KEY,new ActionMessage("message.field.dataType"));
            }
        }
    }
   
    if(dataType!=null && dataType.equals(Field.DataType.DATE.toString()) && !defaultValue.isEmpty() && !defaultValue.equals("now")) {
        DateFormat df=null;
        if(fieldType.equals(Field.FieldType.DATE.toString()))
            df=new SimpleDateFormat("yyyy-MM-dd");
        else if(fieldType.equals(Field.FieldType.DATE_TIME.toString()))
            df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        else if(fieldType.equals(Field.FieldType.TIME.toString()))
            df=new SimpleDateFormat("HH:mm:ss");
        if(df!=null) {
            try {
                    df.parse(defaultValue);
                } catch (ParseException e) {
                    ae.add(Globals.ERROR_KEY,new ActionMessage("message.field.defaultValue"));
                }
        }
    }
    return ae;
  }
View Full Code Here

    try{
      HibernateUtil.startTransaction();
      String path= Config.getStringProperty("CALENDAR_FILES_PATH");
      User currentUser = userAPI.getLoggedInUser(request);
      boolean respectFrontendRoles = !userAPI.isLoggedToBackend(request);
      ActionErrors ae = new ActionErrors();

     
      if (!UtilMethods.isSet(currentUser)) {
        boolean allowEventWithoutUser = Config.getBooleanProperty("ADD_EVENT_WITHOUT_USER",false);
        if(allowEventWithoutUser)
        {
          currentUser = APILocator.getUserAPI().getSystemUser();
        }
        else
        {
          return new ActionForward("/dotCMS/login?referrer="+mapping.findForward("addEvent").getPath(),true);
        }
      }
     
      String startDateDate = request.getParameter("startDateDate");
      String startDateTime = request.getParameter("startDateTime");
      String endDateDate = request.getParameter("endDateDate");
      String endDateTime = request.getParameter("endDateTime");
      String description = request.getParameter("description");
      String[] categoriesArray = request.getParameterValues("categories");
      String title = request.getParameter("title");
      String tags = request.getParameter("tags");
      String location = request.getParameter("location");
      String link = request.getParameter("link");
      String options =
        (request.getParameter("options") != null?PublicEncryptionFactory.decryptString(request.getParameter("options")):"").replaceAll(" ", "");
       
      SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
      SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("MM/dd/yyyy");
     
      Date startDate = null;
      Date endDate = null;
      try {
        startDate = dateFormat.parse(startDateDate + " " + startDateTime);
      } catch (ParseException e) {
        ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "From date"));
        saveMessages(request, ae);       
        return mapping.findForward("addEvent");
      }
     
      try {
        endDate = dateFormat.parse(endDateDate + " " + endDateTime);
      } catch (ParseException e) {
        ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "To date"));
        saveMessages(request, ae);       
        return mapping.findForward("addEvent");
      }
     
      try {
        endDate = dateFormat.parse(endDateDate + " " + endDateTime);
      } catch (ParseException e) {
        ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "To date"));
        saveMessages(request, ae);       
        return mapping.findForward("addEvent");
      }
     
      if(!request.getParameter("recurrenceOccurs").equals("never")){
        try {
          dateOnlyFormat.parse(request.getParameter("recurrenceEnds"));
        } catch (ParseException e) {
          ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "Recurrence end date"));
          saveMessages(request, ae);       
          return mapping.findForward("addEvent");
        }
      }     
     
      //Checking for the folder to store the submitted files
      Host host = hostWebAPI.getCurrentHost(request);
      Event event = new Event();
      Language language = langAPI.getDefaultLanguage();
      Folder folder = APILocator.getFolderAPI().findFolderByPath(path, host,APILocator.getUserAPI().getSystemUser(),false);
            Structure structure = StructureCache.getStructureByName("Event");
            event.setStructureInode(structure.getInode());
      if (!InodeUtils.isSet(folder.getInode())){
        folder = APILocator.getFolderAPI().createFolders(path, host,userAPI.getSystemUser(),false);
      }

      List<Category> categoriesList  =  new ArrayList<Category>();
      if (categoriesArray != null) {
        for (String cat : categoriesArray ) {
            Category node = (Category) catAPI.find(cat, currentUser, respectFrontendRoles);
            if(node!=null){
              categoriesList.add(node);
           }
        }
      }
     
      event.setStartDate(startDate);
      event.setEndDate(endDate);
      event.setTitle(title);
      event.setTags(tags);
      event.setLocation(location);
      event.setLink(link);
      event.setDescription(description);
      event.setLanguageId(language.getId());
       
      FileAsset cmsFile = null;
      FileAsset cmsImage = null;
     
      //Get file type parameters
      if (request instanceof UploadServletRequest)
      {
        UploadServletRequest uploadReq = (UploadServletRequest) request;
       
        java.io.File file = uploadReq.getFile("file");
        java.io.File image = uploadReq.getFile("image");
       
        if(file != null && file.length() > 0) {
          String fileName = uploadReq.getFileName("file");
          cmsFile = saveFile(currentUser, host, file, folder, fileName);
          event.setProperty("file", cmsFile.getIdentifier());
        }
         
        if(image != null && image.length() > 0) {
          String fileName = uploadReq.getFileName("image");
          cmsImage = saveFile(currentUser, host, image, folder, fileName);
          event.setProperty("image", cmsImage.getIdentifier());
        }         
         
      } 

      try {
        PermissionAPI perAPI = APILocator.getPermissionAPI();
        List<Permission> pers = perAPI.getPermissions(event.getStructure());
        APILocator.getContentletAPI().checkin(event, categoriesList, pers, currentUser, false);
        APILocator.getVersionableAPI().setWorking(event);
      } catch (DotContentletValidationException ex) {
       
        Map<String, List<Field>> fields = ex.getNotValidFields();
        List<Field> reqFields = fields.get("required");
        for(Field f : reqFields) {
          if(!f.getFieldType().equals(Field.FieldType.CATEGORY.toString())) {
            ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.contentlet.required", f.getFieldName()));
          } else {
            ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.contentlet.category.required", f.getFieldName()));
          }
        }
       
        saveMessages(request, ae);       
        return mapping.findForward("addEvent");
       
      } catch (DotSecurityException e) {
        ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("you-do-not-have-the-required-permissions"));
        saveMessages(request, ae);       
        return mapping.findForward("addEvent");     
      }
       
      Contentlet cont = conAPI.find(event.getInode(), currentUser, respectFrontendRoles);
View Full Code Here


  @SuppressWarnings("deprecation")
  public ActionErrors validate(ActionMapping arg0, HttpServletRequest request)
  {
    ActionErrors errors = new ActionErrors();
    String title = request.getParameter("title") ;
    if(title == null || title.equals("")){
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.contentlet.title.required"));
    }
    if (request instanceof UploadServletRequest)
    { 
      //Validate that the uploaded image corresponds to a valid image file type
      UploadServletRequest uploadReq = (UploadServletRequest) request;
      java.io.File image = uploadReq.getFile("image");
      if(image != null && image.length() > 0) {
        MimetypesFileTypeMap mimeType = new MimetypesFileTypeMap();
        if(!mimeType.getContentType(image).equals("image/jpeg")
            && !mimeType.getContentType(image).equals("image/pjpeg")
            && !mimeType.getContentType(image).equals("image/gif")
            && !mimeType.getContentType(image).equals("image/png")
            && !mimeType.getContentType(image).equals("image/x-png")){
          errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.contentlet.image.required"));
        }         
      }   
    }     

    return errors;
View Full Code Here

  }

  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        if(request.getParameter("cmd")!=null && request.getParameter("cmd").equals(Constants.ADD)) {

          ActionErrors ae = super.validate(mapping, request);
         
          if (!UtilMethods.isSet(mailingList) && !UtilMethods.isSet(userFilterInode)) {
            ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Please-select-a-Mailing-List"));
          }
         
          if((UtilMethods.isSet(webExpirationDate)) && (expirationDate == null)) {
            ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.campaign.error.expiration.date.incomplete"));
      }
          if(expirationDate != null && (expirationDate.before(new Date()))) {
            ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.campaign.error.wrong.expiration.date"));
          }

          return ae;
        }
        return null;
View Full Code Here

 
  @SuppressWarnings("deprecation")
  public ActionErrors validate(ActionMapping arg0, HttpServletRequest request)
  {
    ContentletAPI conAPI = APILocator.getContentletAPI();
    ActionErrors errors = new ActionErrors();
    Contentlet parentContentlet = new Contentlet()
    HttpSession session = request.getSession();
        Captcha captchaSession = (Captcha) session.getAttribute(Captcha.NAME);

        try{
      parentContentlet = conAPI.find(contentInode, APILocator.getUserAPI().getSystemUser(), true);
    }catch(DotDataException e){
      Logger.error(this, "Unable to look up contentlet with inode " + contentInode, e);
    }catch (DotSecurityException dse) {
      Logger.error(this, "Unable to look up contentlet with inode " + contentInode + " because of security issue", dse);
    }
   
    if(parentContentlet==null || !InodeUtils.isSet(parentContentlet.getInode())){
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Contentlet Inode"));       
      return errors;
    }
    if (!UtilMethods.isSet(name))
    {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Name"));       
    }
    if (!UtilMethods.isSet(email) || ! UtilMethods.isValidEmail(email))
    {       
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Email"));       
    }
    /*  Try to find a title if we don't have one.  */
    if (!UtilMethods.isSet(commentTitle))
      {
      Structure s = StructureCache.getStructureByInode(parentContentlet.getStructureInode());
      List<Field> lf = s.getFields();
      for(Field f : lf){
        if("text".equals(f.getFieldType()) && f.isIndexed() && f.isListed()){
          try{
            commentTitle = "re: " + conAPI.getFieldValue(parentContentlet, f);
          }catch (Exception e) {
            Logger.error(CommentsForm.class, "Unable to set comment title", e);
          }
          break;
        }
      }
      }
    if (!UtilMethods.isSet(comment))
    {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Comment"));
    }
    if (UtilMethods.isSet(accept) && accept == false)
    {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Accept"));
    }

        if ( commentUseCaptcha ) {
            if ( !UtilMethods.isSet( captcha ) || !UtilMethods.isSet( captchaSession ) || !captcha.equals( captchaSession.getAnswer() ) ) {
                errors.add( ActionErrors.GLOBAL_ERROR, new ActionError( "message.contentlet.required", "Validation Image" ) );
            }
        }

        if(commentUseAudioCaptcha && !UtilMethods.isSet(captchaSession)){
        
      Boolean isResponseCorrect =Boolean.FALSE;
      String captchaId = request.getSession().getId()
      if(UtilMethods.isSet(audioCaptcha) && UtilMethods.isSet(captchaId)){
        try {
//          isResponseCorrect = CaptchaServiceSingleton.getInstance().validateResponseForID(captchaId,
//              audioCaptcha);
         
          isResponseCorrect = CaptchaUtil.isValidAudioCaptcha(request);
        } catch (CaptchaServiceException e) {
          Logger.error(CommentsForm.class, "An error ocurred trying to validate audio captcha", e);
        }
       }
   
      if(!isResponseCorrect){
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Validation Sound"));
      }

    }
    return errors;
  }
View Full Code Here

        return ToStringBuilder.reflectionToString(this);
    }


    public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
        ActionErrors ae = new ActionErrors();  
        ae = super.validate(arg0,arg1);
        return ae;
    }
View Full Code Here

  }


  @SuppressWarnings({ "unchecked", "deprecation" })
  public void _saveWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user) throws Exception, DotContentletValidationException {
    ActionErrors ae = new ActionErrors();
    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    String subcmd = req.getParameter("subcmd");

    // Getting the contentlets variables to work
    Contentlet currentContentlet = (Contentlet) req.getAttribute(WebKeys.CONTENTLET_EDIT);
    String currentContentident = currentContentlet.getIdentifier();
    boolean isNew = false;
    if(!(InodeUtils.isSet(currentContentlet.getInode()))){
      isNew = true;
    }
    if(!isNew){
      try{
        currentContentlet = conAPI.checkout(currentContentlet.getInode(), user, false);
      }catch (DotSecurityException dse) {
        SessionMessages.add(httpReq, "message", "message.insufficient.permissions.to.save");
        throw new DotSecurityException("User cannot checkout contentlet : ", dse);
      }
    }
    req.setAttribute(WebKeys.CONTENTLET_FORM_EDIT, currentContentlet);
    req.setAttribute(WebKeys.CONTENTLET_EDIT, currentContentlet);

    ContentletForm contentletForm = (ContentletForm) form;
    String owner = contentletForm.getOwner();

    try{
      _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);
      }
    }
    req.setAttribute("inodeToWaitOn", currentContentlet.getInode());
    req.setAttribute(WebKeys.CONTENTLET_EDIT, currentContentlet);
View Full Code Here

    if (!mapping.getValidate()) {
      return true;
    }

    ActionErrors errors = form.validate(mapping, req);
    if ((errors == null) || errors.isEmpty()) {
      return true;
    }

    if (form.getMultipartRequestHandler() != null) {
      form.getMultipartRequestHandler().rollback();
View Full Code Here

TOP

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

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.