Package com.dotmarketing.portlets.structure.model

Examples of com.dotmarketing.portlets.structure.model.Field


        structure1.setDescription( "Testing import of csv files" );

        StructureFactory.saveStructure( structure1 );

        //Create test fields
        Field textFileStructure1 = new Field( "Title", Field.FieldType.TEXT, Field.DataType.TEXT, structure1, true, true, true, 1, false, false, true );
        FieldFactory.saveField( textFileStructure1 );

        Field hostFileStructure1 = new Field( "Host", Field.FieldType.HOST_OR_FOLDER, Field.DataType.TEXT, structure1, true, true, true, 2, false, false, true );
        FieldFactory.saveField( hostFileStructure1 );

        //----------------PREVIEW = TRUE------------------------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
View Full Code Here


      contentletComment.setLanguageId(beanContentlet.getLanguageId());

      // Add the default fields
      contentletComment.setStructureInode(commentsStructure.getInode());

      Field field;

      /* Set the title if we have one*/
      if(UtilMethods.isSet(commentsOptions.get("commentTitle"))){

        field = commentsStructure.getFieldVar("title");

        conAPI.setContentletProperty(contentletComment, field, commentsOptions.get("commentTitle"));
      }

      /* Validate if a CommentsCount field exists in the contentlet structure
         if not, then create it and populate it.*/

      field = contentletStructure.getFieldVar("commentscount");
      if (field==null || !InodeUtils.isSet(field.getInode())) {
        List<Field> fields = new ArrayList<Field>();
          field = new Field("CommentsCount", Field.FieldType.TEXT, Field.DataType.INTEGER, contentletStructure,
                      false, false, true, Integer.MAX_VALUE, "0", "0", "",true, true, true);
        FieldFactory.saveField(field);
        for(Field structureField: contentletStructure.getFields()){
          fields.add(structureField);
        }
        fields.add(field);
        FieldsCache.removeFields(contentletStructure);
        FieldsCache.addFields(contentletStructure,fields);
      }

      /* Get the  value from the CommentsCount field for this contentlet, if the value
       * is null, then the contentlet has no comments, otherwise increment its value by one
       * and set it to the contentlet.
       */
     
      String velVar = field.getVelocityVarName();

      int comentsCount = -1;
      try {
        Long countValue = contentlet.getLongProperty(velVar);
        comentsCount  = countValue.intValue();
      } catch (Exception e) {
        Logger.debug(this, e.toString());
      }

      if (comentsCount == -1) {
        try {
          String countValue = (contentlet.getStringProperty(velVar) ==  null) ? field.getDefaultValue() : contentlet.getStringProperty(velVar);
          comentsCount  = countValue.equals("") ? 0 : new Integer(countValue).intValue();
        } catch (Exception e) {
          Logger.debug(this, e.toString());
        }
      }
