Author: sohil.shah(a)jboss.com
Date: 2008-07-16 11:12:33 -0400 (Wed, 16 Jul 2008)
New Revision: 11468
Modified:
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
Log:
JBPORTAL-2008 - adding an image from CMS to dashboard renders image's binary
representation
Modified:
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2008-07-16
14:57:17 UTC (rev 11467)
+++
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2008-07-16
15:12:33 UTC (rev 11468)
@@ -231,33 +231,57 @@
resp.setContentType("text/html");
if (file != null)
{
- sHTML = file.getContent().getContentAsString();
-
- // clean html and body tags
- sHTML = this.cleanupContent(sHTML);
-
- // begin modifying links
- StringBuffer buffer = new StringBuffer();
- Matcher m = RELATIVE_URI_PATTERN.matcher(sHTML);
- while (m.find())
+ if(file.getContent().getMimeType().startsWith("image/"))
{
- String relURI = m.group(3) != null ? m.group(3) : m.group(4);
- URLFactory urlFactory = resourceURLFactory;
- if (relURI.endsWith(".html"))
+ String imageURI = path;
+ if(imageURI.startsWith("/"))
{
- urlFactory = textURLFactory;
+ imageURI = path.substring(1);
}
- String absoluteURI = urlFactory.createURL("/" + relURI);
- m.appendReplacement(buffer, "$1$2" +
FileUtil.cleanDoubleSlashes(absoluteURI) + "$2");
+ String absoluteImageURI = resourceURLFactory.createURL("/" +
imageURI);
+ sHTML = "<img
src='"+absoluteImageURI+"'/>";
}
- m.appendTail(buffer);
- sHTML = buffer.toString();
-
- // use the content's title, if exists.
- if (file.getContent().getTitle() != null &&
!"".equals(file.getContent().getTitle()))
+ else if(file.getContent().getMimeType().startsWith("text/"))
{
- resp.setTitle(file.getContent().getTitle());
+ sHTML = file.getContent().getContentAsString();
+
+ // clean html and body tags
+ sHTML = this.cleanupContent(sHTML);
+
+ // begin modifying links
+ StringBuffer buffer = new StringBuffer();
+ Matcher m = RELATIVE_URI_PATTERN.matcher(sHTML);
+ while (m.find())
+ {
+ String relURI = m.group(3) != null ? m.group(3) : m.group(4);
+ URLFactory urlFactory = resourceURLFactory;
+ if (relURI.endsWith(".html"))
+ {
+ urlFactory = textURLFactory;
+ }
+ String absoluteURI = urlFactory.createURL("/" + relURI);
+ m.appendReplacement(buffer, "$1$2" +
FileUtil.cleanDoubleSlashes(absoluteURI) + "$2");
+ }
+ m.appendTail(buffer);
+ sHTML = buffer.toString();
+
+ // use the content's title, if exists.
+ if (file.getContent().getTitle() != null &&
!"".equals(file.getContent().getTitle()))
+ {
+ resp.setTitle(file.getContent().getTitle());
+ }
}
+ else
+ {
+ //Show a link to this resource which opens up in a new window upon
clicking
+ String resourceURI = path;
+ if(resourceURI.startsWith("/"))
+ {
+ resourceURI = path.substring(1);
+ }
+ String absoluteResourceURI = resourceURLFactory.createURL("/" +
resourceURI);
+ sHTML = "<a href='"+absoluteResourceURI+"'
target='_blank'>"+file.getContent().getTitle()+"</a>";
+ }
}
else
{