Package com.dotmarketing.portlets.templates.design.bean

Examples of com.dotmarketing.portlets.templates.design.bean.PreviewFileAsset


   * This method save the imported file on preview file system and return the bean that represent the file.
   *
   * May 7, 2012 - 4:17:26 PM
   */
  public static PreviewFileAsset savePreviewFileAsset(Versionable asset) throws IOException, DotDataException, DotSecurityException{
    PreviewFileAsset result = new PreviewFileAsset();
    String today = SDF.format(new GregorianCalendar().getTime());
    java.io.File todayPreviewAssetDir = new java.io.File(new java.io.File(FileUtil.getRealPath(Config.getStringProperty("PREVIEW_ASSET_PATH"))), today);
    if(!todayPreviewAssetDir.exists())
      todayPreviewAssetDir.mkdir();

    java.io.File importedFilesAssetDir = new java.io.File(todayPreviewAssetDir, "files");
    if(!importedFilesAssetDir.exists())
      importedFilesAssetDir.mkdir();

    java.io.File templatesAssetDir = new java.io.File(todayPreviewAssetDir, "templates");
    if(!templatesAssetDir.exists())
      templatesAssetDir.mkdir();

    java.io.File assetFile = null;
    java.io.File previewAsset = null;
    // if the file imported is a FileAsset/Contentlet...
    if(asset instanceof Contentlet){
      Contentlet c = (Contentlet)asset;
      assetFile = APILocator.getContentletAPI().getBinaryFile(c.getInode(), FileAssetAPI.BINARY_FIELD, APILocator.getUserAPI().getSystemUser());
      previewAsset = new java.io.File(importedFilesAssetDir, assetFile.getName());
      if(previewAsset.exists())
        previewAsset.delete();
      result.setContentlet(true);
      result.setInode(c.getInode());
      result.setParent(c.getFolder());
    }else if(asset instanceof File){ // is a File
      File f = (File)asset;
      assetFile =  APILocator.getFileAPI().getAssetIOFile(f);
      previewAsset = new java.io.File(importedFilesAssetDir, assetFile.getName());
      if(previewAsset.exists())
        previewAsset.delete();
      result.setContentlet(false);
      result.setInode(f.getInode());
      result.setParent(f.getParent());
    }
    //set the real path for the body preview
    result.setRealFileSystemPath(previewAsset.getPath().substring(previewAsset.getPath().indexOf("/_preview")));
    FileInputStream fis = new FileInputStream(assetFile);
    FileOutputStream fos = new FileOutputStream(previewAsset);
    final byte[] buffer = new byte[ 1024 ];
        int n = 0;
        while ((n = fis.read(buffer)) > 0){
View Full Code Here


    if(null!=divFilesToAdd){
      Elements filesToAdd = divFilesToAdd.getElementsByAttributeValueStarting(ID_ATTRIBUTE, FILE_TO_ADD_START_ID);
      for(Element singleFile : filesToAdd){
        String id = singleFile.attr("id");
        String[] values = id.substring(id.indexOf(FILE_TO_ADD_START_ID)+4).split("_");
        PreviewFileAsset p = new PreviewFileAsset();
        p.setInode(values[0]);
        p.setParent(values[1]);
        p.setContentlet(Boolean.parseBoolean(values[2]));
        result.add(p);
      }
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.templates.design.bean.PreviewFileAsset

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.