-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b052c8c
commit f9c2e40
Showing
12 changed files
with
282 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/net/feminaexlux/gallery/struts2/controller/ImageLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.feminaexlux.gallery.struts2.controller; | ||
|
||
import net.feminaexlux.gallery.struts2.model.Image; | ||
import net.feminaexlux.gallery.struts2.service.ImageService; | ||
import net.feminaexlux.gallery.struts2.utility.StringUtility; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.struts2.ServletActionContext; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
public class ImageLoader extends Controller { | ||
private static final Logger LOG = LogManager.getLogger(ImageLoader.class); | ||
|
||
@Autowired | ||
private ImageService imageService; | ||
|
||
private int imageId; | ||
private String imageType; | ||
|
||
public String image() { | ||
if (imageId > 0 && StringUtility.isNotEmpty(imageType)) { | ||
try { | ||
Image image = imageService.getImage(imageId, imageType); | ||
HttpServletResponse response = ServletActionContext.getResponse(); | ||
response.setHeader("Content-Disposition", "attachment;filename=" + image.getName()); | ||
response.setContentType(image.getContentType()); | ||
response.setContentLength(image.getImage().length); | ||
|
||
OutputStream outputStream = response.getOutputStream(); | ||
outputStream.write(image.getImage()); | ||
outputStream.flush(); | ||
outputStream.close(); | ||
} catch (IOException ioException) { | ||
LOG.error("Error uploading file {}\n{}", imageId, ioException); | ||
} | ||
} | ||
|
||
return SUCCESS; | ||
} | ||
|
||
public String thumbnail() { | ||
return SUCCESS; | ||
} | ||
|
||
public void setImageId(int imageId) { | ||
this.imageId = imageId; | ||
} | ||
|
||
public void setImageType(String imageType) { | ||
this.imageType = imageType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/net/feminaexlux/gallery/struts2/service/ImageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package net.feminaexlux.gallery.struts2.service; | ||
|
||
import net.feminaexlux.gallery.struts2.model.Image; | ||
import net.feminaexlux.gallery.struts2.model.ResourceType; | ||
|
||
import java.util.List; | ||
|
||
public class ImageService extends ResourceService { | ||
public Image getImage(int id) { | ||
return super.get(id, ResourceType.IMAGE, Image.class); | ||
} | ||
|
||
public Image getImage(int id, String type) { | ||
return super.get(id, type, Image.class); | ||
} | ||
|
||
public List<Image> getAll() { | ||
return resourceDAO.findAll(Image.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.