Package com.liferay.portlet

Examples of com.liferay.portlet.ActionRequestImpl


  private void _newContent(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user)
  throws Exception {

    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    //Contentlet Form
    ContentletForm cf = (ContentletForm) form;

    String cmd = req.getParameter(Constants.CMD);
View Full Code Here


  public static boolean validate(ActionRequest request, ActionForm form, ActionMapping mapping) {
        if ((request == null) || (form == null) || (mapping == null)) {
            return false;
        }

        ActionRequestImpl reqImpl = (ActionRequestImpl) request;
        HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
        com.dotcms.repackage.org.apache.struts.action.ActionErrors errors = form.validate(mapping, httpReq);

        if ((errors != null) && !errors.isEmpty()) {
           
            request.setAttribute(Globals.ERROR_KEY, errors);
View Full Code Here

    Contentlet workingContentlet = null;

    String sib= req.getParameter("sibbling");
    Boolean populateaccept = Boolean.valueOf(req.getParameter("populateaccept"));

    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
    httpReq.getSession().setAttribute("populateAccept", populateaccept);


    if(UtilMethods.isSet(sib))
    {
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);
    req.setAttribute(WebKeys.CONTENTLET_FORM_EDIT, currentContentlet);
    if (Config.getBooleanProperty("CONTENT_CHANGE_NOTIFICATIONS") && !isNew)
      _sendContentletPublishNotification(currentContentlet, reqImpl.getHttpServletRequest());

    SessionMessages.add(httpReq, "message", "message.contentlet.save");
    if( subcmd != null && subcmd.equals(com.dotmarketing.util.Constants.PUBLISH) ) {
      SessionMessages.add(httpReq, "message", "message.contentlet.published");
    }
View Full Code Here

    String cmd = req.getParameter(Constants.CMD);
    String referer = req.getParameter("referer");
    ContainerForm fm = (ContainerForm) form;

    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    if ((referer != null) && (referer.length() != 0)) {
      referer = URLDecoder.decode(referer, "UTF-8");
    }
View Full Code Here

    // calls edit method from super class that returns parent folder
    super._editWebAsset(req, res, config, form, user, WebKeys.CONTAINER_EDIT);

    // setting parent folder path and inode on the form bean
    ContainerForm cf = (ContainerForm) form;
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
    HttpSession session = httpReq.getSession();

    //Setting the default host = the selected crumbtrail host if it is a new container
        String hostId= (String)session.getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID);
        if(!hostId.equals("allHosts") && cf.getHostId() == null) {
View Full Code Here

     */
  public void _saveWebAsset(ActionRequest req, ActionResponse res,
      PortletConfig config, ActionForm form, User user) throws Exception {

    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    ContainerForm fm = (ContainerForm) form;

    // gets the new information for the container from the request object
    req.setAttribute(WebKeys.CONTAINER_FORM_EDIT,
View Full Code Here

  public void _copyWebAsset(ActionRequest req, ActionResponse res,
      PortletConfig config, ActionForm form, User user) throws Exception {

    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    Logger.debug(this, "I'm copying the Container");

    // gets the current template being edited from the request object
    Container currentContainer = (Container) req
View Full Code Here

  public void _copyWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user)
  throws Exception {

    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    Contentlet currentContentlet = (Contentlet) req.getAttribute(WebKeys.CONTENTLET_EDIT);

    //ContentletForm cf = (ContentletForm)form;
    String structureInode = currentContentlet.getStructureInode();
View Full Code Here

      ContentletForm contentletForm = (ContentletForm) form;
      contentletForm.setMap(contentlet.getMap());
      Structure structure = contentlet.getStructure();
      req.setAttribute("lang",contentlet.getLanguageId());
      if (!InodeUtils.isSet(structure.getInode())) {
        ActionRequestImpl reqImpl = (ActionRequestImpl) req;
        HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
        httpReq.getSession().setAttribute(WebKeys.Structure.STRUCTURE_TYPE, new Integer("1"));
        String selectedStructure = req.getParameter("selectedStructure");
        if (InodeUtils.isSet(selectedStructure)) {
          structure = StructureCache.getStructureByInode(selectedStructure);
        }
      }

      List structures = StructureFactory.getStructuresWithWritePermissions(user, false);
      if(!structures.contains(structure)) {
        structures.add(structure);
      }
      contentletForm.setAllStructures(structures);

      String cmd = req.getParameter(Constants.CMD);
      if ((cmd.equals("new") || !InodeUtils.isSet(contentletForm.getStructure().getInode())) && contentletForm.isAllowChange()) {
        contentletForm.setAllowChange(true);
      } else {
        contentletForm.setAllowChange(false);
      }

      if (cmd != null && cmd.equals(Constants.EDIT)) {
          String sib= req.getParameter("sibbling");
          Boolean populateaccept = Boolean.valueOf(req.getParameter("populateaccept"));
          if(UtilMethods.isSet(sib) && populateaccept)
              contentlet.setInode(sib);

        //Setting categories in the contentlet form
        List<String> categoriesArr = new ArrayList<String> ();
        List<Category> cats = catAPI.getParents(contentlet, user, false);

        for (Category cat : cats) {
          categoriesArr.add(String.valueOf(cat.getInode()));
        }

        contentletForm.setCategories(categoriesArr.toArray(new String[0]));

        if(UtilMethods.isSet(sib) && populateaccept)
                    contentlet.setInode("");
      }

      if(cmd != null && (cmd.equals(Constants.ADD)))
      {
        if(structure != null)
        {
          ActionRequestImpl reqImpl = (ActionRequestImpl) req;
          HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
          HttpSession ses = httpReq.getSession();
          if(contentletForm.getStructure().getStructureType()!=Structure.STRUCTURE_TYPE_FORM){
            req.setAttribute("structure_id",String.valueOf(contentletForm.getStructureInode()));
          }
        }
View Full Code Here

TOP

Related Classes of com.liferay.portlet.ActionRequestImpl

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.