Package com.baasbox.dao

Examples of com.baasbox.dao.FileAssetDao


    }
    return doc;
  }
 
  public static ODocument createFile(String name,String fileName,String meta,String contentType, byte[] content) throws Throwable{
    FileAssetDao dao = FileAssetDao.getInstance();
    ODocument doc=dao.create(name,fileName,contentType,content);
    if (meta!=null && !meta.trim().isEmpty()) {
      ODocument metaDoc=(new ODocument()).fromJSON("{ 'meta' : " + meta + "}");
      doc.merge(metaDoc, true, false);
    }
    dao.save(doc);
    return doc;
  }
View Full Code Here


  }
 

 
  public static ByteArrayOutputStream getFileAsStream (String fileAssetName) throws SqlInjectionException, IOException{
    FileAssetDao dao = FileAssetDao.getInstance();
    ODocument fileAsset=dao.getByName(fileAssetName);
    if (fileAsset==null) return null;
    ORecordBytes record = fileAsset.field("file");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    record.toOutputStream(out);
    return out;
View Full Code Here

  }

 
  private static byte[] getResizedPicture(String fileAssetName, ImageDimensions dimensions) throws SqlInjectionException, DocumentIsNotAnImageException, DocumentIsNotAFileException, IOException, InvalidSizePatternException {
    //load the document
    FileAssetDao dao = FileAssetDao.getInstance();
    ODocument asset=dao.getByName(fileAssetName);
    if (asset==null) return null;
    if (!StorageUtils.docIsAnImage(asset)) throw new DocumentIsNotAnImageException();
   
    //check if the image has been previously resized
    String sizePattern= dimensions.toString();
    try{
      byte[] resizedImage = dao.getStoredResizedPicture( asset,  sizePattern);
      if (resizedImage!=null) return resizedImage;
     
      ByteArrayOutputStream fileContent = StorageUtils.extractFileFromDoc(asset);
      String contentType = getContentType(asset);
      String ext = contentType.substring(contentType.indexOf("/")+1);
      WritebleImageFormat format;
      try{
        format = WritebleImageFormat.valueOf(ext);
      }catch (Exception e){
        format= WritebleImageFormat.png;
      }
      resizedImage=StorageUtils.resizeImage(fileContent.toByteArray(), format, dimensions);
     
      //save the resized image for future requests
      dao.storeResizedPicture(asset, sizePattern, resizedImage);
      return resizedImage;
    }catch ( InvalidModelException e) {
      throw new RuntimeException("A very strange error occurred! ",e);
    }
  }
View Full Code Here

TOP

Related Classes of com.baasbox.dao.FileAssetDao

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.