You are viewing a plain text version of this content. The canonical link for it is here.
Posted to stonehenge-commits@incubator.apache.org by sh...@apache.org on 2008/11/26 10:55:41 UTC

svn commit: r720802 [2/4] - in /incubator/stonehenge/contrib/stocktrader: perl/ perl/trader_client/ perl/trader_client/images/ python/ python/trader_client/ python/trader_client/media/ python/trader_client/media/images/ python/trader_client/templates/

Added: incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_home
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_home?rev=720802&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_home (added)
+++ incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_home Wed Nov 26 02:55:38 2008
@@ -0,0 +1,768 @@
+#!/usr/bin/perl
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use CGI qw/:standard/;
+use WSO2::WSF;
+use XML::LibXML;
+
+my $WSFC_HOME='/opt/wso2/wsf_c/';
+
+my $q = new CGI;
+
+# get the endpoitn from the configuration service
+sub get_endpoint {
+
+    $config_endpoint = $q->cookie('endpoint');
+    $input_xml = <<XML;
+    <ClientConfigRequest xmlns="http://wso2.org/interop/stocktrader/xsd">
+        <Client>PERL_CLIENT</Client>
+    </ClientConfigRequest>
+XML
+
+    my $client = new WSO2::WSF::WSClient( { 'to' => $config_endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' =>  $WSFC_HOME } );
+    my $response_msg = $client->request( { 'payload' => $input_xml } );
+    my $response_str = $response_msg->{str};
+
+    my $response_parser = XML::LibXML->new();
+    $response_xml = $response_parser->parse_string($response_str);
+
+    my $xpc = XML::LibXML::XPathContext->new($response_xml);
+    $xpc->registerNs('ns'=> 'http://wso2.org/interop/stocktrader/xsd');
+
+    $bs =  $xpc->findvalue('//ns:BS');   
+    
+    return $bs;
+}
+
+
+# get market summary
+sub get_market_summary {
+    my $get_market_summary_request = <<XML;
+    <getMarketSummary xmlns="http://trade.samples.websphere.ibm.com"/>
+XML
+    
+    my $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    my $response = $client->request( { 'payload' => $get_market_summary_request } );
+    my $get_market_summary_response = $response->{str};
+
+#    my $get_market_summary_response = <<XML;
+#          <getMarketSummaryResponse xmlns="http://trade.samples.websphere.ibm.com">
+#             <getMarketSummaryReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#                <TSIA>100.000000</TSIA>
+#                <openTSIA>100.000000</openTSIA>
+#                <volume>0</volume>
+#                <topGainers>
+#                   <QuoteDataBean>
+#                      <symbol>s:100</symbol>
+#                      <companyName>S100 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:101</symbol>
+#                      <companyName>S101 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:102</symbol>
+#                      <companyName>S102 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:103</symbol>
+#                      <companyName>S103 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:104</symbol>
+#                      <companyName>S104 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                </topGainers>
+#                <topLosers>
+#                   <QuoteDataBean>
+#                      <symbol>s:100</symbol>
+#                      <companyName>S100 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:101</symbol>
+#                      <companyName>S101 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:102</symbol>
+#                      <companyName>S102 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:103</symbol>
+#                      <companyName>S103 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                   <QuoteDataBean>
+#                      <symbol>s:104</symbol>
+#                      <companyName>S104 Incorporated</companyName>
+#                      <price>100.00</price>
+#                      <open>100.00</open>
+#                      <low>100.00</low>
+#                      <high>100.00</high>
+#                      <change>0</change>
+#                      <volume>0</volume>
+#                   </QuoteDataBean>
+#                </topLosers>
+#                <summaryDate>2008-07-18T16:06:36.328125+05:30</summaryDate>
+#             </getMarketSummaryReturn>
+#          </getMarketSummaryResponse>
+#XML
+  
+    my $parser = XML::LibXML->new();
+    $market_summary_xml = $parser->parse_string($get_market_summary_response);
+  
+    return  $market_summary_xml;
+}
+
+sub get_account_data {
+    my($username) = shift;
+
+    my $get_account_data_request = <<XML;
+          <getAccountData xmlns="http://trade.samples.websphere.ibm.com">
+             <userID>${username}</userID>
+          </getAccountData>
+XML
+
+    $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_account_data_request} );
+    $get_account_data_response = $response->{str};
+
+#    my $get_account_data_response = <<XML;
+#          <getAccountDataResponse xmlns="http://trade.samples.websphere.ibm.com">
+#             <getAccountDataReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#                <accountID>1</accountID>
+#                <loginCount>5</loginCount>
+#                <logoutCount>0</logoutCount>
+#                <lastLogin>2008-07-18T16:06:35.42</lastLogin>
+#                <creationDate>2008-05-21T16:01:44.063</creationDate>
+#                <balance>100000.00</balance>
+#                <openBalance>200000.00</openBalance>
+#                <profileID>uid:0</profileID>
+#             </getAccountDataReturn>
+#          </getAccountDataResponse>
+#XML
+
+
+    my $parser = XML::LibXML->new();
+    $account_data_xml = $parser->parse_string($get_account_data_response);
+
+    return $account_data_xml;
+}
+
+sub get_holdings {
+    my($username) = shift;
+
+    my $get_holdings_request = <<XML;
+      <getHoldings xmlns="http://trade.samples.websphere.ibm.com">
+         <userID>${username}</userID>
+      </getHoldings
+XML
+  
+    $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_holdings_request} );
+
+    my $get_holdings_response = $response->{str};
+  
+#    my $get_holdings_response = <<XML;
+#      <getHoldingsResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <getHoldingsReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <HoldingDataBean>
+#               <holdingID>46</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.157</purchaseDate>
+#               <quoteID>s:9</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>41</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.157</purchaseDate>
+#               <quoteID>s:8</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>37</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.157</purchaseDate>
+#               <quoteID>s:7</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>32</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.14</purchaseDate>
+#               <quoteID>s:6</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>25</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.14</purchaseDate>
+#               <quoteID>s:5</quoteID>
+#            </HoldingDataBean>
+#         </getHoldingsReturn>
+#      </getHoldingsResponse>
+#XML
+
+    my $parser = XML::LibXML->new();
+    $holdings_xml = $parser->parse_string($get_holdings_response);
+
+    return $holdings_xml;
+}
+
+sub get_quote {
+    my($quote_id) = shift;
+
+    my $get_quotes_request = <<XML;
+      <getQuote xmlns="http://trade.samples.websphere.ibm.com">
+         <symbol>${quote_id}</symbol>
+      </getQuote>
+XML
+ 
+    $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_quotes_request } );
+  
+    my $get_quotes_response = $response->{str};
+
+#    my $get_quotes_response = <<XML;
+#      <getQuoteResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <getQuoteReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <symbol>s:0</symbol>
+#            <companyName>S0 Incorporated</companyName>
+#            <price>100.00</price>
+#            <open>100.00</open>
+#            <low>100.00</low>
+#            <high>100.00</high>
+#            <change>0</change>
+#            <volume>0</volume>
+#         </getQuoteReturn>
+#      </getQuoteResponse>
+#XML
+
+    my $parser = XML::LibXML->new();
+    $quote_xml = $parser->parse_string($get_quotes_response);
+
+    return $quote_xml;
+}
+
+sub get_holding_information {
+    my($holdings) = shift;
+   
+    my $index = 0;
+    my $total_holdings = 0;
+    my $market_value = 0;
+    my @sub_nodes;
+
+    my %quote_info;
+
+    my $xpc = XML::LibXML::XPathContext->new($holdings);
+    $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+    @nodes = $xpc->findnodes('//ns:HoldingDataBean');
+    foreach my $bean (@nodes) {
+        my $xpc = XML::LibXML::XPathContext->new($bean);
+        $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+        $quote_id = $xpc->findvalue('./ns:quoteID');
+
+
+        $quantity = $xpc->findvalue('./ns:quantity');
+
+        $purchase_price = $xpc->findvalue('./ns:purchasePrice');
+
+        if(!$quote_info{$quote_id}) {
+            $quotes = get_quote($quote_id);
+            my $xpc_inner = XML::LibXML::XPathContext->new($quotes);
+            $xpc_inner->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+            $price = $xpc_inner->findvalue('//ns:price');
+           
+            $quote_info{$quote_id} = $price;
+        }
+        
+        $quote_price = $quote_info{$quote_id};
+        $market_value += $quote_price + $quantity;
+
+        $total_holdings += $quantity * $purchase_price;
+
+        $index ++;
+    }
+
+    %holding_info = ('totalHoldings' => $market_value,
+                    'noOfHoldings' => $index);
+
+    return %holding_info;
+}
+
+sub convert_date {
+  my($str) = shift;
+  if($str) {
+    $str =~ s/[T:\.]/-/g;
+    @date_arr = split("-", $str);
+    $year = @date_arr[0];
+    $mon = @date_arr[1];
+    $date = @date_arr[2];
+    $hour = @date_arr[3];
+    $min = @date_arr[4];
+    $sec = @date_arr[5];
+
+    if($hour > 12) {
+      $hour = $hour - 12;
+      $ampm = "PM";
+    }
+    else {
+      $ampm = "AM";
+    }
+    return "${mon}/${date}/${year} ${hour}:${min}:${sec} ${ampm}";
+  }
+  return "";
+}
+
+
+my $market_summary_xml  = get_market_summary();
+    
+my $xpc = XML::LibXML::XPathContext->new($market_summary_xml);
+$xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+ 
+my $tsia = $xpc->findvalue('//ns:TSIA');
+
+print $q->header();
+
+$open_tsia = $xpc->findvalue('//ns:openTSIA');
+
+my $gain = $tsia - $open_tsia;
+
+$volume = $xpc->findvalue('//ns:getMarketSummaryReturn/ns:volume');
+
+my @top_gainers = $xpc->findnodes('//ns:topGainers/ns:QuoteDataBean');
+my @top_losers = $xpc->findnodes('//ns:topLosers/ns:QuoteDataBean');
+
+my $username = $q->cookie('username');
+
+
+$account_xml = get_account_data($username);
+
+my $xpc = XML::LibXML::XPathContext->new($account_xml);
+$xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+my @account_data_arr = $xpc->findnodes('//ns:getAccountDataReturn');
+my $account_data = @account_data_arr[0];
+
+
+my $holdings = get_holdings($username);
+my %holding_info = get_holding_information($holdings);
+
+my $no_of_holdings = $holding_info{"noOfHoldings"};
+my $total_holdings = $holding_info{"totalHoldings"};
+
+
+my $html_begin =<<E;
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+	<head>
+		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+		<meta name="generator" content="Adobe GoLive" />
+		<title>WSF/PHP StockTrader Welcome</title>
+		<link href="/trader/style.css" rel="stylesheet" type="text/css" media="all" />
+	</head>
+
+	<body>
+		<div id="content">
+			<div id="header">
+				<div class="logo"><img src="/trader/images/logo.gif"></div>
+			</div>
+			<div id="header-links">
+				<table>
+					<tr>
+					<td>
+						<a href="/cgi-bin/trader">Welcome</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_home">Home</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_account">Account</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_portfolio">Portfolio</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_quotes">Quotes/Trade</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_glossary">Glossary</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_config">Config</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_login">Login/Logout</a>
+					</td>
+					</tr>
+				</table>
+			</div>
+			<div id="middle">
+
+				<div class="main-title"><h1>Home</h1><script type="text/javascript">var thisdate = new Date();
+					document.writeln(thisdate.toLocaleString());</script></div>
+				<h3>${username}</h3>
+
+				<table>
+				<tr>
+				<td>
+				<div class="left">
+					<table class="normal">
+						<thead><tr><th colspan="2">User Statistics</th></tr></thead>
+E
+
+print $html_begin;
+
+if($account_data) {
+
+    my $xpc = XML::LibXML::XPathContext->new($account_data);
+    $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+    my $creation_date = convert_date($xpc->findvalue('//ns:creationDate'));
+
+    my $last_login = convert_date($xpc->findvalue('//ns:lastLogin'));
+
+    my $account_id = $xpc->findvalue('//ns:accountID');
+
+    my $login_count = $xpc->findvalue('//ns:loginCount');
+
+
+my $xml = <<XML;
+    <tbody>
+    <tr><td class="left">Account ID:</td>
+       <td>${account_id}</td></tr>
+    <tr><td class="left">Account Created:</td>
+       <td>${creation_date}</td></tr>
+    <tr><td class="left">Total Logins:</td>
+       <td>${login_count}</td></tr>
+    <tr><td class="left">Session Created:</td>
+       <td>${last_login}</td></tr>
+    </tbody>
+XML
+    print $xml;
+}
+
+print <<E;
+    <thead><tr><th colspan="2">Summary</th></tr></thead>
+E
+
+
+if(%holding_info && $account_data)
+{
+
+    my $xpc = XML::LibXML::XPathContext->new($account_data);
+    $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+    my $balance = $xpc->findvalue('//ns:balance');
+
+    my $open_balance = $xpc->findvalue('//ns:openBalance');
+
+    my $total_cash = $total_holdings + $balance;
+
+    my $gain =  (($total_holdings + $balance) - $open_balance);
+   
+    print ("<tbody>");
+    print ("<tr><td class=\"left\">Cash Balance:</td>
+        <td>${balance}</td></tr>");
+
+    print ("<tr><td class=\"left\">Number of Holdings:</td>
+        <td>${no_of_holdings}</td></tr>");
+
+    print ("<tr><td class=\"left\">Total of Holdings:</td><td>");
+    printf("\$ %.2f",$total_holdings);
+    print ("</td></tr>");
+
+    print ("<tr><td class=\"left\">Sum of Cash and Holdings:</td><td>");
+    printf("\$ %.2f",($total_cash));
+    print ("</td></tr>");
+
+    print ("<tr><td class=\"left\">Opening Balance:</td><td>");
+    printf ("\$ %.2f", $open_balance);
+    print ("</td></tr>");
+
+    print ("<tr><td class=\"left\">Current Gain/(Loss):</td>
+        <td><span class=\"price\">");
+    if ($gain < 0)
+    {
+        printf("\$ (%.2f)", ((-1) * $gain));
+    }
+    elsif ($gain >= 0)
+    {
+        printf("\$ %.2f", $gain);
+    }
+    $gain_percent = ($gain/$open_balance) * 100;
+    print ("</span></td></tr>");
+
+
+    print ("<tr><td class=\"left\">%Gain/(Loss):</td><td>");
+
+    if ($gain_percent > 0)
+    {
+        print ("<span class=\"price-gain\">${gain_percent}%</span>");
+    }
+    elsif ($gain_percent < 0)
+    {
+        print ("<span class=\"price-loss\">${gain_percent}%</span>");
+    }
+    else
+    {
+        print ("<span>${gain_percent}%</span>");
+    }
+    print ("</td></tr>");
+    print("</tbody>");
+}
+
+print <<E;
+    </table>
+</td>
+E
+
+print <<E;
+<td>
+<div class="right">
+<h3>Market Summary</h3>
+<p>
+E
+
+$time = ($sec,$min,$hour,$mday,$mon,$year,$wday,
+$yday,$isdst)=localtime(time);
+printf "%4d-%02d-%02d %02d:%02d:%02d\n",
+$year+1900,$mon+1,$mday,$hour,$min,$sec;
+print <<E;
+</p>
+<table class="table-outer" cellspacing="0">
+E
+    if (%holding_info && $account_data)
+    {
+        print ("<tr><td class=\"special\">Trade Stock Index (TSIA)</td><td>");
+        print($tsia);
+        print(" ");
+        print("<span");
+
+        if ($gain > 0)
+        {
+            print (" class=\"price-gain\">\$");
+        }
+        elsif ($gain < 0)
+        {
+            print (" class=\"price-loss\">\$");
+        }
+        else
+        {
+            print(">");
+        }
+        printf("%.2f</span>", $gain);
+        print ("</td></tr>");
+
+        print ("<tr><td class=\"special\">Trading Volume</td><td>");
+
+        print ($volume);
+        print ("</td></tr>");
+
+        print("<tr><td class=\"special\">Top Gainers</td><td>");
+        print ("<table class=\"table-inner\" cellspacing=\"0\">");
+        print("<thead><tr><th>Symbol</th><th>Price</th><th>Change</th></tr></thead>");
+        print("<tbody>");
+        
+        foreach my $account_data (@top_gainers)
+        {
+            my $xpc = XML::LibXML::XPathContext->new($account_data);
+            $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+
+            my $symbol = $xpc->findvalue('./ns:symbol');
+
+            my $change = $xpc->findvalue('./ns:change');
+
+            my $price = $xpc->findvalue('./ns:price');
+                
+            print ("<tr><td><form action = \"/cgi-bin/trader_quotes\" method = \"post\">
+                <input type=\"hidden\" name=\"SYMBOLS\" value=\"${symbol}\"/>
+                <input type=\"submit\" name=\"GETQUOTE\" value=\"${symbol}\"></input></form></td>");
+
+            printf ("<td>\$%.2f</td>", $price);
+            print ("<td><span");
+
+            if (($change) > 0)
+            {
+                print ("class=\"price-gain\">\$");
+            }
+            elsif (($change) < 0)
+            {
+                print ("class=\"price-loss\">\$");
+            }
+            else
+            {
+                print(">\$");
+            }
+
+            printf ("%.2f", $change);
+            print ("</span></td>");
+            print ("</form></tr>");
+
+        }
+
+        print ("</tbody></table></td></tr>");
+
+        print ("<tr><td class=\"special\">Top Losers</td><td>
+            <table class=\"table-inner\" cellspacing=\"0\"><thead>
+            <tr><th>Symbol</th><th>Price</th><th>Change</th></tr></thead><tbody>");
+
+        $index = 0;
+        foreach my $account_data (@top_losers)
+        {
+            my $xpc = XML::LibXML::XPathContext->new($account_data);
+            $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+
+            my $symbol = $xpc->findvalue('./ns:symbol');
+
+            my $change = $xpc->findvalue('./ns:change');
+
+            my $price = $xpc->findvalue('./ns:price');
+
+
+            print ("<tr><td><form action = \"cgi-bin/trader_quotes\" method = \"post\">
+                <input type=\"submit\" name=\"SYMBOLS\" value=\"${symbol}\"></input></form></td>");
+
+            printf ("<td>\$%.2f</td>", $price);
+            print ("<td><span");
+
+            if (($change) > 0)
+            {
+                print (" class=\"price-gain\">\$");
+            }
+            elsif (($change) < 0)
+            {
+                print (" class=\"price-loss\">\$");
+            }
+            else
+            {
+                print(">\$");
+            }
+            printf ("%.2f", $change);
+            print ("</span></td>");
+            print ("</tr>");
+
+        }
+        print("</tbody></table>");
+        print("</td></tr></table>");
+        print("</div>");
+        print("</td></tr></table>");
+    }
+
+
+my $html_end = <<E;
+
+      <div class="bottom">
+      <form method = "post"  action = "/cgi-bin/trader_quotes">
+      <input type="text" value="" name="SYMBOLS" size="25"/>
+      <input type="submit" value="Get Quote" name="GETQUOTE" class="button"/>
+      </form>
+
+      </div>
+      </div>
+
+      <div id="footer">
+        <div style="float:left;">Copyright 2008, WSO2 Inc.</div>
+        <div style="margin-left:432px;float:left;">Powered by 
+        <img align="top" src="/trader/images/powered-by-logo.gif" style="margin-top:-3px; margin-left: 0px;"/></div>
+      </div>
+    </div>
+  </body>
+</html>
+E
+
+print $html_end;

Added: incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_login
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_login?rev=720802&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_login (added)
+++ incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_login Wed Nov 26 02:55:38 2008
@@ -0,0 +1,227 @@
+#!/usr/bin/perl
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use CGI qw/:standard/;
+use WSO2::WSF;
+use XML::LibXML;
+
+my $q = new CGI;
+
+my $WSFC_HOME='/opt/wso2/wsf_c/';
+
+# if for some bizarre inexplicable reason, user tries to login for the second time redirect his arse
+# back to the home page
+# if ( cookie('icanhazlogin') eq "gudkitteh" ) {
+#     print redirect( -uri => 'http://localhost', -status => 302 );
+# }
+#
+#
+
+# get the endpoitn from the configuration service
+sub get_endpoint {
+
+    $config_endpoint = $q->cookie('endpoint');
+    $input_xml = <<XML;
+    <ClientConfigRequest xmlns="http://wso2.org/interop/stocktrader/xsd">
+        <Client>PERL_CLIENT</Client>
+    </ClientConfigRequest>
+XML
+
+    my $client = new WSO2::WSF::WSClient( { 'to' => $config_endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' =>  $WSFC_HOME } );
+    my $response_msg = $client->request( { 'payload' => $input_xml } );
+    my $response_str = $response_msg->{str};
+
+    my $response_parser = XML::LibXML->new();
+    $response_xml = $response_parser->parse_string($response_str);
+
+    my $xpc = XML::LibXML::XPathContext->new($response_xml);
+    $xpc->registerNs('ns'=> 'http://wso2.org/interop/stocktrader/xsd');
+
+    $bs =  $xpc->findvalue('//ns:BS');   
+    return $bs;
+}
+
+# username and password is given
+my $username = $q->param('USERNAME');
+my $password = $q->param('PASSWORD');
+
+# stores the response XML
+my $response;
+
+# if the response XML is good and a cookie is not set, we use this to set one
+my $cookie;
+
+if ( defined($username) && defined($password) ) {
+    my $login_request =<<EOF;
+      <login xmlns="http://trade.samples.websphere.ibm.com">
+         <userID>${username}</userID>
+         <password>${password}</password>
+      </login>
+EOF
+
+    my $tmp_endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $tmp_endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $login_request } );
+    $response_str = $response->{str};
+
+#    $resposne = <<XML;
+#      <loginResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <loginReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <accountID>1</accountID>
+#            <loginCount>6</loginCount>
+#            <logoutCount>0</logoutCount>
+#            <lastLogin>2008-07-18T16:06:35.42</lastLogin>
+#            <creationDate>2008-05-21T16:01:44.063</creationDate>
+#            <balance>100000.00</balance>
+#            <openBalance>200000.00</openBalance>
+#            <profileID>uid:0</profileID>
+#         </loginReturn>
+#      </loginResponse>
+#XML
+    
+    my $parser = XML::LibXML->new();
+
+    $xml = $parser->parse_string($response_str);
+    # profileID will be set for valid users
+
+    my $xpc = XML::LibXML::XPathContext->new($xml);
+    $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+    my $pid = $xpc->findvalue('//ns:profileID');
+
+    if ( $pid) {
+        # credentials are good, setting the fricking cookie
+        $cookie = cookie( -name  => 'username',
+                          -value => $pid );
+
+    }
+}
+
+if ( defined $cookie ) {
+    print $q->header( -cookie => $cookie);
+    print "<script type=\"text/javascript\">window.location='/cgi-bin/trader_account'</script>";
+    exit(0);
+} else {
+    print $q->header();
+}
+
+my $html_begin =<<EOF;
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+	<head>
+		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+		<title>WSF/Perl StockTrader Welcome</title>
+		<link href="/trader/style.css" rel="stylesheet" type="text/css" media="all" />
+	</head>
+
+	<body>
+
+	<div id="content">
+		<div id="header">
+			<div class="logo"><img src="/trader/images/logo.gif"></div>
+		</div>
+
+		<div id="header-links">
+		<table>
+			<tr>
+			<td>
+			<a href="/cgi-bin/trader">Welcome</a>
+			</td>
+			<td>
+			<a href="/cgi-bin/trader_home">Home</a>
+			</td>
+			<td>
+			<a href="/cgi-bin/trader_account">Account</a>
+			</td>
+			<td>
+			<a href="/cgi-bin/trader_portfolio">Portfolio</a>
+			</td>
+			<td>
+			<a href="/cgi-bin/trader_quotes">Quotes/Trade</a>
+			</td>
+			<td>
+			<a href="/cgi-bin/trader_glossary">Glossary</a>
+			</td>
+			<td>
+			<a href="/cgi-bin/trader_config">Config</a>
+			</td>
+			<td>
+			<a href="/cgi-bin/trader_login">Login/Logout</a>
+			</td>
+			</tr>
+		</table>
+		</div>
+
+		<div id="middle">
+	
+			<div class="main-title">
+			<h1>Login</h1>
+			<script type="text/javascript">
+				var thisdate = new Date();
+				document.writeln(thisdate.toLocaleString());
+			</script>
+			</div>
+		
+			<div class="login">
+EOF
+
+my $login_form =<<EOF;
+				<form method="post"  action="/cgi-bin/trader_login">
+					<table>
+					<tr>
+					<td>Username</td>
+					<td><input name = "USERNAME" size = "25"/></td>
+					</tr>
+					<tr>
+					<td>Password</td>
+					<td><input type="password" name = "PASSWORD" size = "25"/></td>
+					</tr>
+					<tr>
+					<td></td>
+					<td><input type = "submit" name = "LOGINREQUEST" value = "Login" class="button"/></td>
+					</tr>
+					</table>
+				</form>
+EOF
+
+my $html_end =<<EOF;
+				<p>Try password "xxx" for user "uid:0" to access the stock trader web application.</p>
+				<p class="new-user">
+				<a href="/cgi-bin/trader_register">First time user?</a>
+				</p>
+			</div>	
+		</div>
+			<div id="footer">
+				<div style="float:left;">Copyright 2008, WSO2 Inc.</div>
+				<div style="margin-left:432px;float:left;">Powered by 
+				<img align="top" src="/trader/images/powered-by-logo.gif" style="margin-top:-3px; margin-left: 0px;"/></div>
+			</div>
+		</div>
+	
+	</body>
+</html>
+EOF
+
+print $html_begin;
+print $login_form;
+print $html_end;

Added: incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_portfolio
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_portfolio?rev=720802&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_portfolio (added)
+++ incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_portfolio Wed Nov 26 02:55:38 2008
@@ -0,0 +1,473 @@
+#!/usr/bin/perl
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use CGI qw/:standard/;
+use WSO2::WSF;
+use XML::LibXML;
+
+my $WSFC_HOME='/opt/wso2/wsf_c/';
+
+my $q = new CGI;
+
+$username = $q->cookie('username');
+if(!$username) {
+    #print redirect('/cgi-bin/trader_login');
+}
+
+print $q->header();
+
+sub convert_date {
+  my($str) = shift;
+  if($str) {
+    $str =~ s/[T:\.]/-/g;
+    @date_arr = split("-", $str);
+    $year = @date_arr[0];
+    $mon = @date_arr[1];
+    $date = @date_arr[2];
+    $hour = @date_arr[3];
+    $min = @date_arr[4];
+    $sec = @date_arr[5];
+
+    if($hour > 12) {
+      $hour = $hour - 12;
+      $ampm = "PM";
+    }
+    else {
+      $ampm = "AM";
+    }
+    return "${mon}/${date}/${year} ${hour}:${min}:${sec} ${ampm}";
+  }
+  return "";
+}
+
+
+# get the endpoitn from the configuration service
+sub get_endpoint {
+
+    $config_endpoint = $q->cookie('endpoint');
+    $input_xml = <<XML;
+    <ClientConfigRequest xmlns="http://wso2.org/interop/stocktrader/xsd">
+        <Client>PERL_CLIENT</Client>
+    </ClientConfigRequest>
+XML
+
+    my $client = new WSO2::WSF::WSClient( { 'to' => $config_endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' =>  $WSFC_HOME } );
+    my $response_msg = $client->request( { 'payload' => $input_xml } );
+    my $response_str = $response_msg->{str};
+
+    my $response_parser = XML::LibXML->new();
+    $response_xml = $response_parser->parse_string($response_str);
+
+    my $xpc = XML::LibXML::XPathContext->new($response_xml);
+    $xpc->registerNs('ns'=> 'http://wso2.org/interop/stocktrader/xsd');
+
+    $bs =  $xpc->findvalue('//ns:BS');   
+    return $bs;
+}
+
+
+sub get_quote {
+    my($quote_id) = shift;
+
+    my $get_quotes_request = <<XML;
+      <getQuote xmlns="http://trade.samples.websphere.ibm.com">
+         <symbol>${quote_id}</symbol>
+      </getQuote>
+XML
+
+    
+    my $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_quotes_request } );
+
+    $get_quotes_response = $response->{str};
+  
+#    my $get_quotes_response = <<XML;
+#      <getQuoteResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <getQuoteReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <symbol>s:0</symbol>
+#            <companyName>S0 Incorporated</companyName>
+#            <price>100.00</price>
+#            <open>100.00</open>
+#            <low>100.00</low>
+#            <high>100.00</high>
+#            <change>0</change>
+#            <volume>0</volume>
+#         </getQuoteReturn>
+#      </getQuoteResponse>
+#XML
+
+    my $quote_parser = XML::LibXML->new();
+    $quote_xml = $quote_parser->parse_string($get_quotes_response);
+
+    return $quote_xml;
+}
+
+
+
+# Gets holding details of given user
+# @param userid user id of current user
+# returns collection of holding if success. NULL otherwise
+sub get_holdings {
+    my($username) = shift;
+
+    my $get_holdings_request = <<XML;
+      <getHoldings xmlns="http://trade.samples.websphere.ibm.com">
+         <userID>${username}</userID>
+      </getHoldings
+XML
+ 
+    my $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_holdings_request } );
+    
+    my $get_holdings_response = $response->{str};
+
+#    my $get_holdings_response = <<XML;
+#      <getHoldingsResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <getHoldingsReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <HoldingDataBean>
+#               <holdingID>46</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.157</purchaseDate>
+#               <quoteID>s:9</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>41</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.157</purchaseDate>
+#               <quoteID>s:8</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>37</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.157</purchaseDate>
+#               <quoteID>s:7</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>32</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.14</purchaseDate>
+#               <quoteID>s:6</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>25</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.14</purchaseDate>
+#               <quoteID>s:6</quoteID>
+#            </HoldingDataBean>
+#            <HoldingDataBean>
+#               <holdingID>25</holdingID>
+#               <quantity>200</quantity>
+#               <purchasePrice>100.00</purchasePrice>
+#               <purchaseDate>2008-05-21T16:01:44.14</purchaseDate>
+#               <quoteID>s:5</quoteID>
+#            </HoldingDataBean>
+#         </getHoldingsReturn>
+#      </getHoldingsResponse>
+#XML
+
+    my $holdings_parser = XML::LibXML->new();
+    $holdings_xml = $holdings_parser->parse_string($get_holdings_response);
+
+    return $holdings_xml;
+}
+
+
+# Gets closed orders of current user
+# @return collection of orders whose status is closed
+
+sub get_closed_orders
+{
+    my($username) = shift;
+
+    my $get_closed_orders_request = <<XML;
+          <getClosedOrders xmlns="http://trade.samples.websphere.ibm.com">
+             <userID>${username}</userID>
+          </getClosedOrders>
+XML
+
+    my $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_closed_orders_request } );
+   
+    my $get_closed_orders_response = $response->{str};
+
+#    my $get_closed_orders_response = <<XML;
+#      <getClosedOrdersResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <getClosedOrdersReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <OrderDataBean>
+#               <orderID>100000023</orderID>
+#               <orderType>sell</orderType>
+#               <orderStatus>completed</orderStatus>
+#               <openDate>2008-07-22T10:02:42.543</openDate>
+#               <completionDate>2008-07-22T10:02:42.607</completionDate>
+#               <quantity>1</quantity>
+#               <price>96.78</price>
+#               <orderFee>15.95</orderFee>
+#               <symbol>s:0</symbol>
+#            </OrderDataBean>
+#         </getClosedOrdersReturn>
+#      </getClosedOrdersResponse>
+#XML
+
+    my $closed_orders_parser = XML::LibXML->new();
+    $closed_orders_xml = $closed_orders_parser->parse_string($get_closed_orders_response);
+
+    return $closed_orders_xml;
+  
+}
+
+
+my $username = $q->cookie('username');
+my $holdings = get_holdings($username);
+
+print <<E;
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+    <head>
+        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
+        <meta name="generator" content="Adobe GoLive" />
+        <title>WSF/PHP StockTrader Welcome</title>
+        <link href="/trader/style.css" rel="stylesheet" type="text/css" media="all" />
+    </head>
+
+    <body>
+        <div id="content">
+            <div id="header">
+                <div class="logo"><img src="/trader/images/logo.gif"></div>
+            </div>
+            <div id="header-links">
+                <table>
+                    <tr>
+                    <td>
+                        <a href="/cgi-bin/trader">Welcome</a>
+                    </td>
+                    <td>
+                        <a href="/cgi-bin/trader_home">Home</a>
+                    </td>
+                    <td>
+                        <a href="/cgi-bin/trader_account">Account</a>
+                    </td>
+                    <td>
+                        <a href="/cgi-bin/trader_portfolio">Portfolio</a>
+                    </td>
+                    <td>
+                        <a href="/cgi-bin/trader_quotes">Quotes/Trade</a>
+                    </td>
+                    <td>
+                        <a href="/cgi-bin/trader_glossary">Glossary</a>
+                    </td>
+                    <td>
+                        <a href="/cgi-bin/trader_config">Config</a>
+                    </td>
+                    <td>
+                        <a href="/cgi-bin/trader_login">Login/Logout</a>
+                    </td>
+                    </tr>
+                </table>
+            </div>
+            <div id="middle">
+
+E
+
+$get_closed_orders_return = get_closed_orders($username);
+
+if($get_closed_orders_return) {
+    print("<p style=\"color: red\" align=\"center\">Trade Alert: The following orders have completed.</p>");
+    print("<table class=\"table-outer\" cellspacing=\"0\" align=\"center\"><thead>
+            <tr><th>Order ID</th><th>Order Status</th><th>Creation Date</th><th>Completion Date</th>
+            <th>Txn Fee</th><th>Type</th><th>Symbol</th><th>Quantity</th></tr></thead><tbody>");
+
+    my $xpc = XML::LibXML::XPathContext->new($get_closed_orders_return);
+    $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+    @nodes = $xpc->findnodes('//ns:OrderDataBean');
+
+    foreach my $bean (@nodes) {
+
+        my $xpc = XML::LibXML::XPathContext->new($bean);
+        $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+        $open_date = convert_date($xpc->findvalue('./ns:openDate'));
+
+        $completion_date = convert_date($xpc->findvalue('./ns:completionDate'));
+
+        $order_status = $xpc->findvalue('./ns:orderStatus');
+
+        $order_id = $xpc->findvalue('./ns:orderID');
+
+        $order_fee = $xpc->findvalue('./ns:orderFee');
+
+        $order_type = $xpc->findvalue('./ns:orderType');
+
+        $symbol = $xpc->findvalue('./ns:symbol');
+
+        $quantity = $xpc->findvalue('./ns:quantity');
+
+        print ("<tr><td>${order_id}</td>
+            <td>${order_status}</td>
+            <td>${open_date}</td>
+            <td>${completion_date}</td>
+            <td>${order_fee}</td>
+            <td>${order_type}</td>
+            <td>${symbol}</td>
+            <td>${quantity}</td></tr>");        
+    }
+    print("</tbody></table><br/><br/>");
+}
+
+$holdings_return = get_holdings($username);
+if ($holdings_return)
+{
+    print ("<div class=\"main-title\">
+        <h1>Portfolio Information</h1><script type=\"text/javascript\">var thisdate = new Date();
+    document.writeln(thisdate.toLocaleString());</script></div>");
+
+    print ("<table class=\"table-outer\" cellspacing=\"0\" align=\"center\">
+        <thead><tr><th>Holding ID</th><th>Purchase Date</th><th>Symbol</th>
+        <th>Quantity</th><th>Purchase Price</th><th>Current Price</th>
+        <th>Purchase Basis</th><th>Market Value</th><th>Gain(Loss)</th>
+        <th>Trade</th></tr></thead><tbody>");
+
+    $index = 0;
+    $purchaseBasis = 0;
+    $marketValue = 0;
+    $gain = 0;
+
+    my $xpc = XML::LibXML::XPathContext->new($holdings_return);
+    $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+    @nodes = $xpc->findnodes('//ns:HoldingDataBean');
+    foreach my $bean (@nodes)
+    {
+ 
+        my $xpc = XML::LibXML::XPathContext->new($bean);
+        $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+       
+        $quote_id = $xpc->findvalue('./ns:quoteID');
+
+
+        $quantity = $xpc->findvalue('./ns:quantity');
+
+        $purchase_price = $xpc->findvalue('./ns:purchasePrice');
+
+        $purchase_date = $xpc->findvalue('./ns:purchaseDate');
+
+        $holding_id = $xpc->findvalue('./ns:holdingID');
+
+        if(!$quote_info{$quote_id}) {
+            $quotes = get_quote($quote_id);
+            my $xpc2 = XML::LibXML::XPathContext->new($quotes);
+            $xpc2->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+            $price = $xpc2->findvalue('//ns:price');
+           
+            $quote_info{$quote_id} = $price;
+        }
+
+        my $quote_price = $quote_info{$quote_id};
+        $purchase_basis +=  ($purchase_price) * ($quantity);
+        $market_value += ($quote_price) * ($quantity);
+        $gain = ($quote_price - $purchase_price) * ($quantity);
+
+
+        print("<tr><td>${holding_id}</td><td><nobr>${purchase_date}</nobr></td><td>
+            <form action=\"/cgi-bin/trader_quotes\" method=\"post\">
+            <input type=\"hidden\" name=\"SYMBOLS\" value=\"${quote_id}\"/>  
+            <input type=\"submit\" name=\"GETQUOTE\" value=\"${quote_id}\"></input>
+            </form></td>
+            <td class=\"currency\">${quantity}</td><td class=\"currency\">\$${purchase_price}
+            </td><td class=\"currency\">${quote_price}</td><td class=\"currency\">${purchase_basis}</td><td class=\"currency\">
+            ${market_value}
+            </td><td class=\"currency\">");
+
+        if ($gain > 0)
+        {
+            print ("<span class=\"price-gain\">${gain}</span>");
+        }
+        elsif ($gain < 0)
+        {
+            print ("<span class=\"price-loss\">${gain}</span>");
+        }
+        else
+        {
+            print ("<span>${gain}</span>");
+        }
+        print("</td><td class=\"currency\">");
+        print("<form action = \"/cgi-bin/trader_confirmation\" method = \"post\">");
+        print("<input type=\"hidden\" name=\"HOLDINGID\" value=\"${holding_id}\"></input>");
+        print("<input type=\"hidden\" name=\"QUANTITY\" value=\"${quantity}\"></input>");
+        print("<input type=\"hidden\" name=\"SYMBOL\" value=\"${quote_id}\"></input>");
+        print("<input type=\"submit\" value = \"Sell\" name=\"SELL\">");
+        print("</input></td></tr></form>");
+
+    }
+
+    print ("<tr class=\"total\"><td colspan=\"6\">Totals</td><td class=\"currency\">\$${purchase_basis}</td>
+            <td class=\"currency\">\$${market_value}</td><td>");
+
+    $gain = $market_value - $purchase_basis;
+    if ($gain < 0)
+    {
+        print ("<span class=\"price-loss\">\$${gain}</span></td><td></td></tr>");
+    }
+    elsif ($gain > 0)
+    {
+        print ("<span class=\"price-gain\">\$${gain}</span></td><td></td></tr>");
+    }
+    else
+    {
+        print ("<span>\$${gain}</span></td><td></td></tr>");
+    }
+    print ("</tbody></table>");
+}
+
+print <<E;
+            <div class="bottom">
+            <form action = "/cgi-bin/trader_quotes" method = "post">
+            <input type="text" value="" name="SYMBOLS" id="" size="25"/><input type="submit" name="GETQUOTE" value="Get Quote" class="button"/>
+            </form>
+            </div>
+            </div>
+            <div id="footer">
+                <div style="float:left;">Copyright 2008, WSO2 Inc.</div>
+                <div style="margin-left:432px;float:left;">Powered by
+                <img align="top" src="/trader/images/powered-by-logo.gif" style="margin-top:-3px; margin-left: 0px;"/></div>
+            </div>
+        </div>
+    </body>
+</html>
+
+E

Added: incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_quotes
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_quotes?rev=720802&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_quotes (added)
+++ incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_quotes Wed Nov 26 02:55:38 2008
@@ -0,0 +1,630 @@
+#!/usr/bin/perl
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use CGI qw/:standard/;
+use WSO2::WSF;
+use XML::LibXML;
+
+my $q = new CGI;
+
+my $WSFC_HOME='/opt/wso2/wsf_c/';
+
+# get the endpoitn from the configuration service
+sub get_endpoint {
+
+    $config_endpoint = $q->cookie('endpoint');
+    $input_xml = <<XML;
+    <ClientConfigRequest xmlns="http://wso2.org/interop/stocktrader/xsd">
+        <Client>PERL_CLIENT</Client>
+    </ClientConfigRequest>
+XML
+
+    my $client = new WSO2::WSF::WSClient( { 'to' => $config_endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' =>  $WSFC_HOME } );
+    my $response_msg = $client->request( { 'payload' => $input_xml } );
+    my $response_str = $response_msg->{str};
+
+    my $response_parser = XML::LibXML->new();
+    $response_xml = $response_parser->parse_string($response_str);
+
+    my $xpc = XML::LibXML::XPathContext->new($response_xml);
+    $xpc->registerNs('ns'=> 'http://wso2.org/interop/stocktrader/xsd');
+
+    $bs =  $xpc->findvalue('//ns:BS');   
+    
+    return $bs;
+}
+
+
+sub convert_date {
+  my($str) = shift;
+  if($str) {
+    $str =~ s/[T:\.]/-/g;
+    @date_arr = split("-", $str);
+    $year = @date_arr[0];
+    $mon = @date_arr[1];
+    $date = @date_arr[2];
+    $hour = @date_arr[3];
+    $min = @date_arr[4];
+    $sec = @date_arr[5];
+
+    if($hour > 12) {
+      $hour = $hour - 12;
+      $ampm = "PM";
+    }
+    else {
+      $ampm = "AM";
+    }
+    return "${mon}/${date}/${year} ${hour}:${min}:${sec} ${ampm}";
+  }
+  return "";
+}
+
+
+
+# Gets closed orders of current user
+# @return collection of orders whose status is closed
+
+
+sub get_closed_orders
+{
+    my($username) = shift;
+
+    my $get_closed_orders_request = <<XML;
+          <getClosedOrders xmlns="http://trade.samples.websphere.ibm.com">
+             <userID>${username}</userID>
+          </getClosedOrders>
+XML
+
+    my $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_closed_orders_request } );
+    
+    my $get_closed_orders_response = $response->{str};
+
+#    my $get_closed_orders_response = <<XML;
+#      <getClosedOrdersResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <getClosedOrdersReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <OrderDataBean>
+#               <orderID>100000023</orderID>
+#               <orderType>sell</orderType>
+#               <orderStatus>completed</orderStatus>
+#               <openDate>2008-07-22T10:02:42.543</openDate>
+#               <completionDate>2008-07-22T10:02:42.607</completionDate>
+#               <quantity>1</quantity>
+#               <price>96.78</price>
+#               <orderFee>15.95</orderFee>
+#               <symbol>s:0</symbol>
+#            </OrderDataBean>
+#         </getClosedOrdersReturn>
+#      </getClosedOrdersResponse>
+#XML
+
+    my $closed_orders_parser = XML::LibXML->new();
+    $closed_orders_xml = $closed_orders_parser->parse_string($get_closed_orders_response);
+
+    return $closed_orders_xml;
+  
+}
+
+
+
+
+sub get_quote {
+    my($quote_id) = shift;
+
+    my $get_quotes_request = <<XML;
+      <getQuote xmlns="http://trade.samples.websphere.ibm.com">
+         <symbol>${quote_id}</symbol>
+      </getQuote>
+XML
+ 
+    $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $get_quotes_request } );
+    my $get_quotes_response = $response->{str};
+
+#    my $get_quotes_response = <<XML;
+#      <getQuoteResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <getQuoteReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#            <symbol>s:0</symbol>
+#            <companyName>S0 Incorporated</companyName>
+#            <price>100.00</price>
+#            <open>100.00</open>
+#            <low>100.00</low>
+#            <high>100.00</high>
+#            <change>0</change>
+#            <volume>0</volume>
+#         </getQuoteReturn>
+#      </getQuoteResponse>
+#XML
+#
+    my $parser = XML::LibXML->new();
+    $quote_xml = $parser->parse_string($get_quotes_response);
+
+    return $quote_xml;
+}
+
+
+sub buy {
+    $userID = shift;
+    $symbol = shift;
+    $quantity = shift;
+    $orderProcessingMode = shift;
+
+
+    my $buy_request = <<XML;
+      <buy xmlns="http://trade.samples.websphere.ibm.com">
+        <userID>${userID}</userID>
+        <symbol>${symbol}</symbol>
+        <quantity>${quantity}</quantity>
+        <orderProcessingMode>${orderProcessingMode}</orderProcessingMode>
+      </buy>
+XML
+ 
+    my $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $buy_request } );
+
+    my $buy_response = $response->{str};
+  
+#    my $buy_response = <<XML;
+#      <buyResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <buyReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#               <orderID>42</orderID>
+#               <orderType>buy</orderType>
+#               <orderStatus>completed</orderStatus>
+#               <openDate>2008-05-21T16:01:44.157</openDate>
+#               <completionDate>2008-05-21T16:01:44.157</completionDate>
+#               <quantity>200</quantity>
+#               <price>100.00</price>
+#               <orderFee>24.50</orderFee>
+#               <symbol>s:8</symbol>
+#         </buyReturn>
+#      </getQuoteResponse>
+#XML
+
+    my $parser = XML::LibXML->new();
+    $buy_xml = $parser->parse_string($buy_response);
+
+    return $buy_xml;
+}
+
+sub sell_enhanced {
+    $userID = shift;
+    $holdingID = shift;
+    $quantity = shift;
+
+
+    my $sell_request = <<XML;
+      <sellEnhanced xmlns="http://trade.samples.websphere.ibm.com">
+        <userID>${userID}</userID>
+        <holdingID>${holdingID}</holdingID>
+        <quantity>${quantity}</quantity>
+      </sellEnhanced>
+XML
+ 
+    my $endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $sell_request } );
+
+    $sell_response = $response->{str};
+  
+#    my $sell_response = <<XML;
+#      <sellEnhancedResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <sellEnhancedReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#               <orderID>42</orderID>
+#               <orderType>sell</orderType>
+#               <orderStatus>completed</orderStatus>
+#               <openDate>2008-05-21T16:01:44.157</openDate>
+#               <completionDate>2008-05-21T16:01:44.157</completionDate>
+#               <quantity>200</quantity>
+#               <price>100.00</price>
+#               <orderFee>24.50</orderFee>
+#               <symbol>s:8</symbol>
+#         </sellEnhancedReturn>
+#      </sellEnhancedResponse>
+#XML
+
+    my $parser = XML::LibXML->new();
+    $sell_xml = $parser->parse_string($sell_response);
+
+    return $sell_xml;
+}
+
+my $symbol;
+my $is_buy;
+my $is_sell;
+my $is_reply = 0;
+my $buy_return_symbol;
+my $quotes_initial_page = 0;
+my $brx; # buyReturn
+my $sell_enhanced;
+
+my $xpc_buy;
+my $xpc_sell;
+my $xpc_quotes;
+
+if ( defined $q->param('GETQUOTE') ) {
+    $symbol = $q->param('SYMBOLS');
+    
+    $quotes = get_quote($symbol);
+    my $xpc_quotes = XML::LibXML::XPathContext->new($quotes);
+    $xpc_quotes->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+} elsif ( defined( $q->param('BUY') ) || defined( $q->param('SELL') ) ) {
+    my $quantity = $q->param('QUANTITY');
+    # my $userid = get_from_cookie
+    $userid = $q->cookie("username");
+    $is_buy = 0;
+    $is_sell = 0;
+
+    if ( defined $q->param('BUY') ) {
+        my $mode = 0;
+        $is_buy = 1;
+        $symbol = $q->param('SYMBOL');
+        # find out what kind of xml is here and then if the order id is defined
+        # $buy_return = that xml twig
+        
+        $buy_response = buy($userid, $symbol, $quantity, $mode);
+
+        $xpc_buy = XML::LibXML::XPathContext->new($buy_response);
+        $xpc_buy->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+        $order_id = $xpc_buy->findvalue('//ns:orderID');
+
+        if($order_id) {
+            $is_reply = 1;
+        }
+
+    } elsif ( defined $q->param('SELL') ) {
+        $is_sell = 1;
+        $holdingid = $q->param('HOLDINGID');
+	    $sell_response = sell_enhanced($userid, $holdingid, $quantity);
+
+        $xpc_sell = XML::LibXML::XPathContext->new($sell_response);
+        $xpc_sell->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+        $order_id = $xpc_sell->findvalue('//ns:orderID');
+        
+        if($order_id) {
+            $is_reply = 1;
+        }
+    }
+} else {
+    # just wanna visit sire
+    $quotes_initial_page = 1;
+}
+
+my $html_begin = <<E;
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+	<head>
+		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+		<title>WSF/PHP StockTrader Welcome</title>
+		<link href="/trader/style.css" rel="stylesheet" type="text/css" media="all" />
+	</head>
+
+	<body>
+		<div id="content">
+			<div id="header">
+				<div class="logo"><img src="/trader/images/logo.gif"></div>
+			</div>
+			<div id="header-links">
+				<table>
+					<tr>
+					<td>
+						<a href="/cgi-bin/trader">Welcome</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_home">Home</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_account">Account</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_portfolio">Portfolio</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_quotes">Quotes/Trade</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_glossary">Glossary</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_config">Config</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_login">Login/Logout</a>
+					</td>
+					</tr>
+				</table>
+			</div>
+			<div id="middle">
+E
+
+
+print $q->header();
+print $html_begin;
+
+$get_closed_orders_return = get_closed_orders($username);
+
+# check whether there's a new status change happened
+if($get_closed_orders_return) {
+
+    my $xpc = XML::LibXML::XPathContext->new($get_closed_orders_return);
+    $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+
+    @nodes = $xpc->findnodes('//ns:OrderDataBean');
+
+    if(@nodes) { 
+        # checking whether a new status change happened in a particular order
+        print("<p style=\"color: red\" align=\"center\">Trade Alert: The following orders have completed.</p>");
+        print("<table class=\"table-outer\" cellspacing=\"0\" align=\"center\"><thead>
+                <tr><th>Order ID</th><th>Order Status</th><th>Creation Date</th><th>Completion Date</th>
+                <th>Txn Fee</th><th>Type</th><th>Symbol</th><th>Quantity</th></tr></thead><tbody>");
+
+
+
+
+        foreach my $bean (@nodes) {
+
+            my $xpc = XML::LibXML::XPathContext->new($bean);
+            $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+
+            $open_date = convert_date($xpc->findvalue('./ns:openDate'));
+
+            $completion_date = convert_date($xpc->findvalue('./ns:completionDate'));
+
+            $order_status = $xpc->findvalue('./ns:orderStatus');
+
+            $order_id = $xpc->findvalue('./ns:orderID');
+
+            $order_fee = $xpc->findvalue('./ns:orderFee');
+
+            $order_type = $xpc->findvalue('./ns:orderType');
+
+            $symbol = $xpc->findvalue('./ns:symbol');
+
+            $quantity = $xpc->findvalue('./ns:quantity');
+
+            print ("<tr><td>${order_id}</td>
+                <td>${order_status}</td>
+                <td>${open_date}</td>
+                <td>${completion_date}</td>
+                <td>${order_fee}</td>
+                <td>${order_type}</td>
+                <td>${symbol}</td>
+                <td>${quantity}</td></tr>");        
+        }
+        print("</tbody></table><br/><br/>");
+    }
+}
+
+
+
+
+# if isReply
+if ($is_reply)
+{
+    my $order_id;
+    if($is_buy) {
+        $order_id = $xpc_buy->findvalue('//ns:orderID');
+        $quantity = $xpc_buy->findvalue('//ns:quantity');
+    }
+    elsif($is_sell) {
+        $order_id = $xpc_sell->findvalue('//ns:orderID');
+        $quantity = $xpc_sell->findvalue('//ns:quantity');
+    }
+    # Check whether the user has requested to buy or sell some quote.*/
+    print ("<div class=\"main-title\"><h1>New Order</h1>
+        <script type=\"text/javascript\">var thisdate = new Date();
+    document.writeln(thisdate.toLocaleString());</script></div>");
+    print ("<p align=\"center\">Order ${order_id} to ${quantity} shares of s:0 has been submitted for processing.</p>");
+    print ("<p align=\"center\">Order Details:</p>");
+    print ("<table class=\"table-outer\" cellspacing=\"0\" align=\"center\"><thead><tr>
+        <th>Order ID</th><th>Order Status</th><th>Creation Date</th>
+        <th>Completion Date</th><th>Txn Fee</th><th>Type</th><th>Symbol</th>
+            <th>Quantity</th></tr></thead>
+            <tbody>");
+
+    if ($is_buy)
+    {
+        $date_time  = convert_date($xpc_buy->findvalue('//ns:openDate'));
+        $order_status = $xpc_buy->findvalue('//ns:orderStatus');
+        $order_fee = $xpc_buy->findvalue('//ns:orderFee');
+        $order_type = $xpc_buy->findvalue('//ns:orderType');
+        $symbol = $xpc_buy->findvalue('//ns:symbol');
+        $quantity = $xpc_buy->findvalue('//ns:quantity');
+
+        print ("<tr><td>${order_id}</td><td>${order_status}</td><td>${date_time}</td><td>
+            Pending</td><td>\$${order_fee}</td><td>${order_type}</td><td>${symbol}</td>
+            <td>${quantity}</td></tr>");
+    }
+    elsif ($is_sell)
+    {
+        $date_time  = convert_date($xpc_sell->findvalue('//ns:openDate'));
+        $order_status = $xpc_sell->findvalue('//ns:orderStatus');
+        $order_fee = $xpc_sell->findvalue('//ns:orderFee');
+        $order_type = $xpc_sell->findvalue('//ns:orderType');
+        $symbol = $xpc_sell->findvalue('//ns:symbol');
+        $quantity = $xpc_sell->findvalue('//ns:quantity');
+
+        print ("<tr><td>${order_id}</td><td>${order_status}</td><td>${date_time}</td><td>
+            Pending</td><td>\$${order_fee}</td><td>${order_type}</td><td>${symbol}</td>
+            <td>${quantity}</td></tr>");
+    }
+    print ("</tbody></table>");
+}
+
+elsif ($q->param('GETQUOTE'))
+{
+    print("<div class=\"main-title\"><h1>Stock Quotes</h1>");
+    print("<script type=\"text/javascript\">var thisdate = new Date();
+    document.writeln(thisdate.toLocaleString());</script>");
+    print("</div>");
+    print("<table class=\"table-outer\" cellspacing=\"0\" align=\"center\"><thead>
+        <tr><th>Symbol</th><th>Company</th><th>Volume</th><th>Price Range</th>
+        <th>Open Price</th><th>Current Price</th><th>Gain(Loss)</th><th>Trade</th></tr></thead><tbody>");
+    
+    $symbol = $xpc_quotes->findvalue($symbol);
+    if ($quotesReturn->symbol)
+    {
+        $company_name = $xpc_quotes->findvalue("//ns:companyName");
+        $volume = $xpc_quotes->findvalue("//ns:volume");
+        $low = $xpc_quotes->findvalue("//ns:low");
+        $high = $xpc_quotes->findvalue("//ns:high");
+        $open = $xpc_quotes->findvalue("//ns:open");
+        $price = $xpc_quotes->findvalue("//ns:price");
+        $change = $xpc_quotes->findvalue("//ns:change");
+
+        print ("<tr><td>${symbol}</td><td>${company_name}</td>
+            <td>${volume}</td>
+            <td>\$${low}-\$${high}</td><td>\$${open}</td>
+            <td>\$${price}</td><td>");
+
+        if ($change > 0)
+        {
+            print ("<span class=\"price-gain\">\$${change}</span>");
+        }
+        elsif ($change < 0)
+        {
+            print ("<span class=\"price-loss\">\$${change}</span>");
+        }
+        else
+        {
+            print ("<span>\$${change}</span>");
+        }
+        print("</td><td><form action=\"/cgi-bin/trader_confirmation\" method=\"post\">
+            <input type=\"hidden\" name=\"QUANTITY\" value=\"${volume}\">
+            <input type=\"hidden\" name=\"SYMBOL\" value=\"${symbol}\">
+            <input type=\"hidden\" name=\"PRICE\" value=\"${price}\">
+            <input type=\"submit\" name=\"BUY\" value=\"Buy\"></input></form></td></tr>");
+    }
+    print("</tbody></table>");
+}
+
+elsif($quotes_initial_page)
+{
+    print("<div class=\"main-title\"><h1>Stock Quotes</h1>");
+    print("<script type=\"text/javascript\">var thisdate = new Date();
+    document.writeln(thisdate.toLocaleString());</script>");
+    print("</div>");
+    print("<table class=\"table-outer\" cellspacing=\"0\" align=\"center\"><thead>
+        <tr><th>Symbol</th><th>Company</th><th>Volume</th><th>Price Range</th>
+        <th>Open Price</th><th>Current Price</th><th>Gain(Loss)</th><th>Trade</th></tr></thead><tbody>");
+
+    $symbolCount = 0;
+    while($symbolCount < 5)
+    {
+        $new_symbol = "s:${symbolCount}";
+        $new_quotes = get_quote($new_symbol);
+
+        my $xpc = XML::LibXML::XPathContext->new($new_quotes);
+        $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com');
+        if ($new_quotes)
+        {
+
+            $company_name = $xpc->findvalue("//ns:companyName");
+            $volume = $xpc->findvalue("//ns:volume");
+            $low = $xpc->findvalue("//ns:low");
+            $high = $xpc->findvalue("//ns:high");
+            $open = $xpc->findvalue("//ns:open");
+            $price = $xpc->findvalue("//ns:price");
+            $change = $xpc->findvalue("//ns:change");
+            $symbol = $xpc->findvalue("//ns:symbol");
+            
+            if ($symbol)
+            {
+                print ("<tr><td>${symbol}</td><td>${company_name}</td>
+                    <td>${volume}</td><td>\$${low}-\$${high}</td>
+                    <td>\$${open}</td>
+                    <td>\$${price}</td><td>");
+
+                if ($change > 0)
+                {
+                    print ("<span class=\"price-gain\">\$${change}</span>");
+                }
+                elsif ($change < 0)
+                {
+                    print ("<span class=\"price-loss\">\$${change}</span>");
+                }
+                else
+                {
+                    print ("<span>\$${change}</span>");
+                }
+                print("</td><td><form action=\"/cgi-bin/trader_confirmation\" method=\"post\">
+                    <input type=\"hidden\" name=\"QUANTITY\" value=\"${volume}\">
+                    <input type=\"hidden\" name=\"SYMBOL\" value=\"${symbol}\">
+                    <input type=\"hidden\" name=\"PRICE\" value=\"${price}\">
+                    <input type=\"submit\" name=\"BUY\" value=\"Buy\"></input></form></td></tr>");
+            }
+        }
+        $symbolCount ++;
+    }
+    print("</tbody></table>");
+
+}
+
+else
+{
+    print("<div class=\"main-title\"><h1>Stock Quotes</h1>");
+    print("<script type=\"text/javascript\">var thisdate = new Date();
+    document.writeln(thisdate.toLocaleString());</script>");
+    print("</div>");
+}
+
+
+my $html_end =<<E;
+			<div class="bottom">
+
+			<form method = "post"  action = "/cgi-bin/trader_quotes">
+			<input type="text" value="" name="SYMBOLS" size="25"/>
+			<input type="submit" value="Get Quote" name="GETQUOTE" class="button"/>
+			</form>
+
+			</div>
+			</div>
+			<div id="footer">
+				<div style="float:left;">Copyright 2008, WSO2 Inc.</div>
+				<div style="margin-left:432px;float:left;">Powered by 
+                <img align="top" src="/trader/images/powered-by-logo.gif" style="margin-top:-3px; margin-left: 0px;"/></div>
+			</div>
+		</div>
+	</body>
+
+</html>
+E
+
+print $html_end;

Added: incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_register
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_register?rev=720802&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_register (added)
+++ incubator/stonehenge/contrib/stocktrader/perl/trader_client/trader_register Wed Nov 26 02:55:38 2008
@@ -0,0 +1,264 @@
+#!/usr/bin/perl
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use CGI qw/:standard/;
+use WSO2::WSF;
+use XML::LibXML;
+
+my $q = new CGI;
+
+my $WSFC_HOME='/opt/wso2/wsf_c/';
+
+# get the endpoitn from the configuration service
+sub get_endpoint {
+
+    $config_endpoint = $q->cookie('endpoint');
+    $input_xml = <<XML;
+    <ClientConfigRequest xmlns="http://wso2.org/interop/stocktrader/xsd">
+        <Client>PERL_CLIENT</Client>
+    </ClientConfigRequest>
+XML
+
+    my $client = new WSO2::WSF::WSClient( { 'to' => $config_endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' =>  $WSFC_HOME }/opt/wso2/wsf_c/client->request( { 'payload' => $input_xml } );
+    my $response_str = $response_msg->{str};
+
+    my $response_parser = XML::LibXML->new();
+    $response_xml = $response_parser->parse_string($response_str);
+
+    my $xpc = XML::LibXML::XPathContext->new($response_xml);
+    $xpc->registerNs('ns'=> 'http://wso2.org/interop/stocktrader/xsd');
+
+    $bs =  $xpc->findvalue('//ns:BS');   
+    
+    return $bs;
+}
+
+
+# register user
+sub RegisterUser {
+
+    my($userID) = shift;
+    my($password) = shift;
+    my($fullname ) = shift;
+    my($address) = shift;
+    my($email) = shift;
+    my($creditcard) = shift;
+    my($openBalance) = shift;
+
+    my $register_request =<<EOF;
+      <register xmlns="http://trade.samples.websphere.ibm.com">
+         <userID>${userID}</userID>
+         <password>${password}</password>
+         <fullname>${fullname}</fullname>
+         <address>${address}</address>
+         <email>${email}</email>
+         <creditcard>${creditcard}</creditcard>
+         <openBalance>${openBalance}</openBalance>
+      </register>
+EOF
+
+    my $tmp_endpoint = get_endpoint();
+    my $client = new WSO2::WSF::WSClient( { 'to' => $tmp_endpoint,
+                                          'log_file' => '/tmp/stocktrader.log',
+                                          'log_level' => 4,
+                                          'wsfc_home' => $WSFC_HOME } );
+    $response = $client->request( { 'payload' => $register_request } );
+    $response_str = $response->{str};
+
+#    $response_str = <<XML;
+#      <registerResponse xmlns="http://trade.samples.websphere.ibm.com">
+#         <registerReturn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+#         </registerReturn>
+#      </registerResponse>
+#XML
+    return $response_str;    
+}
+
+print $q->header();
+
+if ($q->param('REGISTERUSER'))
+{
+	# New user registration
+	$userID = $q->param('REQUESTEDID');
+	$openBalance = $q->param('OPENBALANCE');
+	$fullname = $q->param('FULLNAME');
+	$email = $q->param('EMAIL');
+	$address = $q->param('ADDRESS');
+	$password = $q->param('PASSWORD');
+	$creditcard = $q->param('CREDITCARD');
+	$confpassword = $q->param('CONFIRMATIONPASSWORD');
+
+    $invalidInformation = 0;
+
+	if (!$userID  || $password != $confpassword)
+	{
+		$invalidInformation = 1;
+	}
+	else
+	{
+		$response = RegisterUser($userID, $password, $fullname, 
+			$address, $email, $creditcard, $openBalance);
+		if ($response)
+		{
+			$successfulRegistration = 1;
+		}
+		else
+		{
+			$invalidInformation = 1;
+		}
+	}
+}
+
+
+print <<HTML_CODE;
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+	<head>
+		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+		<meta name="generator" content="Adobe GoLive" />
+		<title>WSF/PHP StockTrader Welcome</title>
+		<link href="/trader/style.css" rel="stylesheet" type="text/css" media="all" />
+	</head>
+
+	<body>
+		<div id="content">
+			<div id="header">
+			    <div class="logo"><img src="/trader/images/logo.gif"></div>
+			</div>
+			<div id="header-links">
+				<table>
+					<tr>
+					<td>
+						<a href="/cgi-bin/trader">Welcome</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_home">Home</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_account">Account</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_portfolio">Portfolio</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_quotes">Quotes/Trade</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_glossary">Glossary</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_config">Config</a>
+					</td>
+					<td>
+						<a href="/cgi-bin/trader_login">Login/Logout</a>
+					</td>
+					</tr>
+				</table>
+			</div>
+			<div id="middle">
+				<div class="main-title">
+					<h1>Register</h1>
+					<script type="text/javascript">
+						var thisdate = new Date();
+						document.writeln(thisdate.toLocaleString());
+					</script>
+				</div>
+
+HTML_CODE
+				if ($successfulRegistration)
+				{
+					print("<p style=\"color: red\" align=\"center\">
+						Registration was successful, please <a href =\"/cgi-bin/trader_login\">login</a>.</p>");
+				}
+
+				else
+				{
+					if ($invalidInformation)
+					{
+						print("<p style=\"color: red\" align=\"center\">Please enter valid information.</p>");
+					}
+					print ("<table class=\"profile\" cellspacing=\"0\" width=\"100%\">
+					<thead>
+					<tr>
+					<th>
+					Create Account Profile:
+					</th>
+					</tr>
+					</thead>
+					<tbody>
+					<tr>
+						<td>
+							<form action=\"/cgi-bin/trader_register\" method=\"post\">
+							<table cellspacing=\"0\" align=\"center\">
+								<tr>
+									<td colspan=\"4\" >
+										&nbsp;
+									</td>
+								</tr>
+								<tr>
+									<td>Requested ID:</td>
+									<td><input name=\"REQUESTEDID\" type=\"text\" id=\"\" size=\"25\"/></td>
+									<td>Opening Balance:</td>
+									<td><input type=\"text\" name=\"OPENBALANCE\" value=\"100000\" id=\"\" size=\"25\"/></td>
+								</tr>
+								<tr>
+									<td>Full Name:</td>
+									<td><input type=\"text\" name=\"FULLNAME\" id=\"\" size=\"25\"/></td>
+									<td>Email Address:</td>
+									<td><input type=\"text\" name=\"EMAIL\" id=\"\" size=\"25\"/></td>
+								</tr>
+								<tr>
+									<td>Address:</td>
+									<td><input name=\"ADDRESS\" type=\"text\" id=\"\" size=\"25\"/></td>
+									<td>Password:</td>
+									<td><input name=\"PASSWORD\" type=\"password\" id=\"\" size=\"25\"/></td>
+								</tr>
+								<tr>
+									<td>Credit Card:</td>
+									<td><input name=\"CREDITCARD\" type=\"text\" id=\"\" size=\"25\"/></td>
+									<td>Confirm Password:</td>
+									<td><input name=\"CONFIRMATIONPASSWORD\" type=\"password\" id=\"\" size=\"25\"/></td>
+								</tr>
+								<tr>
+									<td colspan=\"4\" class=\"button\">
+										<input type=\"submit\" name=\"REGISTERUSER\" value=\"Register\" class=\"button\"/>
+									</td>
+								</tr>
+							</table>
+							</form>	
+						</td>
+					</tr>
+					</tbody>
+					</table>");
+				}
+
+print <<HTML_CODE;
+			</div>
+			<div id="footer">
+				<div style="float:left;">Copyright 2008, WSO2 Inc.</div>
+				<div style="margin-left:432px;float:left;">Powered by 
+			    <img align="top" src="/trader/images/powered-by-logo.gif" style="margin-top:-3px; margin-left: 0px;"/></div>
+			</div>
+		</div>
+	</body>
+
+</html>
+HTML_CODE

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/README
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/README?rev=720802&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/python/trader_client/README (added)
+++ incubator/stonehenge/contrib/stocktrader/python/trader_client/README Wed Nov 26 02:55:38 2008
@@ -0,0 +1,28 @@
+How to run WSF/Python Stock Trader Web Application
+--------------------------------------------------
+
+* Still work only on Linux
+
+1. Prerequisites
+
+    1.1 WSFC
+    
+    SVN: http://wso2.org/repos/wso2/trunk/wsf/c/
+    http://wso2.org/projects/wsf/c
+
+    1.2 WSF/Python
+    
+    SVN: http://svn.wso2.org/repos/wso2/branches/wsf/python/1.0.0alpha/wsf/python
+        1.2.1 Building and Installing WSF/Python extension.
+            Use following command to build the extension.
+                - python setup.py --with-wsfc={PATH TO WSFC HOME} build
+            Use following command to install the extension.
+                - sudo python setup.py --with-wsfc={PATH TO WSFC HOME} install
+
+2. Configuring Web Application
+    2.1 Change the LOG_DIR, LOG_LEVEL variables in request_processor.py to point location and log level that you prefer.
+    2.2 Change the WSFC_HOME variable to point to WSFC installation directory.
+    2.3 Change the 'document_root' of the line (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/home/milinda/wso2/stock_trader/media'}) in urls.py to point to directory where stock_trader/media will reside.
+
+3. Starting Django Test Server
+    Execute python manage.py runserver while insde the stock_trader django application directory.

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/__init__.py
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/__init__.py?rev=720802&view=auto
==============================================================================
    (empty)

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/manage.py
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/manage.py?rev=720802&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/python/trader_client/manage.py (added)
+++ incubator/stonehenge/contrib/stocktrader/python/trader_client/manage.py Wed Nov 26 02:55:38 2008
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/Thumbs.db
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/Thumbs.db?rev=720802&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/Thumbs.db
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/bg.gif
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/bg.gif?rev=720802&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/bg.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/button-bg.gif
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/button-bg.gif?rev=720802&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/button-bg.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/footer-bg.gif
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/footer-bg.gif?rev=720802&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/footer-bg.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/green-arrow.gif
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/green-arrow.gif?rev=720802&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/green-arrow.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/header-bg.gif
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/header-bg.gif?rev=720802&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/contrib/stocktrader/python/trader_client/media/images/header-bg.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream