Преглед на файлове

Merge pull request #3234 from afishbeck/boxform_wsecl

gh-3209 Add Block input form to WsECl

Reviewed-By: Kevin Wang <kevin.wang@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman преди 13 години
родител
ревизия
39a1f67a5c
променени са 6 файла, в които са добавени 302 реда и са изтрити 9 реда
  1. 72 4
      esp/services/ws_ecl/ws_ecl_service.cpp
  2. 1 1
      esp/services/ws_ecl/ws_ecl_service.hpp
  3. 1 0
      esp/xslt/CMakeLists.txt
  4. 209 0
      esp/xslt/wsecl3_boxform.xsl
  5. 18 3
      esp/xslt/wsecl3_form.xsl
  6. 1 1
      esp/xslt/wsecl3_tabview.xsl

+ 72 - 4
esp/services/ws_ecl/ws_ecl_service.cpp

@@ -1486,7 +1486,7 @@ bool CWsEclBinding::getSchema(StringBuffer& schema, IEspContext &ctx, CHttpReque
     return true;
 }
 
-int CWsEclBinding::getGenForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo)
+int CWsEclBinding::getGenForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, bool box)
 {
     IProperties *parms = request->queryParameters();
 
@@ -1509,7 +1509,24 @@ int CWsEclBinding::getGenForm(IEspContext &context, CHttpRequest* request, CHttp
     }
 
     context.addOptions(ESPCTX_ALL_ANNOTATION);
-    getSchema(formxml, context, request, wsinfo);
+    if (box)
+    {
+        StringBuffer xmlreq;
+        getWsEcl2XmlRequest(xmlreq, context, request, wsinfo, "xml", NULL, 0);
+        if (xmlreq.length())
+        {
+            Owned<IPropertyTree> pretty = createPTreeFromXMLString(xmlreq.str(), ipt_ordered);
+            if (pretty)
+            {
+                toXML(pretty, xmlreq.clear());
+                formxml.append("<Request>");
+                encodeUtf8XML(xmlreq, formxml);
+                formxml.append("</Request>");
+            }
+        }
+    }
+    else
+        getSchema(formxml, context, request, wsinfo);
 
     formxml.append("<CustomViews>");
     if (web)
@@ -1525,7 +1542,12 @@ int CWsEclBinding::getGenForm(IEspContext &context, CHttpRequest* request, CHttp
     Owned<IXslTransform> xform = xslp->createXslTransform();
 
     StringBuffer xslfile(getCFD());
-    xform->loadXslFromFile(xslfile.append("./xslt/wsecl3_form.xsl").str());
+    if (box)
+        xslfile.append("./xslt/wsecl3_boxform.xsl");
+    else
+        xslfile.append("./xslt/wsecl3_form.xsl");
+
+    xform->loadXslFromFile(xslfile.str());
     xform->setXmlSource(formxml.str(), formxml.length()+1);
 
     // pass params to form (excluding form and __querystring)
@@ -1605,12 +1627,25 @@ void buildParametersXml(IPropertyTree *parmtree, IProperties *parms)
     DBGLOG("parmtree: %s", xml.str());
 }
 
+void appendValidInputBoxContent(StringBuffer &xml, const char *in)
+{
+    //more later
+    Owned<IPropertyTree> validAndFlat = createPTreeFromXMLString(in, ipt_ordered);
+    toXML(validAndFlat, xml, 0, 0);
+}
 
 void CWsEclBinding::getWsEcl2XmlRequest(StringBuffer& soapmsg, IEspContext &context, CHttpRequest* request, WsEclWuInfo &wsinfo, const char *xmltype, const char *ns, unsigned flags)
 {
     Owned<IPropertyTree> parmtree = createPTree();
     IProperties *parms = context.queryRequestParameters();
 
+    const char *boxInput = parms->queryProp("_boxFormInput");
+    if (boxInput)
+    {
+        appendValidInputBoxContent(soapmsg, boxInput);
+        return;
+    }
+
     buildParametersXml(parmtree, parms);
 
     StringBuffer element;
@@ -1932,6 +1967,36 @@ int CWsEclBinding::onGetSoapBuilder(IEspContext &context, CHttpRequest* request,
     return getXmlTestForm(context, request, response, wsinfo, "soap");
 }
 
+bool checkWsEclFormType(StringBuffer &form, const char *value)
+{
+    if (value)
+    {
+        bool save = (strieq(value, "ecl")||strieq(value, "box"));
+        if (save || (strieq(value, "soap")||strieq(value, "json")))
+        {
+            form.set(value);
+            return save;
+        }
+    }
+    form.set("ecl");
+    return false;
+}
+
+void getWsEclFormType(CHttpRequest* request, CHttpResponse* response, StringBuffer &form)
+{
+    bool save=false;
+    if (strieq(form, "default"))
+    {
+        CEspCookie *cookie = request->queryCookie("defaultWsEclForm");
+        checkWsEclFormType(form, (cookie) ? cookie->getValue() : NULL);
+    }
+    else if (checkWsEclFormType(form, form.str()))
+    {
+        CEspCookie *cookie = request->queryCookie("defaultWsEclForm");
+        if (!cookie || !strieq(cookie->getValue(), form.str()))
+            response->addCookie(new CEspCookie("defaultWsEclForm", form));
+    }
+}
 
 int CWsEclBinding::getWsEcl2Form(CHttpRequest* request, CHttpResponse* response, const char *thepath)
 {
@@ -1946,8 +2011,11 @@ int CWsEclBinding::getWsEcl2Form(CHttpRequest* request, CHttpResponse* response,
     splitLookupInfo(request->queryParameters(), thepath, wuid, qs, qid);
     WsEclWuInfo wsinfo(wuid.str(), qs.str(), qid.str(), context->queryUserId(), context->queryPassword());
 
+    getWsEclFormType(request, response, formtype);
     if (strieq(formtype.str(), "ecl"))
-        return getGenForm(*context, request, response, wsinfo);
+        return getGenForm(*context, request, response, wsinfo, false);
+    else if (strieq(formtype.str(), "box"))
+        return getGenForm(*context, request, response, wsinfo, true);
     else if (strieq(formtype.str(), "soap"))
         return getXmlTestForm(*context, request, response, "soap", wsinfo);
     else if (strieq(formtype.str(), "json"))

+ 1 - 1
esp/services/ws_ecl/ws_ecl_service.hpp

@@ -145,7 +145,7 @@ public:
     void xsltTransform(const char* xml, unsigned int len, const char* xslFileName, IProperties *params, StringBuffer& ret);
 
     int getWsEcl2TabView(CHttpRequest* request, CHttpResponse* response, const char *thepath);
-    int getGenForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo);
+    int getGenForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, bool boxform);
     int getWsEcl2Form(CHttpRequest* request, CHttpResponse* response, const char *thepath);
 
     bool isValidServiceName(IEspContext &context, const char *name){return true;}

+ 1 - 0
esp/xslt/CMakeLists.txt

@@ -35,6 +35,7 @@ FOREACH( iFILES
     ${CMAKE_CURRENT_SOURCE_DIR}/yuitree.xsl
     ${CMAKE_CURRENT_SOURCE_DIR}/xmlformatter.xsl
     ${CMAKE_CURRENT_SOURCE_DIR}/wsecl3_form.xsl
+    ${CMAKE_CURRENT_SOURCE_DIR}/wsecl3_boxform.xsl
     ${CMAKE_CURRENT_SOURCE_DIR}/wsecl3_links.xslt
     ${CMAKE_CURRENT_SOURCE_DIR}/wsecl3_tabview.xsl
     ${CMAKE_CURRENT_SOURCE_DIR}/wsecl3_xmltest.xsl

+ 209 - 0
esp/xslt/wsecl3_boxform.xsl

@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+## Copyright (c) 2012 HPCC Systems.  All rights reserved.
+-->
+<!DOCTYPE xsl:stylesheet [
+<!ENTITY nbsp "&#160;">
+<!ENTITY apos "&#39;">
+]>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0" xml:space="default" exclude-result-prefixes="xsd">
+    <xsl:strip-space elements="*"/>
+    <xsl:output method="html" indent="yes" omit-xml-declaration="yes" version="4.01" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
+
+    <xsl:param name="queryParams" select="''"/>
+    <xsl:variable name="QueryInput" select="/FormInfo/Request"/>
+    <xsl:variable name="queryPath" select="/FormInfo/QuerySet"/>
+    <xsl:variable name="methodName" select="/FormInfo/QueryName"/>
+    <xsl:variable name="methodHelp" select="/FormInfo/Help"/>
+    <xsl:variable name="methodDesc" select="/FormInfo/Info"/>
+    <xsl:variable name="serviceVersion" select="/FormInfo/Version"/>
+
+    <!-- ===============================================================================
+  global settings
+  ================================================================================ -->
+   <!-- config -->
+   <xsl:template match="FormInfo">
+      <html>
+          <head>
+              <title>WsECL Service form</title>
+              <link rel="shortcut icon" href="/esp/files/img/affinity_favicon_1.ico"/>
+              <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/fonts/fonts-min.css"/>
+              <link rel="stylesheet" type="text/css" href="/esp/files/css/espdefault.css"/>
+              <link rel="stylesheet" type="text/css" href="/esp/files/gen_form.css"/>
+              <script type="text/javascript">
+
+      <xsl:text disable-output-escaping="yes">
+<![CDATA[
+function setESPFormAction()
+{
+    var form = document.forms['esp_form'];
+    if (!form)  return false;
+
+    var actval = document.getElementById('submit_type');
+    var actionpath = "/jserror";
+    if (actval && actval.value)
+    {
+        if (actval.value=="esp_soap")
+            actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes" select="concat('/WsEcl/forms/soap/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+        else if (actval.value=="run_xslt")
+            actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes" select="concat('/WsEcl/xslt/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+        else if (actval.value=="xml")
+            actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes" select="concat('/WsEcl/submit/query/', $queryPath, '/', $methodName, '?view=xml&amp;display')"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+        else
+            actionpath= "]]></xsl:text><xsl:value-of disable-output-escaping="yes" select="concat('/WsEcl/xslt/query/', $queryPath, '/', $methodName, '?view=')"/><xsl:text disable-output-escaping="yes"><![CDATA["+actval.value;
+    }
+
+    form.action = actionpath;
+    return true;
+}
+
+function switchInputForm()
+{
+    var inputform = document.getElementById('SelectForm');
+    if (inputform.value!="DynamicForm")
+       return false;
+    document.location.href = "]]></xsl:text><xsl:value-of disable-output-escaping="yes" select="concat('/WsEcl/forms/ecl/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+    return true;
+}
+]]></xsl:text>
+<xsl:call-template name="GetHtmlHeadAddon"/>
+</script>
+</head>
+      <body class="yui-skin-sam" onload="onPageLoad()">
+               <p align="center"/>
+                <table cellSpacing="0" cellPadding="1" width="100%" bgColor="#4775FF" border="0">
+                    <tr align="left" class="service">
+                        <td height="23">
+                            <font color="#efefef">
+                                <b>
+                                    <xsl:value-of select="/FormInfo/QuerySet"/>
+                                    <xsl:if test="number($serviceVersion)&gt;0">
+                                        <xsl:value-of select="concat(' [Version ', $serviceVersion, ']')"/>
+                                    </xsl:if>
+                                </b>
+                            </font>
+                        </td>
+                    </tr>
+                    <tr class="method">
+                        <td height="23" align="left">
+                            <xsl:variable name="params">
+                                <xsl:if test="$queryParams">
+                                    <xsl:value-of select="concat('&amp;', substring($queryParams,2))"/>
+                                </xsl:if>
+                            </xsl:variable>
+                            <b><xsl:value-of select="$methodName"/>
+                            </b>&nbsp;<a>
+                                <xsl:attribute name="href"><xsl:call-template name="build_link"><xsl:with-param name="type" select="'wsdl'"/></xsl:call-template></xsl:attribute>
+                                <xsl:attribute name="target">_blank</xsl:attribute>
+                                <img src="/esp/files/img/wsdl.gif" title="WSDL" border="0" align="bottom"/>
+                            </a>&nbsp;<a>
+                                <xsl:attribute name="href"><xsl:call-template name="build_link"><xsl:with-param name="type" select="'xsd'"/></xsl:call-template></xsl:attribute>
+                                <xsl:attribute name="target">_blank</xsl:attribute>
+                                <img src="/esp/files/img/xsd.gif" title="Schema" border="0" align="bottom"/>
+                            </a>&nbsp;<a>
+                                <xsl:attribute name="href"><xsl:call-template name="build_link"><xsl:with-param name="type" select="'reqxml'"/></xsl:call-template></xsl:attribute>
+                                <img src="/esp/files/img/reqxml.gif" title="Sample Request XML" border="0" align="bottom"/>
+                            </a>&nbsp;<a>
+                                <xsl:attribute name="href"><xsl:call-template name="build_link"><xsl:with-param name="type" select="'respxml'"/></xsl:call-template></xsl:attribute>
+                                <img src="/esp/files/img/respxml.gif" title="Sample Response XML" border="0" align="bottom"/>
+                            </a>&nbsp;&nbsp;
+                            <select id="SelectForm" name="select_form" onChange="switchInputForm()">
+                               <option value="InputBox" selected="selected">Input Box</option>
+                               <option value="DynamicForm">Dynamic Form</option>
+                            </select>&nbsp;<br/>
+                        </td>
+                    </tr>
+                    <xsl:if test="$methodDesc and $methodDesc!=''">
+                    <tr>
+                        <td class="desc">
+                            <table cellSpacing="0" border="0">
+                                <tr>
+                                    <td valign="middle" align="left">
+                                        <br/>
+                                        <xsl:value-of disable-output-escaping="yes" select="$methodDesc"/>
+                                    </td>
+                                </tr>
+                            </table>
+                        </td>
+                    </tr>
+                    </xsl:if>
+                    <xsl:if test="$methodHelp and $methodHelp!=''">
+                    <tr>
+                        <td class="help">
+                            <table cellSpacing="0" border="0">
+                                <tr>
+                                    <td valign="middle" align="left">
+                                        <xsl:value-of disable-output-escaping="yes" select="$methodHelp"/>
+                                    </td>
+                                </tr>
+                            </table>
+                        </td>
+                    </tr>
+                    </xsl:if>
+                    <tr bgColor="#efefef">
+                        <td>
+                            <p align="left"/>
+                            <xsl:variable name="action">
+                                <xsl:call-template name="build_link"><xsl:with-param name="type" select="'action'"/></xsl:call-template>
+                            </xsl:variable>
+            <form id="esp_form" method="POST" enctype="application/x-www-form-urlencoded" action="/jserror">
+               <xsl:attribute name="onSubmit">return setESPFormAction()</xsl:attribute>
+               <table cellSpacing="0" width="100%" border="0">
+                 <tr>
+                  <td>Query Input:</td>
+                </tr>
+                <tr><td bgcolor="#030303" height="1"/></tr>
+                <tr><td height="4"/></tr>
+                <tr>
+                  <td>
+                   <textarea name="_boxFormInput" rows="40" cols="120"><xsl:value-of select="$QueryInput"/>
+                   </textarea>
+                  </td>
+                </tr>
+                <tr><td height="4"/></tr>
+                <tr><td bgcolor="#030303" height="1"/></tr>
+                <tr><td height="6"/></tr>
+                <tr class="commands">
+                  <td align="left">
+                    <select id="submit_type" name="submit_type_">
+                        <xsl:for-each select="/FormInfo/CustomViews/Result">
+                            <option value="{.}"><xsl:value-of select="."/></option>
+                        </xsl:for-each>
+                        <option value="run_xslt">Output Tables</option>
+                        <option value="xml">Output XML</option>
+                        <option value="esp_soap">SOAP Test</option>
+                    </select>&nbsp;
+                    <input type="submit" value="Submit" name="S1"/>
+                  </td>
+                 </tr>
+                </table>
+            </form>
+                      </td>
+                    </tr>
+                 </table>
+              </body>
+          </html>
+    </xsl:template>
+    <xsl:template name="GetHtmlHeadAddon">
+        <xsl:variable name="items" select="//xsd:annotation/xsd:appinfo/form/@html_head"/>
+        <xsl:variable name="s" select="string($items)"/>
+        <xsl:value-of select="$s" disable-output-escaping="yes"/>
+    </xsl:template>
+    <xsl:template name="build_link">
+        <xsl:param name="type" select="'unkown'"/>
+         <xsl:variable name="params">
+              <xsl:if test="$queryParams">
+                  <xsl:value-of select="concat('&amp;', substring($queryParams,2))"/>
+              </xsl:if>
+          </xsl:variable>
+          <xsl:choose>
+              <xsl:when test="$type='reqxml'"><xsl:value-of select="concat('/WsEcl/example/request/query/', $queryPath, '/', $methodName,'?display')"/></xsl:when>
+              <xsl:when test="$type='respxml'"><xsl:value-of select="concat('/WsEcl/example/response/query/', $queryPath, '/', $methodName,'?display')"/></xsl:when>
+              <xsl:when test="$type='xsd'"><xsl:value-of select="concat('/WsEcl/definitions/query/', $queryPath, '/', $methodName,'/main/',$methodName,'.xsd')"/></xsl:when>
+              <xsl:when test="$type='wsdl'"><xsl:value-of select="concat('/WsEcl/definitions/query/', $queryPath, '/', $methodName,'/main/',$methodName,'.wsdl')"/></xsl:when>
+              <xsl:when test="$type='action'"><xsl:value-of select="concat('/WsEcl/submit/query/', $queryPath, '/', $methodName,$queryParams)"/></xsl:when>
+          </xsl:choose>
+    </xsl:template>
+</xsl:stylesheet>
+<!-- ********************************************************************************************************** -->

+ 18 - 3
esp/xslt/wsecl3_form.xsl

@@ -93,7 +93,8 @@
                 <script type="text/javascript" src="/esp/files/req_array.js"/>
                 <script type="text/javascript" src="/esp/files/hashtable.js"/>
                 <script type="text/javascript" src="/esp/files/gen_form.js"/>
-                <script type="text/javascript"><xsl:text disable-output-escaping="yes"><![CDATA[
+                <script type="text/javascript"><xsl:text disable-output-escaping="yes">
+                <![CDATA[
   var isIE = (navigator.appName == "Microsoft Internet Explorer");
 
   function getRequestFormHtml()
@@ -175,7 +176,17 @@ function setESPFormAction()  // reqType: 0: regular form, 1: soap, 2: form param
 
     return true;
 }
-]]></xsl:text>
+function switchInputForm()
+{
+    var inputform = document.getElementById('SelectForm');
+    if (inputform.value!="InputBox")
+       return false;
+    document.location.href = "]]></xsl:text><xsl:value-of disable-output-escaping="yes" select="concat('/WsEcl/forms/box/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+    return true;
+}
+
+]]>
+</xsl:text>
 <xsl:call-template name="GetHtmlHeadAddon"/>
 </script>
 
@@ -226,7 +237,11 @@ function setESPFormAction()  // reqType: 0: regular form, 1: soap, 2: form param
                             </a>&nbsp;<a>
                                 <xsl:attribute name="href"><xsl:call-template name="build_link"><xsl:with-param name="type" select="'respxml'"/></xsl:call-template></xsl:attribute>
                                 <img src="/esp/files/img/respxml.gif" title="Sample Response XML" border="0" align="bottom"/>
-                            </a>
+                            </a>&nbsp;&nbsp;
+                            <select id="SelectForm" name="select_form" onChange="switchInputForm()">
+                               <option value="DynamicForm" selected="selected">Dynamic Form</option>
+                              <option value="InputBox">Input Box</option>
+                            </select>&nbsp;<br/>
                         </td>
                     </tr>
                     <xsl:if test="$methodDesc and $methodDesc!=''">

+ 1 - 1
esp/xslt/wsecl3_tabview.xsl

@@ -113,7 +113,7 @@
                     </ul>
                     <div class="yui-content"  style="height:94%">
                             <div id="tab1" style="height:100%">
-                                <iframe src="/WsEcl/forms/ecl/query/{$qset}/{$qname}" width="100%" height="100%" frameborder="0" border="0">
+                                <iframe src="/WsEcl/forms/default/query/{$qset}/{$qname}" width="100%" height="100%" frameborder="0" border="0">
                                     <p>Your browser does not support iframes.</p>
                                 </iframe>
                         </div>