use OpenSRF::System;
use OpenSRF::AppSession;
use XML::LibXML;
+use XML::LibXSLT;
use Encode;
use Unicode::Normalize;
# set the bootstrap config when this module is loaded
-my ($bootstrap, $cstore, $supercat, $actor, $parser, $search);
+my ($bootstrap, $cstore, $supercat, $actor, $parser, $search, $xslt, $cn_browse_xslt, %browse_types);
+
+$browse_types{call_number}{xml} = sub {
+ my $tree = shift;
+
+ my $year = (gmtime())[5] + 1900;
+ my $content = '';
+
+ $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
+
+ for my $cn (@$tree) {
+ (my $cn_class = $cn->class_name) =~ s/::/-/gso;
+ $cn_class =~ s/Fieldmapper-//gso;
+
+ my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
+ my $cn_lib = $cn->owning_lib->shortname;
+ my $cn_label = $cn->label;
+
+ $cn_label =~ s/\n//gos;
+ $cn_label =~ s/'/'/go;
+
+ (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
+ $ou_class =~ s/Fieldmapper-//gso;
+
+ my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
+ my $ou_name = $cn->owning_lib->name;
+
+ $ou_name =~ s/\n//gos;
+ $ou_name =~ s/'/'/go;
+
+ (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
+ $rec_class =~ s/Fieldmapper-//gso;
+
+ my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
+
+ $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
+ $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
+
+ my $r_doc = $parser->parse_string($cn->record->marc);
+ $r_doc->documentElement->setAttribute( id => $rec_tag );
+ $content .= entityize($r_doc->documentElement->toString);
+
+ $content .= "</hold:volume>";
+ }
+
+ $content .= '</hold:volumes>';
+ return ("Content-type: application/xml\n\n",$content);
+};
+
+
+$browse_types{call_number}{html} = sub {
+ my $tree = shift;
+ my $p = shift;
+ my $n = shift;
+
+ if (!$cn_browse_xslt) {
+ $cn_browse_xslt = $parser->parse_file(
+ OpenSRF::Utils::SettingsClient
+ ->new
+ ->config_value( dirs => 'xsl' ).
+ "/CNBrowse2HTML.xsl"
+ );
+ $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
+ }
+
+ my (undef,$xml) = $browse_types{call_number}{xml}->($tree);
+
+ return (
+ "Content-type: text/html\n\n",
+ entityize(
+ $cn_browse_xslt->transform(
+ $parser->parse_string( $xml ),
+ 'prev' => "'$p'",
+ 'next' => "'$n'"
+ )->toString(1)
+ )
+ );
+};
sub import {
my $self = shift;
$actor = OpenSRF::AppSession->create('open-ils.actor');
$search = OpenSRF::AppSession->create('open-ils.search');
$parser = new XML::LibXML;
+ $xslt = new XML::LibXSLT;
+
+ $cn_browse_xslt = $parser->parse_file(
+ OpenSRF::Utils::SettingsClient
+ ->new
+ ->config_value( dirs => 'xsl' ).
+ "/CNBrowse2HTML.xsl"
+ );
+
+ $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
+
}
sub oisbn {
$type = 'record';
$type = 'metarecord' if ($1 =~ /^metabib/o);
$type = 'isbn' if ($1 =~ /^isbn/o);
+ $type = 'call_number' if ($1 =~ /^call_number/o);
$command = 'retrieve';
+ $command = 'browse' if ($type eq 'call_number');
+ }
+
+ if ($type eq 'call_number' and $command eq 'browse') {
+ $lib = uc($lib);
+ print "Location: $root/browse/$base_format/call_number/$lib/$id\n\n";
+ return 302;
}
if ( !grep
return $stuff;
}
-my %browse_types = (
- call_number => {
- xml => sub {
- my $tree = shift;
-
- my $year = (gmtime())[5] + 1900;
- my $content = '';
-
- $content .= "Content-type: application/xml\n\n";
- $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
-
- for my $cn (@$tree) {
- (my $cn_class = $cn->class_name) =~ s/::/-/gso;
- $cn_class =~ s/Fieldmapper-//gso;
-
- my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
- my $cn_lib = $cn->owning_lib->shortname;
- my $cn_label = $cn->label;
-
- (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
- $ou_class =~ s/Fieldmapper-//gso;
-
- my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
- my $ou_name = $cn->owning_lib->name;
-
- (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
- $rec_class =~ s/Fieldmapper-//gso;
-
- my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
-
- $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
- $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
-
- my $r_doc = $parser->parse_string($cn->record->marc);
- $r_doc->documentElement->setAttribute( id => $rec_tag );
- $content .= entityize($r_doc->documentElement->toString);
-
- $content .= "</hold:volume>";
- }
-
- $content .= '</hold:volumes>';
- return $content;
- }
- }
-
-);
sub string_browse {
my $apache = shift;
return Apache2::Const::DECLINED if (-e $apache->filename);
my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
#warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
-
$site ||= $cgi->param('searchOrg');
$page ||= $cgi->param('startPage') || 0;
$page_size ||= $cgi->param('count') || 9;
- $page = 0 if ($page !~ /^\d+$/);
+ $page = 0 if ($page !~ /^-?\d+$/);
+
+ my $prev = join('/', $base,$format,$axis,$site,$string,$page - 1,$page_size);
+ my $next = join('/', $base,$format,$axis,$site,$string,$page + 1,$page_size);
unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
warn "something's wrong...";
$page
)->gather(1);
- my $content = $browse_types{$axis}{$format}->($tree);
- print $content;
+ my ($header,$content) = $browse_types{$axis}{$format}->($tree,$prev,$next);
+ print $header.$content;
return Apache2::Const::OK;
}
--- /dev/null
+<?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:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:marc="http://www.loc.gov/MARC21/slim"
+ xmlns:hold="http://open-ils.org/spec/holdings/v1"
+ xmlns:act='http://open-ils.org/spec/actors/v1'
+ 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"/>
+ </head>
+ <body>
+ <span>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="$prev"/>
+ </xsl:attribute>
+ <xsl:text>Previous</xsl:text>
+ </a>
+ <xsl:text> -- </xsl:text>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="$next"/>
+ </xsl:attribute>
+ <xsl:text>Next</xsl:text>
+ </a>
+ </span>
+ <hr/>
+ <xsl:apply-templates select="//hold:volume"/>
+ <hr/>
+ <span>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="$prev"/>
+ </xsl:attribute>
+ <xsl:text>Previous</xsl:text>
+ </a>
+ <xsl:text> -- </xsl:text>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="$next"/>
+ </xsl:attribute>
+ <xsl:text>Next</xsl:text>
+ </a>
+ </span>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="hold:volume">
+ <div style="border:solid #999999 1px;">
+ <span>
+ <dl>
+ <xsl:value-of select="@label"/>
+ <dd><xsl:apply-templates select="marc:record"/></dd>
+ <dd><xsl:value-of select="act:owning_lib/@name"/></dd>
+ </dl>
+ </span>
+ </div>
+ </xsl:template>
+
+ <xsl:template match="marc:record">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('/opac/extras/unapi?format=htmlholdings-full;id=',@id)"/>
+ </xsl:attribute>
+ <xsl:value-of select="marc:datafield[@tag='245']/marc:subfield[@code='a']"/>
+ </a>
+ <xsl:text> By </xsl:text>
+ <xsl:value-of select="marc:datafield[@tag='100']/marc:subfield[@code='a']"/>
+ </xsl:template>
+
+</xsl:stylesheet>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
<link href="{$base_dir}/htmlcard.css" rel="stylesheet" type="text/css" />
<xsl:apply-templates select="/marc:collection/xhtml:link"/>
+ <title><xsl:value-of select="//marc:datafield[@tag='245']/marc:subfield[@code='a']"/></title>
</head>
<body>
<xsl:apply-templates select="//marc:record"/>
<xsl:apply-templates select="marc:datafield[@tag!='082' and @tag!='092' and @tag!='010']"/>
<span class="bottom">
<xsl:apply-templates select="xhtml:link[@rel='otherFormat' and contains(@href,'format=')]"/>
- <xsl:apply-templates select="xhtml:abbr[@class='unapi-id']"/>
<xsl:apply-templates select="marc:controlfield[@tag='001']"/>
<xsl:apply-templates select="marc:datafield[@tag='082' or @tag='092' or @tag='010']"/>
</span>
+ <xsl:apply-templates select="xhtml:abbr[@class='unapi-id']"/>
</div>
<br/>
<xsl:apply-templates select="hold:volumes"/>
</xsl:template>
<xsl:template match="hold:volume">
- <li> <b><xsl:value-of select="./@label"/></b>
+ <li>
+ <b>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('/opac/extras/browse/html/call_number/',@lib,'/',@label)"/>
+ </xsl:attribute>
+ <xsl:value-of select="./@label"/>
+ </a>
+ </b>
<xsl:apply-templates select="hold:copies"/>
</li>
</xsl:template>
<xsl:template match="marc:datafield">
<xsl:if test="starts-with(@tag, '1')">
- <p class="mainheading"><xsl:value-of select="."/></p>
+ <p class="mainheading">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('/opac/extras/opensearch/1.1/-/html-full/author?searchTerms=',.)"/>
+ </xsl:attribute>
+ <xsl:value-of select="."/>
+ </a>
+ </p>
</xsl:if>
<xsl:if test="starts-with(@tag, '24') and /marc:record/marc:datafield[@tag='100']">
<p class="note"><xsl:value-of select="."/></p>
</xsl:if>
+ <xsl:if test="@tag='600'">
+ <span class='counter'><xsl:number count="marc:datafield[@tag='600']"/>.</span> <xsl:apply-templates select="marc:subfield"/>
+ </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:template match="marc:subfield">
<xsl:if test="@code!='2'">
<xsl:if test="@code!='a'">--</xsl:if>
- <xsl:value-of select="."/>
+ <xsl:choose>
+ <xsl:when test="./@code!='v' and ./parent::*[starts-with(@tag,'6')]">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('/opac/extras/opensearch/1.1/-/html-full/subject?searchTerms=',.)"/>
+ </xsl:attribute>
+ <xsl:value-of select="."/>
+ </a>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:if>
</xsl:template>