Package com.dotmarketing.portlets.contentlet.business

Examples of com.dotmarketing.portlets.contentlet.business.ContentletAPI


    Contentlet newCont = new Contentlet();

    Structure fileAssetStr = StructureCache.getStructureByVelocityVarName(FileAssetAPI.DEFAULT_FILE_ASSET_STRUCTURE_VELOCITY_VAR_NAME);

    ContentletAPI conAPI = APILocator.getContentletAPI();

    newCont.setStructureInode(fileAssetStr.getInode());

    try {

      newCont.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());

      for(Field field : FieldsCache.getFieldsByStructureVariableName(fileAssetStr.getInode())){
        if(field.getVelocityVarName().equals(FileAssetAPI.TITLE_FIELD))
          conAPI.setContentletProperty(newCont, field, fileName);

        if(field.getVelocityVarName().equals(FileAssetAPI.HOST_FOLDER_FIELD))
          conAPI.setContentletProperty(newCont, field, APILocator.getHostAPI().findSystemHost().getInode());

        if(field.getVelocityVarName().equals(FileAssetAPI.BINARY_FIELD)){

          File binaryFile = null;
          if(UtilMethods.isSet(fileName)){
            fileName = ContentletUtil.sanitizeFileName(fileName);
            binaryFile = new File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                + File.separator + user.getUserId() + File.separator + FieldsCache.getField(fieldInode).getFieldContentlet()
                + File.separator + fileName.trim());
            }

          conAPI.setContentletProperty(newCont, field, binaryFile);
        }
      }

      newCont = conAPI.checkin(newCont, sysUser, false);

    } catch (Exception e) {
      Logger.error(this,"Contentlet failed while creating new binary content",e);
    }
