PAL Portal (J2 デスクトップの調査)

続き・・・

jetspeed.url.retrieveContentは既に確認しているので、詳細は飛ばすが、jetspeed.url.retrieveContentはアクセスに成功すると、contentListener.notifySuccess( data, requestUrl, domainModelObject ) ;を呼び出す。ここで、contentListenerは、PortletContentListenerなので、

jetspeed.om.PortletContentListener.prototype =
{
notifySuccess: function( /* String */ portletContent, /* String */ requestUrl, /* Portlet */ portlet )
{
portlet.setPortletContent( portletContent, requestUrl );
},
notifyFailure: function( /* String */ type, /* String */ error, /* String */ requestUrl, /* Portlet */ portlet )
{
dojo.debug( "PortletContentListener notifyFailure url=" + requestUrl + " type=" + type + " error=" + error ) ;
}
};

portletContentはStringっぽいな。retrieveContentでmimeTypeがtext/htmlとしてアクセスしたからかね。setPortletContentを見てみよう。

setPortletContent: function( portletContent, renderUrl )
{
var windowWidget = this.getPortletWindow();
if ( windowWidget )
{
windowWidget.setPortletContent( portletContent, renderUrl );
}
},

まず、getPortletWindowは

getPortletWindow: function()
{
var windowWidgetId = this.getProperty( jetspeed.id.PORTLET_PROP_WIDGET_ID );
if ( windowWidgetId )
return dojo.widget.byId( windowWidgetId );
return null;
},

dojoのポートレットウィンドウのウィジェットを取得しているのね。それをsetPortletContentに戻して、そのウィジェットのsetPortletContentを見てみると、

setPortletContent: function( html, url )
{
var initialHtmlStr = html.toString();
if ( ! this.getInitProperty( jetspeed.id.PORTLET_PROP_EXCLUDE_PCONTENT ) )
{
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: [] };
this.setContent( setContentObj );
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 ( this.portlet )
this.portlet.postParseAnnotateHtml( this.containerNode );
}

まず、始めのif文は、jetspeed.id.PORTLET_PROP_EXCLUDE_PCONTENTはnullだろうから、入って、ポートレットのコンテンツに対して、PContentクラスを持つ div タグを追加するだろう。

次に、this.portletはnullでないので、this.portlet.preParseAnnotateHtmlを実行。

preParseAnnotateHtml: function( /* String */ portletContent )
{
return jetspeed.ui.preParseAnnotateHtml( portletContent );
},

jetspeed.ui.preParseAnnotateHtmlは、

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 };
};

やっていることをまとめると、ポートレットのコンテンツにJavaScriptのタグが含まれているなら、それをscriptsかremoteScriptsに入れる。remoteScriptsはjsファイルみたいな呼び出しをされていた場合みたいだな。

それがポートレットウィンドウのsetPortletContentでppRにセットする。そしたら、setContentObjを作成して、setContentを呼び出す。このsetContentはdojo.widget.html.ContentPaneのメソッド。コンテンツは、ここで、this.containerNodeまたはthis.domNodeにくっつけることになる。続いて、javascriptの処理。まず、scriptタグで記述されているスクリプトを順にevalで実行。続いて、src属性でscriptタグにあるものをthis._executeScriptsに渡す。この_executeScriptsもdojo.widget.html.ContentPaneのメソッド。dojo.io.bindを使って、取得して処理するようだ。そして、最後に、this.portlet.postParseAnnotateHtmlを実行。

postParseAnnotateHtml: function( /* DOMNode */ containerNode )
{
if ( containerNode )
{
var cNode = containerNode;
var formList = cNode.getElementsByTagName( "form" );
var debugOn = jetspeed.debug.postParseAnnotateHtml;
if ( formList )
{
for ( var i = 0 ; i < formList.length ; i++ )
{
var cForm = formList[i];
var cFormAction = cForm.action;
var cFormPortletEntityId = this.entityId;  // BOZO:can I assume that it is always my entity-id (ignoring the one in parsedPseudoUrl)
var parsedPseudoUrl = this.parseJSPseudoUrlActionRender( cFormAction );
var submitOperation = parsedPseudoUrl.operation;
if ( submitOperation == this.PORTLET_REQUEST_ACTION || submitOperation == this.PORTLET_REQUEST_RENDER )
{
var replacementActionUrl = this._generateJSPseudoUrlActionRender( parsedPseudoUrl );
if ( replacementActionUrl == cFormAction )
{
if ( debugOn )
dojo.debug( "postParseAnnotateHtml [" + this.entityId + "] adding onSubmit (portlet-" + submitOperation + ") and leaving form action as is: " + cFormAction );
}
else
{
cForm.action = replacementActionUrl;
if ( debugOn )
dojo.debug( "postParseAnnotateHtml [" + this.entityId + "] adding onSubmit (portlet-" + submitOperation + ") and changing form action attribute from: " + cFormAction + " to: " +  replacementActionUrl );
}
this._addOnSubmitActionRender( cForm, cFormPortletEntityId, submitOperation );
}
else
{
if ( djConfig.isDebug )  // want to see this, for now
dojo.debug( "postParseAnnotateHtml [" + this.entityId + "] form action attribute doesn't match annotation criteria, leaving as is: " + cFormAction ) ;
}
}
}
var aList = cNode.getElementsByTagName( "a" );
if ( aList )
{
for ( var i = 0 ; i < aList.length ; i++ )
{
var aNode = aList[i];
var aHref = aNode.href;
var parsedPseudoUrl = this.parseJSPseudoUrlActionRender( aHref );
var replacementHref = this._generateJSPseudoUrlActionRender( parsedPseudoUrl );
if ( ! replacementHref )
{
if ( debugOn )
dojo.debug( "postParseAnnotateHtml [" + this.entityId + "] leaving href as is: " + aHref );
}
else if ( replacementHref == aHref )
{
if ( debugOn )
dojo.debug( "postParseAnnotateHtml [" + this.entityId + "] href parsed and regenerated identically: " + aHref );
}
else
{
if ( debugOn )
dojo.debug( "postParseAnnotateHtml [" + this.entityId + "] href parsed, replacing: " + aHref + " with: " + replacementHref );
aNode.href = replacementHref;
}
}
}
}
},

長いな・・・。これをざっと見た感じでは、formとaタグのリンクの書き換えだな。

今日はここまで・・・

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です