Package com.itstherules.mediacentre.controller

Source Code of com.itstherules.mediacentre.controller.PhotosController

package com.itstherules.mediacentre.controller;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.itstherules.image.AWTImage;
import com.itstherules.image.IImage;
import com.itstherules.mediacentre.PathResolver;
import com.itstherules.stream.model.ItemsModel;


public class PhotosController extends BaseController {
 
  private static final String EXTENSIONS = ".jpg,.jpeg,.png";

  @Override
  public void list(Map<String, Object> parameters, HttpServletResponse response) throws IOException {
    ItemsModel itemsModel = new ItemsModel("photos", (String) parameters.get("directory"), EXTENSIONS);
    parameters.put("items", itemsModel.asList());
    merge("photos/list.freemarker", parameters, response.getWriter());
  }
 
 
  @Override
  public void show(Map<String, Object> parameters, HttpServletResponse response) throws IOException {
    merge("photos/show.freemarker", parameters, response.getWriter());
  }
 
  @Override
  public void update(Map<String, Object> parameters, HttpServletResponse response) throws IOException {
    String directory = (String) parameters.get("directory");
    String imageName = (String) parameters.get("image");
    IImage image = new AWTImage(PathResolver.resolve("photos/"+directory+"/"+imageName, PhotosController.class));
    image.rotate(getIntParameter(parameters.get("rotation")));
    image.scale(getIntParameter(parameters.get("width")), getIntParameter(parameters.get("height")), true, true);
    image.save();
    try {
      IImage thumbnailImage = new AWTImage(PathResolver.resolve("photos/"+directory+"/thumbnails/"+imageName, PhotosController.class));
        thumbnailImage.rotate(getIntParameter(parameters.get("rotation")));
        thumbnailImage.save();
    } catch(FileNotFoundException e){
    }
    PrintWriter writer = response.getWriter();
    writer.write("saved=true");
    writer.close();

  }


  private int getIntParameter(Object object) {
    return Integer.parseInt((String) object);
  }
}
TOP

Related Classes of com.itstherules.mediacentre.controller.PhotosController

TOP
Copyright © 2018 www.massapi.com. 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.