Package com.dotmarketing.portlets.contentlet.struts

Examples of com.dotmarketing.portlets.contentlet.struts.ContentletForm


    // 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);
    String inode = req.getParameter("inode");
    String inodeStr = (InodeUtils.isSet(inode) ? inode : "");
    Contentlet contentlet = new Contentlet();

    if(InodeUtils.isSet(inodeStr))
      contentlet = conAPI.find(inodeStr, user, false);

    req.setAttribute(WebKeys.CONTENTLET_EDIT, contentlet);
    Structure structure = contentlet.getStructure();

    String selectedStructure = "";
    if (InodeUtils.isSet(req.getParameter("selectedStructure"))) {
      selectedStructure = req.getParameter("selectedStructure");
      structure = (Structure) InodeFactory.getInode(selectedStructure, Structure.class);
      contentlet.setStructureInode(structure.getInode());
    } else if (cmd.equals("newedit")) {
      structure = StructureFactory.getDefaultStructure();
      contentlet.setStructureInode(structure.getInode());
    }

    String langId = req.getParameter("lang");
    if(UtilMethods.isSet(langId)) {
      try {
        contentlet.setLanguageId(Integer.parseInt(langId));
      } catch (NumberFormatException e) {
        contentlet.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
      }
    }else{
      contentlet.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
    }

    Map<String, Object> lastSearchMap = new HashMap<String, Object>();
    lastSearchMap.put("structure", structure);
    lastSearchMap.put("fieldsSearch",new HashMap<String,String>());
    lastSearchMap.put("categories",new ArrayList<String>());
    lastSearchMap.put("showDeleted",false);
    lastSearchMap.put("filterSystemHost",false);
    lastSearchMap.put("filterLocked",false);
    lastSearchMap.put("page",1);
    lastSearchMap.put("orderBy","modDate desc");
    httpReq.getSession().setAttribute(WebKeys.CONTENTLET_LAST_SEARCH, lastSearchMap);


    // Checking permissions to add new of structure selected
    _checkWritePermissions(structure, user, httpReq);

    List<Field> list = (List<Field>) FieldsCache.getFieldsByStructureInode(structure.getInode());
    for (Field field : list) {
      String defaultValue = field.getDefaultValue();
      if (UtilMethods.isSet(defaultValue)) {
        String typeField = field.getFieldContentlet();
        if (typeField.startsWith("bool")) {
          boolean defaultValueBoolean = false;
          if(defaultValue.equalsIgnoreCase("true") || defaultValue.equalsIgnoreCase("1") || defaultValue.equalsIgnoreCase("yes")
              || defaultValue.equalsIgnoreCase("y") || defaultValue.equalsIgnoreCase("on"))
            defaultValueBoolean = true;
          contentlet.setBoolProperty(field.getVelocityVarName(), defaultValueBoolean);
        } else if (typeField.startsWith("date")) {
            if(defaultValue.equals("now"))
                contentlet.setDateProperty(field.getVelocityVarName(), new Date());
            else {
                DateFormat df=null;
                final String ft=field.getFieldType();
                  if(ft.equals(Field.FieldType.DATE.toString()))
                      df=new SimpleDateFormat("yyyy-MM-dd");
                  else if(ft.equals(Field.FieldType.DATE_TIME.toString()))
                      df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                  else if(ft.equals(Field.FieldType.TIME.toString()))
                      df=new SimpleDateFormat("HH:mm:ss");
                  try {
                      contentlet.setDateProperty(field.getVelocityVarName(), df.parse(defaultValue));
                  }
                  catch(ParseException e) {
                      // pass it as null
                  }
            }
        } else if (typeField.startsWith("float")) {
            contentlet.setFloatProperty(field.getVelocityVarName(), Float.parseFloat(defaultValue));
        } else if (typeField.startsWith("integer")) {
            contentlet.setLongProperty(field.getVelocityVarName(), Long.parseLong(defaultValue));
        } else if (typeField.startsWith("text")) {
            contentlet.setStringProperty(field.getVelocityVarName(), defaultValue);
        }

         if (field.getFieldType().equals(Field.FieldType.IMAGE.toString())
            || field.getFieldType().equals(Field.FieldType.FILE.toString())) {
          try {
            //Identifier id = (Identifier) InodeFactory.getInode((String) value, Identifier.class);
              String value=contentlet.getStringProperty(field.getVelocityVarName());
            Identifier id = APILocator.getIdentifierAPI().find((String) value);
            if (InodeUtils.isSet(id.getInode())) {
              if (field.getFieldType().equals(Field.FieldType.IMAGE.toString())) {
                File inodeAux = (File) APILocator.getVersionableAPI().findWorkingVersion(id,  APILocator.getUserAPI().getSystemUser(), false);
                value = inodeAux.getInode();
              } else if (field.getFieldType().equals(Field.FieldType.FILE.toString())) {
                File inodeAux = (File) APILocator.getVersionableAPI().findWorkingVersion(id,  APILocator.getUserAPI().getSystemUser(), false);
                value = inodeAux.getInode();
              }
              contentlet.setStringProperty(field.getVelocityVarName(), value);
            }
          } catch (Exception ex) {
            Logger.debug(this, ex.toString());
          }
        }

      }
    }

    //Setting review intervals form properties
    if (structure.getReviewInterval() != null) {
      String interval = structure.getReviewInterval();
      Pattern p = Pattern.compile("(\\d+)([dmy])");
      Matcher m = p.matcher(interval);
      boolean b = m.matches();
      if (b) {
        cf.setReviewContent(true);
        String g1 = m.group(1);
        String g2 = m.group(2);
        cf.setReviewIntervalNum(g1);
        cf.setReviewIntervalSelect(g2);
      }
    }

  }
