zoom: configurable element sets for record transforms.
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 23 Jun 2011 10:56:22 +0000 (12:56 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 23 Jun 2011 10:56:22 +0000 (12:56 +0200)
The target profile based transform is specified by element_transform
in element torus of of the ZOOM filter configuration ; default value
is "pz2". Target profile based retrieval is specified by element_raw
in configuration. It will perform same steps, but omit the XSL transform.
Default value is "raw".

doc/zoom.xml
etc/config-zoom.xml
m4
src/filter_zoom.cpp
xml/schema/filter_zoom.rnc
xml/schema/filter_zoom.rng
xml/schema/filter_zoom.xsd

index db06242..253be8f 100644 (file)
@@ -62,7 +62,9 @@
      and takes the following content:
    </para>
    <variablelist>
-     <varlistentry><term>attribute <literal>url</literal></term><listitem><para>
+     <varlistentry>
+       <term>attribute <literal>url</literal></term>
+       <listitem><para>
           URL of Web service to be used to fetch target profile
           for a given database (udb). The special sequence
           <literal>%db</literal> of the URL is replaced by the
         </para>
        </listitem>
      </varlistentry>
-     <varlistentry><term>attribute <literal>xsldir</literal></term><listitem><para>
+     <varlistentry>
+       <term>attribute <literal>xsldir</literal></term>
+       <listitem><para>
           Directory that is searched for XSL stylesheets. Stylesheets
           are specified in the target profile by the
           <literal>transform</literal> element.
         </para>
        </listitem>
      </varlistentry>
-     <varlistentry><term>element <literal>records</literal></term><listitem><para>
+     <varlistentry>
+       <term>attribute <literal>element_transform</literal></term>
+       <listitem><para>
+          Specifies the element that triggers retrieval and transform using
+          the parameters elementSet, recordEncoding, requestSyntax, transform
+          from the target profile. Default value
+          is "pz2", due to the fact that for historical reasons the
+          common format is that used in Pazpar2.
+        </para>
+       </listitem>
+     </varlistentry>
+     <varlistentry>
+       <term>attribute <literal>element_raw</literal></term>
+       <listitem><para>
+          Specifies an element that triggers retrieval using the
+          parameters elementSet, recordEncoding, requestSyntax from the
+          target profile. Same actions as for element_transform, but without
+          the XSL transform. Useful for debugging. The default value is "raw".
+        </para>
+       </listitem>
+     </varlistentry>
+     <varlistentry>
+       <term>element <literal>records</literal></term>
+       <listitem><para>
           Local target profiles. This element may includes zero or
           more <literal>record</literal> elements (one per target
           profile). See section TARGET PROFILE.
      following content:
    </para>
    <variablelist>
-     <varlistentry><term>attribute <literal>cql</literal></term><listitem><para>
-          CQL field.
+     <varlistentry>
+       <term>attribute <literal>cql</literal></term>
+       <listitem>
+        <para>
+          CQL field that we are mapping "from".
         </para>
        </listitem>
      </varlistentry>
-     <varlistentry><term>attribute <literal>ccl</literal></term><listitem><para>
-          CCL field.
+     <varlistentry>
+       <term>attribute <literal>ccl</literal></term>
+       <listitem>
+        <para>
+          CCL field that we are mapping "to".
         </para>
        </listitem>
      </varlistentry>
        <term>elementSet</term><listitem>
         <para>
           Specifies the elementSet to be sent to the target if record
-          transform is enabled (not to be used with the record_transform
+          transform is enabled (not to be confused' with the record_transform
           module). The record transform is enabled only if the client uses
-          record syntax = XML and element set = 
-          <literal>pz2</literal>. If record transform is not enabled, this
-          setting is  not used and the element set specified by the client
+          record syntax = XML and a element set determined by
+          the <literal>element_transform</literal> /
+          <literal>element_raw</literal> from the configuration.
+          By default that is the element sets <literal>pz2</literal>
+          and <literal>raw</literal>.
+          If record transform is not enabled, this setting is 
+          not used and the element set specified by the client
           is passed verbatim.
         </para>
        </listitem>
         <para>
           Specifies a XSL stylesheet filename to be used if record
           transform is anabled; see desciprion of elementSet.
+          The XSL transform is only used if the element set is set to the
+          value of <literal>element_transform</literal> in the configuration.
         </para>
        </listitem>
      </varlistentry>
index daea9da..171a1bc 100644 (file)
@@ -10,6 +10,8 @@
       <torus
          url="http://newmk2.indexdata.com/torus2/searchable.ebsco/records/?query=udb%3D%db"
             xsldir="."
+            element_transform="pz"
+            element_raw="raw"
            >   
        <records>
          <record>
@@ -78,7 +80,7 @@
         <retrievalinfo   xmlns="http://indexdata.com/yaz" version="1.0">
           <retrieval syntax="xml" name="usi">
             <backend syntax="xml" name="pz2">
-              <xslt stylesheet="../xml/xslt/pz22usi.xsl"/>
+              <xslt stylesheet="pz22usi.xsl"/>
             </backend>
           </retrieval>
           <retrieval syntax="xml"/>
diff --git a/m4 b/m4
index f7d7eb4..c9c894a 160000 (submodule)
--- a/m4
+++ b/m4
@@ -1 +1 @@
-Subproject commit f7d7eb4b44b7fdad1942e32856d6afc2e6dcabda
+Subproject commit c9c894a0b63f9ce9578570e3507c3e6232ec4797
index f9c07df..9ceaf0c 100644 (file)
@@ -134,6 +134,8 @@ namespace metaproxy_1 {
             std::map<std::string,std::string> fieldmap;
             std::string xsldir;
             CCL_bibset bibset;
+            std::string element_transform;
+            std::string element_raw;
             std::map<std::string,SearchablePtr> s_map;
         };
     }
@@ -314,7 +316,7 @@ void yf::Zoom::Impl::release_frontend(mp::Package &package)
     }
 }
 
