portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smi...@apache.org
Subject svn commit: r477288 - in /portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed: desktop/core.js widget/PortletWindow.js
Date Mon, 20 Nov 2006 18:55:48 GMT
Author: smilek
Date: Mon Nov 20 10:55:47 2006
New Revision: 477288

URL: http://svn.apache.org/viewvc?view=rev&rev=477288
Log:
PortletWindow.setPortletContent now uses 0.4.0 dojo code to process portlet script content;
added navigation to category-portlet-selector via 'plus' button

Modified:
    portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/desktop/core.js
    portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/widget/PortletWindow.js

Modified: portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/desktop/core.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/desktop/core.js?view=diff&rev=477288&r1=477287&r2=477288
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/desktop/core.js (original)
+++ portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/desktop/core.js Mon Nov 20 10:55:47
2006
@@ -181,7 +181,7 @@
 //jetspeed.debugContentDumpIds = [ "page-.*" ];                   // dump page psml response
 //jetspeed.debugContentDumpIds = [ "addportlet" ];                // dump portlet selector
response
 //jetspeed.debugContentDumpIds = [ "P-10acd169a40-10001", "P-10acd169a40-10000" ];
-jetspeed.debugContentDumpIds = [ "notifyGridSelect", "P-10acd169a40-10001", "reports-select"
];
+jetspeed.debugContentDumpIds = [ "notifyGridSelect", "P-10acd169a40-10001", "reports-select",
"P-10ea50cab5b-10001" ];
 
 // ... load page /portlets
 jetspeed.page = null ;
@@ -671,6 +671,7 @@
     JETSPEED: null,   //   /jetspeed
     AJAX_API: null,   //   /jetspeed/ajaxapi
     DESKTOP: null,    //   /jetspeed/desktop
+    PORTAL: null,     //   /jetspeed/portal
     PORTLET: null,    //   /jetspeed/portlet
     initialized: false
 };
@@ -711,6 +712,7 @@
     jetspeed.url.path.SERVER = serverUri;
     jetspeed.url.path.AJAX_API = jetspeed.url.path.JETSPEED + "/ajaxapi";
     jetspeed.url.path.DESKTOP = jetspeed.url.path.JETSPEED + "/desktop";
+    jetspeed.url.path.PORTAL = jetspeed.url.path.JETSPEED + "/portal";
     jetspeed.url.path.PORTLET = jetspeed.url.path.JETSPEED + "/portlet";
     
     jetspeed.url.path.initialized = true;
@@ -2104,7 +2106,15 @@
     pageActionProcess: function( /* String */ actionName, evt )
     {
         if ( actionName == null ) return;
-        alert( "pageActionProcess: " + actionName + " - not yet implemented" );
+        if ( actionName == "addportlet" )
+        {
+            var addportletPageUrl = jetspeed.url.path.SERVER + jetspeed.url.path.DESKTOP
+ "/system/customizer/selector.psml?" + this.getPath();
+            jetspeed.pageNavigate( addportletPageUrl ); 
+        }
+        else
+        {
+            alert( "pageActionProcess: " + actionName + " - not yet implemented" );
+        }
     },
 
 
@@ -2364,10 +2374,6 @@
         return { url: justTheUrl, operation: op, portletEntityId: entityId };
     },
 
