adding html "card catalog" output type; adding html and htmlcard output types to...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 29 Mar 2006 12:54:32 +0000 (12:54 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 29 Mar 2006 12:54:32 +0000 (12:54 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@3450 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/extras/htmlcard.css [new file with mode: 0755]
Open-ILS/web/opac/extras/os.css
Open-ILS/xsl/MARC21slim2HTMLCard.xsl [new file with mode: 0755]

index e393b75..db63c20 100644 (file)
@@ -75,18 +75,27 @@ sub unapi {
        my $apache = shift;
        return Apache2::Const::DECLINED if (-e $apache->filename);
 
-       print "Content-type: application/xml; charset=utf-8\n";
-       
        my $cgi = new CGI;
+       my $rel_name = quotemeta($cgi->url(-relative=>1));
+
+       my $add_path = 1;
+       $add_path = 0 if ($cgi->url(-path_info=>1) =~ /$rel_name$/);
+
+
+       my $url = $cgi->url(-path_info=>$add_path);
+       my $root = (split 'unapi', $url)[0];
+       my $base = (split 'unapi', $url)[0] . 'unapi';
+
 
        my $uri = $cgi->param('uri') || '';
-       my $base = $cgi->url;
        my $host = $cgi->virtual_host || $cgi->server_name;
 
        my $format = $cgi->param('format');
        my ($id,$type,$command) = ('','','');
 
        if (!$format) {
+               print "Content-type: application/xml; charset=utf-8\n";
+       
                if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) {
                        $id = $2;
                        $type = 'record';
@@ -175,9 +184,43 @@ sub unapi {
                print "Location: $base/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
                        if ($type eq 'record');
                return 302;
+       } elsif ($format =~ /^html/o) {
+               my $feed = create_record_feed(
+                       $format => [ $id ],
+                       $base,
+               );
+
+               $feed->root($root);
+               $feed->creator($host);
+               $feed->update_ts(gmtime_ISO8601());
+
+               print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
+               print entityize($feed->toString) . "\n";
+
+               return Apache2::Const::OK;
        }
 
-       print "\n" . $supercat->request("open-ils.supercat.$type.$format.$command",$id)->gather(1);
+       my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
+       $req->wait_complete;
+
+       if ($req->failed) {
+               print "Content-type: text/html; charset=utf-8\n\n";
+               $apache->custom_response( 404, <<"              HTML");
+               <html>
+                       <head>
+                               <title>$type $id not found!</title>
+                       </head>
+                       <body>
+                               <br/>
+                               <center>Sorry, we couldn't $command a $type with the id of $id.</center>
+                       </body>
+               </html>
+               HTML
+               return 404;
+       }
+
+       print "Content-type: application/xml; charset=utf-8\n\n";
+       print $req->gather(1);
 
        return Apache2::Const::OK;
 }
@@ -187,16 +230,27 @@ sub supercat {
        my $apache = shift;
        return Apache2::Const::DECLINED if (-e $apache->filename);
 
-       my $path = $apache->path_info;
-
        my $cgi = new CGI;
-       my $base = $cgi->url;
+
+       my $rel_name = quotemeta($cgi->url(-relative=>1));
+
+       my $add_path = 1;
+       $add_path = 0 if ($cgi->url(-path_info=>1) =~ /$rel_name$/);
+
+
+       my $url = $cgi->url(-path_info=>$add_path);
+       my $root = (split 'supercat', $url)[0];
+       my $base = (split 'supercat', $url)[0] . 'supercat';
+       my $path = (split 'supercat', $url)[1];
+       my $unapi = (split 'supercat', $url)[0] . 'unapi';
+
+       my $host = $cgi->virtual_host || $cgi->server_name;
 
        my ($id,$type,$format,$command) = reverse split '/', $path;
 
-       print "Content-type: application/xml; charset=utf-8\n";
        
        if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
+               print "Content-type: application/xml; charset=utf-8\n";
                if ($1) {
                        my $list = $supercat
                                ->request("open-ils.supercat.$1.formats")
@@ -270,9 +324,40 @@ sub supercat {
                print "Location: $base/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
                        if ($type eq 'record');
                return 302;
+       } elsif ($format =~ /^html/o) {
+               my $feed = create_record_feed( $format => [ $id ], $unapi,);
+
+               $feed->root($root);
+               $feed->creator($host);
+               $feed->update_ts(gmtime_ISO8601());
+
+               print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
+               print entityize($feed->toString) . "\n";
+
+               return Apache2::Const::OK;
+       }
+
+       my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
+       $req->wait_complete;
+
+       if ($req->failed) {
+               print "Content-type: text/html; charset=utf-8\n\n";
+               $apache->custom_response( 404, <<"              HTML");
+               <html>
+                       <head>
+                               <title>$type $id not found!</title>
+                       </head>
+                       <body>
+                               <br/>
+                               <center>Sorry, we couldn't $command a $type with the id of $id.</center>
+                       </body>
+               </html>
+               HTML
+               return 404;
        }
 
-       print "\n" . $supercat->request("open-ils.supercat.$type.$format.$command",$id)->gather(1);
+       print "Content-type: application/xml; charset=utf-8\n\n";
+       print $req->gather(1);
 
        return Apache2::Const::OK;
 }
@@ -592,6 +677,7 @@ sub create_record_feed {
        $feed->unapi($unapi);
 
        $type = 'atom' if ($type eq 'html');
+       $type = 'marcxml' if ($type eq 'htmlcard');
 
        for my $rec (@$records) {
                my $item_tag = "tag:$host,$year:biblio-record_entry/" . $rec;
index 2608e37..80a3aba 100644 (file)
@@ -447,4 +447,53 @@ sub toString {
 package OpenILS::WWW::SuperCat::Feed::html::item;
 use base 'OpenILS::WWW::SuperCat::Feed::atom::item';
 
+#----------------------------------------------------------
+
+package OpenILS::WWW::SuperCat::Feed::htmlcard;
+use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
+
+sub new {
+       my $class = shift;
+       my $self = $class->SUPER::new;
+       $self->type('text/html');
+       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 $lib = $self->lib || '-';
+
+       $self->composeDoc;
+
+        $_parser ||= new XML::LibXML;
+        $_xslt ||= new XML::LibXSLT;
+
+       $xslt_file ||=
+                OpenSRF::Utils::SettingsClient
+                               ->new
+                               ->config_value( dirs => 'xsl' ).
+                "/MARC21slim2HTMLCard.xsl";
+
+        # parse the MODS xslt ...
+        my $atom2html_xslt = $_xslt->parse_stylesheet( $_parser->parse_file($xslt_file) );
+
+       my $new_doc = $atom2html_xslt->transform(
+               $self->{doc},
+               base_dir => "'$root'",
+               lib => "'$lib'",
+               searchTerms => "'$search'",
+       );
+
+       return $new_doc->toString(1); 
+}
+
+
+package OpenILS::WWW::SuperCat::Feed::htmlcard::item;
+use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item';
+
 1;
diff --git a/Open-ILS/web/opac/extras/htmlcard.css b/Open-ILS/web/opac/extras/htmlcard.css
new file mode 100755 (executable)
index 0000000..6147618
--- /dev/null
@@ -0,0 +1,15 @@
+html { font: 9pt Verdana, Arial, "Arial Unicode MS", Helvetica, sans-serif; line-height: 1.4em; text-align: left; }
+blockquote { margin-left: 20px; margin-bottom: 1em; }
+body { background: #FFF; margin: 1pc; padding: 0;}
+p.mainheading { font-weight:bold; margin-bottom: 0pt;margin-top:0pt}
+span.title { font-style:italic; text-indent:15pt;}
+span.titlemain { font-style:italic; text-indent:0pt; font-weight:bold;}
+span.counter { font-weight:bold; padding-left:6pt; padding-right:4pt; }
+p.note { font-size:8pt;  margin-bottom:0pt; margin-top:0pt;}
+p.extent { margin-bottom:0pt; margin-top:0pt; text-indent:15pt;}
+span.link { clear:left;}
+span.DDC { margin-left:6pt; font-weight:bold; }
+span.LCCN { font-style:italic; font-family:times;}
+div.cardimage { background: ivory; width:350pt;border:brown solid 1px;padding:10pt;}
+span.oclc {font-family:fixed;}
+span.bottom { display:block; text-align:right;}
index 4fc3c02..e9e8708 100644 (file)
@@ -19,12 +19,13 @@ input.searchbox {
 div#searchdiv {
        z-index:10;
        position: absolute;
-       top: 100;
+       top: 0;
        right: 0;
        width:11em;
        background-color: lightgray;
        border:2px solid lightblue;
        border-right: 0px;
+       border-top: 0px;
        filter: alpha(opacity=50);
        -moz-opacity: .5;
 }
diff --git a/Open-ILS/xsl/MARC21slim2HTMLCard.xsl b/Open-ILS/xsl/MARC21slim2HTMLCard.xsl
new file mode 100755 (executable)
index 0000000..fc28d8b
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+  
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns="http://www.w3.org/1999/xhtml"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:marc="http://www.loc.gov/MARC21/slim" 
+  version="1.0">
+  <xsl:output method="html" doctype-public="-//W3C/DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/strict.dtd" />    
+  <xsl:template match="/">
+     <html>
+       <head>
+         <meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
+         <link href="{$base_dir}/htmlcard.css" rel="stylesheet" type="text/css" />
+       </head>
+       <body>
+        <xsl:apply-templates select="//marc:record"/>
+       </body>
+     </html>
+  </xsl:template>
+      
+  <xsl:template match="marc:record">
+    <div class="cardimage">
+     <xsl:apply-templates select="marc:datafield[@tag!='082' and @tag!='092' and @tag!='010']"/>
+     <span class="bottom">
+      <xsl:apply-templates select="marc:controlfield[@tag='001']"/>
+      <xsl:apply-templates select="marc:datafield[@tag='082' or @tag='092' or @tag='010']"/>
+     </span>
+    </div>
+    <br/>
+  </xsl:template>
+      
+  <xsl:template match="marc:controlfield">
+      <span class="oclc">#<xsl:value-of select="substring(.,4)"/></span>
+  </xsl:template>
+      
+  <xsl:template match="marc:datafield">
+    <xsl:if test="starts-with(@tag, '1')">
+      <p class="mainheading"><xsl:value-of select="."/></p>
+    </xsl:if>
+
+    <xsl:if test="starts-with(@tag, '24') and /marc:record/marc:datafield[@tag='100']">
+      <span class="title"><xsl:value-of select="."/></span>
+    </xsl:if>
+
+    <xsl:if test="starts-with(@tag, '24') and not(/marc:record/marc:datafield[@tag='100'])">
+      <span class="titlemain"><xsl:value-of select="."/></span><br/>
+    </xsl:if>
+
+    <xsl:if test="@tag='260'">
+      <xsl:value-of select="."/>
+    </xsl:if>
+
+    <xsl:if test="@tag='300'">
+      <p class="extent"><xsl:value-of select="."/></p>
+     </xsl:if>
+
+    <xsl:if test="starts-with(@tag, '5')">
+      <p class="note"><xsl:value-of select="."/></p>
+    </xsl:if>
+
+    <xsl:if test="@tag='650'">
+      <span class='counter'><xsl:number count="marc:datafield[@tag='650']"/>.</span> <xsl:apply-templates select="marc:subfield"/>
+    </xsl:if>
+
+    <xsl:if test="@tag='653'">
+      <span class="counter"><xsl:number format="i" count="marc:datafield[@tag='653']"/>.</span> <xsl:apply-templates select="marc:subfield"/>
+    </xsl:if>
+
+    <xsl:if test="@tag='010'">
+      <xsl:variable name="LCCN.nospace" select="translate(., ' ', '')"/>
+      <xsl:variable name="LCCN.length" select="string-length($LCCN.nospace)"/>
+      <xsl:variable name="LCCN.display" select="concat(substring($LCCN.nospace, 1, $LCCN.length - 6), '-', format-number(substring($LCCN.nospace, $LCCN.length - 5),'#'))"/>
+      <span class="LCCN">LCCN:<xsl:value-of select="$LCCN.display"/></span>
+    </xsl:if>
+
+    <xsl:if test="@tag='082' or @tag='092'">
+      <span class="DDC"><xsl:value-of select="marc:subfield[@code='a']"/></span>
+    </xsl:if>
+
+    <xsl:if test="@tag='856'">
+     <br/><xsl:apply-templates mode="link" select="marc:subfield" />
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="marc:subfield" mode="link">
+    <xsl:if test="@code='u'">
+      <span class="link">
+        <a class="url" href="{.}"/>
+      </span>
+    </xsl:if>
+  </xsl:template>
+  
+  <xsl:template match="marc:subfield">
+    <xsl:if test="@code!='2'">    
+     <xsl:if test="@code!='a'">--</xsl:if>
+     <xsl:value-of select="."/>
+    </xsl:if>
+  </xsl:template>
+
+</xsl:stylesheet>