View Full Code Here

  {

    //This needs to be updated to use a lucene fix
    // Condition
    Structure commentsStructure = StructureCache.getStructureByVelocityVarName(CommentsWebAPI.commentsVelocityStructureName);
    Field field = commentsStructure.getFieldVar("emailResponse");
    String responseField = field.getFieldContentlet();

    //Get the Email Field
    field = commentsStructure.getFieldVar("email");
    String emailField = field.getVelocityVarName();

    //Get the Date Published Field
    field = commentsStructure.getFieldVar("datePublished");
    String dateField = field.getVelocityVarName();

    //Get the Email Response Field
    field = commentsStructure.getFieldVar("emailResponse");
    String emailResponseField = field.getVelocityVarName();

    // Order
    String order = "";

    // Gather all comment no matter the value of the Email Response
View Full Code Here

      int count=0;
      for(Contentlet contentlet : contentlets) {
          contentletList.append(count==0 ? "" : ",")
              .append('"').append(contentlet.getIdentifier()).append('"');
          if(contentlet.getStructure().getStructureType()== Structure.STRUCTURE_TYPE_WIDGET) {
                    Field field=contentlet.getStructure().getFieldVar("widgetPreexecute");
                    if (field!= null && UtilMethods.isSet(field.getValues()))
                        widgetpree.append(field.getValues().trim());
                }
          if(++count>=c.getMaxContentlets()) break;
      }
     
      StringBuilder contentletListFull = new StringBuilder();
            int countFull=0;
            for(Contentlet contentlet : contentletsFull) {
                contentletListFull.append(countFull==0 ? "" : ",")
                    .append('"').append(contentlet.getIdentifier()).append('"');
                if(contentlet.getStructure().getStructureType()== Structure.STRUCTURE_TYPE_WIDGET) {
                    Field field=contentlet.getStructure().getFieldVar("widgetPreexecute");
                    if (field!= null && UtilMethods.isSet(field.getValues()))
                        widgetpreeFull.append(field.getValues().trim());
                }
                if(++countFull>=c.getMaxContentlets()) break;
            }
     
      sb.append("#if($request.session.getAttribute(\"tm_date\"))");
View Full Code Here

    Iterator<Field> fieldsIt=fields.iterator();

    String widgetCode="";

    while (fieldsIt.hasNext()) {
      Field field=(Field) fieldsIt.next();
     
      String contField=field.getFieldContentlet();
      String contFieldValue=null;
      Object contFieldValueObject=null;
      FieldAPI fdAPI=APILocator.getFieldAPI();
      String velPath=(!EDIT_MODE) ? "live/" : "working/";
      if(fdAPI.isElementConstant(field)){
        if(field.getVelocityVarName().equals("widgetPreexecute")){
          continue;
        }
        if(field.getVelocityVarName().equals("widgetCode")) {
          widgetCode="#set($_dummy=$!dotcms_content_" + content.getIdentifier() + ".put(\"" + field.getVelocityVarName() + "\", $velutil.mergeTemplate(\"" + velPath + content.getInode() + "_" + field.getInode()  + "." + Config.getStringProperty("VELOCITY_FIELD_EXTENSION") + "\")))";
          continue;
        }else{
            String fv=field.getValues()!=null ? field.getValues() : "";
          if(fv.contains("$") || fv.contains("#")){
            sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", $velutil.mergeTemplate(\"").append(velPath).append(content.getInode()).append("_").append(field.getInode()).append(".").append(Config.getStringProperty("VELOCITY_FIELD_EXTENSION")).append("\")))");
          }else{
            sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", \"").append(UtilMethods.espaceForVelocity(field.getValues()).trim()).append("\"))");
          }
          continue;
        }

      }
      if (UtilMethods.isSet(contField)) {
        try {
          contFieldValueObject=conAPI.getFieldValue(content, field);
          contFieldValue=contFieldValueObject == null ? "" : contFieldValueObject.toString();
        } catch (Exception e) {
          Logger.error(ContentletMapServices.class, "writeContentletToFile: " + e.getMessage());
        }
        if (!field.getFieldType().equals(Field.FieldType.DATE_TIME.toString()) && !field.getFieldType().equals(Field.FieldType.DATE.toString())
            && !field.getFieldType().equals(Field.FieldType.TIME.toString())) {
          if (fdAPI.isNumeric(field)) {
            sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", ").append(contFieldValue).append("))");
          } else {
            if(contFieldValue.contains("$") || contFieldValue.contains("#")){
              sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", $velutil.mergeTemplate(\"").append(velPath).append(content.getInode()).append("_").append(field.getInode()).append(".").append(Config.getStringProperty("VELOCITY_FIELD_EXTENSION")).append("\")))");
            }else{
              sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", \"").append(UtilMethods.espaceForVelocity(contFieldValue).trim()).append("\"))");
            }
          }
        }

      }

      if (field.getFieldType().equals(Field.FieldType.TEXT.toString()) || field.getFieldType().equals(Field.FieldType.TEXT_AREA.toString())
          || field.getFieldType().equals(Field.FieldType.WYSIWYG.toString())) {

      } else if (field.getFieldType().equals(Field.FieldType.IMAGE.toString())) {
        String identifierValue=content.getStringProperty(field.getVelocityVarName());
        if( InodeUtils.isSet(identifierValue) ) {
          if (EDIT_MODE){
            sb.append("#set($").append(field.getVelocityVarName()).append("=$filetool.getFile('").append(identifierValue).append("',false))");
          }else{
            sb.append("#set($").append(field.getVelocityVarName()).append("=$filetool.getFile('").append(identifierValue).append("',true))");
          }
        }else{
          sb.append("#set($").append(field.getVelocityVarName()).append("=$filetool.getNewFile())");
        }

        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageInode\", $").append(field.getVelocityVarName()).append(".getInode() ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageIdentifier\", $").append(field.getVelocityVarName()).append(".getIdentifier() ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageWidth\", $").append(field.getVelocityVarName()).append(".getWidth() ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageHeight\", $").append(field.getVelocityVarName()).append(".getHeight() ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageExtension\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append(".getExtension()) ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageURI\", $filetool.getURI($").append(field.getVelocityVarName()).append(") ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageTitle\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append(".getTitle()) ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageFriendlyName\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append(".getFriendlyName()) ))");

        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImagePath\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append(".getPath()) ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ImageName\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append(".getFileName()) ))");

      } else if (field.getFieldType().equals(Field.FieldType.FILE.toString())) {
        String identifierValue=content.getStringProperty(field.getVelocityVarName());
        if( InodeUtils.isSet(identifierValue) ) {
          if (EDIT_MODE){
            sb.append("#set( $").append(field.getVelocityVarName()).append("Object=$filetool.getFile('").append(identifierValue).append("',false))");
          }else{
            sb.append("#set( $").append(field.getVelocityVarName()).append("Object=$filetool.getFile('").append(identifierValue).append("',true))");
          }
        }else{
          sb.append("#set( $").append(field.getVelocityVarName()).append("Object=$filetool.getNewFile())");
        }


        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FileInode\", $").append(field.getVelocityVarName()).append("Object.getInode() ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FileIdentifier\", $").append(field.getVelocityVarName()).append("Object.getIdentifier() ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FileFriendlyName\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append("Object.getFriendlyName()) ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FileExtension\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append("Object.getExtension()) ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FileURI\", $filetool.getURI($").append(field.getVelocityVarName()).append("Object) ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FileTitle\", $").append(field.getVelocityVarName()).append("Object.getTitle() ))");

        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FilePath\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append("Object.getPath()) ))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("FileName\", $UtilMethods.espaceForVelocity($").append(field.getVelocityVarName()).append("Object.getFileName()) ))");

      } //http://jira.dotmarketing.net/browse/DOTCMS-2178
      else if (field.getFieldType().equals(Field.FieldType.BINARY.toString())) {
        java.io.File binFile;
        String fileName="";
        String filesize="";
        try {
          binFile=content.getBinary(field.getVelocityVarName());
          if(binFile != null) {
            fileName=binFile.getName();
            filesize=FileUtil.getsize(binFile);
          }
        } catch (IOException e) {
          Logger.error(ContentletServices.class, "Unable to retrive binary file for content id " + content.getIdentifier() + " field " + field.getVelocityVarName(), e);
          continue;
        }
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("BinaryFileTitle\", \"").append(UtilMethods.espaceForVelocity(fileName)).append("\"))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("BinaryFileSize\", \"").append(UtilMethods.espaceForVelocity(filesize)).append("\"))");
        String binaryFileURI=fileName.length()>0? UtilMethods.espaceForVelocity("/contentAsset/raw-data/"+content.getIdentifier()+"/"+ field.getVelocityVarName() + "/" + content.getInode()):"";
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("BinaryFileURI\", \"").append(binaryFileURI).append("\"))");
      } else if (field.getFieldType().equals(Field.FieldType.SELECT.toString())) {
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("SelectLabelsValues\", \""
                ).append( field.getValues().replaceAll("\\r\\n", " ").replaceAll("\\n", " ")).append("\"))");

      } else if (field.getFieldType().equals(Field.FieldType.RADIO.toString())) {
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("RadioLabelsValues\", \""
                ).append(field.getValues().replaceAll("\\r\\n", " ").replaceAll("\\n", " ")).append("\"))");

      } else if (field.getFieldType().equals(Field.FieldType.CHECKBOX.toString())) {
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("CheckboxLabelsValues\", \""
                ).append(field.getValues().replaceAll("\\r\\n", " ").replaceAll("\\n", " ")).append("\"))");

      } else if (field.getFieldType().equals(Field.FieldType.DATE.toString())) {
        String shortFormat="";
        String dbFormat="";
        if (contFieldValueObject != null && contFieldValueObject instanceof Date) {
          shortFormat=UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "MM/dd/yyyy");
          dbFormat=UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "yyyy-MM-dd");
        }
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", $date.toDate(\"yyyy-MM-dd\", \"").append(dbFormat).append("\")))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ShortFormat\", \"").append(shortFormat).append("\"))");
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("DBFormat\", \"").append(dbFormat).append("\"))");
      } else if (field.getFieldType().equals(Field.FieldType.TIME.toString())) {
        String shortFormat="";
        if (contFieldValueObject != null && contFieldValueObject instanceof Date) {
          shortFormat=UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "H:mm:ss");
        }
        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", $date.toDate(\"H:mm:ss\", \"").append(shortFormat).append("\")))");
        sb.append("#set($_dummy=$!dotcms_content_").append( content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("ShortFormat\", \"").append(shortFormat).append("\"))");

      } else if (field.getFieldType().equals(Field.FieldType.DATE_TIME.toString())) {
        String shortFormat="";
        String longFormat="";
        String dbFormat="";
        if (contFieldValueObject != null && contFieldValueObject instanceof Date) {
          shortFormat=UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "MM/dd/yyyy");
          longFormat=UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "MM/dd/yyyy H:mm:ss");
          dbFormat=UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "yyyy-MM-dd H:mm:ss");
        }

        sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "\", $date.toDate(\"yyyy-MM-dd H:mm:ss\", \"" ).append( dbFormat ).append( "\")))");
        sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "ShortFormat\", \"" ).append( shortFormat ).append( "\"))");
        sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "DBFormat\", \"" ).append( dbFormat ).append( "\"))");
        sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "LongFormat\", \"" ).append( longFormat ).append( "\"))");

      } else if (field.getFieldType().equals(Field.FieldType.BUTTON.toString())) {
        sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "ButtonValue\", \"" ).append( (field.getFieldName() == null ? "" : field.getFieldName())
            ).append( "\"))");
        sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "ButtonCode\", \"" ).append( (field.getValues() == null ? "" : field.getValues()) ).append( "\"))");

      } else if (field.getFieldType().equals(Field.FieldType.CATEGORY.toString())) {

        // Get the Category Field
        Category category=categoryAPI.find(field.getValues(), systemUser, false);

        // Get all the Contentlets Categories
        List<Category> selectedCategories=categoryAPI.getParents(content, systemUser, false);

        // Initialize variables
        String catInodes="";
        Set<Category> categoryList=new HashSet<Category>();
        List<Category> categoryTree=categoryAPI.getAllChildren(category, systemUser, false);

        if (selectedCategories.size() > 0 && categoryTree != null) {
          for (int k=0; k < categoryTree.size(); k++) {
            Category cat=(Category) categoryTree.get(k);
            for (Category categ : selectedCategories) {
              if (categ.getInode().equalsIgnoreCase(cat.getInode())) {
                categoryList.add(cat);
              }
            }
          }
        }

        if (categoryList.size() > 0) {
          Iterator<Category> it=categoryList.iterator();
          StringBuilder catbuilder=new StringBuilder();
          while (it.hasNext()) {
            Category cat=(Category) it.next();
            catbuilder.append("\"").append(cat.getInode()).append("\"") ;
            if (it.hasNext()) {
              catbuilder.append(",");
            }
          }
          catInodes=catbuilder.toString();
         
          sb.append("#set($catobjects=$categories.filterCategoriesByUserPermissions([" ).append( catInodes ).append( "]))");
          sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoryObjects\", $catobjects))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "Categories\", $categories.fetchCategoriesInodes($catobjects)))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "\", $categories.fetchCategoriesInodes($catobjects)))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesNames\", $categories.fetchCategoriesNames($catobjects)))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesKeys\", $categories.fetchCategoriesKeys($catobjects)))");
        }
        else {
            sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoryObjects\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "Categories\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesNames\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesKeys\", $contents.getEmptyList()))");
        }       
      }

    }