-    preParseAnnotateHtml: function( /* String */ portletContent )
-    {
-        return jetspeed.ui.preParseAnnotateHtml( portletContent );
-    },
     postParseAnnotateHtml: function( /* DOMNode */ containerNode )
     {   
         if ( containerNode )
@@ -3882,59 +3888,6 @@
     var nWidget = dojo.widget.createWidget( "jetspeed:PortletWindow", createWidgetParams
);
     
     return nWidget;
-};
-
-jetspeed.ui.preParseAnnotateHtml = function( /* String */ initialHtmlStr, /* String */ url
)
-{   // deal with embedded script tags -  /=/=/=/=/=  taken from dojo ContentPane.js  splitAndFixPaths()
 =/=/=/=/=/
-    var scripts = [];
-    var remoteScripts = [];
-    // cut out all script tags, stuff them into scripts array
-    var match = [];
-    while ( match )
-    {
-        match = initialHtmlStr.match(/<script([^>]*)>([\s\S]*?)<\/script>/i);
-        if(!match){ break; }
-        if(match[1]){
-            attr = match[1].match(/src=(['"]?)([^"']*)\1/i);
-            if ( attr )
-            {
-                // remove a dojo.js or dojo.js.uncompressed.js from remoteScripts
-                if ( (attr[2].search(/\/?\bdojo.js(?:\.uncompressed.js)?/i) != -1) &&
(dojo.hostenv.getBaseScriptUri() == attr[2].match(/[.\/]*/)[0]) )
-                {	
-                    dojo.debug("Security note! inhibit:"+attr[2]+" from  beeing loaded again.");
-                }
-                else
-                {
-                    remoteScripts.push( attr[2] );
-                }
-            }
-        }
-        if ( match[2] )
-        {
-            // get rid of html comment blanket
-            var scriptText = match[2].replace(/^\s*<!--/, "");
-            scriptText = scriptText.replace(/-->\s*$/, "");
-
-            scriptText = scriptText.replace(/function\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/g,
"window.$1 = function(" );
-
-            // strip out all djConfig variables from script tags nodeValue
-            // this is ABSOLUTLY needed as reinitialize djConfig after dojo is initialised
-            // makes a dissaster greater than Titanic                
-            scripts.push(scriptText.replace(/(?:var )?\bdjConfig\b(?:[\s]*=[\s]*\{[^}]+\}|\.[\w]*[\s]*=[\s]*[^;\n]*)?;?|dojo.hostenv.writeIncludes\(\s*\);?/g,
""));
-        }
-        initialHtmlStr = initialHtmlStr.replace(/<script[^>]*>[\s\S]*?<\/script>/i,
"");
-    }
-    //dojo.debug( "= = = = = =  annotated content for: " + ( url ? url : "unknown url" )
);
-    //dojo.debug( initialHtmlStr );
-    //if ( scripts.length > 0 )
-    //{
-    //    dojo.debug( "      = = =  script content for: " + ( url ? url : "unknown url" )
);
-    //    for ( var i = 0 ; i < scripts.length; i++ )
-    //        dojo.debug( "      =[" + (i+1) + "]:" + scripts[i] );
-    //}
-    //     /=/=/=/=/=  end of taken from dojo ContentPane.js  splitAndFixPaths()  =/=/=/=/=/
-    //dojo.debug( "preParse  scripts: " + ( scripts ? scripts.length : "0" ) + " remoteScripts:
" + ( remoteScripts ? remoteScripts.length : "0" ) );
-    return { preParsedContent: initialHtmlStr, preParsedScripts: scripts, preParsedRemoteScripts:
remoteScripts };
 };
 
 // ... fade-in convenience methods (work with set of nodes)

Modified: portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/widget/PortletWindow.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/widget/PortletWindow.js?view=diff&rev=477288&r1=477287&r2=477288
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/widget/PortletWindow.js (original)
+++ portals/jetspeed-2/trunk/src/webapp/javascript/jetspeed/widget/PortletWindow.js Mon Nov
20 10:55:47 2006
@@ -61,6 +61,11 @@
     lastUntiledPositionInfo: null,
     lastTiledPositionInfo: null,
 
