Package com.dotmarketing.portlets.structure.model

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


    response.getWriter().println("<?xml version=\"1.0\" encoding='UTF-8'?>")
    response.getWriter().println("<contentlets>")
    for(Contentlet c : cons){
        Map m = c.getMap();
        Structure s = c.getStructure();
        for(Field f : s.getFields()){
          if(f.getFieldType().equals(Field.FieldType.BINARY.toString())){

              m.put(f.getVelocityVarName(), "/contentAsset/raw-data/" +  c.getIdentifier() + "/" + f.getVelocityVarName()  );
           
              m.put(f.getVelocityVarName() + "ContentAsset", c.getIdentifier() + "/" +f.getVelocityVarName()  );
View Full Code Here


 
 
  private JSONObject contentletToJSON(Contentlet con) throws JSONException{
    JSONObject jo = new JSONObject();
   
    Structure s = con.getStructure();
    Map map = con.getMap();
    for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { 
      String key = (String) it.next()
      if(Arrays.binarySearch(ignoreFields, key) < 0){
        jo.put(key, map.get(key));
      }

    } 

    for(Field f : s.getFields()){
      if(f.getFieldType().equals(Field.FieldType.BINARY.toString())){

          jo.put(f.getVelocityVarName(), "/contentAsset/raw-data/" +  con.getIdentifier() + "/" + f.getVelocityVarName()  );
       
          jo.put(f.getVelocityVarName() + "ContentAsset", con.getIdentifier() + "/" +f.getVelocityVarName()  );
View Full Code Here

      context.put("EDIT_CONTAINER_PERMISSION" + c.getIdentifier(), permissionAPI.doesUserHavePermission(c, PERMISSION_WRITE, user, true));

      boolean hasWritePermOverTheStructure = false;

      for (ContainerStructure cs : APILocator.getContainerAPI().getContainerStructures(c)) {
        Structure st = StructureCache.getStructureByInode(cs.getStructureId());

        hasWritePermOverTheStructure |= permissionAPI.doesUserHavePermission(st, PERMISSION_WRITE, user, true);
      }


      context.put("ADD_CONTENT_PERMISSION" + c.getIdentifier(), new Boolean(hasWritePermOverTheStructure));

      Logger.debug(VelocityServlet.class, String.valueOf("container" + c.getIdentifier()) + "=/working/" + c.getIdentifier() + "."
          + Config.getStringProperty("VELOCITY_CONTAINER_EXTENSION"));

      String sort = (c.getSortContentletsBy() == null) ? "tree_order" : c.getSortContentletsBy();

      boolean staticContainer = !UtilMethods.isSet(c.getLuceneQuery());

      List<Contentlet> contentlets = null;

      // get contentlets only for main frame
      if (request.getParameter("mainFrame") != null) {
        if (staticContainer) {
          Logger.debug(VelocityServlet.class, "Static Container!!!!");

          Logger.debug(VelocityServlet.class, "html=" + htmlPage.getInode() + " container=" + c.getInode());

          // The container doesn't have categories
          Identifier idenHtmlPage = APILocator.getIdentifierAPI().find(htmlPage);
          Identifier idenContainer = APILocator.getIdentifierAPI().find(c);
          contentlets = conAPI.findPageContentlets(idenHtmlPage.getInode(), idenContainer.getInode(), sort, true, -1, user, true);
          Logger.debug(
              VelocityServlet.class,
              "Getting contentlets for language="
                  + (String) request.getSession().getAttribute(com.dotmarketing.util.WebKeys.HTMLPAGE_LANGUAGE)
                  + " contentlets =" + contentlets.size());

        }

        if (UtilMethods.isSet(contentlets) && contentlets.size() > 0) {
          Set<String> contentletIdentList = new HashSet<String>();
          List<Contentlet> contentletsFilter = new ArrayList<Contentlet>();
          for (Contentlet cont : contentlets) {
            if (!contentletIdentList.contains(cont.getIdentifier())) {
              contentletIdentList.add(cont.getIdentifier());
              contentletsFilter.add(cont);
            }
          }
          contentlets = contentletsFilter;
        }
        List<String> contentletList = new ArrayList<String>();

        if (contentlets != null && contentlets.size() > 0) {
          Iterator<Contentlet> iter = contentlets.iterator();
          int count = 0;

          while (iter.hasNext() && (count < c.getMaxContentlets())) {
            count++;

            Contentlet contentlet = (Contentlet) iter.next();
            Identifier contentletIdentifier = APILocator.getIdentifierAPI().find(contentlet);

            boolean hasWritePermOverContentlet = permissionAPI.doesUserHavePermission(contentlet, PERMISSION_WRITE, user, true);

            context.put("EDIT_CONTENT_PERMISSION" + contentletIdentifier.getInode(), new Boolean(hasWritePermOverContentlet));

            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

            // to check user has permission to write this container
            boolean hasWritePermOverTheStructure = false;

      for (ContainerStructure cs : APILocator.getContainerAPI().getContainerStructures(c)) {
        Structure st = StructureCache.getStructureByInode(cs.getStructureId());

        hasWritePermOverTheStructure |= permissionAPI.doesUserHavePermission(st, PERMISSION_WRITE, backendUser);
      }


            context.put( "ADD_CONTENT_PERMISSION" + c.getIdentifier(), new Boolean( hasWritePermOverTheStructure ) );

            Logger.debug( VelocityServlet.class, String.valueOf( "container" + c.getIdentifier() ) + "=/working/" + c.getIdentifier() + "."
                    + Config.getStringProperty( "VELOCITY_CONTAINER_EXTENSION" ) );

            String sort = (c.getSortContentletsBy() == null) ? "tree_order" : c.getSortContentletsBy();

            List<Contentlet> contentlets = null;

            boolean staticContainer = !UtilMethods.isSet( c.getLuceneQuery() );

            // get contentlets only for main frame
            if ( request.getParameter( "mainFrame" ) != null ) {
                if ( staticContainer ) {
                    Logger.debug( VelocityServlet.class, "Static Container!!!!" );

                    Logger.debug( VelocityServlet.class, "html=" + htmlPage.getInode() + " container=" + c.getInode() );

                    // The container doesn't have categories
                    Identifier idenHtmlPage = APILocator.getIdentifierAPI().find( htmlPage );
                    Identifier idenContainer = APILocator.getIdentifierAPI().find( c );
                    contentlets = conAPI.findPageContentlets( idenHtmlPage.getInode(), idenContainer.getInode(), sort, true, -1, backendUser, true );
                    Logger.debug(
                            VelocityServlet.class,
                            "Getting contentlets for language="
                                    + (String) request.getSession().getAttribute( com.dotmarketing.util.WebKeys.HTMLPAGE_LANGUAGE )
                                    + " contentlets =" + contentlets.size() );

                } else {
                    String luceneQuery = c.getLuceneQuery();
                    int limit = c.getMaxContentlets();
                    String sortBy = c.getSortContentletsBy();
                    int offset = 0;
                    contentlets = conAPI.search( luceneQuery, limit, offset, sortBy, backendUser, true );
                }

                if ( UtilMethods.isSet( contentlets ) && contentlets.size() > 0 ) {
                    Set<String> contentletIdentList = new HashSet<String>();
                    List<Contentlet> contentletsFilter = new ArrayList<Contentlet>();
                    for ( Contentlet cont : contentlets ) {
                        if ( !contentletIdentList.contains( cont.getIdentifier() ) ) {
                            contentletIdentList.add( cont.getIdentifier() );
                            contentletsFilter.add( cont );
                        }
                    }
                    contentlets = contentletsFilter;
                }
                List<String> contentletList = new ArrayList<String>();

                if ( contentlets != null ) {
                    Iterator<Contentlet> iter = contentlets.iterator();
                    int count = 0;

                    while ( iter.hasNext() && (count < c.getMaxContentlets()) ) {
                        count++;

                        Contentlet contentlet = (Contentlet) iter.next();
                        Identifier contentletIdentifier = APILocator.getIdentifierAPI().find( contentlet );

                        boolean hasWritePermOverContentlet = permissionAPI.doesUserHavePermission( contentlet, PERMISSION_WRITE, backendUser );

                        context.put( "EDIT_CONTENT_PERMISSION" + contentletIdentifier.getInode(), new Boolean( hasWritePermOverContentlet ) );

                        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

    if (content.getOwner() != null)
      sb.append("#set($ContentOwnerId= \"" ).append( content.getOwner() ).append( "\")");

    // Structure fields

    Structure structure= content.getStructure();

    List<Field> fields= FieldsCache.getFieldsByStructureInode(structure.getInode());
    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;
      String velPath= (!EDIT_MODE) ? "live/" : "working/";
      if(fAPI.isElementConstant(field)){
          if(field.getVelocityVarName().equals("widgetPreexecute")){
          continue;
        }
        if(field.getVelocityVarName().equals("widgetCode")){
          widgetCode= "#set($" + field.getVelocityVarName() + "=$velutil.mergeTemplate(\"" + velPath +  content.getInode() + "_" + field.getInode() + "." + Config.getStringProperty("VELOCITY_FIELD_EXTENSION") + "\"))";
          continue;
        }else{
          String fieldValues=field.getValues()==null?"":field.getValues();
          if(fieldValues.contains("$") || fieldValues.contains("#")){
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "= $velutil.mergeTemplate(\"" ).append( velPath ).appendcontent.getInode() ).append( "_" ).append( field.getInode() ).append( "." ).append( Config.getStringProperty("VELOCITY_FIELD_EXTENSION") ).append( "\"))");
          }else{
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "= \"" ).append( UtilMethods.espaceForVelocity(fieldValues).trim() ).append( "\")");
          }
          continue;
        }
      }
      if (UtilMethods.isSet(contField)) {
        try {
          contFieldValueObject= conAPI.getFieldValue(content, field);
          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())){
          if(contFieldValue.contains("$") || contFieldValue.contains("#")){
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "=$velutil.mergeTemplate(\"" ).append( velPath ).appendcontent.getInode() ).append( "_" ).append( field.getInode() ).append( "." ).append( Config.getStringProperty("VELOCITY_FIELD_EXTENSION") ).append( "\"))");
          }else{
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "=\"" ).append( UtilMethods.espaceForVelocity(contFieldValue).trim() ).append( "\")");
          }
        }

      }

      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( "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($" ).append( field.getVelocityVarName() ).append( "ImageInode=$" ).append( field.getVelocityVarName() ).append( "Object.getInode() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageIdentifier=$" ).append( field.getVelocityVarName() ).append( "Object.getIdentifier() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageWidth=$" ).append( field.getVelocityVarName() ).append( "Object.getWidth() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageHeight=$" ).append( field.getVelocityVarName() ).append( "Object.getHeight() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageExtension=$" ).append( field.getVelocityVarName() ).append( "Object.getExtension() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageURI=$filetool.getURI($" ).append( field.getVelocityVarName() ).append( "Object))");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageTitle=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getTitle()) )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageFriendlyName=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getFriendlyName()) )");

        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImagePath=$" ).append( field.getVelocityVarName() ).append( "Object.getPath())");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageName=$" ).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($" ).append( field.getVelocityVarName() ).append( "BinaryFileTitle=\"" ).append( UtilMethods.espaceForVelocity(fileName) ).append( "\" )");
        sb.append("#set($" ).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($" ).append( field.getVelocityVarName() ).append( "BinaryFileURI=\"" ).append( binaryFileURI).append("\" )");
      }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($" ).append( field.getVelocityVarName() ).append( "FileInode=$" ).append( field.getVelocityVarName() ).append( "Object.getInode() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileIdentifier=$" ).append( field.getVelocityVarName() ).append( "Object.getIdentifier() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileExtension=$" ).append( field.getVelocityVarName() ).append( "Object.getExtension() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileURI=$filetool.getURI($" ).append( field.getVelocityVarName() ).append( "Object))");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileTitle=$" ).append( field.getVelocityVarName() ).append( "Object.getTitle() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileFriendlyName=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getFriendlyName() ))");

        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FilePath=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getPath()) )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileName=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getFileName()) )");


      } else if (field.getFieldType().equals(Field.FieldType.SELECT.toString())) {
        sb.append("#set($" ).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($" ).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($" ).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($" ).append( field.getVelocityVarName() ).append( "=$date.toDate(\"yyyy-MM-dd\", \"" ).append( dbFormat ).append( "\"))");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ShortFormat=\"" ).append( shortFormat ).append( "\" )");
        sb.append("#set($" ).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( $" ).append( field.getVelocityVarName() ).append( "ShortFormat=\"" ).append( shortFormat ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "= $date.toDate(\"H:mm:ss\", \"" ).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( $" ).append( field.getVelocityVarName() ).append( "= $date.toDate(\"yyyy-MM-dd H:mm:ss\", \"" ).append( dbFormat ).append( "\"))");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ShortFormat=\"" ).append( shortFormat ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "LongFormat=\"" ).append( longFormat ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "DBFormat=\"" ).append( dbFormat ).append( "\" )");
      } else if (field.getFieldType().equals(Field.FieldType.BUTTON.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ButtonValue=\"" ).append( (field.getFieldName()== null ? "" : field.getFieldName()) ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ButtonCode=\"" ).append( (field.getValues()== null ? "" : field.getValues()) ).append( "\" )");
      }//http://jira.dotmarketing.net/browse/DOTCMS-2869
