Package org.myphotodiary.json

Examples of org.myphotodiary.json.JsonObject


        getServletContext().log(
            "No directory data for: " + path, ex);
      }

      // Create Json response
      JsonObject rsp = new JsonObject();
      // Get the directory specific data
      if ((directory != null) && (directory.isIndexingAllowedBoolean())) {
        if (directory.getDescription() != null) {
          rsp.addParameter(Configuration.dirDescParam, directory.getDescription());
        }
        if (directory.getLatitude() != null) {
          rsp.addParameter(Configuration.latParam, directory.getLatitude());
        }
        if (directory.getLongitude() != null) {
          rsp.addParameter(Configuration.lngParam, directory.getLongitude());
        }
        if (directory.getDate() != null) {
          rsp.addParameter(Configuration.dirDateParam, directory.getDate());
        }
        rsp.addParameter(Configuration.groupParam,
            (directory.getGroup() == null ? Configuration.publicGroup : directory.getGroup().getGroupName()));

        List<Attribute> dirAttributes = directory.getAttributes();
        if (dirAttributes != null) {
          JsonArray attributes = new JsonArray();
          for (Attribute attribute: dirAttributes) {
            attributes.addItem(attribute.getName());
          }
          rsp.addParameter(Configuration.attrParam, attributes);
        }
      }
      else {
        rsp.addParameter(Configuration.dirDescParam, JsonEntity.NULL);
      }
      getServletContext().log("Json response: " + rsp.toString());
      // Reply the Json response
      response.setContentType(Configuration.jsonContentType);
      response.setCharacterEncoding(Configuration.contentEncoding);
      PrintWriter out = response.getWriter();
      out.print(rsp.toString());
      out.flush();
      tx.commit();
    } catch (AuthenticationException ex) {
      getServletContext().log("Unauthorized user", ex);
      tx.rollback();
View Full Code Here


        getServletContext().log(
            "No image data for: " + dir + " / " + name, ex);
      }

      // Get the image specific data and map it to a Json response
      JsonObject rsp = updateImageData(img);
      if (img != null) {
        rsp.addParameter(Configuration.descParam, img.getDescription())
        .addParameter(Configuration.ratingParam, img.getRating())
        .addParameter(Configuration.dateParam, img.getDate().toString());
        List<Attribute> imgAttributes = img.getAttributes();
        if (imgAttributes != null) {
          JsonArray attributes = new JsonArray();
          for (Attribute attribute: imgAttributes) {
            attributes.addItem(attribute.getName());
          }
          rsp.addParameter(Configuration.attrParam, attributes);
        }
      }
      else {
        rsp.addParameter(Configuration.descParam, JsonEntity.NULL)
        .addParameter(Configuration.ratingParam, Image.NOT_RATED)
        .addParameter(Configuration.dateParam, JsonEntity.NULL);
      }
      getServletContext().log("Json response: " + rsp.toString());
      // Reply the Json response
      response.setContentType(Configuration.jsonContentType);
      response.setCharacterEncoding(Configuration.contentEncoding);
      PrintWriter out = response.getWriter();
      out.print(rsp.toString());
      out.flush();
    } catch (Exception ex) {
      getServletContext().log("Cannot GET image data", ex);
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
View Full Code Here

   * @throws IOException
   * @throws ImageProcessingException
   * @throws MetadataException
   */
  public JsonObject updateImageData(Image image) throws IOException, ImageProcessingException {
    JsonObject imgData = new JsonObject();

    if (image != null) {
      File imageFile = new File(cfg.getImageRootPath() + image.getDirectory().getPath() + "\\\\" + image.getName());
      Metadata metadata = ImageMetadataReader.readMetadata(imageFile);
      // Un-comment to reverse engineer EXIF data structure
      //      for (com.drew.metadata.Directory directory: metadata.getDirectories()) {
      //        for (Tag tag : directory.getTags()) {
      //          cfg.getCtxt().log("" + tag);
      //        }
      //      }
      // retrieve jpeg tags if any
      JpegDirectory jpegDir = metadata.getDirectory(JpegDirectory.class);
      ExifSubIFDDirectory exifDir = metadata.getDirectory(ExifSubIFDDirectory.class);
      try {
        imgData.addParameter(Configuration.heigthParam, jpegDir.getImageHeight());
        imgData.addParameter(Configuration.widthParam, jpegDir.getImageWidth());
      }
      catch (MetadataException ex1) {
        imgData.addParameter(Configuration.heigthParam, exifDir.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT ));
        imgData.addParameter(Configuration.widthParam, exifDir.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH ));
      }

      //      try {
      //        SimpleDateFormat sdf = new SimpleDateFormat(Configuration.DATE_FORMAT);
      //        if (exifDir != null) {
View Full Code Here

        // create an empty list
        images = new LinkedList<Image>();
      }

      // Create Json response
      JsonObject rsp = new JsonObject();
      JsonArray imgList = new JsonArray();
      JsonArray thumbList = new JsonArray();
      // Get the image specific data
      for (Image img : images) {
        JsonObject im = new JsonObject();
        JsonObject th = new JsonObject();
        im.addParameter(Configuration.urlParam, cfg.getImageRootUrl(request)
            + img.getDirectory().getPath() + "/" + img.getName());
        imgList.addItem(im);
        th.addParameter(Configuration.urlParam, cfg.getImageRootUrl(request)
            + img.getDirectory().getPath() + "/"
            + Configuration.thumbDirName + "/" + img.getName());
        thumbList.addItem(th);
      }
      rsp.addParameter(Configuration.imgListParam, imgList);
