Author: andrei_exadel
Date: 2009-03-11 09:49:58 -0400 (Wed, 11 Mar 2009)
New Revision: 12921
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java
Log:
getDirectImageLink method added
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-03-11
13:44:03 UTC (rev 12920)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-03-11
13:49:58 UTC (rev 12921)
@@ -35,6 +35,7 @@
import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.Constants;
import org.richfaces.realworld.service.IImageAction;
+import org.richfaces.realworld.util.DirectLinkHelper;
@Name("imageManager")
@Scope(ScopeType.CONVERSATION)
@@ -51,6 +52,9 @@
@In
private User user;
+ @In(create=true)
+ private DirectLinkHelper directLink;
+
public void deleteImage(Image image){
String imagePath = image.getPath();
imageAction.deleteImage(image);
@@ -86,4 +90,8 @@
Events.instance().raiseEvent(Constants.CLEAR_EDITOR_EVENT, "");
}
+ public String getImageDirectLink(Image image) {
+ return directLink.getDirectImageLink(image.getId());
+ }
+
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java 2009-03-11
13:44:03 UTC (rev 12920)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java 2009-03-11
13:49:58 UTC (rev 12921)
@@ -8,8 +8,11 @@
import java.io.InputStream;
import java.io.OutputStream;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
import javax.imageio.ImageIO;
import javax.persistence.EntityManager;
+import javax.servlet.http.HttpServletRequest;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
@@ -32,7 +35,12 @@
protected Long imageId;
private Long id;
+
+ private static final String IMAGE_DIRECT_LINK =
"/includes/directImage.seam?imageId=";
+
+ private static String imageDirectLinkPrefix;
+
public synchronized void paintImage(OutputStream out, Object data)
throws IOException {
Image im = em.find(Image.class, id);
@@ -64,4 +72,30 @@
public void start(){
id=imageId;
}
+
+ public String getDirectImageLink(Long id) {
+ if (imageDirectLinkPrefix == null) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ if (context == null) {
+ return null;
+ }
+ ExternalContext extc = context.getExternalContext();
+ if (extc == null) {
+ return null;
+ }
+
+ Object request = extc.getRequest();
+
+ if (request instanceof HttpServletRequest) {
+ HttpServletRequest servletRequest = (HttpServletRequest)request;
+ String contextPath = servletRequest.getContextPath();
+ StringBuffer url = servletRequest.getRequestURL();
+ int i = url.indexOf(contextPath);
+ if (i > 0) {
+ imageDirectLinkPrefix = url.substring(0, i) + contextPath + IMAGE_DIRECT_LINK;
+ }
+ }
+ }
+ return imageDirectLinkPrefix + id;
+ }
}
\ No newline at end of file
Show replies by date