Author: julien(a)jboss.com
Date: 2007-02-22 08:53:56 -0500 (Thu, 22 Feb 2007)
New Revision: 6376
Modified:
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java
Log:
JBPORTAL-538 : packport of "CMSPortlet displays only in default page when link is
clicked on a different page."
Modified:
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java 2007-02-22
13:32:54 UTC (rev 6375)
+++
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java 2007-02-22
13:53:56 UTC (rev 6376)
@@ -51,6 +51,9 @@
/** . */
protected String targetWindowRef;
+ /** . */
+ public static String TARGET_WINDOW_REF;
+
public CMS getCMSService()
{
return CMSService;
@@ -63,12 +66,12 @@
public String getTargetWindowRef()
{
- return targetWindowRef;
+ return TARGET_WINDOW_REF;
}
public void setTargetWindowRef(String targetWindowRef)
{
- this.targetWindowRef = targetWindowRef;
+ TARGET_WINDOW_REF = targetWindowRef;
}
public ControllerCommand doMapping(ServerInvocation invocation, String
portalContextPath, String portalRequestPath)
Modified:
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java 2007-02-22
13:32:54 UTC (rev 6375)
+++
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java 2007-02-22
13:53:56 UTC (rev 6376)
@@ -29,6 +29,7 @@
import org.jboss.portal.cms.model.File;
import org.jboss.portal.cms.util.FileUtil;
import org.jboss.portal.core.cms.command.StreamContentCommand;
+import org.jboss.portal.core.cms.CMSObjectCommandFactory;
import org.jboss.portal.core.command.portlet.CoreInvocationContext;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portlet.JBossRenderResponse;
@@ -40,6 +41,7 @@
import javax.portlet.PortletSecurityException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.PortletURL;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
@@ -139,8 +141,11 @@
{
try
{
- // String linkMode = req.getPreferences().getValue("linkMode",
LINK_MODE_PORTLET);
-// boolean useCMSLink = LINK_MODE_CMS.equals(linkMode);
+ //
+ PortletInvocation invocation = ((JBossRenderResponse)resp).getInvocation();
+ boolean useFactoryURL =
invocation.getWindowContext().getId().equals(CMSObjectCommandFactory.TARGET_WINDOW_REF);
+
+ //
String path = req.getParameter("path");
if (path == null)
{
@@ -150,7 +155,7 @@
// Get the file from the CMS, localized.
Command fileGet;
- File file = null;
+ File file;
if (path == null)
{
fileGet = CMSService.getCommandFactory().createFileGetCommand(indexpage,
req.getLocale());
@@ -214,7 +219,7 @@
while (m.find())
{
String relURI = m.group(3) != null ? m.group(3) : m.group(4);
- String absoluteURI = this.buildURL(resp, "/" + relURI);
+ String absoluteURI = this.buildURL(resp, "/" + relURI,
useFactoryURL);
m.appendReplacement(buffer, "$1$2" +
FileUtil.cleanDoubleSlashes(absoluteURI) + "$2");
/* if(!relURI.startsWith("mailto") &&
!relURI.startsWith("http"))
{
@@ -250,12 +255,22 @@
* Rewrites urls. Typically, this is used for image src calls from the html, so they
route thru the
* CMSObjectCommandMapper and invoke the StreamObjectCommand.
*/
- public String buildURL(RenderResponse resp, String path)
+ public String buildURL(RenderResponse resp, String path, boolean useFactoryURL)
{
- StreamContentCommand cmd = new StreamContentCommand(path);
- PortletInvocation invocation = ((JBossRenderResponse)resp).getInvocation();
- CoreInvocationContext ccrc = (CoreInvocationContext)invocation.getContext();
- return ccrc.encodeURL(cmd, null, true);
+ useFactoryURL |= path.endsWith(".html") == false;
+ if (useFactoryURL)
+ {
+ StreamContentCommand cmd = new StreamContentCommand(path);
+ PortletInvocation invocation = ((JBossRenderResponse)resp).getInvocation();
+ CoreInvocationContext ccrc = (CoreInvocationContext)invocation.getContext();
+ return ccrc.encodeURL(cmd, null, true);
+ }
+ else
+ {
+ PortletURL url = resp.createRenderURL();
+ url.setParameter("path", path);
+ return url.toString();
+ }
}
public void doHelp(RenderRequest req, RenderResponse resp) throws IOException,
PortletException
@@ -276,23 +291,19 @@
}
/**
- *
- * @param originalContent
- * @return
- */
- private String cleanupContent(String content)
+ *
+ */
+ private String cleanupContent(String content)
+ {
+ //including content only between the <body> and </body>
+ if (content.toLowerCase().indexOf("<body") != -1)
{
- //including content only between the <body> and </body>
- if(content.toLowerCase().indexOf("<body")!=-1)
- {
- Matcher h = STRIP_TAGS_PATTERN.matcher(content);
- while (h.find())
- {
- content = h.group(2);
- }
- }
-
-
- return content;
+ Matcher h = STRIP_TAGS_PATTERN.matcher(content);
+ while (h.find())
+ {
+ content = h.group(2);
+ }
+ }
+ return content;
}
}