View Full Code Here


  @SuppressWarnings("unchecked")
  public void _editWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user)
  throws Exception {

    ContentletForm cf = (ContentletForm) form;
    ContentletAPI contAPI = APILocator.getContentletAPI();

    Contentlet contentlet = (Contentlet) req.getAttribute(WebKeys.CONTENTLET_EDIT);
    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))
    {
      Contentlet sibbling=conAPI.find(sib, user,false);
      conAPI.unlock(sibbling, user, false);
      if(populateaccept){
        contentlet = sibbling;
        contentlet.setInode("");
        //http://jira.dotmarketing.net/browse/DOTCMS-5802
        Structure structure = contentlet.getStructure();
        List<Field> list = (List<Field>) FieldsCache.getFieldsByStructureInode(structure.getInode());
        for (Field field : list) {
          if(field.getFieldContentlet().startsWith("binary")){
            httpReq.getSession().setAttribute(field.getFieldContentlet() + "-sibling", sib+","+field.getVelocityVarName());
            java.io.File inputFile = APILocator.getContentletAPI().getBinaryFile(sib, field.getVelocityVarName(), user);
            if(inputFile != null){
              java.io.File acopyFolder=new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                  + java.io.File.separator + user.getUserId() + java.io.File.separator + field.getFieldContentlet()
                                  + java.io.File.separator + UUIDGenerator.generateUuid());
             
              if(!acopyFolder.exists())
                              acopyFolder.mkdir();
             
              String shortFileName = FileUtil.getShortFileName(inputFile.getAbsolutePath());
             
              java.io.File binaryFile = new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                  + java.io.File.separator + user.getUserId() + java.io.File.separator + field.getFieldContentlet()
                  + java.io.File.separator + shortFileName.trim());
             
              FileUtil.copyFile(inputFile, binaryFile);
            }
          }
        }
      }
    }

    if(InodeUtils.isSet(contentlet.getInode())){
      workingContentlet = contAPI.findContentletByIdentifier(contentlet.getIdentifier(), false, contentlet.getLanguageId(), user, false);
    }else{
      workingContentlet = contentlet;
    }

    if(!InodeUtils.isSet(contentlet.getInode())) {
        String langId = req.getParameter("lang");
        if(UtilMethods.isSet(langId)) {
            contentlet.setLanguageId(Long.parseLong(langId));
        }
        else {
            contentlet.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
        }
    }

    GregorianCalendar cal = new GregorianCalendar();
    if (contentlet.getModDate() == null) {
      contentlet.setModDate(cal.getTime());
    }

    if(!UtilMethods.isSet(contentlet.getInode())) {
        req.setAttribute(WebKeys.CONTENT_EDITABLE, true);
    }
    else if(perAPI.doesUserHavePermission(contentlet, PermissionAPI.PERMISSION_WRITE, user) && workingContentlet.isLocked()){

      String lockedUserId = APILocator.getVersionableAPI().getLockedBy(workingContentlet);
      if(user.getUserId().equals(lockedUserId)){
        req.setAttribute(WebKeys.CONTENT_EDITABLE, true);
      }else{
        req.setAttribute(WebKeys.CONTENT_EDITABLE, false);
      }
    }else{
      req.setAttribute(WebKeys.CONTENT_EDITABLE, false);
    }

    if (contentlet.isArchived()) {
      Company comp = PublicCompanyFactory.getDefaultCompany();
      String message = LanguageUtil.get(comp.getCompanyId(), user.getLocale(), "message.contentlet.edit.deleted");
      SessionMessages.add(req, "custommessage", message);
    }

    //  http://jira.dotmarketing.net/browse/DOTCMS-1073
    //  retrieve file names while edit
    /*Logger.debug(this,"EditContentletAAction : retrieving binary field values.");
    Structure structure = contentlet.getStructure();
    List<Field> list = (List<Field>) FieldsCache.getFieldsByStructureInode(structure.getInode());
    for (Field field : list) {
      String value = "";
      if(field.getFieldContentlet().startsWith("binary")){
        //  http://jira.dotmarketing.net/browse/DOTCMS-2178
        java.io.File binaryFile = conAPI.getBinaryFile(contentlet.getInode(),field.getVelocityVarName(),user);
        //http://jira.dotmarketing.net/browse/DOTCMS-3463
        contentlet.setBinary(field.getVelocityVarName(),binaryFile);
      }
    }*/
    cf.setMap(new HashMap<String, Object>(contentlet.getMap()));

    Logger.debug(this, "EditContentletAction: contentletInode=" + contentlet.getInode());

    req.setAttribute(WebKeys.CONTENTLET_EDIT, contentlet);

    if (contentlet.getReviewInterval() != null) {
      String interval = contentlet.getReviewInterval();
      Pattern p = Pattern.compile("(\\d+)([dmy])");
      Matcher m = p.matcher(interval);
      boolean b = m.matches();
      if (b) {
        cf.setReviewContent(true);
        String g1 = m.group(1);
        String g2 = m.group(2);
        cf.setReviewIntervalNum(g1);
        cf.setReviewIntervalSelect(g2);
      }
    }
    //DOTCMS-6097
    if(UtilMethods.isSet(req.getParameter("is_rel_tab")))
      req.setAttribute("is_rel_tab", req.getParameter("is_rel_tab"));