View Full Code Here

        // create an empty list
        images = new LinkedList<Image>();
      }

      // Create Json response
      JsonObject rsp = new JsonObject();
      JsonArray imgList = new JsonArray();
      JsonArray thumbList = new JsonArray();
      // Get the image specific data
      for (Image img : images) {
        JsonObject im = new JsonObject();
        JsonObject th = new JsonObject();
        im.addParameter(Configuration.urlParam, cfg.imageRootUrl
            + img.getDirectory().getPath() + "/" + img.getName());
        imgList.addItem(im);
        th.addParameter(Configuration.urlParam, cfg.imageRootUrl
            + img.getDirectory().getPath() + "/"
            + Configuration.thumbDirName + "/" + img.getName());
        thumbList.addItem(th);
      }
      rsp.addParameter(Configuration.imgListParam, imgList);
View Full Code Here

        getServletContext().log(
            "No directory data for: " + path, ex);
      }

      // Create Json response
      JsonObject rsp = new JsonObject();
      // Get the directory specific data
      if ((directory != null) && (directory.isIndexingAllowedBoolean())) {
        if (directory.getDescription() != null) {
          rsp.addParameter(Configuration.dirDescParam, directory.getDescription());
        }
        if (directory.getLatitude() != null) {
          rsp.addParameter(Configuration.latParam, directory.getLatitude());
        }
        if (directory.getLongitude() != null) {
          rsp.addParameter(Configuration.lngParam, directory.getLongitude());
        }
        if (directory.getDate() != null) {
          rsp.addParameter(Configuration.dirDateParam, directory.getDate());
        }
        List<Attribute> dirAttributes = directory.getAttributes();
        if (dirAttributes != null) {
          JsonArray attributes = new JsonArray();
          for (Attribute attribute: dirAttributes) {
            attributes.addItem(attribute.getName());
          }
          rsp.addParameter(Configuration.attrParam, attributes);
        }
      }
      else {
        rsp.addParameter(Configuration.dirDescParam, JsonEntity.NULL);
      }
      getServletContext().log("Json response: " + rsp.toString());
      // Reply the Json response
      response.setContentType(Configuration.jsonContentType);
      response.setCharacterEncoding(Configuration.contentEncoding);
      PrintWriter out = response.getWriter();
      out.print(rsp.toString());
      out.flush();
    } catch (Exception ex) {
      getServletContext().log("Cannot GET directory data", ex);
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
View Full Code Here

      } catch (NoResultException ex) {
        getServletContext().log("No image data for: " + dir + " / " + name, ex);
      }

      // Get the image specific data and map it to a Json response
      JsonObject rsp = updateImageData(img);
      if (img != null) {
        rsp.addParameter(Configuration.descParam, img.getDescription())
        .addParameter(Configuration.ratingParam, img.getRating())
        .addParameter(Configuration.dateParam, img.getDate().toString());
        List<Attribute> imgAttributes = img.getAttributes();
        if (imgAttributes != null) {
          JsonArray attributes = new JsonArray();
          for (Attribute attribute: imgAttributes) {
            attributes.addItem(attribute.getName());
          }
          rsp.addParameter(Configuration.attrParam, attributes);
        }
      }
      else {
        rsp.addParameter(Configuration.descParam, JsonEntity.NULL)
        .addParameter(Configuration.ratingParam, Image.NOT_RATED)
        .addParameter(Configuration.dateParam, JsonEntity.NULL);
      }
      getServletContext().log("Json response: " + rsp.toString());
      // Reply the Json response
      response.setContentType(Configuration.jsonContentType);
      response.setCharacterEncoding(Configuration.contentEncoding);
      PrintWriter out = response.getWriter();
      out.print(rsp.toString());
      out.flush();
    } catch (AuthenticationException ex) {
      getServletContext().log("Unauthenticated user", ex);
      response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
      return;
View Full Code Here

   * @throws IOException
   * @throws ImageProcessingException
   * @throws MetadataException
   */
  public JsonObject updateImageData(Image image) throws IOException, ImageProcessingException {
    JsonObject imgData = new JsonObject();

    if (image != null) {
      File imageFile = new File(cfg.getImageRootPath() + image.getDirectory().getPath() + "\\\\" + image.getName());
      Metadata metadata = ImageMetadataReader.readMetadata(imageFile);
      // Un-comment to reverse engineer EXIF data structure (do not erase)
      //      for (com.drew.metadata.Directory directory: metadata.getDirectories()) {
      //        for (Tag tag : directory.getTags()) {
      //          cfg.getCtxt().log("" + tag);
      //        }
      //      }
      // retrieve jpeg tags if any
      JpegDirectory jpegDir = metadata.getDirectory(JpegDirectory.class);
      ExifSubIFDDirectory exifDir = metadata.getDirectory(ExifSubIFDDirectory.class);
      try {
        imgData.addParameter(Configuration.heigthParam, jpegDir.getImageHeight());
        imgData.addParameter(Configuration.widthParam, jpegDir.getImageWidth());
      }
      catch (MetadataException ex1) {
        imgData.addParameter(Configuration.heigthParam, exifDir.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT ));
        imgData.addParameter(Configuration.widthParam, exifDir.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH ));
      }

      //      try {
      //        SimpleDateFormat sdf = new SimpleDateFormat(Configuration.DATE_FORMAT);
      //        if (exifDir != null) {
View Full Code Here

      } catch (NoResultException ex) {
        getServletContext().log("No image data for: " + dir + " / " + name, ex);
      }

      // Get the image specific data and map it to a Json response
      JsonObject rsp = updateImageData(img);
      if (img != null) {
        rsp.addParameter(Configuration.descParam, img.getDescription())
        .addParameter(Configuration.ratingParam, img.getRating())
        .addParameter(Configuration.dateParam, img.getDate().toString());
        List<Attribute> imgAttributes = img.getAttributes();
        if (imgAttributes != null) {
          JsonArray attributes = new JsonArray();
          for (Attribute attribute: imgAttributes) {
            attributes.addItem(attribute.getName());
          }
          rsp.addParameter(Configuration.attrParam, attributes);
        }
      }
      else {
        rsp.addParameter(Configuration.descParam, JsonEntity.NULL)
        .addParameter(Configuration.ratingParam, Image.NOT_RATED)
        .addParameter(Configuration.dateParam, JsonEntity.NULL);
      }
      getServletContext().log("Json response: " + rsp.toString());
      // Reply the Json response
      response.setContentType(Configuration.jsonContentType);
      response.setCharacterEncoding(Configuration.contentEncoding);
      PrintWriter out = response.getWriter();
      out.print(rsp.toString());
      out.flush();
    } catch (AuthenticationException ex) {
      getServletContext().log("Unauthenticated user", ex);
      response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
      return;
View Full Code Here

   * @throws IOException
   * @throws ImageProcessingException
   * @throws MetadataException
   */
  public JsonObject updateImageData(Image image) throws IOException, ImageProcessingException {
    JsonObject imgData = new JsonObject();

    if (image != null) {
      File imageFile = new File(cfg.getImageRootPath() + image.getDirectory().getPath() + "\\\\" + image.getName());
      Metadata metadata = ImageMetadataReader.readMetadata(imageFile);
      // Un-comment to reverse engineer EXIF data structure (do not erase)
      //      for (com.drew.metadata.Directory directory: metadata.getDirectories()) {
      //        for (Tag tag : directory.getTags()) {
      //          cfg.getCtxt().log("" + tag);
      //        }
      //      }
      // retrieve jpeg tags if any
      JpegDirectory jpegDir = metadata.getDirectory(JpegDirectory.class);
      ExifSubIFDDirectory exifDir = metadata.getDirectory(ExifSubIFDDirectory.class);
      try {
        imgData.addParameter(Configuration.heigthParam, jpegDir.getImageHeight());
        imgData.addParameter(Configuration.widthParam, jpegDir.getImageWidth());
      }
      catch (MetadataException ex1) {
        imgData.addParameter(Configuration.heigthParam, exifDir.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT ));
        imgData.addParameter(Configuration.widthParam, exifDir.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH ));
      }

      //      try {
      //        SimpleDateFormat sdf = new SimpleDateFormat(Configuration.DATE_FORMAT);
      //        if (exifDir != null) {
View Full Code Here

TOP

Related Classes of org.myphotodiary.json.JsonObject

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.