Package org.vosao.entity

Examples of org.vosao.entity.FileEntity


    }
    if (servedFromCache(request.getPathInfo(), request, response)) {
      logger.info("from cache " + request.getPathInfo());
      return;
    }
    FileEntity file = getDao().getFileDao().getByName(
        folder.getEntity().getId(), filename);
    if (file != null) {
      byte[] content = getDao().getFileDao().getFileContent(file);
      if (file.getSize() < CacheService.MEMCACHE_LIMIT) {
        getSystemService().getFileCache().put(request.getPathInfo(),
            new FileCacheItem(file, content,
                VosaoContext.getInstance().getUser() == null));
      }
      sendFile(file, content, request, response);
View Full Code Here


        "files.success_delete"));
  }

  @Override
  public String getFilePath(Long fileId) {
    FileEntity file = getDao().getFileDao().getById(fileId);
    if (file != null) {
      FolderEntity folder = getDao().getFolderDao().getById(
          file.getFolderId());
      return "/file" + getBusiness().getFolderBusiness().getFolderPath(
          folder) + "/" + file.getFilename();
    }
    return "";
  }
View Full Code Here

  public FileEntity saveFile(String filename, byte[] data) {
    try {
      String path = FolderUtil.getFilePath(filename);
      String name = FolderUtil.getFileName(filename);
      FolderEntity folder = getFolderBusiness().createFolder(path);
      FileEntity file = getDao().getFileDao().getByName(folder.getId(), name);
      if (file == null) {
        file = new FileEntity(name, name, folder.getId(),
            MimeType.getContentTypeByExt(FolderUtil.getFileExt(filename)),
            new Date(), data.length);
      }
      getDao().getFileDao().save(file, data);
      getSystemService().getFileCache().remove(filename);
View Full Code Here

        .findFolderByPath(getFolderBusiness().getTree(), path);
    if (folder == null) {
      logger.error("Folder not found. " + path);
      return;
    }
    FileEntity file = getDao().getFileDao().getByName(folder.getEntity()
        .getId(), name);
    if (file == null) {
      logger.error("File not found. " + filename);
      return;
    }
    FolderPermissionEntity perm = getFolderPermissionBusiness()
        .getPermission(folder.getEntity(),
            VosaoContext.getInstance().getUser());
    if (perm.isChangeGranted()) {
      getDao().getFileDao().remove(file.getId());
      getSystemService().getFileCache().remove(filename);
    }
  }
View Full Code Here

    return "";
  }

  @Override
  public ServiceResponse updateContent(Long fileId, String content) {
    FileEntity file = getDao().getFileDao().getById(fileId);
    if (file != null) {
      try {
        getDao().getFileDao().save(file, content.getBytes("UTF-8"));
        FolderEntity folder = getDao().getFolderDao().getById(
            file.getFolderId());
        String cacheUrl = getBusiness().getFolderBusiness()
            .getFolderPath(folder) + "/" + file.getFilename();
        getBusiness().getSystemService().getFileCache().remove(cacheUrl);
        return ServiceResponse.createSuccessResponse(
            Messages.get("file.success_update"));
      } catch (UnsupportedEncodingException e) {
        return ServiceResponse.createErrorResponse(
View Full Code Here

  }

  @Override
  public void remove(List<Long> ids) {
    for (Long id : ids) {
      FileEntity file = getDao().getFileDao().getById(id);
      if (file != null) {
        getSystemService().getFileCache().remove(getFilePath(file));
      }
    }
    getDao().getFileDao().remove(ids);
View Full Code Here

  }
 
  @Override
  public FileVO getFile(Long id, String encoding) {
    try {
      FileEntity file = getDao().getFileDao().getById(id);
      FileVO vo = new FileVO(file);
      FolderEntity folder = getDao().getFolderDao().getById(file
        .getFolderId());
      vo.setLink("/file" + getBusiness().getFolderBusiness()
          .getFolderPath(folder) + "/" + file.getFilename());
      String ext = FolderUtil.getFileExt(file.getFilename());
      vo.setTextFile(getBusiness().getConfigBusiness().isTextFileExt(ext));
      vo.setImageFile(getBusiness().getConfigBusiness()
          .isImageFileExt(ext));
      if (vo.isTextFile()) {
        vo.setContent(new String(getDao().getFileDao()
View Full Code Here

    }
  }

  @Override
  public ServiceResponse saveFile(Map<String, String> vo) {
    FileEntity file = null;
    if (!StringUtils.isEmpty(vo.get("id"))) {
      file = getDao().getFileDao().getById(Long.valueOf(vo.get("id")));
    }
    if (file == null) {
      file = new FileEntity();
    }
    file.setFilename(vo.get("name"));
    file.setTitle(vo.get("title"));
    file.setFolderId(Long.valueOf(vo.get("folderId")));
    file.setLastModifiedTime(new Date());
    List<String> errors = getBusiness().getFileBusiness()
      .validateBeforeUpdate(file);
    if (errors.isEmpty()) {
      FolderEntity folder = getDao().getFolderDao().getById(
          file.getFolderId());
      file.setMimeType(MimeType.getContentTypeByExt(
          FolderUtil.getFileExt(file.getFilename())));
      String cacheUrl = getBusiness().getFolderBusiness()
          .getFolderPath(folder) + "/" + file.getFilename();
      getBusiness().getSystemService().getFileCache().remove(cacheUrl);
      getDao().getFileDao().save(file);
      return ServiceResponse.createSuccessResponse(
          Messages.get("file.success_update"));
    }
View Full Code Here

    for (FileFactory factory : systemFileFactory.getFactories()) {
      if (factory.isCreatable(factoryPath)) {
        return factory.createFile(data);
      }
    }
    FileEntity file = new FileEntity();
    file.setFilename(newName);
    file.setFolderId(folder.getId());
    file.setTitle(newName);
    file.setLastModifiedTime(new Date());
    file.setSize(length.intValue());
    file.setMimeType(contentType);
    getDao().getFileDao().save(file, data);
    return new FileResource(getBusiness(), file);
  }
View Full Code Here

    return null;
  }
 
  private String processResourceFileJSON(FileItemStream imageItem, byte[] data,
      FolderEntity folder) throws UploadException {
    FileEntity file = processResourceFile(imageItem, data, folder);
    String message = createMessage("success", file.getId().toString());
    return message;
  }
View Full Code Here

TOP

Related Classes of org.vosao.entity.FileEntity

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.