Author: taylor
Date: Tue Dec 19 15:16:43 2006
New Revision: 488849

URL: http://svn.apache.org/viewvc?view=rev&rev=488849
Log:
Jetspeed SSO Web Content improved functionality
* fix HTTPS support
* handle onclick javascript rules

contribution from Tom Campbell and Joe Kueser

Modified:
    
portals/jetspeed-2/trunk/applications/demo/src/webapp/WEB-INF/conf/default-rewriter-rules.xml
    
portals/jetspeed-2/trunk/components/rewriter/src/java/org/apache/jetspeed/rewriter/WebContentRewriter.java

Modified: 
portals/jetspeed-2/trunk/applications/demo/src/webapp/WEB-INF/conf/default-rewriter-rules.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/demo/src/webapp/WEB-INF/conf/default-rewriter-rules.xml?view=diff&rev=488849&r1=488848&r2=488849
==============================================================================
--- 
portals/jetspeed-2/trunk/applications/demo/src/webapp/WEB-INF/conf/default-rewriter-rules.xml
 (original)
+++ 
portals/jetspeed-2/trunk/applications/demo/src/webapp/WEB-INF/conf/default-rewriter-rules.xml
 Tue Dec 19 15:16:43 2006
@@ -66,8 +66,11 @@
 <tag id='td'>
     <attribute id='background' rule='base'/>
 </tag>
+<tag id='td'>
+    <attribute id='onclick' rule='base'/>
+</tag>
 
-<!-- sample rules -->
+    <!-- sample rules -->
 <rule id='portal-popup' popup='true' use-base='true' suffix='/portal' 
ignore-prefixes='javascript:,mailto:'/>
 <rule id='test' use-base='false' suffix='/whatever&amp;xxx=1' popup='1'/>
 

Modified: 
portals/jetspeed-2/trunk/components/rewriter/src/java/org/apache/jetspeed/rewriter/WebContentRewriter.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/rewriter/src/java/org/apache/jetspeed/rewriter/WebContentRewriter.java?view=diff&rev=488849&r1=488848&r2=488849
==============================================================================
--- 
portals/jetspeed-2/trunk/components/rewriter/src/java/org/apache/jetspeed/rewriter/WebContentRewriter.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/rewriter/src/java/org/apache/jetspeed/rewriter/WebContentRewriter.java
 Tue Dec 19 15:16:43 2006
@@ -14,7 +14,7 @@
  */
 package org.apache.jetspeed.rewriter;
 
-import java.net.URL;
+import java.util.StringTokenizer;
 
 import javax.portlet.PortletURL;
 
@@ -26,6 +26,13 @@
  */
 public class WebContentRewriter extends RulesetRewriterImpl implements Rewriter
 {
+    /* (non-Javadoc)
+    * @see 
org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#convertTagEvent(java.lang.String,
 org.xml.sax.Attributes)
+    */
+    public void enterConvertTagEvent(String tagid, MutableAttributes 
attributes) {
+        super.enterConvertTagEvent(tagid, attributes);
+    }
+
     /** parameters that need to be propagated in the action URL (since HTTP 
request parameters will not be available) */
     public static final String ACTION_PARAMETER_URL    = "_AP_URL";
     public static final String ACTION_PARAMETER_METHOD = "_AP_METHOD";
@@ -62,21 +69,8 @@
     public String rewriteUrl(String url, String tag, String attribute, 
MutableAttributes otherAttributes)
     {
          String modifiedURL = url;
-        
-        // Any relative URL needs to be converted to a full URL
-        if (url.startsWith("/") || (!url.startsWith("http:") && 
!url.startsWith("https:"))) 
-        {
-            if (this.getBaseUrl() != null)
-            {
-                modifiedURL = getBaseRelativeUrl(url) ;
-                // System.out.println("WebContentRewriter.rewriteUrl() - 
translated URL relative to base URL - result is: "+modifiedURL);
-               }
-            else
-            {
-                modifiedURL = url; // leave as is
-               }
-        }
-         
+        modifiedURL = getModifiedURL(url);
+
         // translate "submit" URL's as actions
         //  <A href="..."/>
         //  <FORM submit="..."/>
@@ -98,10 +92,67 @@
                     modifiedURL = actionURL.toString();
                 }
         }
+
+        // Deal with links in an "onclick".
+        if (attribute.equalsIgnoreCase("onclick"))
+        {
+            // Check for onclick with location change
+            for (int i=0; i < otherAttributes.getLength(); i++) {
+
+                String name = otherAttributes.getQName(i);
+
+                if (name.equalsIgnoreCase("onclick")) {
+
+                    String value = otherAttributes.getValue(i);
+
+                    int index = value.indexOf(".location=");
+                    if (index >= 0) {
+                        String oldLocation = value.substring(index + 
".location=".length());
+                        StringTokenizer tokenizer = new 
StringTokenizer(oldLocation, "\'\"");
+                        oldLocation = tokenizer.nextToken();
+
+                        modifiedURL = oldLocation;
+                        url = oldLocation;
+                        modifiedURL = getModifiedURL(url);
+
+                        // Regular URL just add a portlet action
+                        if (this.actionURL != null)
+                        {
+                            // create Action URL
+                            actionURL.setParameter(ACTION_PARAMETER_URL, 
modifiedURL);
+                            modifiedURL = actionURL.toString();
+                        }
+
+
+                        modifiedURL = value.replaceAll(oldLocation, 
modifiedURL);
+                    }
+                }
+            }
+
+
+        }
         
         // if ( !url.equalsIgnoreCase( modifiedURL ))
         //     System.out.println("WebContentRewriter.rewriteUrl() - In tag: 
"+tag+", for attribute: "+attribute+", converted url: "+url+", to: 
"+modifiedURL+", base URL was: "+getBaseUrl());
 
+        return modifiedURL;
+    }
+
+    private String getModifiedURL(String url) {
+        String modifiedURL = url;
+        // Any relative URL needs to be converted to a full URL
+        if (url.startsWith("/") || (!url.startsWith("http:") && 
!url.startsWith("https:")))
+        {
+            if (this.getBaseUrl() != null)
+            {
+                modifiedURL = getBaseRelativeUrl(url) ;
+                // System.out.println("WebContentRewriter.rewriteUrl() - 
translated URL relative to base URL - result is: "+modifiedURL);
+               }
+            else
+            {
+                modifiedURL = url; // leave as is
+               }
+        }
         return modifiedURL;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to