-yf::Zoom::Impl::Impl()
+yf::Zoom::Impl::Impl() : element_transform("pz2") , element_raw("raw")
 {
     bibset = ccl_qual_mk();
 }
@@ -475,6 +477,10 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only)
                     torus_url = mp::xml::get_text(attr->children);
                 else if (!strcmp((const char *) attr->name, "xsldir"))
                     xsldir = mp::xml::get_text(attr->children);
+                else if (!strcmp((const char *) attr->name, "element_transform"))
+                    element_transform = mp::xml::get_text(attr->children);
+                else if (!strcmp((const char *) attr->name, "element_raw"))
+                    element_raw = mp::xml::get_text(attr->children);
                 else
                     throw mp::filter::FilterException(
                         "Bad attribute " + std::string((const char *)
@@ -683,7 +689,8 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
 {
     *number_of_records_returned = 0;
     Z_Records *records = 0;
-    bool enable_pz2_transform = false;
+    bool enable_pz2_retrieval = false; // whether target profile is used
+    bool enable_pz2_transform = false; // whether XSLT is used as well
 
     if (start < 0 || number_to_present <= 0)
         return records;
@@ -696,27 +703,34 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
 
     char oid_name_str[OID_STR_MAX];
     const char *syntax_name = 0;
-
-    if (preferredRecordSyntax)
+    
+    if (preferredRecordSyntax &&
+        !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)
+        && element_set_name)
     {
-        if (!oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)
-            && element_set_name &&
-            !strcmp(element_set_name, "pz2"))
+        if (!strcmp(element_set_name, m_p->element_transform.c_str()))
         {
-            if (b->sptr->request_syntax.length())
-                syntax_name = b->sptr->request_syntax.c_str();
+            enable_pz2_retrieval = true;
             enable_pz2_transform = true;
         }
-        else
+        else if (!strcmp(element_set_name, m_p->element_raw.c_str()))
         {
-            syntax_name =
-                yaz_oid_to_string_buf(preferredRecordSyntax, 0, oid_name_str);
+            enable_pz2_retrieval = true;
         }
     }
+    
+    if (enable_pz2_retrieval)
+    {
+        if (b->sptr->request_syntax.length())
+            syntax_name = b->sptr->request_syntax.c_str();
+    }
+    else if (preferredRecordSyntax)
+        syntax_name =
+            yaz_oid_to_string_buf(preferredRecordSyntax, 0, oid_name_str);
 
     b->set_option("preferredRecordSyntax", syntax_name);
 
-    if (enable_pz2_transform)
+    if (enable_pz2_retrieval)
     {
         element_set_name = 0;
         if (b->sptr->element_set.length())
@@ -756,7 +770,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
                 npr = zget_surrogateDiagRec(odr, odr_database, sur_error,
                                             addinfo);
             }
-            else if (enable_pz2_transform)
+            else if (enable_pz2_retrieval)
             {
                 char rec_type_str[100];
 
@@ -774,7 +788,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
                 int rec_len;
                 const char *rec_buf = ZOOM_record_get(recs[i], rec_type_str,
                                                       &rec_len);
-                if (rec_buf && b->xsp)
+                if (rec_buf && b->xsp && enable_pz2_transform)
                 {
                     xmlDoc *rec_doc = xmlParseMemory(rec_buf, rec_len);
                     if (rec_doc)
index 3c22312..e148d78 100644 (file)
@@ -9,6 +9,8 @@ filter_zoom =
   element mp:torus {
     attribute url { xsd:string },
     attribute xsldir { xsd:string }?,
+    attribute element_transform { xsd:string }?,
+    attribute element_raw { xsd:string }?,
     element mp:records {
       element mp:record {
         element mp:authentication { xsd:string }?,
index ce977e1..47983c9 100644 (file)
           </attribute>
         </optional>
         <optional>
+          <attribute name="element_transform">
+            <data type="string"/>
+          </attribute>
+        </optional>
+        <optional>
+          <attribute name="element_raw">
+            <data type="string"/>
+          </attribute>
+        </optional>
+        <optional>
           <element name="mp:records">
             <zeroOrMore>
               <element name="mp:record">
index 979131f..4914d89 100644 (file)
@@ -17,6 +17,8 @@
       </xs:sequence>
       <xs:attribute name="url" use="required" type="xs:string"/>
       <xs:attribute name="xsldir" type="xs:string"/>
+      <xs:attribute name="element_transform" type="xs:string"/>
+      <xs:attribute name="element_raw" type="xs:string"/>
     </xs:complexType>
   </xs:element>
   <xs:element name="records">