Author: abelevich
Date: 2009-04-08 08:40:06 -0400 (Wed, 08 Apr 2009)
New Revision: 13428
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
Log:
change direct link creation
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-04-08
11:44:03 UTC (rev 13427)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-04-08
12:40:06 UTC (rev 13428)
@@ -49,8 +49,6 @@
private static final String IMAGE_DIRECT_LINK =
"/includes/directImage.seam?imageId=";
- private static String imageDirectLinkPrefix;
-
@In IImageAction imageAction;
@In FileManager fileManager;
@@ -110,29 +108,43 @@
}
public String getImageDirectLink(Image image) {
- if (imageDirectLinkPrefix == null) {
- FacesContext context = FacesContext.getCurrentInstance();
- if (context == null) {
- return null;
- }
- ExternalContext extc = context.getExternalContext();
- if (extc == null) {
- return null;
- }
-
- //TODO nick - see
org.ajax4jsf.renderkit.RendererUtils#encodeResourceURL(TemplateContext, Object)
- 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;
- }
- }
+ String directLink = null;
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ if (context == null) {
+ return null;
}
- return imageDirectLinkPrefix + image.getId();
- }
+
+ String value = context.getApplication().getViewHandler().getResourceURL(context,
IMAGE_DIRECT_LINK + image.getId());
+
+ ExternalContext externalContext = context.getExternalContext();
+ String relativeURL = externalContext.encodeResourceURL(value);
+ Object request = externalContext.getRequest();
+
+ if(request instanceof HttpServletRequest) {
+ directLink = createServerURL((HttpServletRequest)request) + relativeURL;
+ }
+
+ return directLink;
+
+ }
+
+ protected String createServerURL(HttpServletRequest request) {
+ StringBuffer url = new StringBuffer();
+
+ if(request != null) {
+ String name = request.getServerName();
+ String protocol = (request.getProtocol().split("/"))[0].toLowerCase();
+
+ int port = request.getServerPort();
+
+ url.append(protocol);
+ url.append("://");
+ url.append(name);
+ url.append(":");
+ url.append(Integer.toString(port));
+ }
+
+ return url.toString();
+ }
}
Show replies by date