Package com.dotmarketing.portlets.fileassets.business

Examples of com.dotmarketing.portlets.fileassets.business.FileAsset


        //Get the theme files
        List<FileAsset> themeFiles = APILocator.getFileAssetAPI().findFileAssetsByFolder( themeFolder, APILocator.getUserAPI().getSystemUser(), false );

        //We need to verify if we have the template.vtl file
        FileAsset themeTemplate = null;
        Boolean haveHtmlHead = false;
        for ( FileAsset themeFile : themeFiles ) {
            if ( Template.THEME_TEMPLATE.equals( themeFile.getFileName() ) ) {
                themeTemplate = themeFile;
            } else if ( Template.THEME_HTML_HEAD.equals( themeFile.getFileName() ) ) {
                haveHtmlHead = true;
            }
        }

        //Getting the theme path
        String themePath;
        if ( themeFolder.getHostId().equals( hostId ) ) {
            themePath = Template.THEMES_PATH + themeFolder.getName() + "/";
        } else {
            Host themeHost = APILocator.getHostAPI().find( themeFolder.getHostId(), APILocator.getUserAPI().getSystemUser(), false );
            themePath = "//" + themeHost.getHostname() + Template.THEMES_PATH + themeFolder.getName() + "/";
        }

        //Getting the template.vtl file path
        String themeTemplatePath;
        if ( UtilMethods.isSet( themeTemplate ) && InodeUtils.isSet( themeTemplate.getInode() ) ) {
            themeTemplatePath = themeTemplate.getFileAsset().getPath();
        } else {//If the theme doesn't provide a template.vtl file lest use ours
            themeTemplatePath = "static/template/" + Template.THEME_TEMPLATE;
        }

        //Setting required theme data for the Layout template
View Full Code Here


   * @throws DotSecurityExceptionlanguageId
   */
  private static void addFileToContentlet(Contentlet contentlet, Field field,Host host, java.io.File uploadedFile, User user, String title)throws DotSecurityException, DotDataException{
    String folderPath = ROOT_FILE_FOLDER+contentlet.getStructure().getName();
    try {
      FileAsset file = saveFile(user,host,uploadedFile,folderPath, title);
      contentlet.setStringProperty(field.getVelocityVarName(), file.getIdentifier());
    } catch (Exception e) {
      Logger.error(SubmitContentUtil.class, e.getMessage());
      throw new DotDataException("File could not be saved. "+e.getMessage());
    }
  }