View Full Code Here

            contentletList.add(String.valueOf(contentletIdentifier.getInode()));
            Logger.debug(this, "Adding contentlet=" + contentletIdentifier.getInode());
            Structure contStructure = contentlet.getStructure();
            if (contStructure.getStructureType() == Structure.STRUCTURE_TYPE_WIDGET) {
              Field field = contStructure.getFieldVar("widgetPreexecute");
              if (field != null && UtilMethods.isSet(field.getValues())) {
                preExecuteCode.append(field.getValues().trim() + "\n");
                widgetPreExecute = true;
              }
            }

          }
View Full Code Here

                        contentletList.add( String.valueOf( contentletIdentifier.getInode() ) );
                        Logger.debug( this, "Adding contentlet=" + contentletIdentifier.getInode() );
                        Structure contStructure = contentlet.getStructure();
                        if ( contStructure.getStructureType() == Structure.STRUCTURE_TYPE_WIDGET ) {
                            Field field = contStructure.getFieldVar( "widgetPreexecute" );
                            if ( field != null && UtilMethods.isSet( field.getValues() ) ) {
                                preExecuteCode.append( field.getValues().trim() + "\n" );
                                widgetPreExecute = true;
                            }

                        }
                    }
View Full Code Here

                }
            }
          content = contentAPI.findContentletByIdentifier(assetIdentifier, live, lang, user, respectFrontendRoles);
          assetInode = content.getInode();
        }
        Field field = content.getStructure().getFieldVar(fieldVarName);
        if(field == null){
          Logger.debug(this,"Field " + fieldVarName + " does not exists within structure " + content.getStructure().getVelocityVarName());
          resp.sendError(404);
          return;
        }

        if(isTempBinaryImage)
          inputFile = contentAPI.getBinaryFile(content.getInode(), field.getVelocityVarName(), APILocator.getUserAPI().getSystemUser());
        else
          inputFile = contentAPI.getBinaryFile(content.getInode(), field.getVelocityVarName(), user);
        if(inputFile == null){
          Logger.debug(this,"binary file '" + fieldVarName + "' does not exist for inode " + content.getInode());
          resp.sendError(404);
          return;
        }