View Full Code Here

      req.setAttribute("is_rel_tab", req.getParameter("is_rel_tab"));
  }

  @SuppressWarnings("deprecation")
  private boolean _populateContent(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user, Contentlet contentlet) throws Exception, DotContentletValidationException {
    ContentletForm contentletForm = (ContentletForm) form;
    if(InodeUtils.isSet(contentletForm.getIdentifier()) && !contentletForm.getIdentifier().equals(contentlet.getIdentifier())){
      throw new DotContentletValidationException("The content form submission data id different from the content which is trying to be edited");
    }
    try {
      String structureInode = contentlet.getStructureInode();
      if (!InodeUtils.isSet(structureInode)) {
        String selectedStructure = req.getParameter("selectedStructure");
        if (InodeUtils.isSet(selectedStructure)) {
          structureInode = selectedStructure;
        }
      }
      contentlet.setStructureInode(structureInode);

      contentlet.setIdentifier(contentletForm.getIdentifier());
      contentlet.setInode(contentletForm.getInode());
      contentlet.setLanguageId(contentletForm.getLanguageId());
      contentlet.setReviewInterval(contentletForm.getReviewInterval());
      List<String> disabled = new ArrayList<String>();
      CollectionUtils.addAll(disabled, contentletForm.getDisabledWysiwyg().split(","));
      contentlet.setDisabledWysiwyg(disabled);

      List<Field> fields = FieldsCache.getFieldsByStructureInode(structureInode);
      for (Field field : fields){
        if ((fAPI.isElementConstant(field))){
View Full Code Here

      }
    }
    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
View Full Code Here

  private void _loadForm(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user,
      boolean validate) throws Exception {
    try {

      Contentlet contentlet = (Contentlet) req.getAttribute(WebKeys.CONTENTLET_EDIT);
      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()));
          }
        }
      }

    } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.contentlet.struts.ContentletForm

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.