Package org.damour.base.client.objects

Examples of org.damour.base.client.objects.Photo


    try {
      for (final FileItem item : fileItems) {

        File fileObject = null;
        if (item.getContentType().contains("image")) {
          fileObject = new Photo();
        } else {
          fileObject = new File();
        }
        fileObject.setOwner(owner);

        String parentFolderId = request.getParameter("parentFolder");
        Folder parentFolder = null;
        if (parentFolderId != null && !"".equals(parentFolderId)) {
          parentFolder = (Folder) session.load(Folder.class, new Long(parentFolderId));
          if (!SecurityHelper.doesUserHavePermission(session, owner, parentFolder, PERM.WRITE)) {
            Cookie cookie = new Cookie(item.getFieldName(), "");
            cookie.setMaxAge(0);
            cookie.setPath("/");
            response.addCookie(cookie);
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            response.flushBuffer();
            Logger.log("Unauthorized upload requested: " + request.getRemoteAddr());
            return;
          }
        }
        fileObject.setParent(parentFolder);

        fileObject.setContentType(item.getContentType());
        String name = item.getName();
        if (name.lastIndexOf("/") >= 0) {
          name = name.substring(name.lastIndexOf("/") + 1);
        }
        if (name.lastIndexOf("\\") >= 0) {
          name = name.substring(name.lastIndexOf("\\") + 1);
        }

        fileObject.setName(name);
        fileObject.setDescription(name);
        session.save(fileObject);

        status.setStatus(FileUploadStatus.WRITING_FILE);
        java.io.File outputPath = new java.io.File(java.io.File.separatorChar + "tmp" + java.io.File.separatorChar + BaseSystem.getDomainName(request));
        java.io.File outputFile = new java.io.File(outputPath, fileObject.getId() + "_" + fileObject.getName());
        outputPath.mkdirs();
        item.write(outputFile);
        tx = session.beginTransaction();
        fileObject.setNameOnDisk(fileObject.getId() + "_" + fileObject.getName());
        fileObject.setSize(outputFile.length());
        session.save(fileObject);
        tx.commit();
        Logger.log("Wrote to file: " + outputFile.getCanonicalPath());

        status.setStatus(FileUploadStatus.WRITING_DATABASE);
        saveFileFromStream(fileObject, new FileInputStream(outputFile));

        try {

          // if we are uploading a photo, create slideshow (sane size) image and thumbnail
          if (fileObject instanceof Photo) {
            // convert file to png for faster inclusion in thumbnails
            BufferedImage bi = javax.imageio.ImageIO.read(outputFile);
            ByteArrayOutputStream pngOut = new ByteArrayOutputStream();
            ImageIO.write(bi, "png", pngOut);

            tx = session.beginTransaction();
            Photo photo = (Photo) fileObject;
            photo.setWidth(bi.getWidth());
            photo.setHeight(bi.getHeight());

            PhotoThumbnail thumbFile = new PhotoThumbnail();
            thumbFile.setHidden(true);
            thumbFile.setOwner(owner);
            thumbFile.setParent(parentFolder);
            thumbFile.setName(createFileName("", name, "_thumb"));
            thumbFile.setDescription("Thumbnail for " + name);
            session.save(thumbFile);

            PhotoThumbnail previewFile = new PhotoThumbnail();
            previewFile.setHidden(true);
            previewFile.setOwner(owner);
            previewFile.setParent(parentFolder);
            previewFile.setName(createFileName("", name, "_preview"));
            previewFile.setDescription("Preview image for " + name);
            session.save(previewFile);
           
            PhotoThumbnail slideFile = new PhotoThumbnail();
            slideFile.setHidden(true);
            slideFile.setOwner(owner);
            slideFile.setParent(parentFolder);
            slideFile.setName(createFileName("", name, "_slideshow"));
            slideFile.setDescription("Slideshow image for " + name);
            session.save(slideFile);

           
            photo.setThumbnailImage(thumbFile);
            photo.setSlideshowImage(slideFile);
            photo.setPreviewImage(previewFile);

           
            ByteArrayInputStream pngIn = new ByteArrayInputStream(pngOut.toByteArray());

            ByteArrayOutputStream thumbOutStream = new ByteArrayOutputStream();
View Full Code Here


    Transaction tx = session.beginTransaction();

    Random r = new Random();
    List<Photo> photosList = new ArrayList<Photo>();
    for (int i = 0; i < 100; i++) {
      Photo p = new Photo();
      p.setName("photox" + i);
      p.setGlobalRead(true);
      p.setAverageRating(100f * r.nextFloat());
      photosList.add(p);
      session.save(p);
    }
    tx.commit();

View Full Code Here

      tooltip += "Size: " + formatter.format(((File) object).getSize()) + " bytes";
    }

    if (StringUtils.isEmpty(thumbnailImageURL)) {
      if (object instanceof Photo) {
        Photo photo = (Photo) object;
        if (photo.getThumbnailImage() != null) {
          thumbnailImageURL = BaseApplication.getSettings().getString("GetFileService", BaseApplication.GET_FILE_SERVICE_PATH)
              + photo.getThumbnailImage().getId() + "_inline_" + photo.getName();
        }
      }
    }

    init(widget, thumbnailImageURL, tooltip);
View Full Code Here

    // return;
    // }

    if (object instanceof File) {
      if (object instanceof Photo) {
        Photo photo = preview && ((Photo) object).getSlideshowImage() != null ? ((Photo) object).getSlideshowImage() : (Photo) object;
        String url = BaseApplication.getSettings().getString("GetFileService", BaseApplication.GET_FILE_SERVICE_PATH) + photo.getId() + "_inline_" + photo.getName();
        Image image = new Image(url);
        image.setHeight(photo.getHeight() + "px");
        image.setWidth(photo.getWidth() + "px");
        final PromptDialogBox promptDialog = new PromptDialogBox("Preview", "Close", null, null, true, true);
        promptDialog.setContent(image);
        promptDialog.center();
      } else if ("audio/mpeg".equals(object.getContentType())) {
        String url = BaseApplication.getSettings().getString("GetFileService", BaseApplication.GET_FILE_SERVICE_PATH) + object.getId() + "_inline_" + object.getName();
View Full Code Here

      tooltip += "<BR>";
      tooltip += "Size: " + formatter.format(file.getSize()) + " bytes";

      String thumbnailImageURL = null;
      if (file instanceof Photo) {
        Photo photo = (Photo) file;
        if (photo.getThumbnailImage() != null) {
          thumbnailImageURL = BaseApplication.getSettings().getString("GetFileService", BaseApplication.GET_FILE_SERVICE_PATH) + photo.getThumbnailImage().getId() + "_inline_" + photo.getName();
        }
      }
      new ToolTip(treeItemLabel, thumbnailImageURL, tooltip);
      fileItem.setUserObject(file);
      if (parentItem != null) {
View Full Code Here

TOP

Related Classes of org.damour.base.client.objects.Photo

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.