View Full Code Here

   */
  private static Contentlet addFileToContentlet(Contentlet contentlet, Field field,Host host, java.io.File uploadedFile, User user, String title)throws DotSecurityException, DotDataException{
    String identifier = String.valueOf(contentlet.getIdentifier());
    String folderPath = ROOT_FILE_FOLDER+contentlet.getStructure().getName()+"/"+identifier.substring(0, 1)+"/"+identifier.substring(1, 2)+"/"+identifier+"/";
    try {
      FileAsset file = saveFile(user,host,uploadedFile,folderPath, title);
      conAPI.setContentletProperty(contentlet, field, ((FileAsset)file).getIdentifier());
      return contentlet;
    } catch (Exception e) {
      Logger.error(SubmitContentUtil.class, e.getMessage());
      throw new DotDataException("File could not be saved. "+e.getMessage());
View Full Code Here

                return;
            }
           
            // get the asset in order to build etag and check permissions
            long defLang=APILocator.getLanguageAPI().getDefaultLanguage().getId();
            FileAsset fileasset;
            try {
                fileasset = APILocator.getFileAssetAPI().fromContentlet(
                    APILocator.getContentletAPI().findContentletByIdentifier(ident.getId(), live, defLang, user, true));
            }
            catch(DotSecurityException ex) {
                resp.sendError(403);
                return;
            }
           
            boolean userHasEditPerms = false;
            if(!live) {
                userHasEditPerms = APILocator.getPermissionAPI().doesUserHavePermission(fileasset,PermissionAPI.PERMISSION_EDIT,user);
                if(req.getParameter("recompile")!=null && userHasEditPerms) {
                    CacheLocator.getCSSCache().remove(host.getIdentifier(), actualUri, false);
                    CacheLocator.getCSSCache().remove(host.getIdentifier(), actualUri, true);
                }
            }
           
            CachedCSS cache = CacheLocator.getCSSCache().get(host.getIdentifier(), actualUri, live, user);
           
            byte[] responseData=null;
            Date cacheMaxDate=null;
            CachedCSS cacheObject=null;
           
            if(cache==null || cache.data==null) {
                // do compile!
                synchronized(ident.getId().intern()) {
                    cache = CacheLocator.getCSSCache().get(host.getIdentifier(), actualUri, live, user);
                    if(cache==null || cache.data==null) {
                        Logger.debug(this, "compiling css data for "+host.getHostname()+":"+uri);
                       
                        try {
                            compiler.compile();
                        }
                        catch(Throwable ex) {
                            Logger.error(this, "Error compiling "+host.getHostname()+":"+uri, ex);
                            throw new Exception(ex);
                        }
                       
                        // build cache object
                        ContentletVersionInfo vinfo = APILocator.getVersionableAPI().getContentletVersionInfo(ident.getId(), defLang);
                        CachedCSS newcache = new CachedCSS();
                        newcache.data = compiler.getOutput();
                        newcache.hostId = host.getIdentifier();
                        newcache.uri = actualUri;
                        newcache.live = live;
                        newcache.modDate = vinfo.getVersionTs();
                        newcache.imported = new ArrayList<ImportedAsset>();
                        for(String importUri : compiler.getAllImportedURI()) {
                            // newcache entry for the imported asset
                            ImportedAsset asset = new ImportedAsset();
                            asset.uri = importUri;
                            Identifier ii;
                            if(importUri.startsWith("//")) {
                                importUri=importUri.substring(2);
                                String hn=importUri.substring(0, importUri.indexOf('/'));
                                String uu=importUri.substring(importUri.indexOf('/'));
                                ii = APILocator.getIdentifierAPI().find(APILocator.getHostAPI().findByName(hn, user, live),uu);
                            }
                            else {
                                ii = APILocator.getIdentifierAPI().find(host, importUri);
                            }
                            ContentletVersionInfo impInfo = APILocator.getVersionableAPI().getContentletVersionInfo(ii.getId(), defLang);
                            asset.modDate = impInfo.getVersionTs();
                            newcache.imported.add(asset);
                            Logger.debug(this, host.getHostname()+":"+actualUri+" imports-> "+importUri);
                           
                            // actual cache entry for the imported asset. If needed
                            synchronized(ii.getId().intern()) {
                                if(CacheLocator.getCSSCache().get(ii.getHostId(), importUri, live, user)==null) {
                                    CachedCSS entry = new CachedCSS();
                                    entry.data = null;
                                    entry.hostId = ii.getHostId();
                                    entry.imported = new ArrayList<ImportedAsset>();
                                    entry.live = live;
                                    entry.modDate = impInfo.getVersionTs();
                                    entry.uri = importUri;
                                    CacheLocator.getCSSCache().add(entry);
                                }
                            }
                        }
                        CacheLocator.getCSSCache().add(newcache);
                        cacheMaxDate = newcache.getMaxDate();
                        cacheObject = newcache;
                        responseData = compiler.getOutput();
                    }
                }
            }
           
            if(responseData==null) {
                if(cache!=null && cache.data!=null) {
                    // if css is cached an valid is used as response
                    responseData = cache.data;
                    cacheMaxDate = cache.getMaxDate();
                    cacheObject = cache;
                    Logger.debug(this, "using cached css data for "+host.getHostname()+":"+uri);
                }
                else {
                    resp.sendError(500, "no data!");
                    return;
                }
            }
           
           
            boolean doDownload = true;
           
            if(live) {
                // we use etag dot:inode:cacheMaxDate:filesize and lastMod:cacheMaxDate
                // so the browser downloads it if any of the imported files changes
                doDownload = DownloadUtil.isModifiedEtag(req, resp, fileasset.getInode(),
                        cacheMaxDate.getTime(), fileasset.getFileSize());
            }
           
            if(doDownload) {
                // write the actual response to the user
                resp.setContentType("text/css");
View Full Code Here

                    Logger.debug(this.getClass(), "Can't find content with id " + id);
                    return;
                  }
                }

                FileAsset fa = APILocator.getFileAssetAPI().fromContentlet(cont);
                isSet = InodeUtils.isSet(cont.getInode());
                fileName = fa.getFileName();
                isCont = true;
                inodeOrId = cont.getInode();
              contAssetPath = APILocator.getFileAssetAPI().getRealAssetPath(cont.getInode());
              java.util.Map<String, Object> keyValueMap = null;
              String JSONValue = cont.getStringProperty(FileAssetAPI.META_DATA_FIELD);
              //Convert JSON to Table Display {key, value, order}
              if(UtilMethods.isSet(JSONValue)){
                keyValueMap =  com.dotmarketing.portlets.structure.model.KeyValueFieldUtil.JSONValueToHashMap(JSONValue);
                if(UtilMethods.isSet((String)keyValueMap.get("width"))){
                  imgWidth = Integer.parseInt((String)keyValueMap.get("width"));
                }
                if(UtilMethods.isSet((String)keyValueMap.get("height"))){
                  imgLength = Integer.parseInt((String)keyValueMap.get("height"));
                }
              }
              if(!contAssetPath.endsWith(java.io.File.separator)){
                contAssetPath += java.io.File.separator;
              }
              ext = fa.getExtension();
              }else if(InodeUtils.isSet(identifier.getId())){
                    file = fileAPI.find(inode,user,true);
                    isSet =InodeUtils.isSet(file.getInode());
                    fileName = file.getFileName();
                    inodeOrId = inode;
View Full Code Here

                        cont = APILocator.getContentletAPI().findContentletByIdentifier( identifier, true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false );
                    } catch ( DotContentletStateException se ) {
                        cont = APILocator.getContentletAPI().findContentletByIdentifier( identifier, false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false );
                    }

                FileAsset fa = APILocator.getFileAssetAPI().fromContentlet(cont);
                isSet = InodeUtils.isSet(cont.getInode());
                fileName = fa.getFileName();
                isCont = true;
                inodeOrId = cont.getInode();
              contAssetPath = APILocator.getFileAssetAPI().getRealAssetPath(cont.getInode());
              if(!contAssetPath.endsWith(java.io.File.separator)){
                contAssetPath += java.io.File.separator;
View Full Code Here

        Assert.assertEquals(200, response.getStatus());
        Contentlet cont=APILocator.getContentletAPI().find(response.getHeaders().getFirst("inode"),sysuser,false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
        Assert.assertTrue(response.getLocation().toString().endsWith("/api/content/inode/"+cont.getInode()));
        FileAsset file=APILocator.getFileAssetAPI().fromContentlet(cont);
        Assert.assertEquals("/resources/newfile"+salt+".txt",file.getURI());
        Assert.assertEquals("demo.dotcms.com", APILocator.getHostAPI().find(file.getHost(), sysuser, false).getHostname());
        Assert.assertEquals("this is the salt "+salt, IOUtils.toString(file.getFileInputStream()));
    }
View Full Code Here

      boolean publish = new Boolean(map.get("publish"));

      List<FileAsset> assetsList = new ArrayList<FileAsset>();
      for(String fileId : identifierList.split(",")){ 
        Contentlet fileContent = conAPI.search("+identifier:"+fileId+" +structureType:" + Structure.STRUCTURE_TYPE_FILEASSET+" +working:true +deleted:false", 1, 0, "modDate asc" , user, false).get(0);
        FileAsset file = fileAssetAPI.fromContentlet(fileContent);
        assetsList.add(file);
      }
     
      long numberOfContentltet = assetsList.size();
      long toprocess=numberOfContentltet;
View Full Code Here

            sb.append("</li>\n");
          }
        }
      } else {
        if(item instanceof FileAsset){
          FileAsset fa =(FileAsset)item;
          title = fa.getTitle();
          title = retrieveTitle(title, user);
          inode = fa.getInode();
          if (fa.isShowOnMenu()) {
            if (!APILocator.getPermissionAPI().doesUserHavePermission(fa, PermissionAPI.PERMISSION_PUBLISH, user, false)) {
              show = false;
            }
            if (APILocator.getPermissionAPI().doesUserHavePermission(fa, PermissionAPI.PERMISSION_READ, user, false)) {
              sb.append("<li class=\"" + className + "\" id=\"inode_" + inode + "\" >" + title + "</li>\n");
View Full Code Here

              sb.append("</li>\n");
            }
          }
        } else {
          if(item instanceof FileAsset){
            FileAsset fa =(FileAsset)item;
            title = fa.getTitle();
            title = retrieveTitle(title, user);
            inode = fa.getInode();
            if (fa.isShowOnMenu()) {
              if (!APILocator.getPermissionAPI().doesUserHavePermission(fa, PermissionAPI.PERMISSION_PUBLISH, user, false)) {
                show = false;
              }
              if (APILocator.getPermissionAPI().doesUserHavePermission(fa, PermissionAPI.PERMISSION_READ, user, false)) {
                sb.append("<li class=\"" + className + "\" id=\"inode_" + inode + "\" >" + title + "</li>\n");
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.fileassets.business.FileAsset

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.