Welcome Guest! Register/Login
Web services for automated content conversion and deployment

Building Web Applications with Hyper.Net Framework SDK

Show Comments (0)    Public Domain Bookmark this publication
Building Web Applications with the Hyper.Net Framework SDK The Hyper.Net Framework SDK in Detail How to Build a Basic Hyper.Net Web Application Using the Hyper.Net Framework SDK Creating an Application Using C# The Code Explained
The Code Explained
The first thing to do is the standard stuff: reference namespaces and other system specifics like the Xml namespace. That’s at the top in the usual place.
Also, we want to run the code in the Page_Load event, so this will be the only code we need to touch.
The construction rules section of the primary Hyper.Net configuration file defines the type of query strings that can are passed to our link handler ASPX. We’ll use those by default, but in a very specialized project you may want to pass your own query string names. Once more, it’s out of the scope of this paper dive into those seas, so let’s move on.
By default the query strings we must take care of are: DOC_UNID (Document Unique ID), DB (Hypermedia Database), PT (Publication Title) and DH (Document Heading).
Because the DOC_UNID is the most important value, the first thing to do is to see whether it was passed or not, and if so, redirect immediately to the page with this value. This value will be supplied for example when the link is to another topic in the same publication. At transformation time, the target topic id can be determined. That’s what we do with the following lines of code:
string DOC_UNID = Request.QueryString["DOC_UNID"];
if(DOC_UNID != string.Empty && DOC_UNID != null)
{
  System.Configuration.AppSettingsReader configurationAppSettings =
      new System.Configuration.AppSettingsReader();
  string _topicaspx =
  ((string)(configurationAppSettings.GetValue("ContentDisplayURL", typeof(string))));
 Response.Redirect(string.Format("{0}?DOC_UNID={1}", _topicaspx, DOC_UNID));
 }
If this value was not passed, it means the target destination must be dynamically computed. This means we need to look to see whether the other parameters where passed or not and act accordingly. So we have to do some replacements in these variables and later perform the proper logic. The following lines of code set the other variables if found.
string DB = Request.QueryString["DB"];
if (DB !="" && DB != null) DB = DB.Replace( "'", "''" );
string PT = Request.QueryString["PT"];
if (PT !="" && PT != null) PT = PT.Replace( "'", "''" );
string DH = Request.QueryString["DH"];
if (DH !=""&& DH != null) DH = DH.Replace( "'", "''" );
Now we have to analyze these variables and apply the proper logic. If either of DH or PT has a value we must go to the database and search for any document that matches, either by document heading or by publication title, and either redirect if only one matching target topic is found, or present a summary of matched target topics if more are found. For that we must create a Hyper.NetField1 that must be attached to our Hyper.Net Search object, and define the output nodes for the XML search result. We do this in the following lines of code.
if((DH != string.Empty && DH != null) || (PT != string.Empty && PT != null))
{
 Search _srch = new Search("topic.aspx","Content","NSM",-1);
 
 _srch.SearchCriteria = publication.IsEffective == 1 &
                        publication.Audience == "Production";
    
 if(DH != string.Empty)
   _srch.SearchCriteria = _srch.SearchCriteria & topic.Heading == DH;
 if(PT != string.Empty)
   _srch.SearchCriteria = _srch.SearchCriteria & publication.Title == PT;
 Hyper.NetField[] _hnfa = new Hyper.NetField[4];
 _hnfa[0] = topic.TopicID;
 _hnfa[1] = topic.Heading;
 _hnfa[2] = publication.Title;
 _hnfa[3] = publication.Category;
 
 _srch.AddNewOutputNode("Topic",_hnfa,"{0} {1} {2} {3}");
 XmlDocument _res = _srch.Execute();
...
 
In the code above, we have used for the first time the Search class and other HNFSDK functions to create a powerful object-oriented search to fulfill our needs.
The rest of the code traverses the resulting XML and dynamically generates HTML to be delivered to the browser. This does require solid understanding of C#, but is a standard .Net procedure. To save space and allow us to keep the examples together, we’ll cut some code from the explanation. If you remember the span_result HTML tag we created before, you’ll find it is used here to present the search result summary. Keep in mind this code runs when multiple link targets have been found. We do this with the following lines of code:
if(_res.DocumentElement.ChildNodes.Count > 0)
{
  XmlNodeList _xndl = _res.SelectNodes("//Topic");
  if(_xndl.Count == 1)     Page.Response.Redirect(string.Format("{0}?DOC_UNID={1}", _topicaspx,
       _xndl[0].Attributes["topic_TopicID"].Value));
  else
  {
    span_result.InnerHtml =  string.Format("<b>{0}</b> documents matching the criteria were found.<br><br>",_xndl.Count);
...
Let’s move onto displaying the content of topics.


1
Please refer to the online help to learn about this and other classes mentioned in this paper.
Loading, please wait...
About Publications
Contributor
Aruna
Published: 5/19/2010
Tags:
0 128 0
Display Options
Embed, Share & Subscribe
Download
Rate & Report
Statistics