//      else if (field.getFieldType().equals(Field.FieldType.CUSTOM_FIELD.toString())){
//         sb.append("#set( $" + field.getVelocityVarName() + "Code=\"" + UtilMethods.espaceForVelocity(field.getValues()) + "\" )");
//      }//http://jira.dotmarketing.net/browse/DOTCMS-3232
      else if (field.getFieldType().equals(Field.FieldType.HOST_OR_FOLDER.toString())){
        if(InodeUtils.isSet(content.getFolder())){
          sb.append("#set( $ConHostFolder='" ).append( content.getFolder() ).append( "' )");
        }else{
          sb.append("#set( $ConHostFolder='" ).append( content.getHost() ).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) {
            StringBuilder catbuilder=new StringBuilder();
          Iterator<Category> it= categoryList.iterator();
          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( $" ).append( field.getVelocityVarName() ).append( "FilteredCategories=$categories.filterCategoriesByUserPermissions([" ).append( catInodes ).append( "] ))");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "Categories=$categories.fetchCategoriesInodes($").append(field.getVelocityVarName()).append("FilteredCategories))");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesNames=$categories.fetchCategoriesNames($").append(field.getVelocityVarName()).append("FilteredCategories))");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "=$").append(field.getVelocityVarName()).append("Categories)");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesKeys=$categories.fetchCategoriesKeys($").append(field.getVelocityVarName()).append("FilteredCategories))");
        }
        else {
            sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FilteredCategories=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "Categories=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesNames=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesKeys=$contents.getEmptyList())");
        }
      }
    }


        // get the contentlet categories to make a list
        String categories= "";
        Set<Category> categoryList= new HashSet<Category>(categoryAPI.getParents(content, systemUser, false));
        if (categoryList!=null && categoryList.size()>0) {
            StringBuilder catbuilder=new StringBuilder();
      Iterator<Category> it= categoryList.iterator();
      while (it.hasNext()) {
        Category category= (Category) it.next();
            catbuilder.append("\"").append(category.getInode()).append("\"") ;
        if (it.hasNext()) {
              catbuilder.append(",");
            }
          }
      categories=catbuilder.toString();

      sb.append("#set($ContentletFilteredCategories=$categories.filterCategoriesByUserPermissions([" ).append( categories ).append( "] ))");
          sb.append("#set($ContentletCategories=$categories.fetchCategoriesInodes($ContentletFilteredCategories))");
          sb.append("#set($ContentletCategoryNames=$categories.fetchCategoriesNames($ContentletFilteredCategories))");
          sb.append("#set($ContentletCategoryKeys=$categories.fetchCategoriesKeys($ContentletFilteredCategories))");
        }
        else {
            sb.append("#set($ContentletFilteredCategories=$contents.getEmptyList())");
            sb.append("#set($ContentletCategories=$contents.getEmptyList())");
            sb.append("#set($ContentletCategoryNames=$contents.getEmptyList())");
            sb.append("#set($ContentletCategoryKeys=$contents.getEmptyList())");
        }

    //This needs to be here because the all fields like cats etc.. need to be parsed first and it needs to be before
    // the $CONTENT_INODE is reset sb.append("#set( $CONTENT_INODE=\"" + content.getInode() + "\" )");
    //http://jira.dotmarketing.net/browse/DOTCMS-2808
    sb.append(widgetCode);

    // This is code is repeated because the bug GETTYS-268, the content
    // variables were been overwritten
    // by the parse inside the some of the content fields
    // To edit the look, see
    // WEB-INF/velocity/static/preview/content_controls.vtl

    if(EDIT_MODE) {
      sb.append("#set( $EDIT_CONTENT_PERMISSION=$EDIT_CONTENT_PERMISSION" ).append( identifier.getInode() ).append( " )");
    }

    sb.append("#set( $CONTENT_INODE=\"" ).append( content.getInode() ).append( "\" )");
    sb.append("#set( $IDENTIFIER_INODE=\"" ).append( identifier.getInode() ).append( "\" )");

    sb.append("#set( $ContentInode=\"" ).append( content.getInode() ).append( "\" )");
    sb.append("#set( $ContentIdentifier=\"" ).append( identifier.getInode() ).append( "\" )");
    sb.append("#set( $ContentletTitle=\"" ).append( UtilMethods.espaceForVelocity(conAPI.getName(content, APILocator.getUserAPI().getSystemUser(), true)) ).append( "\" )");
    sb.append("#set( $ContentletStructure=\"" ).append( content.getStructureInode() ).append( "\" )");

    if(structure.getStructureType()== Structure.STRUCTURE_TYPE_WIDGET){
      sb.append("#set( $isWidget= \"" ).append( true ).append( "\")");
      if(structure.getName().equals(FormAPI.FORM_WIDGET_STRUCTURE_NAME_FIELD_NAME)){
        sb.append("#set($isFormWidget= \"" ).append( true ).append( "\")");
      }else{
        sb.append("#set($isFormWidget= \"" ).append( false ).append( "\")");
      }
    }else{
View Full Code Here

   * @return
   * @deprecated getting the structure by its name might not be safe, since the
     * structure name can be changed by the user, use getStructureByVelocityVarName
   */
  public Structure findStructureByName(String structureName) {
    Structure structure =StructureCache.getStructureByType(structureName);
    //http://jira.dotmarketing.net/browse/DOTCMS-6282
    if(!UtilMethods.isSet(structure.getInode())){
      return findStructureByVelocityVarName(structureName);
    }
    return structure;

  }
View Full Code Here

  public List<Relationship> getRelationshipsOfStructure(long structureInode, boolean hasParent) {
    return getRelationshipsOfStructure(((Long) structureInode).toString(), hasParent);
  }

  public List<Relationship> getRelationshipsOfStructure(String structureInode, boolean hasParent) {
    Structure st = (Structure) InodeFactory.getInode(structureInode, Structure.class);
    return RelationshipFactory.getAllRelationshipsByStructure(st, hasParent);
  }
View Full Code Here

        }else if (arg0.endsWith(VELOCITY_STRUCTURE_EXTENSION))
        {
            try
            {
                //Integer.parseInt(x);
                Structure  structure = (Structure) InodeFactory.getInode(x, Structure.class);
                result = StructureServices.buildVelocity(structure);
            }
            catch(NumberFormatException e)
            {
                Logger.warn(this,"getResourceStream: Invalid resource path provided = " + arg0 + ", request discarded.");
View Full Code Here

 
      if (title == null) {
        return;
      }
     
      Structure slideShowSt = StructureCache.getStructureByVelocityVarName("slideShow");
      List<Field> fields = FieldsCache.getFieldsByStructureVariableName("slideShow");
      Field slideShowTitleF = null;
      Field slideShowCreditsF = null;
      Field slideShowAudioTitleF = null;
      Field slideShowAudioFileF = null;
     
      if (slideShowSt == null ||(!InodeUtils.isSet(slideShowSt.getInode())) ) {
        slideShowSt = new Structure ();
        slideShowSt.setDefaultStructure(false);
        slideShowSt.setName("Slide Show");
        slideShowSt.setDescription("Slide Show Base Structure");
        slideShowSt.setFixed(true);
        slideShowSt.setStructureType(Structure.STRUCTURE_TYPE_CONTENT);
        //Create the structure
        StructureFactory.saveStructure(slideShowSt);       
      }
 
      if (fields != null)
        for (Field field : fields) {
          if (field.getFieldName().equals("Title")) {
            slideShowTitleF = field;
          } else if (field.getFieldName().equals("Credits")) {
            slideShowCreditsF = field;
          } else if (field.getFieldName().equals("Audio Title")) {
            slideShowAudioTitleF = field;
          } else if (field.getFieldName().equals("MP3 File")) {
            slideShowAudioFileF = field;
          }
        }
     
      boolean fieldAdded = false;
      if (slideShowTitleF == null) {
        //Creating the field
        slideShowTitleF = new Field("Title", FieldType.TEXT, DataType.TEXT, slideShowSt, true, true, true, 1, true, false,true);
        FieldFactory.saveField(slideShowTitleF);
        fieldAdded = true;
      }
      if (slideShowCreditsF == null) {
        //Creating the credits field
        slideShowCreditsF = new Field("Credits", FieldType.TEXT_AREA, DataType.LONG_TEXT, slideShowSt, false, false, true, 2, true, false, true);
        FieldFactory.saveField(slideShowCreditsF);
        fieldAdded = true;
      }
      if (slideShowAudioTitleF == null) {
        //Create the audio title field
        slideShowAudioTitleF = new Field("Audio Title", FieldType.TEXT, DataType.TEXT, slideShowSt, false, false, true, 3, true, false, true);
        FieldFactory.saveField(slideShowAudioTitleF);
        fieldAdded = true;
      }
      if (slideShowAudioFileF == null) {
        //Create the audio file
        slideShowAudioFileF = new Field("MP3 File", FieldType.FILE, DataType.INTEGER, slideShowSt, false, false, false, 4, true, false, true);
        FieldFactory.saveField(slideShowAudioFileF);
        fieldAdded = true;
      }
      if (fieldAdded) {
        FieldsCache.removeFields(slideShowSt);
        StructureCache.removeStructure(slideShowSt);
        StructureServices.removeStructureFile(slideShowSt);
        StructureFactory.saveStructure(slideShowSt);
      }
     
     
      Structure slideSt = StructureCache.getStructureByVelocityVarName("slideImage");
      fields = FieldsCache.getFieldsByStructureVariableName("slideImage");
      Field slideTitleF = null;
      Field slideImageF = null;
      Field slideTextBodyF = null;
      Field slideTimingF = null;
 
      if (slideSt == null || (!InodeUtils.isSet(slideSt.getInode()))) {
        //Create the structure
        slideSt = new Structure ();
        slideSt.setDefaultStructure(false);
        slideSt.setName("Slide Image");
        slideSt.setVelocityVarName("slideImage");
        slideSt.setDescription("Slide Image");
        slideSt.setFixed(true);
        slideSt.setStructureType(Structure.STRUCTURE_TYPE_CONTENT);
        //Create the structure
        StructureFactory.saveStructure(slideSt);
      }
 
      if (fields != null)
View Full Code Here

    HibernateUtil.flush();   

    /*
     * Create test contentlet
     */
    Structure structure = StructureCache.getStructureByVelocityVarName("webPageContent");
    Contentlet contentlet = new Contentlet();
    contentlet.setStructureInode(structure.getInode());
    contentlet.setHost(host.getIdentifier());
    contentlet.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
    contentlet.setStringProperty("title", "test5086");
    contentlet.setStringProperty("body", "test5086");
    contentlet.setHost(host.getIdentifier());
View Full Code Here

TOP

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

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.