View Full Code Here


    //Host?
    perm = hostAPI.find(assetId, userAPI.getSystemUser(), false);
   
    if(perm == null) {
      //Content?
      ContentletAPI contAPI = APILocator.getContentletAPI();
      try {
        perm = contAPI.findContentletByIdentifier(assetId, false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), userAPI.getSystemUser(), false);
      } catch (DotContentletStateException e) {
      }
    }
   
    if(perm == null) {
View Full Code Here

   
  }
 
  public void execute(JobExecutionContext ctx) throws JobExecutionException {

    ContentletAPI conAPI = APILocator.getContentletAPI();
    FieldAPI fieldAPI = APILocator.getFieldAPI();
    PermissionAPI perAPI = APILocator.getPermissionAPI();
    try {
 
        List<Structure> allStructures = StructureFactory.getStructures();   
        for(Structure structure:allStructures){
         
          boolean isCongigured = false;
          String host = "";
          String username = "";
          String password = "";
          int port = 0;
          boolean isSSL = true;
   
          try{
            host = Config.getStringProperty("pop."+structure.getVelocityVarName()+".host");
            username = Config.getStringProperty("pop."+structure.getVelocityVarName()+".login");
            password = Config.getStringProperty("pop."+structure.getVelocityVarName()+".password");
            port = Config.getIntProperty("pop."+structure.getVelocityVarName()+".port");
            isSSL  = Config.getBooleanProperty("pop."+structure.getVelocityVarName()+".ssl");
          }catch (Exception e) {
           
          }
   
          if(UtilMethods.isSet(host)
              && UtilMethods.isSet(port)
              && UtilMethods.isSet(isSSL)
              && UtilMethods.isSet(username)
              && UtilMethods.isSet(password)){
            isCongigured = true;
          }
   
          if(isCongigured){
           
            String messageIdFieldVarNm = "";
            String subjectFieldVarNm = "";
            String bodyFieldVarNm = "";
            String fromFieldVarNm = "";
            String toFieldVarNm = "";
            String ccFieldVarNm = "";
            String bccFieldVarNm = "";
            String dateFieldVarNm = "";
            String referencesFieldVarNm = "";
            String inReplyToFieldVarNm = "";
            String attachment1FieldVarNm = "";
            String attachment2FieldVarNm = "";
            String attachment3FieldVarNm = "";
            String attachment4FieldVarNm = "";
            String attachment5FieldVarNm = "";
            String attachment6FieldVarNm = "";
            String attachment7FieldVarNm = "";
            String attachment8FieldVarNm = "";
            String attachment9FieldVarNm = "";
            String attachment10FieldVarNm = "";
           
            try{
              messageIdFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".messageId");
              subjectFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".subject");
              bodyFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".body");
              fromFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".from");
              toFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".to");
              ccFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".cc");
              bccFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".bcc");
              dateFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".date");
              referencesFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".references");
              inReplyToFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".inReplyTo");
              attachment1FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment1");
              attachment2FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment2");
              attachment3FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment3");
              attachment4FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment4");
              attachment5FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment5");
              attachment6FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment6");
              attachment7FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment7");
              attachment8FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment8");
              attachment9FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment9");
              attachment10FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment10");
            }catch (Exception e) {
             
            }
   
            List<Field> fields = FieldsCache.getFieldsByStructureVariableName(structure.getVelocityVarName());
   
            ContentletRelationships contRel;
            ArrayList<Category> cats;
            User systemUser = null;
            try {
              systemUser = APILocator.getUserAPI().getSystemUser();
            } catch (DotDataException e) {
              Logger.error(this, e.getMessage());
            }
   
            try {
              List<Map<String,Object>> emails = EmailUtils.getEmails(host, port, isSSL, username, password);
   
              for(Map<String,Object> email:emails){
                Contentlet contentlet = new Contentlet();
                contentlet.setStructureInode(structure.getInode());
   
                for (Field field : fields){
                  if(fieldAPI.isElementConstant(field)){
                    continue;
                  }
                  Object value = null;
                  // using the standard headers/names from javax.mail.* to retrieve the email headers and field's values below
                  if(UtilMethods.isSet(messageIdFieldVarNm) && field.getVelocityVarName().equals(messageIdFieldVarNm)){
                    if(email.get("Message-ID") != null)
                      value = email.get("Message-ID");
                  }else if(UtilMethods.isSet(subjectFieldVarNm) && field.getVelocityVarName().equals(subjectFieldVarNm)){
                    if(email.get("Subject") != null)
                      value = email.get("Subject");
                  }else if(UtilMethods.isSet(bodyFieldVarNm) && field.getVelocityVarName().equals(bodyFieldVarNm)){
                    if(email.get("Body") != null)
                      value = email.get("Body");
                  }else if(UtilMethods.isSet(fromFieldVarNm) && field.getVelocityVarName().equals(fromFieldVarNm)){
                    if(email.get("From") != null)
                      value = email.get("From");
                  } else if(UtilMethods.isSet(toFieldVarNm) && field.getVelocityVarName().equals(toFieldVarNm)){
                    if(email.get("To") != null)
                      value = email.get("To");
                  }else if(UtilMethods.isSet(ccFieldVarNm) && field.getVelocityVarName().equals(ccFieldVarNm)){
                    if(email.get("Cc") != null)
                      value = email.get("Cc");
                  }else if(UtilMethods.isSet(bccFieldVarNm) && field.getVelocityVarName().equals(bccFieldVarNm)){
                    if(email.get("Bcc") != null)
                      value = email.get("Bcc");
                  }else if(UtilMethods.isSet(dateFieldVarNm) && field.getVelocityVarName().equals(dateFieldVarNm)){
                    if(email.get("Date") != null)
                      value = email.get("Date");
                  }else if(UtilMethods.isSet(referencesFieldVarNm) && field.getVelocityVarName().equals(referencesFieldVarNm)){
                    if(email.get("References") != null)
                      value = email.get("References");
                  }else if(UtilMethods.isSet(inReplyToFieldVarNm) && field.getVelocityVarName().equals(inReplyToFieldVarNm)){
                    if(email.get("In-Reply-To") != null)
                      value = email.get("In-Reply-To");
                  }else if(UtilMethods.isSet(attachment1FieldVarNm) && field.getVelocityVarName().equals(attachment1FieldVarNm)){
                    if(email.get("attachment1") != null)
                      value = email.get("attachment1");
                  }else if(UtilMethods.isSet(attachment2FieldVarNm) && field.getVelocityVarName().equals(attachment2FieldVarNm)){
                    if(email.get("attachment2") != null)
                      value = email.get("attachment2");
                  }else if(UtilMethods.isSet(attachment3FieldVarNm) && field.getVelocityVarName().equals(attachment3FieldVarNm)){
                    if(email.get("attachment3") != null)
                      value = email.get("attachment3");
                  }else if(UtilMethods.isSet(attachment4FieldVarNm) && field.getVelocityVarName().equals(attachment4FieldVarNm)){
                    if(email.get("attachment4") != null)
                      value = email.get("attachment4");
                  }else if(UtilMethods.isSet(attachment5FieldVarNm) && field.getVelocityVarName().equals(attachment5FieldVarNm)){
                    if(email.get("attachment5") != null)
                      value = email.get("attachment5");
                  }else if(UtilMethods.isSet(attachment6FieldVarNm) && field.getVelocityVarName().equals(attachment6FieldVarNm)){
                    if(email.get("attachment6") != null)
                      value = email.get("attachment6");
                  }else if(UtilMethods.isSet(attachment7FieldVarNm) && field.getVelocityVarName().equals(attachment7FieldVarNm)){
                    if(email.get("attachment7") != null)
                      value = email.get("attachment7");
                  }else if(UtilMethods.isSet(attachment8FieldVarNm) && field.getVelocityVarName().equals(attachment8FieldVarNm)){
                    if(email.get("attachment8") != null)
                      value = email.get("attachment8");
                  }else if(UtilMethods.isSet(attachment9FieldVarNm) && field.getVelocityVarName().equals(attachment9FieldVarNm)){
                    if(email.get("attachment9") != null)
                      value = email.get("attachment9");
                  }else if(UtilMethods.isSet(attachment10FieldVarNm) && field.getVelocityVarName().equals(attachment10FieldVarNm)){
                    if(email.get("attachment10") != null)
                      value = email.get("attachment10");
                  }
   
                  String typeField = field.getFieldType();
   
                  /* Validate if the field is read only, if so then check to see if it's a new contentlet
                   * and set the structure field default value, otherwise do not set the new value.
                   */
                  if (!typeField.equals(Field.FieldType.HIDDEN.toString()) &&
                      !typeField.equals(Field.FieldType.IMAGE.toString()) &&
                      !typeField.equals(Field.FieldType.FILE.toString()))
                  {
                    if(field.isReadOnly() && !InodeUtils.isSet(contentlet.getInode()))
                      value = field.getDefaultValue();
                    if (field.getFieldType().equals(Field.FieldType.WYSIWYG.toString())) {
                      //WYSIWYG workaround because the WYSIWYG includes a <br> even if the field was left blank by the user
                      //we have to check the value to leave it blank in that case.
                      if (value instanceof String && ((String)value).trim().toLowerCase().equals("<br>")) {
                        value = "";
                      }
                    }
                  }
                  if ((value != null || field.getFieldType().equals(Field.FieldType.BINARY.toString())) && APILocator.getFieldAPI().valueSettable(field)
                      && !field.getFieldType().equals(Field.FieldType.HOST_OR_FOLDER.toString()))
                    try{
                      conAPI.setContentletProperty(contentlet, field, value);
                    }catch (Exception e) {
                      Logger.info(this, "Unable to set field " + field.getFieldName() + " to value " + value);
                      Logger.debug(this, "Unable to set field " + field.getFieldName() + " to value " + value, e);
                    }
                }
   
                contRel = retrieveRelationshipsData(contentlet,systemUser,email);
   
                cats = new ArrayList<Category>();
   
                Contentlet con = conAPI.checkin(contentlet, contRel,
                    cats, perAPI.getPermissions(contentlet, false, true), systemUser, false);
               
                // When a large number of new mails with a number of replies come in.
                // To relate the content based on lucene query, the new content created must be indexed.
                conAPI.isInodeIndexed(con.getInode());
              }
            } catch (MessagingException e) {
              Logger.error(this, e.getMessage());
            } catch (IOException e) {
              Logger.error(this, e.getMessage());
View Full Code Here

   *
   * @param contentlet
   * @return
   */
  public static String toPrettyHTMLString(Contentlet contentlet) {
      ContentletAPI conAPI = APILocator.getContentletAPI();
      User user = null;
      try{
        user = APILocator.getUserAPI().getSystemUser();
      }catch (DotDataException e) {
      Logger.error(Contentlet.class, "Unable to get system user", e);
    }
        StringBuffer sb = new StringBuffer();
        Structure st = StructureCache.getStructureByInode(contentlet.getStructureInode());
        List<Field> fields = FieldsCache.getFieldsByStructureInode(st.getInode());
        for (Field f : fields) {
            if (f.isListed()) {
                if (f.getFieldType().equals(Field.FieldType.DATE.toString())) {
                    Date value = new Date();
         
          value = (Date) conAPI.getFieldValue(contentlet, f);
         
                    sb.append(f.getFieldName() + ": " + UtilMethods.dateToHTMLDate(value) + "<br>");
                } else if (f.getFieldType().equals(Field.FieldType.DATE_TIME.toString())) {
                    Date value = new Date();
         
          value = (Date) conAPI.getFieldValue(contentlet, f);
         
                    sb.append(f.getFieldName() + ": " + UtilMethods.dateToHTMLDate(value) + " "
                            + UtilMethods.dateToHTMLTime(value) + "<br>");
                } else if (f.getFieldType().equals(Field.FieldType.TIME.toString())) {
                    Date value = new Date();
         
          value = (Date) conAPI.getFieldValue(contentlet, f);
         
                    sb.append(f.getFieldName() + ": " + UtilMethods.dateToHTMLTime(value) + "<br>");
                } else if (f.getFieldType().equals(Field.FieldType.MULTI_SELECT.toString()) || f.getFieldType().equals(Field.FieldType.RADIO.toString())
                        || f.getFieldType().equals(Field.FieldType.SELECT.toString()) || f.getFieldType().equals(Field.FieldType.TEXT.toString())
                        || f.getFieldType().equals(Field.FieldType.TEXT_AREA.toString()) || f.getFieldType().equals(Field.FieldType.WYSIWYG.toString())) {
                    String value = "";
         
          value = ((Object) conAPI.getFieldValue(contentlet, f)).toString();
         
                    sb.append(f.getFieldName() + ": " + UtilMethods.shortenString(value, 30) + "<br>");
                }
            }
        }
View Full Code Here

    //Host?
    perm = hostAPI.find(assetId, userAPI.getSystemUser(), false);
   
    if(perm == null) {
      //Content?
      ContentletAPI contAPI = APILocator.getContentletAPI();
      try {
        perm = contAPI.findContentletByIdentifier(assetId, false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), userAPI.getSystemUser(), false);
      } catch (DotContentletStateException e) {
      }
    }
   
    if(perm == null) {
View Full Code Here

   
    //GIT-2816
    RenderRequestImpl reqImpl = (RenderRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
    HttpSession ses = httpReq.getSession();
    ContentletAPI conAPI = APILocator.getContentletAPI();

    List<String> tempBinaryImageInodes = (List<String>) ses.getAttribute(Contentlet.TEMP_BINARY_IMAGE_INODES_LIST);   
    if(UtilMethods.isSet(tempBinaryImageInodes) && tempBinaryImageInodes.size() > 0){
      for(String inode : tempBinaryImageInodes){
        conAPI.delete(conAPI.find(inode, APILocator.getUserAPI().getSystemUser(), false), APILocator.getUserAPI().getSystemUser(), false, true);
      }
      tempBinaryImageInodes.clear();
    }
   
    if (req.getParameter("popup") != null)
View Full Code Here

      if(map.get("title") !=null){
        return map.get("title").toString();
      }

      try {
          ContentletAPI conAPI = APILocator.getContentletAPI();
          String x = conAPI.getName(this, APILocator.getUserAPI().getSystemUser(), false);
          map.put("title", x);
          return x;
    } catch (Exception e) {
      Logger.error(this,"Unable to get title" ,e);
      return  "";
View Full Code Here

        return ToStringBuilder.reflectionToString(this);
    }

    public boolean equals(Contentlet contentlet)throws DotRuntimeException {
      try{
          ContentletAPI conAPI = APILocator.getContentletAPI();
        return conAPI.isContentEqual(this, contentlet, APILocator.getUserAPI().getSystemUser(), true);
      }catch (DotSecurityException e) {
      throw new DotRuntimeException("Security Exception happened");
    }catch (DotDataException e) {
       throw new DotRuntimeException("Data Exception happened");
    }
View Full Code Here

      Contentlet firstContentlet = conAPI.find(inode, currentUser, true);

      List<Map<String,String>> contentletList = new ArrayList<Map<String,String>>();

      LanguageAPI langAPI = APILocator.getLanguageAPI();
      ContentletAPI contentletAPI = APILocator.getContentletAPI();
      List<Language> langs = langAPI.getLanguages();
      Contentlet languageContentlet = null;

      String identifier = String.valueOf(firstContentlet.getIdentifier());

      Structure targetStructure = firstContentlet.getStructure();
      List<Field> targetFields = FieldsCache.getFieldsByStructureInode(targetStructure.getInode());

      boolean parent = false;
      try{
            parent = firstContentlet.getBoolProperty("dotCMSParentOnTree") ;
        }
        catch(Exception e){

        }

      for(Language lang : langs){

        Map<String, String> contentDetails = new HashMap<String, String>();
        try{
          languageContentlet = null;
          languageContentlet = contentletAPI.findContentletByIdentifier(firstContentlet.getIdentifier(), true, lang.getId(), currentUser, false);
        }catch (Exception e) {
          try{
          languageContentlet = contentletAPI.findContentletByIdentifier(firstContentlet.getIdentifier(), false, lang.getId(), currentUser, false);
          }catch (Exception e1) {  }
        }

        boolean hasListedFields = false;
View Full Code Here

        callbackData.put("contentletLocked", contentlet.isLocked());

      }

      if(publish && contentlet!=null){
        ContentletAPI capi = APILocator.getContentletAPI();
        capi.publish(contentlet, user, true);
        capi.unlock(contentlet, user, true);
        callbackData.put("contentletLocked", contentlet.isLocked());
      }

      if (contentlet!=null && contentlet.getStructure().getVelocityVarName().equalsIgnoreCase("host")) {
        String copyOptionsStr = (String)contentletFormData.get("copyOptions");
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.contentlet.business.ContentletAPI

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.