View Full Code Here

    //Structure fields
    List<Field> fields = structure.getFields();
    Iterator<Field> fieldsIt = fields.iterator();

    while (fieldsIt.hasNext()) {
      Field field = (Field) fieldsIt.next();

      String contField = field.getFieldContentlet();
      String contFieldValue = null;
      Object contFieldValueObject = null;
      if (UtilMethods.isSet(contField)) {
        try {
          //contFieldValueObject = PropertyUtils.getProperty(content, contField);
          contFieldValueObject = field.getFieldName();
          contFieldValue = contFieldValueObject == null?"":contFieldValueObject.toString();
        } catch (Exception e) {
          Logger.error(ContentletServices.class, "writeContentletToFile: " + e.getMessage());
        }
        if (!field.getFieldType().equals(Field.FieldType.DATE_TIME.toString()) &&
            !field.getFieldType().equals(Field.FieldType.DATE.toString()) &&
            !field.getFieldType().equals(Field.FieldType.TIME.toString()))
          sb.append("#set( $" ).append( field.getVelocityVarName() ).append( " =\"" ).append( UtilMethods.espaceForVelocity(contFieldValue).trim() ).append( "\" )");
      }
      String fv=field.getValues()!=null ? field.getValues() : "";
      if (field.getFieldType().equals(Field.FieldType.TEXT.toString()) || field.getFieldType().equals(Field.FieldType.TEXT_AREA.toString()) || field.getFieldType().equals(Field.FieldType.WYSIWYG.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( " =\"[ #fixBreaks($" ).append( field.getVelocityVarName() ).append( ") ]\")");
      } else if (field.getFieldType().equals(Field.FieldType.IMAGE.toString())) {
        //Identifier id = (Identifier) InodeFactory.getChildOfClassByRelationType(content, Identifier.class, field.getFieldRelationType());       
        String uri = "/html/images/shim.gif";                  
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ImageInode =\"" ).append( Long.MAX_VALUE ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ImageWidth =\"" ).append( 150 ).append( "\" )"); //Original value was 165
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ImageHeight =\"" ).append( 150 ).append( "\" )"); //Originak value was 65
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ImageExtension =\"gif\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ImageURI =\"" ).append( uri ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ImageTitle =\"[ Test Image Structure ]\" )");
      } else if (field.getFieldType().equals(Field.FieldType.FILE.toString())) {
        //Identifier id = (Identifier) InodeFactory.getChildOfClassByRelationType(content, Identifier.class, field.getFieldRelationType());
        String uri = "/html/images/shim.gif";                  
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FileInode =\"" ).append( Long.MAX_VALUE ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FileExtension =\"gif\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FileURI =\"" ).append( uri ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FileTitle =\"[ Test File Structure ]\" )");
      } else if (field.getFieldType().equals(Field.FieldType.SELECT.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "SelectLabelsValues = \"" ).append( fv.replaceAll("\\r\\n", " ").replaceAll("\\n", " ") ).append( "\")");
      } else if (field.getFieldType().equals(Field.FieldType.RADIO.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "RadioLabelsValues = \"" ).append( fv.replaceAll("\\r\\n", " ").replaceAll("\\n", " ") ).append( "\" )");
      } else if (field.getFieldType().equals(Field.FieldType.CHECKBOX.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CheckboxLabelsValues = \"" ).append( fv.replaceAll("\\r\\n", " ").replaceAll("\\n", " ") ).append( "\" )");
      } else if (field.getFieldType().equals(Field.FieldType.DATE.toString())) {       
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( " =\"[ " ).append( field.getVelocityVarName() ).append( " ]\")");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ShortFormat =\"[ " ).append( field.getVelocityVarName() ).append( " ]\")");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "DBFormat =\"[ " ).append( field.getVelocityVarName() ).append( " ]\")");
      } else if (field.getFieldType().equals(Field.FieldType.TIME.toString())) {       
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ShortFormat =\"[ " ).append( field.getVelocityVarName() ).append( " ]\")");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( " =\"[ " ).append( field.getVelocityVarName() ).append( "\" ])");
      } else if (field.getFieldType().equals(Field.FieldType.DATE_TIME.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( " =\"[ " ).append( field.getVelocityVarName() ).append( " ] \")");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ShortFormat =\"[ " ).append( field.getVelocityVarName() ).append( " ]\")");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "LongFormat =\"[ " ).append( field.getVelocityVarName() ).append( " ]\")");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "DBFormat =\"[ " ).append( field.getVelocityVarName() ).append( " ]\")");
      } else if (field.getFieldType().equals(Field.FieldType.BUTTON.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ButtonValue =\"" ).append( fv ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ButtonCode =\"" ).append( fv ).append( "\" )");
      }
    }

    //sets the categories as a list on velocity
    sb.append("#set( $ContentletCategories =[] )");
