Backport r13424 and r13580 from trunk: RefWorks export support
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 14 Jul 2009 02:37:04 +0000 (02:37 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 14 Jul 2009 02:37:04 +0000 (02:37 +0000)
Patch from Warren Layton implementing RefWorks export via SuperCat:

"The patch a new transform, MARC21slim2MARCtxt.xsl, which converts MARC
into the MARC-ish plain text format accepted by RefWorks (see [1]).
The patch also adds a new feed to SuperCat, called "marctxt"."

As well as a reworked patch for the default opac skin to expose this
functionality as a link next to the "Place a Hold" link.

git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6@13581 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm
Open-ILS/web/opac/locale/en-US/opac.dtd
Open-ILS/web/opac/skin/default/js/rdetail.js
Open-ILS/web/opac/skin/default/xml/page_rdetail.xml
Open-ILS/xsl/MARC21slim2MARCtxt.xsl [new file with mode: 0644]

index 20b5f08..d2f5888 100644 (file)
@@ -145,7 +145,7 @@ sub child_init {
                ->gather(1);
 
     $list = [ map { (keys %$_)[0] } @$list ];
-    push @$list, 'htmlholdings','html';
+    push @$list, 'htmlholdings','html', 'marctxt';
 
     for my $browse_axis ( qw/title author subject topic series item-age/ ) {
         for my $record_browse_format ( @$list ) {
@@ -259,6 +259,7 @@ sub unapi {
        <format name='htmlholdings' type='text/html'/>
        <format name='html-full' type='text/html'/>
        <format name='htmlholdings-full' type='text/html'/>
+       <format name='marctxt' type='text/plain'/>
                                FORMATS
                        } elsif ($type eq 'metarecord') {
                                $body .= <<"                            FORMATS";
@@ -313,6 +314,7 @@ sub unapi {
        <format name='htmlholdings' type='text/html'/>
        <format name='html-full' type='text/html'/>
        <format name='htmlholdings-full' type='text/html'/>
+       <format name='marctxt' type='text/plain'/>
                        FORMATS
 
 
@@ -405,7 +407,7 @@ sub unapi {
               @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
             and !grep
               { $_ eq $base_format }
-              qw/opac html htmlholdings/
+              qw/opac html htmlholdings marctxt/
        ) {
                print "Content-type: text/html; charset=utf-8\n\n";
                $apache->custom_response( 406, <<"              HTML");
@@ -547,6 +549,10 @@ sub supercat {
                                   <format>
                                     <name>html-full</name>
                                     <type>text/html</type>
+                                  </format>
+                                  <format>
+                                    <name>marctxt</name>
+                                    <type>text/plain</type>
                                   </format>";
                        }
 
@@ -612,6 +618,10 @@ sub supercat {
                           <format>
                             <name>html-full</name>
                             <type>text/html</type>
+                          </format>
+                          <format>
+                            <name>marctxt</name>
+                            <type>text/plain</type>
                           </format>";
 
                for my $h (@$list) {
@@ -1222,7 +1232,7 @@ sub create_record_feed {
        $feed->unapi($unapi) if ($flesh);
 
        $type = 'atom' if ($type eq 'html');
-       $type = 'marcxml' if ($type eq 'htmlholdings');
+       $type = 'marcxml' if (($type eq 'htmlholdings') || ($type eq 'marctxt'));
 
        #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
 
index 27f9d6b..5c16872 100644 (file)
@@ -744,4 +744,57 @@ sub new {
 package OpenILS::WWW::SuperCat::Feed::htmlholdings::item;
 use base 'OpenILS::WWW::SuperCat::Feed::htmlcard::item';
 
+
+package OpenILS::WWW::SuperCat::Feed::marctxt;
+use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
+
+sub new {
+       my $class = shift;
+       my $self = $class->SUPER::new;
+       $self->{type} = 'text/plain';
+       $self->{xsl} = "/MARC21slim2MARCtxt.xsl";
+       return $self;
+}
+
+
+our ($_parser, $_xslt, $xslt_file);
+
+sub toString {
+       my $self = shift;
+       my $base = $self->base || '';
+       my $root = $self->root || '';
+       my $search = $self->search || '';
+       my $class = $self->class || '';
+       my $lib = $self->lib || '-';
+
+       $self->composeDoc;
+
+        $_parser ||= new XML::LibXML;
+        $_xslt ||= new XML::LibXSLT;
+
+       $xslt_file ||=
+                OpenSRF::Utils::SettingsClient
+                               ->new
+                               ->config_value( dirs => 'xsl' ).
+                $self->{xsl};
+
+        # parse the MARC text xslt ...
+        my $marctxt_xslt = $_xslt->parse_stylesheet( $_parser->parse_file($xslt_file) );
+
+       my $new_doc = $marctxt_xslt->transform(
+               $self->{doc},
+               base_dir => "'$root'",
+               lib => "'$lib'",
+               searchTerms => "'$search'",
+               searchClass => "'$class'",
+       );
+
+       return $marctxt_xslt->output_string($new_doc); 
+}
+
+
+package OpenILS::WWW::SuperCat::Feed::marctxt::item;
+use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item';
+
+
 1;
index fdaf656..f920c1e 100644 (file)
@@ -434,6 +434,7 @@ Please see a librarian to renew your account.">
 <!ENTITY opac.holds.xulRecipient "Enter recipient barcode">
 <!ENTITY opac.holds.recipient "Recipient">
 <!ENTITY opac.holds.placeHold "Place Hold">
+<!ENTITY opac.holds.exportRefWorks "Export to RefWorks">
 <!ENTITY opac.holds.contactPhone "Contact telephone number">
 <!ENTITY opac.holds.contactEmail "Contact email address">
 <!ENTITY opac.holds.pickupLocation "Pickup location">
index 5c81e45..c2db9d8 100644 (file)
@@ -1,12 +1,21 @@
 /* */
 
-
 detachAllEvt('common', 'run');
 attachEvt("common", "run", rdetailDraw);
 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
 attachEvt("rdetail", "recordDrawn", rdetailGetPageIds);
 
+/* Per-skin configuration settings */
+var rdetailLocalOnly = true;
+var rdetailShowLocal = true;
+var rdetailShowCopyLocation = true;
+var rdetailGoogleBookPreview = true;
+var rdetailDisplaySerialHoldings = true;
+var rdetailEnableRefWorks = true;
+var rdetailRefWorksHost = 'http://www.refworks.com';
+
+/* vars vars vars */
 var record = null;
 var cp_statuses = null;
 var recordsCache = [];
@@ -17,33 +26,14 @@ var statusRow = null;
 var numStatuses = null;
 var defaultCN;
 var callnumberCache = {};
-var rdetailLocalOnly = true;
 var globalCNCache = {};
 var localTOC;
 var cachedRecords;
 var _statusPositions = {};
-
-var rdetailShowLocal = true;
-var rdetailShowCopyLocation = true;
-var googleBookPreview = true;
-var displaySerialHoldings = true;
 var opac_strings;
 
-/* serials are currently the only use of Dojo strings in the OPAC */
-if (displaySerialHoldings) {
-       dojo.requireLocalization("openils.opac", "opac");
-       opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
-}
-
 var nextContainerIndex;
 
-function rdetailReload() {
-       var args = {};
-       args[PARAM_LOCATION] = getNewSearchLocation();
-       args[PARAM_DEPTH] = depthSelGetDepth();
-       goTo(buildOPACLink(args));
-}
-
 var nextRecord;
 var prevRecord;
 
@@ -52,7 +42,18 @@ var rdetailNext = null;
 var rdetailStart = null;
 var rdetailEnd = null;
 
+/* serials are currently the only use of Dojo strings in the OPAC */
+if (rdetailDisplaySerialHoldings) {
+       dojo.requireLocalization("openils.opac", "opac");
+       opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
+}
 
+function rdetailReload() {
+       var args = {};
+       args[PARAM_LOCATION] = getNewSearchLocation();
+       args[PARAM_DEPTH] = depthSelGetDepth();
+       goTo(buildOPACLink(args));
+}
 
 /* looks to see if we have a next and/or previous record in the
    record cache, if so, set up the nav links */
@@ -124,7 +125,7 @@ function rdetailDraw() {
        req.callback(_rdetailDraw);
        req.send();
 
-       if (displaySerialHoldings) {
+       if (rdetailDisplaySerialHoldings) {
                var req = new Request(FETCH_MFHD_SUMMARY, getRid());
                req.callback(_holdingsDraw);
                req.send();
@@ -368,6 +369,27 @@ function _rdetailDraw(r) {
        $('rdetail_place_hold').setAttribute(
                        'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
 
+       var RW = $('rdetail_exp_refworks');
+       if (RW && rdetailEnableRefWorks) {
+
+               var here = (findOrgUnit(getLocation())).name();
+               var org_name = here.replace(" ", "+");
+               var cgi = new CGI();
+
+               RW.setAttribute(
+                       'href',
+                       rdetailRefWorksHost + '/express/expressimport.asp?vendor='
+                       + org_name
+                       + '&filter=MARC+Format&database=All+MARC+Formats&encoding=65001&url=http%3A%2F%2F'
+                       + cgi.server_name + '/opac/extras/supercat/marctxt/record/'
+                       + record.doc_id()
+              );
+
+               RW.setAttribute('target', 'RefWorksMain');
+
+               unHideMe($('rdetail_exp_refworks_span'));
+       }
+
        $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
        G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
        runEvt("rdetail", "recordDrawn");
@@ -914,7 +936,7 @@ function _rdetailSortStatuses(a, b) {
  * Check for a Google Book preview 
  */
 function rdetailCheckForGBPreview() {
-       if (!googleBookPreview) return;
+       if (!rdetailGoogleBookPreview) return;
        searchForGBPreview( cleanISBN(record.isbn()) );
 }
 
index 9d259ce..88b7a24 100644 (file)
@@ -52,6 +52,9 @@
                                </td>
 
                                <td align='right' style='padding-right: 7px;' width='33%'>
+                                       <span id='rdetail_exp_refworks_span' class='hide_me' style='padding-right: 7px;'>
+                                               <a id='rdetail_exp_refworks'>&opac.holds.exportRefWorks;</a>
+                                       </span>
                                        <span style='padding-right: 7px;'>
                                                <a id='rdetail_place_hold' class='classic_link'>&opac.holds.placeHold;</a>
                                        </span>
diff --git a/Open-ILS/xsl/MARC21slim2MARCtxt.xsl b/Open-ILS/xsl/MARC21slim2MARCtxt.xsl
new file mode 100644 (file)
index 0000000..5cf6d93
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">
+    <xsl:output method="text"/>
+
+    <xsl:template match="marc:record">
+       <xsl:text>&#10;LEADER </xsl:text>
+       <xsl:value-of select="marc:leader"/>
+        
+        <xsl:for-each select="marc:controlfield">
+            <xsl:text>&#10;</xsl:text>
+            <xsl:value-of select="@tag"/>
+            <xsl:text>    </xsl:text>
+            <xsl:value-of select="marc:controlfield"/>
+            <xsl:value-of select="."/>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield">
+            <xsl:text>&#10;</xsl:text>
+            <xsl:value-of select="@tag"/>
+            <xsl:text> </xsl:text>
+            <xsl:value-of select="@ind1"/>
+            <xsl:value-of select="@ind2"/>
+            <xsl:text> </xsl:text>
+            <xsl:for-each select="marc:subfield">
+                <xsl:if test="@code != 'a'">
+                    <xsl:text>|</xsl:text>
+                    <xsl:value-of select="@code"/>
+                </xsl:if>
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+       <xsl:text>&#10;</xsl:text>
+       </xsl:template>
+</xsl:stylesheet>
+