Pages

Thursday, May 9, 2013

Evolution of RQL and Management Server Plugins

In the Beginning

There was COM using VB, but susceptible to server timeout in large operations and cannot cancel the server side operation once it has started.

Set objIO = CreateObject("RDCMSASP.RdPageData")
objIO.XmlServerClassName = "RDCMSServer.XmlServer"
xmlData = "<IODATA sessionkey=""" & session("sessionkey") & """ loginguid=""" & session("loginguid") & """><PAGE action=""load"" guid=""" & strTreeGuid & """/></IODATA>" 
xmlData = objIO.ServerExecuteXml (xmlData, sError)
' parse that xmlData

Shortly After

There was COM using C#. It is a cleaner language, but one has to relax COM security for this to work. Also, it is susceptible to server timeout in large operations and cannot cancel the server side operation once it has started.

// look up how to transfer asp session to aspx session
// Basically, asp page loop through all sessions and submit them to aspx
// which then save the received sessions into aspx sessions
string _LoginGuid = HttpContext.Current.Session["projectguid"].ToString();
string _SessionKey = HttpContext.Current.Session["sessionkey"].ToString();
string _PageGuid = HttpContext.Current.Session["treeguid"].ToString();
object objRQL;

object[] RQL_Server = { "RDCMSServer.XmlServer" };
objRQL.GetType().InvokeMember("XmlServerClassName", BindingFlags.SetProperty, null, objRQL, RQL_Server);
object[] RQL_Command = { string.Format("<IODATA sessionkey=\"{0}\" loginguid=\"{1}\"><PAGE action=\"load\" guid=\"{2}\"/></IODATA>", _LoginGuid, _SessionKey, _PageGuid) };
object retObj = objRQL.GetType().InvokeMember("ServerExecuteXml", BindingFlags.InvokeMethod, null, objRQL, RQL_Command);

if (retObj != null)
{
	// parse that retObj
}

Not Long After

There was web service using C#. It has the benefit of a cleaner language and no need for extra configuration in COM security, but the plugin will be competing with Management Server for communication bandwidth because many core components are also using the web service. Also, it is susceptible to server timeout in large operations and cannot cancel the server side operation once it has started.

// look up how to transfer asp session to aspx session
// Basically, asp page loop through all sessions and submit them to aspx
// which then save the received sessions into aspx sessions
string _LoginGuid = HttpContext.Current.Session["projectguid"].ToString();
string _SessionKey = HttpContext.Current.Session["sessionkey"].ToString();
string _PageGuid = HttpContext.Current.Session["treeguid"].ToString();

// RqlService is a class manually generated using Visual Stuio by pointing to the web service URL
RqlService RqlServiceObj = new RqlService();

string RQL_Command = string.Format("<IODATA sessionkey=\"{0}\" loginguid=\"{1}\"><PAGE action=\"load\" guid=\"{2}\"/></IODATA>", _LoginGuid, _SessionKey, _PageGuid);
object retObj = RqlServiceObj.ExecuteString(RQL_Command);

if (retObj != null)
{
	// parse that retObj
}

Overtime

Some people advanced to AJAX against an ASP connector or the web service because these plugins are easy to write, troubleshoot, and no longer susceptible to server timeout in large operations and run away server side operation once it has started. It is best practice to use ASP connector instead of web service because ASP connector do not compete with core component for communication bandwidth and it is compatible with Management Server 6.x, 7.x, 9.x, 10.x, whereas the web service is only available beginning at 7.x, changes location at 10.x and 11.x. Hence plugins written against the web service is not all version compatible automatically.

// AJAX ASP
var strRQLXML = padRQLXML('<PAGE action="load" guid="<%= session("treeguid") %>">');

$.post('rqlaction.asp', { rqlxml: strRQLXML },
function(data){
	// parse $(data)
});

function padRQLXML(innerRQLXML)
{
	return '<IODATA loginguid="<%= session("loginguid") %>" sessionkey="<%= session("sessionkey") %>">' + innerRQLXML + '</IODATA>';
}
<?xml version="1.0" encoding="utf-8" ?>
<%
	' action.asp
	Response.ContentType = "text/xml"

	Dim objIO	'Declare the objects
	Dim xmlData, sError, retXml
	set objIO = Server.CreateObject("RDCMSASP.RdPageData")
	objIO.XmlServerClassName = "RDCMSServer.XmlServer"

	xmlData = Request.Form("rqlxml")
	
	xmlData = objIO.ServerExecuteXml (xmlData, sError) 

	Set objIO = Nothing
	
	If sError <> "" Then
        retXml = "<ERROR>" & sError & "</ERROR>"
	Else
        retXml = xmlData
	End If
	
	Response.Write(retXml)
%>
// AJAX web service
var SOAPMessage = '';
SOAPMessage += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cms="http://reddot.de/cms/webservices/navigation/1_1"><soapenv:Header/><soapenv:Body><cms:ExecuteString><cms:command>';
SOAPMessage += padRQLXML(InnerRQL);
SOAPMessage += '</cms:command></cms:ExecuteString></soapenv:Body></soapenv:Envelope>';

$.ajax({
	type: 'POST',
	url: '/CMS/Navigation/Services/RQLService.asmx',
	data: SOAPMessage,
	contentType: 'text/xml; charset=utf-8',
	dataType: 'xml',
	beforeSend: function(xhr) {
		xhr.setRequestHeader('SOAPAction', '"http://reddot.de/cms/webservices/navigation/1_1/ExecuteString"');
	},
	success: function (data) {
		// parse $(data)
	},
	error: function (message) {
		//alert(message);
	}
});
	
function padRQLXML(InnerRQL)
{
	var Rql = '<IODATA loginguid="<%= session("loginguid") %>" sessionkey="<%= session("sessionkey") %>"><![CDATA[' + InnerRQL + ']]></IODATA>';
		
	return Rql;
}

Finally

Management Server is at version 11.x. One has to change the COM object name in ASP in order for VB plugins to continue to work, and this should only be a short term fix because as stated in the RQL manual, COM will be obsolete and web service will be the sole future. One also has to change the web service URL and SOAP format in order for AJAX web service plugins to continue to work in 11.x. The question: how to write a plugin that is 7.x to 11.x compatible automatically? Answer: use a AJAX RQL connector library at https://github.com/jhuangsoftware/j-rql-connector

<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="Rqlconnector.js"></script>
<script type="text/javascript">
var LoginGuid = '<%= session("loginguid") %>';
var SessionKey = '<%= session("sessionkey") %>';
var RqlConnectorObj = new RqlConnector(LoginGuid, SessionKey);

var strRQLXML = '<PAGE action="load" guid="' + PageGuid + '"/>';
RqlConnectorObj.SendRql(strRQLXML, false, function(data){
	// parse $(data)
});
</script>
' quick and short term change to make VB to continue to work
Set objIO = CreateObject("OTWSMS.AspLayer.PageData")
xmlData = "<IODATA sessionkey=""" & session("sessionkey") & """ loginguid=""" & session("loginguid") & """><PAGE action=""load"" guid=""" & strTreeGuid & """/></IODATA>" 
xmlData = objIO.ServerExecuteXml (xmlData, sError)
' parse that xmlData

NOTE

The AJAX RQL Connector is meant to be used on something small to medium things, like to automatically send some RQLs whenever a user does something in SmartEdit or Page Preview, or to send some RQLs based on user inputs in a plugin interface. Ideally, all plugins should use this connector library over other RQL libraries (Java, C#, PHP?) because a plugin should be plug-and-play with no dependency on any other external installations or configurations.

Does it mean other RQL libraries (Java, C#, PHP?) are bad? No. They are still useful for large implementations, where a plugin should really be called an application integration. However, please be aware that support for RQL libraries (Java, C#, PHP?) falls outside of OpenText support because in event of error, one has to proof the fault is at RQL level, not the library that encapsulates the RQL.

Wednesday, May 8, 2013

List versus Container Best Practices

There has been many confusions over when to use a list element or a container element. For Example, I want to have a slider module on my home page.

The flexslider has the following HTML code:

<div class="flexslider" id="myflexslider">
	<ul class="slides">
		<li>
			<img src="slide1.jpg" />
		</li>
		<li>
			<img src="slide2.jpg" />
		</li>
		<li>
			<img src="slide3.jpg" />
		</li>
		<li>
			<img src="slide4.jpg" />
		</li>
	</ul>
</div>
<script type="text/javascript" charset="utf-8">
    $('#myflexslider').flexslider();
</script>

The Bad Solution

Each slide is a page containing a slide image. Then a list placeholder is used to pull in images.

<!-- flexslider content class -->
<!IoRangeRedDotMode>
<div class="alert-reddot <!IoRangeNoEditMode>alert-error<!/IoRangeNoEditMode><!IoRangeRedDotEditOnly>alert-success<!/IoRangeRedDotEditOnly>">
    <div><!IoRedDotOpenPage> [<!IoRangeNoEditMode>Open to Edit<!/IoRangeNoEditMode><!IoRangeRedDotEditOnly>Close to Save<!/IoRangeRedDotEditOnly> Page]</div>
    <!IoRangeRedDotEditOnly>
    <div><!IoRedDot_lst_slides> [Manage Slides]</div>
    <!/IoRangeRedDotEditOnly>
</div>
<!/IoRangeRedDotMode>
<div class="flexslider" id="myflexslider">
    <ul class="slides">
        <!IoRangeList>
        <li>
            <!-- <%lst_slides%> -->
            <!IoRedDot_img_slide><%img_slide%>
        </li>
        <!/IoRangeList>
    </ul>
</div>
<script type="text/javascript" charset="utf-8">
    $('#myflexslider').flexslider();
</script>

This is a sub-optimal method because

  1. The slider pages will get published out as these useless HTML snippet pages, occupying space and unnecessarily indexed. Of course, one can prevent it by setting the template of the content class not to publish or use a content class without template. Nevertheless, it causes more work.
  2. After editing a slider page in SmartEdit, user can't submit or release the slider page because it is hidden behind a list. Of course, one can make the slider page hidden behind the list accessible in SmartEdit. Nevertheless, it causes more work.

The Current Best Practice Solution

Each slide is a page containing a slide image. Then a container placeholder is used to contain the pages.

<!-- flexslider content class -->
<!IoRangeRedDotMode>
<div class="alert-reddot <!IoRangeNoEditMode>alert-error<!/IoRangeNoEditMode><!IoRangeRedDotEditOnly>alert-success<!/IoRangeRedDotEditOnly>">
    <div><!IoRedDotOpenPage> [<!IoRangeNoEditMode>Open to Edit<!/IoRangeNoEditMode><!IoRangeRedDotEditOnly>Close to Save<!/IoRangeRedDotEditOnly> Page]</div>
    <!IoRangeRedDotEditOnly>
    <div><!IoRedDot_con_slides> [Manage Slides]</div>
    <!/IoRangeRedDotEditOnly>
</div>
<!/IoRangeRedDotMode>
<div class="flexslider" id="myflexslider">
    <ul class="slides">
        <%con_slides%>
    </ul>
</div>
<script type="text/javascript" charset="utf-8">
    $('#myflexslider').flexslider();
</script>
<!-- flexslider slide content class -->
<li>
    <!IoRedDotOpenPage><!IoRedDot_img_slide><%img_slide%>
</li>