View Full Code Here

    removeFieldFile(fieldInode, contentletIdent, EDIT_MODE);
  }
 
  public static InputStream buildVelocity(String fieldInode, String contentInode, boolean EDIT_MODE) throws DotDataException, DotSecurityException {
    InputStream result;
    Field field = FieldFactory.getFieldByInode(fieldInode);
    if(!UtilMethods.isSet(field)){
      Logger.warn(FieldServices.class,"Field not found.  Unable to load velocity code");
      return new ByteArrayInputStream("".toString().getBytes());
    }
    ContentletAPI conAPI = APILocator.getContentletAPI();
    FieldAPI fAPI = APILocator.getFieldAPI();
    Contentlet content = conAPI.find(contentInode, APILocator.getUserAPI().getSystemUser(), true);
    if(!UtilMethods.isSet(content)){
      Logger.warn(FieldServices.class,"Content not found.  Unable to load velocity code");
      return new ByteArrayInputStream("".toString().getBytes());
    }
    Object contFieldValueObject = conAPI.getFieldValue(content, field);
    String contFieldValue = "";
   
    if(fAPI.isElementConstant(field)){
      contFieldValue = field.getValues() == null ? "" : field.getValues();
    }else{
      contFieldValue = contFieldValueObject == null ? "" : contFieldValueObject.toString();
    }
   
    if(contFieldValue != null && contFieldValue.endsWith("#")){
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.structure.model.Field

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.