+    // see setPortletContent for info on these ContentPane settings:
+    executeScripts: false,
+    scriptSeparation: false,
+    adjustPaths: false,
+
     /*  static   */
     staticDefineAsAltInitParameters: function( defineIn, params )
     {
@@ -1614,56 +1619,109 @@
         {
             initialHtmlStr = '<div class="PContent" >' + initialHtmlStr + '</div>';
  // BOZO: get this into the template ?
         }
-        var ppR = null;
-        if ( this.portlet )
-        {
-            ppR = this.portlet.preParseAnnotateHtml( initialHtmlStr, url );
-        }
-        else
-        {
-            ppR = jetspeed.ui.preParseAnnotateHtml( initialHtmlStr, url );
-        }
-        //this.executeScripts = true;
 
-        var setContentObj = { titles: [], scripts: ppR.preParsedScripts, linkStyles: [],
styles: [], remoteScripts: ppR.preParsedRemoteScripts, xml: ppR.preParsedContent, url: url,
requires: [] };
+        /* IMPORTANT:
+              We are avoiding a call to ContentPane.splitAndFixPaths for these reasons:
+                  - it does more than we need (wasting time)
+                  - we want to use its script processing but we don't need executeScripts
to be set to false
+
+              So we have copied the script processing code from ContentPane.splitAndFixPaths
(0.4.0), and we call our copy here.
+
+              We set executeScripts=false to delay script execution until after call to dojo.widget.getParser().createSubComponents
+                  - this allows dojo.addOnLoad to work normally
+                  - we call ContentPane._executeScripts after calling ContentPane.setContent
(which calls createSubComponents)
+
+              We set scriptSeparation=false to opt-out of support for scoping scripts to
ContentPane widget instance
+                  - this feature, while cool, requires script modification in most cases
(e.g. if one of your scripts calls another)
+                  
+              Although we don't call ContentPane.splitAndFixPaths, it is notable that adjustPaths=false
is likely correct for portlet content
+                  - e.g. when set to true, security-permissions.css is still fetched but
not used (not affected by scriptSeparation)
+
+              A better use of ContentPane features, particularly, scriptSeparation=true,
can be accomplished as follows:
+                  - code: 
+                          this.executeScripts = true;
+                          this.scriptSeparation = true;
+                          this.adjustPaths = false;
+                          this.setContent( initialHtmlStr );
+
+                  - this requires script content to follow the conventions shown in: security/permissions/view-dojo-scriptScope.vm,
+                    which works in both portal and desktop, should allow (at least with scripts
name collisions), coexistence
+                    of multiple instances of same portlet (with permissions there would be
id collisions among widgets)
+        */
 
+        var setContentObj = this._splitAndFixPaths_scriptsonly( initialHtmlStr, url );
+        
         this.setContent( setContentObj );
+        this._executeScripts( setContentObj.scripts );
 
-        if ( setContentObj.scripts && setContentObj.scripts.length > 0 )
-        {   // do inline scripts  - taken from dojo ContentPane.js _executeScripts
-		    var repl = null;
-		    for( var i = 0; i < setContentObj.scripts.length; i++ )
-            {
-			    // not sure why comment and carraige return clean is needed
-			    // but better safe than sorry so we keep it, Fredrik
-			    // Clean up content: remove inline script  comments
-                repl = new RegExp('//.*?$', 'gm');
-			    setContentObj.scripts[i] = setContentObj.scripts[i].replace(repl, '\n');
-	
-
-                // BOZO: despite the comment above from the dojo code, we cannot do this
(carriage returns are syntatically required in javascript)
-			    // Clean up content: remove carraige returns
-			    //repl = new RegExp('[\n\r]', 'g');
-			    //setContentObj.scripts[i] = setContentObj.scripts[i].replace(repl, ' ');
-            
-			    // Execute commands
-                
-                if ( jetspeed.debug.setPortletContent )
-                    dojo.debug( "setPortletContent [" + ( this.portlet ? this.portlet.entityId
: this.widgetId ) + "] script: " + setContentObj.scripts[i] );
-                
-			    eval( setContentObj.scripts[i] );
-		    }
-        }
-        else
-        {
-            if ( jetspeed.debug.setPortletContent )
-                dojo.debug( "setPortletContent [" + ( this.portlet ? this.portlet.entityId
: this.widgetId ) + "]" );
-        }
-        
-        this._executeScripts( { scripts: [], remoteScripts: setContentObj.remoteScripts }
);
+        if ( jetspeed.debug.setPortletContent )
+            dojo.debug( "setPortletContent [" + ( this.portlet ? this.portlet.entityId :
this.widgetId ) + "]" );
 
         if ( this.portlet )
             this.portlet.postParseAnnotateHtml( this.containerNode );
+    },
+
+    _splitAndFixPaths_scriptsonly: function( /* String */ s, /* String */ url )
+    {
+        var forcingExecuteScripts = true;
+        var scripts = [] ;
+        // deal with embedded script tags 
+        // /=/=/=/=/=  begin  ContentPane.splitAndFixPaths   code  =/=/=/=/=/
+        //   - only modification is: replacement of "this.executeScripts" with "forcingExecuteScripts"
+        //
+				var regex = /<script([^>]*)>([\s\S]*?)<\/script>/i;
+				var regexSrc = /src=(['"]?)([^"']*)\1/i;
+				var regexDojoJs = /.*(\bdojo\b\.js(?:\.uncompressed\.js)?)$/;
+				var regexInvalid = /(?:var )?\bdjConfig\b(?:[\s]*=[\s]*\{[^}]+\}|\.[\w]*[\s]*=[\s]*[^;\n]*)?;?|dojo\.hostenv\.writeIncludes\(\s*\);?/g;
+				var regexRequires = /dojo\.(?:(?:require(?:After)?(?:If)?)|(?:widget\.(?:manager\.)?registerWidgetPackage)|(?:(?:hostenv\.)?setModulePrefix|registerModulePath)|defineNamespace)\((['"]).*?\1\)\s*;?/;
+
+				while(match = regex.exec(s)){
+					if(forcingExecuteScripts && match[1]){
+						if(attr = regexSrc.exec(match[1])){
+							// remove a dojo.js or dojo.js.uncompressed.js from remoteScripts
+							// we declare all files named dojo.js as bad, regardless of path
+							if(regexDojoJs.exec(attr[2])){
+								dojo.debug("Security note! inhibit:"+attr[2]+" from  being loaded again.");
+							}else{
+								scripts.push({path: attr[2]});
+							}
+						}
+					}
+					if(match[2]){
+						// remove all invalid variables etc like djConfig and dojo.hostenv.writeIncludes()
+						var sc = match[2].replace(regexInvalid, "");
+    						if(!sc){ continue; }
+		
+						// cut out all dojo.require (...) calls, if we have execute 
+						// scripts false widgets dont get there require calls
+						// takes out possible widgetpackage registration as well
+						while(tmp = regexRequires.exec(sc)){
+							requires.push(tmp[0]);
+							sc = sc.substring(0, tmp.index) + sc.substr(tmp.index + tmp[0].length);
+						}
+						if(forcingExecuteScripts){
+							scripts.push(sc);
+						}
+					}
+					s = s.substr(0, match.index) + s.substr(match.index + match[0].length);
+				}
+        // /=/=/=/=/=  end  ContentPane.splitAndFixPaths   code  =/=/=/=/=/
+
+        //dojo.debug( "= = = = = =  annotated content for: " + ( url ? url : "unknown url"
) );
+        //dojo.debug( initialHtmlStr );
+        //if ( scripts.length > 0 )
+        //{
+        //    dojo.debug( "      = = =  script content for: " + ( url ? url : "unknown url"
) );
+        //    for ( var i = 0 ; i < scripts.length; i++ )
+        //        dojo.debug( "      =[" + (i+1) + "]:" + scripts[i] );
+        //}
+        //dojo.debug( "preParse  scripts: " + ( scripts ? scripts.length : "0" ) + " remoteScripts:
" + ( remoteScripts ? remoteScripts.length : "0" ) );
+        return {"xml": 		    s, // Object
+				"styles":		[],
+				"titles": 		[],
+				"requires": 	[],
+				"scripts": 		scripts,
+				"url": 			url};
     }
 });
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message