Content Rendering Modules
Technical introduction to objects
Class OptiWebRequest
This class provides functions to handle the communication with the Selligent WebAgent.
OptiWebRequest will fetch the incoming parameters from the .NET Page Object, package it into the XML document, and send the document to the Selligent WebAgent for processing.
- Constructors
The OptiWebRequest can be constructed in two ways:
- public OptiWebRequest(System.Web.UI.Page iPage) — Constructs a new OptiWebRequest object based on information in the .NET Page object. Request variables(POST/GET) will automatically be added to the request. If an ID variable is available this is used to initialize the ID attribute.
- public OptiWebRequest() — Constructs an empty OptiWebRequest object.
- Attributes
- public String ID — The SELLIGENT ID code used to generate the next request.
- public bool AutoRedirect — This property will enable or disable the automatic redirect when a redirect response has been received. The default value is true.
- public String MessagentUrl — The URL of the Messagent backend DLL.
Example: http://myserver/optiext/optiextension.dll
- Methods
- public OptiWebResult Send() — Sends the request to Selligent backed DLL and returns the generated result. If an error occurs, the function returns null. If a Redirect is received and the AutoRedirect property is set (default) the object will execute an automatic redirect
Class OptiWebResult
-
Description — The OptiWebResult class is internal and can only be generated by a call to OptiWebRequest.Send().
-
Methods — The OptiWebResult class exposes no methods.
-
Attributes
-
publicOptiWebResultType ResultType// Mail, Page or Redirect.
-
publicString Html // entire html
-
publicString HtmlDocType // Doctype
-
publicString TextBody// email text version
-
publicString Subject// email subjectline
-
publicOptiAddress Reply// email reply address
-
publicOptiAddress To// email to address
-
publicString Url// URL of page or email
-
publicOptiAddress From// email from address
-
publicString HtmlHead// page html header content
-
publicString HtmlBodyAttr// page html body attributes
-
publicString HtmlBody// page html body content
All attributes containing different parts of the Response generated by Selligent .
.NET websites
Messagent.Net is a class library that can be used when integrating Selligentcontent in .NET websites. The example below illustrates the usage of Messagent.NET where a renderer page is being designed step by step.
Requirements: MessagentNET.dll
1. Create a new ASPX page (myrenderer.aspx)
2. Create a folder BIN and store the MessagentNET.dll in it
The SMS file structure will look like this:
../anyfolder/myrenderer.aspx
../anyfolder/BIN/MessagentNET.dll
3. Add directives and imports to the file by pasting the following code at the top of the ASPX page:
<%@PageLanguage="C#"ContentType="text/html"ResponseEncoding="iso-8859-1" aspcompat="true"%>
<%@ImportNamespace="System"%>
<%@importNamespace="System.Configuration"%>
<%@importNamespace="MessagentNET"%>
4. Add a tag for server side script
<scriptrunat="server">
</script>
5. Within the Script tag, add the following variables to get the different parts of the HTML:
String incHead, incBody, incBodyAttr;
6. Within the <script> tag, add the Page_Load method
protectedvoidPage_Load(objectsender,EventArgse)
{
}
- Inside the Page_load
event, add the following code and replace the code in red with your
own Selligent installation URL.
//Check if there is a Selligent ID in the URL
if(""+Request.QueryString["ID"]!="")
{
//1. new Request instance
OptiWebRequest iRequest =new OptiWebRequest(this);
//2. Set request params
iRequest.CollectDebugInfo = false;
iRequest.AutoRedirect = false;
iRequest.MessagentUrl = "http://xxxxxxxxxx/optiext/optiextension.dll";
//Replace http://xxxxxxxxx with your SELLIGENT installation URL
//3. Capture and add GET and POST parameters
//GET parameters
foreach (string var in Request.QueryString)
{
iRequest.Attributes[var] = Request.QueryString[var];
}
//POST parameters
foreach (stringvar in Request.Form.AllKeys)
{
iRequest.Attributes[var] = Request.Form[var];
}
//3. new Response instance and assign request.send() to it
OptiWebResult m_WebResult = iRequest.Send();
//4. Setting our variables
incHead = m_WebResult.HtmlHead;
//check if we should redirect
if (m_WebResult.ResultType == OptiWebResult.OptiWebResultType.Redirect)
{
//write javascript redirect to page
incBody = "<script language=\"javascript\" type=\"text/javascript\">\n\tdocument.location = \"" + m_WebResult.Url + "\";\n</scr" + "ipt>";
}
else
{
//write content to page
incBody = m_WebResult.HtmlBody;
incBodyAttr = " " + m_WebResult.HtmlBodyAttr;
}
}
else
{
//no ID found error
incHead = "";
incBody = "Error - No ID provided";
incBodyAttr = "";
} - Build an HTML file and
use the variables created earlier.
This is an empty example of content renderer page. Normally this will be a page in your CMS with all the CSS and default content already present.
<html>
<head>
<%=incHead%>
</head>
<body<%=incBodyAttr%>>
<!--
put header/navigation here -->
<%=incBody%>
<!--
put footer/navigation here -->
</body>
</html>
The result of the above steps looks like following:
<%@PageLanguage="C#"ContentType="text/html"ResponseEncoding="iso-8859-1" aspcompat="true"%>
<%@ImportNamespace="System"%>
<%@importNamespace="System.Configuration"%>
<%@importNamespace="MessagentNET"%>
<scriptrunat="server">
//Vars used in the html
with content from SELLIGENT
StringincHead,
incBody, incBodyAttr;
///<summary>
///Page
load event
///</summary>
///<param
name="sender"></param>
///<param
name="e"></param>
protected void Page_Load(object sender,EventArgse)
{
//Check if there is an SELLIGENT
ID in the querystring
if(""+Request.QueryString["ID"]!="")
{
//1. new Request instance
OptiWebRequestiRequest = newOptiWebRequest(this);
//2. Set request params
iRequest.CollectDebugInfo = false;
iRequest.AutoRedirect= false;
iRequest.MessagentUrl="http://xxxxxxxxxx/optiext/optiextension.dll";
//3. Capture and add GET
and POST parameters
foreach (string var in Request.QueryString)
{
iRequest.Attributes[var] = Request.QueryString[var];
}
foreach (string var in Request.Form.AllKeys)
{
iRequest.Attributes[var] = Request.Form[var];
}
//4. new Response instance
with request.send output
OptiWebResultm_WebResult = iRequest.Send();
//5. Setting our vars
incHead = m_WebResult.HtmlHead;
//check if we should redirect
if (m_WebResult.ResultType ==OptiWebResult.OptiWebResultType.Redirect)
{
//write javascript redirect
to page
incBody ="<script
language=\"javascript\" type=\"text/javascript\">\n\tdocument.location
= \""+ m_WebResult.Url
+"\";\n</scr"+"ipt>";
}
else
{
//write content to page
incBody = m_WebResult.HtmlBody;
incBodyAttr =" "+
m_WebResult.HtmlBodyAttr;
}
}
else
{
//no ID found error
incHead ="";
incBody ="Error
- No ID provided";
incBodyAttr ="";
}
}
</script>
<html>
<head>
<%=incHead%>
</head>
<body<%=incBodyAttr%>>
<h1>HEADER</H1>
<hr>
<%=incBody%>
<h1>FOOTER</H1>
<hr>
</body>
</html>
JSP/JAVA websites
- Create an aspx page
that will handle content requests from JSP/JAVA.
Therefore put the file GetMessage4jsp.aspx in the optiext-folder of your SELLIGENT installation
Put the MessagentNET.dll in the bin folder if not already present. - Open the file GetMessage4jsp.aspx
and edit this line to point to your optiextension.dll iRequest.MessagentUrl
= "http://xxxxxxxxxx/optiext/optiextension.dll";
The content of the file GetMessage4jsp.aspx is as following
<?xmlversion="1.0" encoding="iso-8859-1"?>
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" aspcompat="true" %>
<%@ Import Namespace="System" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="MessagentNET" %>
<script runat="server">
String incHead, incBody, incBodyAttr;
protected void Page_Load(object sender, EventArgs e)
{
if(""+Request.QueryString["ID"]!="")
{
OptiWebRequest iRequest = new OptiWebRequest(this);
iRequest.CollectDebugInfo = false;
iRequest.AutoRedirect = false;
iRequest.MessagentUrl="http://xxxxxxxxxx/optiext/optiextension.dll";
foreach (string var in Request.QueryString)
{
iRequest.Attributes[var] = Request.QueryString[var];
}
foreach (string var in Request.Form.AllKeys)
{
iRequest.Attributes[var] = Request.Form[var];
}
OptiWebResult m_WebResult = iRequest.Send();
incHead = m_WebResult.HtmlHead;
if(m_WebResult.ResultType==OptiWebResult.OptiWebResultType.Redirect)
{
incBody="<script language=\"javascript\" type=\"text/javascript\">\n\tdocument.location = \"" + m_WebResult.Url + "\";\n</scr"+"ipt>";
}
else{
incBody = m_WebResult.HtmlBody;
incBodyAttr = m_WebResult.HtmlBodyAttr;
}
else
{
incHead = "";
incBody = "Error - No ID provided";
incBodyAttr = "";
}
}
</script>
<message>
<HEAD><![CDATA[<%=incHead%>]]></HEAD>
<BODY><![CDATA[<%=incBody%>]]></BODY>
<BODY_ATTR><![CDATA[<%=incBodyAttr%>]]></BODY_ATTR>
</message>
-
Create a new JSP page as a content renderer page (myrenderer.jsp)
-
Add page directives to the myrenderer.jsp page
<%@pagecontentType="text/html;charset=iso-8859-1"language="java" import="javax.xml.parsers.*,org.w3c.dom.*"errorPage=""%>
-
Add variable to hold XML and helper method to get a specific value from the XML
<%!
// 1. Create Document for XML
Documentdoc;
// 2. Create Method to get a specific value from the XML
StringgetXMLValue(Stringname) {
NodeListnlist=doc.getElementsByTagName(name);
Stringvalue = nlist.item(0).getFirstChild().getNodeValue();
return value;
}
%> -
Add call to the GetMessage4jsp.aspx page by pasting the code below. Make sure to edit the URL in red to point to your own Selligent installation.
<%
// 1. Get SIM ID from querystring
StringID = request.getParameter("ID");
// 2. Add GET and POST parameters
Stringparam = "";
java.util.Enumeration<String> params = request.getParameterNames();
while(params.hasMoreElements()) {
StringparamName = (String) params.nextElement();
if(!paramName.toUpperCase().equals("ID")) {
StringparamValue = request.getParameter(paramName);
if(paramValue != "" && paramValue != null) {
param = param + "&" + paramName + "=" + paramValue;
}
}
}
// 3. Set the URL to your GetMessage4jsp.aspx file
Stringxmlfile ="http://messagent.xxxx.com/optiext/GetMessage4jsp.aspx?ID=" +ID+param;
// 4. Create new Instance of DocumentBuilderFactory
DocumentBuilderFactorydbf=DocumentBuilderFactory.newInstance();
// 5. New Instance of DocumentBuilder
DocumentBuilderdb=dbf.newDocumentBuilder();
// 6. Get the xml content and put in doc variable
doc=db.parse(xmlfile);
%> -
Build HTML and fill with dynamic content.
The result of the previous step looks like following:
<%@pagecontentType="text/html;
charset=iso-8859-1"language="java"import="javax.xml.parsers.*,org.w3c.dom.*"errorPage=""%>
<%!
// 1. Create Document for
XML received
Document doc;
// 2. Create Method to
get a specific value from the XML
String getXMLValue(String name) {
NodeList nlist=doc.getElementsByTagName(name);
String value = nlist.item(0).getFirstChild().getNodeValue();
return value;
}
%>
<%
// 1. Get the SIM ID from
querystring
String ID = request.getParameter("ID");
// 2. Add GET and POST
parameters
String param = "";
java.util.Enumeration<String>
params = request.getParameterNames();
while (params.hasMoreElements()) {
String paramName = (String) params.nextElement();
if (!paramName.toUpperCase().equals("ID"))
{
String paramValue = request.getParameter(paramName);
if (paramValue != "" &&
paramValue != null) {
param = param + "&"
+ paramName + "=" + paramValue;
}
}
}
// 3. Set the URL to your
GetMessage4jsp.aspx
String xmlfile =http://messagent.xxxx.com/optiext/GetMessage4jsp.aspx?ID=+ID+param;
// 4. Create new Instance
of DocumentBuilderFactory
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
// 5. New Instance of DocumentBuilder
DocumentBuilder db=dbf.newDocumentBuilder();
// 6. Get the xml content
and put in doc var
doc=db.parse(xmlfile);
%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD
XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<%=getXMLValue("HEAD")%>
</head>
<body<%=getXMLValue("BODY_ATTR")%>>
<!-- PUT HTML -->
<%=getXMLValue("BODY")%>
<!--
PUT HTML -->
</body>
</html>
PHP website pages
-
Create an ASPX page that will handle content requests from PHP:
Put the file GetMessage4php.aspx in the optiext-folder of your Selligent installation.
Put the MessagentNET.dll in the bin folder. - Next, open the file
GetMessage4php.aspx and edit the line to point to our optiextension.dll
iRequest.MessagentUrl ="http://xxxxxxxxxx/optiext/optiextension.dll";
GetMessage4php.aspx
<%@PageLanguage="C#"ContentType="text/html"ResponseEncoding="iso-8859-1"aspcompat="true"%>
<%@ImportNamespace="System"%>
<%@importNamespace="System.Configuration"%>
<%@importNamespace="MessagentNET"%>
<scriptrunat="server">
StringincHead, incBody, incBodyAttr;
protectedvoidPage_Load(objectsender,EventArgse)
{
if(""+Request.QueryString["ID"]!="")
{
OptiWebRequestiRequest =newOptiWebRequest(this);
iRequest.CollectDebugInfo =false;
iRequest.AutoRedirect =false;
iRequest.MessagentUrl ="http://xxxxxxxxxx/optiext/optiextension.dll";
foreach(stringvar in Request.QueryString)
{
iRequest.Attributes[var] =Request.QueryString[var];
}
foreach(stringvar in Request.Form.AllKeys)
{
iRequest.Attributes[var] =Request.Form[var];
}
OptiWebResultm_WebResult = iRequest.Send();
incHead = m_WebResult.HtmlHead;
if(m_WebResult.ResultType==OptiWebResult.OptiWebResultType.Redirect)
{
incBody ="<script language=\"javascript\" type=\"text/javascript\">\n\tdocument.location = \""+ m_WebResult.Url +"\";\n</scr"+"ipt>";
}
else
{
incBody = m_WebResult.HtmlBody;
incBodyAttr = m_WebResult.HtmlBodyAttr;
}
}
else
{
incHead ="";
incBody ="Error - No ID provided";
incBodyAttr ="";
}
}
</script>
<?xmlversion="1.0"encoding="iso-8859-1"?>
<message>
<HEAD><![CDATA[<%=incHead%>]]></HEAD>
<BODY><![CDATA[<%=incBody%>]]></BODY>
<BODY_ATTR><![CDATA[<%=incBodyAttr%>]]></BODY_ATTR>
</message> -
Create a PHP content renderer and name it myrenderer.jsp
-
Open the php tag
<?php?>
-
Inside the php tag, retrieve POST and GET parameters
// 1. Get the SIM ID from the querystring
$parameters ="";
// 2. Get POST params
foreach($_POST as $name => $value)
{
if(strtoupper($name)<>"ID")
{
$parameters = $parameters . "&" . $name . "=" . urlencode($value);
}
}
// 3. Get GET params,
foreach($_GET as $name => $value)
{
if(strtoupper($name)<>"ID")
{
$parameters = $parameters . "&" . $name . "=" . urlencode($value);
}
} -
Inside the php tag , make the call to the GetMessage4php.aspx page and change the URL in red to point to your own Selligent installation
// 4. URL to your GetMessage4php -> change xxxxx to your domain
$xmldoc ="http://messagent.xxxx.com/optiext/GetMessage4php.aspx?ID=".$_GET["ID"].$parameters;
// 5. Encoding
$myXMLString = file_get_contents($xmldoc);
$myXMLString = utf8_encode($myXMLString);
// 6. New Instance of DOMDocument
$doc = new DOMDocument('1.0', 'UTF-8');
// 7. Load results into doc object
$doc->loadXML($myXMLString); -
Inside the php tag, assign variables to use in HTML
// 8. Settings parameters
$messagent_head = $doc->getElementsByTagName("HEAD");
$messagent_bodyattr = $doc->getElementsByTagName("BODY_ATTR");
$messagent_body = $doc->getElementsByTagName("BODY");
// 9. Settings parameters to use in HTML
$msgHeadStr = $messagent_head->item(0)->nodeValue;
$msgBodyAttrStr = $messagent_bodyattr->item(0)->nodeValue;
$msgBodyStr = $messagent_body->item(0)->nodeValue;
?> -
Create the HTML using the variables
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $msgHeadStr; ?>
</head>
<body<?php echo $msgBodyAttrStr ;?>>
<?php echo $msgBodyStr ; ?>
</body>
</html>The final result of the above steps looks like following
<?php
// 1. Get the SIM ID from querystring
$parameters="";
// 2. Get POST params
foreach($_POST as $name => $value)
{
if(strtoupper($name)<>"ID")
{
$parameters = $parameters . "&" . $name . "=" . urlencode($value);
}
}
// 3. Get GET params
foreach($_GET as $name => $value)
{
if(strtoupper($name)<>"ID")
{
$parameters = $parameters . "&" . $name . "=" . urlencode($value);
}
}
// 4. URL to your GetMessage4php -> change xxxxx to your domain
$xmldoc ="http://messagent.xxxx.com/optiext/GetMessage4php.aspx?ID=".$_GET["ID"].$parameters;
// 5. Encoding
$myXMLString = file_get_contents($xmldoc);
$myXMLString = utf8_encode($myXMLString);
// 6. New Instance of DOMDocument
$doc = new DOMDocument('1.0', 'UTF-8');
// 7. Load results into doc object
$doc->loadXML($myXMLString);
// 8. Settings parameters
$messagent_head = $doc->getElementsByTagName("HEAD");
$messagent_bodyattr = $doc->getElementsByTagName("BODY_ATTR");
$messagent_body = $doc->getElementsByTagName("BODY");
// 9. Settings parameters to use in HTML
$msgHeadStr = $messagent_head->item(0)->nodeValue;
$msgBodyAttrStr = $messagent_bodyattr->item(0)->nodeValue;
$msgBodyStr = $messagent_body->item(0)->nodeValue;
?>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $msgHeadStr; ?>
</head>
<body <?php echo $msgBodyAttrStr ;?>>
<?php echo $msgBodyStr ; ?>
</body>
</html>