Package com.dotmarketing.portlets.contentlet.business

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


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


    return mapper.writeValueAsString(map);
  }
  public List<String> dependenciesLeftToReindex(Contentlet con) throws DotStateException, DotDataException, DotSecurityException {
      List<String> dependenciesToReindex = new ArrayList<String>();

      ContentletAPI conAPI=APILocator.getContentletAPI();

      String relatedSQL = "select tree.* from tree where parent = ? or child = ? order by tree_order";
      DotConnect db = new DotConnect();
      db.setSQL(relatedSQL);
        db.addParam(con.getIdentifier());
        db.addParam(con.getIdentifier());
        ArrayList<HashMap<String, String>> relatedContentlets = db.loadResults();

        if(relatedContentlets.size()>0) {

            List<Relationship> relationships = RelationshipFactory.getAllRelationshipsByStructure(con.getStructure());

            for(Relationship rel : relationships) {

                List<Contentlet> oldDocs = new ArrayList <Contentlet>();

                String q = "";
                boolean isSameStructRelationship = rel.getParentStructureInode().equalsIgnoreCase(rel.getChildStructureInode());

                if(isSameStructRelationship)
                    q = "+type:content +(" + rel.getRelationTypeValue() + "-parent:" + con.getIdentifier() + " " +
                        rel.getRelationTypeValue() + "-child:" + con.getIdentifier() + ") ";
                else
                    q = "+type:content +" + rel.getRelationTypeValue() + ":" + con.getIdentifier();

                oldDocs  = conAPI.search(q, -1, 0, null, APILocator.getUserAPI().getSystemUser(), false);

                List<String> oldRelatedIds = new ArrayList<String>();
                if(oldDocs.size() > 0) {
                    for(Contentlet oldDoc : oldDocs) {
                        oldRelatedIds.add(oldDoc.getIdentifier());
View Full Code Here

    } else{
      /**
       * Call to the usual permalink functionality redirecting to the page or file location
       */
      /*Check if is a contentlet and redirect to the specified page*/
      ContentletAPI contentletApi = APILocator.getContentletAPI();
      String luceneQuery = "+type:content +live:true +deleted:false +identifier:" + iden.getInode();
     
      List<Contentlet> contentlets = new ArrayList<Contentlet>();
      try
      {
        User user = APILocator.getUserAPI().getSystemUser();
        contentlets = contentletApi.search(luceneQuery,0,0,"",user,false);
      }
      catch(Exception ex)
      {
        Logger.info(PermalinkServlet.class,ex.getMessage());
      }
View Full Code Here

     * @throws InterruptedException
     */
    @Test
    public void importFile () throws DotDataException, DotSecurityException, IOException, InterruptedException {

        ContentletAPI contentletAPI = APILocator.getContentletAPI();

        //Create a test structure
        String structure1Suffix = String.valueOf( new Date().getTime() );
        Structure structure1 = new Structure();
        structure1.setName( "Import Test " + structure1Suffix );
        structure1.setVelocityVarName( "ImportTest_" + structure1Suffix );
        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
        Reader reader = createTempFile( "Title, Host" + "\r\n" +
                "Test1, " + defaultHost.getIdentifier() + "\r\n" +
                "Test2, " + defaultHost.getIdentifier() + "\r\n" +
                "Test3, " + defaultHost.getIdentifier() + "\r\n" +
                "Test4, " + defaultHost.getIdentifier() + "\r\n" );
        CsvReader csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        String[] csvHeaders = csvreader.getHeaders();

        //Preview=true
        HashMap<String, List<String>> results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, true, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, true, false, true );

        //As it was a preview nothing should be saved
        List<Contentlet> savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 0 );

        //----------------PREVIEW = FALSE-----------------------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
        reader = createTempFile( "Title, Host" + "\r\n" +
                "Test1, " + defaultHost.getIdentifier() + "\r\n" +
                "Test2, " + defaultHost.getIdentifier() + "\r\n" +
                "Test3, " + defaultHost.getIdentifier() + "\r\n" +
                "Test4, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, false, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, false, false, true );

        //Now we should have saved data
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //----------------USING WRONG HOST IDENTIFIERS----------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
        reader = createTempFile( "Title, Host" + "\r\n" +
                "Test5, " + defaultHost.getIdentifier() + "\r\n" +
                "Test6, " + "999-99999999-99999999-00000" + "\r\n" +
                "Test7, " + "44444444-5555555555-2222" + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=true
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, true, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, true, true, true );

        //We should have the same amount on data
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //---------------USING KEY FIELDS-----------------------------------------
        //------------------------------------------------------------------------

        //Making sure the contentlets are in the indexes
        List<ContentletSearch> contentletSearchResults;
        int x = 0;
        do {
            Thread.sleep( 200 );
            //Verify if it was added to the index
            contentletSearchResults = contentletAPI.searchIndex( "+structureName:" + structure1.getVelocityVarName() + " +working:true +deleted:false +" + structure1.getVelocityVarName() + ".title:Test1 +languageId:1", 0, -1, null, user, true );
            x++;
        } while ( (contentletSearchResults == null || contentletSearchResults.isEmpty()) && x < 100 );

        //Create the csv file to import
        reader = createTempFile( "Title, Host" + "\r\n" +
                "Test1, " + defaultHost.getIdentifier() + "\r\n" +
                "Test2, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{textFileStructure1.getInode()}, false, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, false, false, true );//We should expect warnings: Line #X. The key fields chosen match 1 existing content(s) - more than one match suggests key(s) are not properly unique

        //We used the key fields, so the import process should update instead to add new records
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //---------------USING IDENTIFIER COLUMN----------------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import

        String id1 = null;
        String id2 = null;
        for ( Contentlet content : savedData ) {
            if ( content.getMap().get( "title" ).equals( "Test1" ) ) {
                id1 = content.getIdentifier();
            } else if ( content.getMap().get( "title" ).equals( "Test2" ) ) {
                id2 = content.getIdentifier();
            }
        }

        reader = createTempFile( "Identifier, Title, Host" + "\r\n" +
                id1 + ", Test1_edited, " + defaultHost.getIdentifier() + "\r\n" +
                id2 + ", Test2_edited, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, false, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, false, false, true );

        //We used a identifier column, so the import process should update instead to add new records
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //-------------------------LANGUAGE AND KEY FIELDS------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
        reader = createTempFile( "languageCode, countryCode, Title, Host" + "\r\n" +
                "es, ES, Test1_edited, " + defaultHost.getIdentifier() + "\r\n" +
                "es, ES, Test2_edited, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        int languageCodeHeaderColumn = 0;
        int countryCodeHeaderColumn = 1;
        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{textFileStructure1.getInode()}, false, true, user, -1, csvHeaders, csvreader, languageCodeHeaderColumn, countryCodeHeaderColumn, reader );
        //Validations
        validate( results, false, false, false );

        //We used the key fields, so the import process should update instead to add new records
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 6 );

        //Validate we saved the contentlets on spanish
View Full Code Here

  public void migrateStructure(Structure struct) throws DotDataException, DotSecurityException, DotMappingException {
   
    new ESContentletIndexAPI().checkAndInitialiazeIndex();
   
   
    ContentletAPI capi = APILocator.getContentletAPI();

    String type = struct.getVelocityVarName();
    for (int i = 0; i < 10000; i++) {

      int limit = 100;
      int offset = i * 100;

      List<Contentlet> cons = capi.findByStructure(struct.getInode(), APILocator.getUserAPI().getSystemUser(), false, limit, offset);
      if (cons.size() == 0) {
        break;
      }
      Client client = new ESClient().getClient();
      BulkRequestBuilder bulkRequest = client.prepareBulk();
View Full Code Here

      for (String ignoredTag : ignoredTags)
        ignoredTagsList.add(ignoredTag.trim());

      String query = "+type:content +deleted:false +live:true "+languageId+" +structureName:" + st.getVelocityVarName();
      List<Contentlet> hits = new ArrayList <Contentlet>();
      ContentletAPI conAPI = APILocator.getContentletAPI();

      try {
        hits = conAPI.search(query,  -1, 0, null, userAPI.getSystemUser(), false);
      } catch (DotDataException e) {
        Logger.debug(DotCMSMacroWebAPI.class,"Error retriving data");
      } catch (DotSecurityException e) {
        Logger.debug(DotCMSMacroWebAPI.class,"Error retriving data, user does not have permissions");
      } catch (Exception e) {
View Full Code Here

  public static InputStream buildStream(HTMLPage htmlPage, Identifier identifier, boolean EDIT_MODE) throws DotDataException, DotSecurityException {
    String folderPath = (!EDIT_MODE) ? "live/" : "working/";
    InputStream result;
    StringBuilder sb = new StringBuilder();

    ContentletAPI conAPI = APILocator.getContentletAPI();
    Template cmsTemplate = com.dotmarketing.portlets.htmlpages.factories.HTMLPageFactory.getHTMLPageTemplate(htmlPage, EDIT_MODE);
    if(cmsTemplate == null || ! InodeUtils.isSet(cmsTemplate.getInode())){
      Logger.error(This.class, "PAGE DOES NOT HAVE A VALID TEMPLATE (template unpublished?) : page id " + htmlPage.getIdentifier() + ":" + identifier.getURI()   );
    }
   
    //gets pageChannel for this path
    java.util.StringTokenizer st = new java.util.StringTokenizer(String.valueOf(identifier.getURI()),"/");
    String pageChannel = null;
    if(st.hasMoreTokens()){
      pageChannel = st.nextToken();
    }
   
   
   
   
    // set the page cache var
    if(htmlPage.getCacheTTL() > 0 && LicenseUtil.getLevel() > 99){
      sb.append("#set($dotPageCacheDate = \"").append( new java.util.Date() ).append("\")");
      sb.append("#set($dotPageCacheTTL = \"").append( htmlPage.getCacheTTL()  ).append("\")");
    }
   
   
   
    // set the host variables
    HTMLPageAPI htmlPageAPI = APILocator.getHTMLPageAPI();

    Host host = htmlPageAPI.getParentHost(htmlPage);
    sb.append("#if(!$doNotParseTemplate)");
      sb.append("$velutil.mergeTemplate('" ).append( folderPath ).append( host.getIdentifier() ).append( "." ).append( Config.getStringProperty("VELOCITY_HOST_EXTENSION") ).append( "')");
    sb.append(" #end ");
   
   
   
    //creates the context where to place the variables
    // Build a context to pass to the page
    sb.append("#if(!$doNotSetPageInfo)");
    sb.append("#set ( $quote = '\"' )");
    sb.append("#set ($HTMLPAGE_INODE = \"" ).append( String.valueOf(htmlPage.getInode()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_IDENTIFIER = \"" ).append( String.valueOf(htmlPage.getIdentifier()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_TITLE = \"" ).append( UtilMethods.espaceForVelocity(htmlPage.getTitle()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_FRIENDLY_NAME = \"" + UtilMethods.espaceForVelocity(htmlPage.getFriendlyName()) ).append( "\" )");
    sb.append("#set ($TEMPLATE_INODE = \"" ).append( String.valueOf(cmsTemplate.getInode()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_META = \"" ).append( UtilMethods.espaceForVelocity(htmlPage.getMetadata()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_META = \"#fixBreaks($HTMLPAGE_META)\")");
   
    sb.append("#set ($HTMLPAGE_DESCRIPTION = \"" ).append( UtilMethods.espaceForVelocity(htmlPage.getSeoDescription()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_DESCRIPTION = \"#fixBreaks($HTMLPAGE_DESCRIPTION)\")");
   
    sb.append("#set ($HTMLPAGE_KEYWORDS = \"" ).append( UtilMethods.espaceForVelocity(htmlPage.getSeoKeywords()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_KEYWORDS = \"#fixBreaks($HTMLPAGE_KEYWORDS)\")");
   
   
    sb.append("#set ($HTMLPAGE_SECURE = \"" ).append( String.valueOf(htmlPage.isHttpsRequired()) ).append( "\" )");
    sb.append("#set ($VTLSERVLET_URI = \"" ).append( UtilMethods.encodeURIComponent(identifier.getURI()) ).append( "\" )");
    sb.append("#set ($HTMLPAGE_REDIRECT = \"" ).append( UtilMethods.espaceForVelocity(htmlPage.getRedirect()) ).append( "\" )");
   
    sb.append("#set ($pageTitle = \"" ).append( UtilMethods.espaceForVelocity(htmlPage.getTitle()) ).append( "\" )");
    sb.append("#set ($pageChannel = \"" ).append( pageChannel ).append( "\" )");
    sb.append("#set ($friendlyName = \"" ).append( UtilMethods.espaceForVelocity(htmlPage.getFriendlyName()) ).append( "\" )");

    Date moddate = null;
    if(UtilMethods.isSet(htmlPage.getModDate())){
      moddate = htmlPage.getModDate();
    } else {
      moddate = htmlPage.getStartDate();
    }

    moddate = new Timestamp(moddate.getTime());

    sb.append("#set ($HTML_PAGE_LAST_MOD_DATE= $date.toDate(\"yyyy-MM-dd HH:mm:ss.SSS\", \"" ).append( moddate ).append( "\"))");
    sb.append("#set ($HTMLPAGE_MOD_DATE= $date.toDate(\"yyyy-MM-dd HH:mm:ss.SSS\", \"" ).append( moddate ).append( "\"))");
    sb.append(" #end ");
           
    //get the containers for the page and stick them in context
    //List identifiers = InodeFactory.getChildrenClass(cmsTemplate, Identifier.class);

        List<Container> containerList = APILocator.getTemplateAPI().getContainersInTemplate(cmsTemplate, APILocator.getUserAPI().getSystemUser(), false);

    Iterator i = containerList.iterator();
    while(i.hasNext()){
      Container ident = (Container) i.next();
     
      Container c = null;
      if (EDIT_MODE) {
        c = (Container) APILocator.getVersionableAPI().findWorkingVersion(ident.getIdentifier(),APILocator.getUserAPI().getSystemUser(),false);
      }
      else {
        c = (Container) APILocator.getVersionableAPI().findLiveVersion(ident.getIdentifier(),APILocator.getUserAPI().getSystemUser(),false);
      }
      //sets container to load the container file
      sb.append("#set ($container").append(ident.getIdentifier() ).append( " = \"" ).append( folderPath ).append( ident.getIdentifier() ).append( "." ).append( Config.getStringProperty("VELOCITY_CONTAINER_EXTENSION") ).append( "\" )");

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

      boolean dynamicContainer = UtilMethods.isSet(c.getLuceneQuery());

      int langCounter = 0;


      List<Contentlet> contentlets = new ArrayList<Contentlet>();
      List<Contentlet> contentletsFull = new ArrayList<Contentlet>();
      if (!dynamicContainer) {
        Identifier idenHtmlPage = APILocator.getIdentifierAPI().find(htmlPage);
        Identifier idenContainer = APILocator.getIdentifierAPI().find(c);
        //The container doesn't have categories
        try{
          contentlets = conAPI.findPageContentlets(idenHtmlPage.getId(), idenContainer.getId(), sort, EDIT_MODE, -1,APILocator.getUserAPI().getSystemUser() ,false);
          if(EDIT_MODE)
              contentletsFull=contentlets;
          else
              contentletsFull = conAPI.findPageContentlets(idenHtmlPage.getId(), idenContainer.getId(), sort, true, -1,APILocator.getUserAPI().getSystemUser() ,false);
        }catch(Exception e){
          Logger.error(PageServices.class,"Unable to retrive contentlets on page", e);
        }
        Logger.debug(PageServices.class, "HTMLPage= " + htmlPage.getInode() + " Container=" + c.getInode() + " Language=-1 Contentlets=" + contentlets.size());
      }
View Full Code Here

    // gets the identifier for this asset
    APILocator.getVersionableAPI().setDeleted(currWebAsset, false);
  }

  public static boolean unPublishAsset(WebAsset currWebAsset, String userId, Inode parent) throws DotStateException, DotDataException, DotSecurityException {
    ContentletAPI conAPI = APILocator.getContentletAPI();
    HostAPI hostAPI = APILocator.getHostAPI();
   
    // gets the identifier for this asset
    Identifier identifier = APILocator.getIdentifierAPI().find(currWebAsset);
View Full Code Here

        String title = WikiUtils.normalizeTitle(wikiName);
        if (wiki != null) {
          String struct = wiki.split("\\|")[0];
          String field = wiki.split("\\|")[1];

          ContentletAPI capi = APILocator.getContentletAPI();
          String query = "+structureInode:" + struct + " +" + field
              + ":\"" + title
              + "\" +languageId:1* +deleted:false +live:true";
          List<com.dotmarketing.portlets.contentlet.model.Contentlet> cons = null;
          try {
            cons = capi.search(query, 1, 0, "text1", user, true);
          } catch (DotDataException e) {
            Logger.debug(this, "DotDataException: "  + e.getMessage(), e);
          } catch (DotSecurityException e) {
            Logger.debug(this, "DotSecurityException: "  + e.getMessage(), e);
          } catch (Exception e) {
View Full Code Here

    removeContentletMapFile(content, EDIT_MODE);
  }

  public static InputStream buildVelocity(Contentlet content, boolean EDIT_MODE) throws DotDataException, DotSecurityException, DotContentletStateException {
    InputStream result;
    ContentletAPI conAPI=APILocator.getContentletAPI();
    User systemUser=APILocator.getUserAPI().getSystemUser();

    if (!InodeUtils.isSet(content.getInode())|| !InodeUtils.isSet(content.getIdentifier())) {
      throw new DotContentletStateException("The contentlet inode and identifier must be set");
    }
    // let's write this puppy out to our file
    StringBuilder sb=new StringBuilder();
    String conTitle=conAPI.getName(content, APILocator.getUserAPI().getSystemUser(), true);
    // CONTENTLET CONTROLS BEGIN
    // To edit the look, see
    // WEB-INF/velocity/static/preview/content_controls.vtl
    sb.append("#set( $dotcms_content_").append(content.getIdentifier()).append("=${contents.getEmptyMap()})");
//    Was put in to fix DOTCMS-995 but it caused DOTCMS-1210.
//      I actually think it should be fine passed the ctx which is a chained context here
//    sb.append("#set($velocityContext=$UtilMethods.pushVelocityContext($velocityContext))");
//    sb.append("$!velocityContext.put(\"content\",$content)");

    sb.append("$!dotcms_content_").append(content.getIdentifier()).append(".put(\"permission\", $EDIT_CONTENT_PERMISSION").append(content.getIdentifier()).append(" )");
    sb.append("$!dotcms_content_").append(content.getIdentifier()).append(".put(\"inode\", '").append(content.getInode()).append("'  )");
    sb.append("$!dotcms_content_").append(content.getIdentifier()).append(".put(\"identifier\", '").append(content.getIdentifier()).append("'  )");
    sb.append("$!dotcms_content_").append(content.getIdentifier()).append(".put(\"structureInode\", '").append(content.getStructureInode()).append("'  )");
    sb.append("$!dotcms_content_").append(content.getIdentifier()).append(".put(\"contentTitle\", \"").append(UtilMethods.espaceForVelocity(conTitle)).append("\" )");
    sb.append("$!dotcms_content_").append(content.getIdentifier()).append(".put(\"detailPageURI\", \"").append(getDetailPageURI(content)).append("\"  )");
    Structure structure=content.getStructure();

    String modDateStr=UtilMethods.dateToHTMLDate((Date) content.getModDate(), "yyyy-MM-dd H:mm:ss");
    sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"modDate\", $date.toDate(\"yyyy-MM-dd H:mm:ss\", \"").append(modDateStr).append("\")))");
    sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"contentLastModDate\", $date.toDate(\"yyyy-MM-dd H:mm:ss\", \"").append(modDateStr).append("\")))");
    sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"contentLastModUserId\", \"").append(content.getModUser()).append("\"))");
    if (content.getOwner() != null)
      sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"contentOwnerId\", \"").append(content.getOwner()).append("\"))");

    // Structure fields
    List<Field> fields=FieldsCache.getFieldsByStructureInode(content.getStructureInode());
    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())
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.