]> granicus.if.org Git - docbook-dsssl/commitdiff
Liza Daly reported that the dc:identifer-generation code was garbage (she was right).
authorKeith Fahlgren <abdelazer@users.sourceforge.net>
Tue, 17 Feb 2009 04:03:20 +0000 (04:03 +0000)
committerKeith Fahlgren <abdelazer@users.sourceforge.net>
Tue, 17 Feb 2009 04:03:20 +0000 (04:03 +0000)
Added new tests:
- should include at least one dc:identifier
- should include an ISBN as URN for dc:identifier if an ISBN was in the metadata
- should include an ISSN as URN for dc:identifier if an ISSN was in the metadata
- should include an biblioid as a dc:identifier if an biblioid was in the metadata
- should include a URN for a biblioid with @class attribute as a dc:identifier if an biblioid was in the metadata

xsl/epub/bin/spec/epub_spec.rb
xsl/epub/bin/spec/files/biblioid.doi.xml [new file with mode: 0644]
xsl/epub/bin/spec/files/biblioid.xml [new file with mode: 0644]
xsl/epub/bin/spec/files/isbn.xml [new file with mode: 0644]
xsl/epub/bin/spec/files/issn.xml [new file with mode: 0644]
xsl/epub/bin/spec/files/nogoodid.xml [new file with mode: 0644]
xsl/epub/docbook.xsl

index 8174feda0f490f06cc1254c66fbb6880f925a0da..22143ddd6bcbdb579fe340576348f476372d96cd 100755 (executable)
@@ -16,6 +16,20 @@ require 'docbook'
 
 $DEBUG = false
 
+def opf_lines(filename, filedir)
+  shortname = filename.gsub(/\W/, '')
+  tmpdir = File.join(Dir::tmpdir(), shortname); Dir.mkdir(tmpdir) rescue Errno::EEXIST
+  epub = DocBook::Epub.new(File.join(filedir, filename), tmpdir)
+  epubfile  = File.join(tmpdir, shortname + ".epub")
+  epub.render_to_file(epubfile, $DEBUG)
+  FileUtils.copy(epubfile, "." + shortname + ".epub") if $DEBUG
+  success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{File.expand_path(epubfile)}")
+  raise "Could not unzip #{epubfile}" unless success
+  opf_file = Dir.glob(File.join(tmpdir, "**", "*.opf")).first
+  opf_lines = File.open(opf_file).readlines
+  return opf_lines
+end
+
 describe DocBook::Epub do
   before(:all) do
     @filedir = File.expand_path(File.join(File.dirname(__FILE__), 'files'))
@@ -136,6 +150,32 @@ describe DocBook::Epub do
     @valid_epub.should_not satisfy {|ve| DocBook::Epub.invalid?(ve)}
   end
 
+  it "should include at least one dc:identifier" do
+    # TODO Consider UUID
+    opf_lns = opf_lines('nogoodid.xml', @filedir)
+    opf_lns.to_s.should =~ /identifier[^>]+>[^<][^_<]+</
+  end
+
+  it "should include an ISBN as URN for dc:identifier if an ISBN was in the metadata" do
+    opf_lns = opf_lines('isbn.xml', @filedir)
+    opf_lns.to_s.should =~ /identifier[^>]+>urn:isbn:123456789X</
+  end
+
+  it "should include an ISSN as URN for dc:identifier if an ISSN was in the metadata" do
+    opf_lns = opf_lines('issn.xml', @filedir)
+    opf_lns.to_s.should =~ /identifier[^>]+>urn:issn:X987654321</
+  end
+
+  it "should include an biblioid as a dc:identifier if an biblioid was in the metadata" do
+    opf_lns = opf_lines('biblioid.xml', @filedir)
+    opf_lns.to_s.should =~ /identifier[^>]+>thebiblioid</
+  end
+
+  it "should include a URN for a biblioid with @class attribute as a dc:identifier if an biblioid was in the metadata" do
+    opf_lns = opf_lines('biblioid.doi.xml', @filedir)
+    opf_lns.to_s.should =~ /identifier[^>]+>urn:doi:thedoi</
+  end
+
   it "should not include PDFs in rendered epub files as valid image inclusions" do
     begin
       tmpdir = File.join(Dir::tmpdir(), "epubinclusiontest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
diff --git a/xsl/epub/bin/spec/files/biblioid.doi.xml b/xsl/epub/bin/spec/files/biblioid.doi.xml
new file mode 100644 (file)
index 0000000..d7c592c
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<book>
+  <bookinfo>
+    <title>Test: biblioid</title>
+    <author>
+      <firstname>Keith</firstname>
+      <surname>Fahlgren</surname>
+      <affiliation>
+        <address>
+          <email>keith@oreilly.com</email>
+        </address>
+      </affiliation>
+    </author>
+    <biblioid class="doi">thedoi</biblioid>
+  </bookinfo>
+  <chapter>
+    <title>Chapter One</title>
+    <para>This document has a biblioid assigned.</para>
+  </chapter>
+</book>
+
+
diff --git a/xsl/epub/bin/spec/files/biblioid.xml b/xsl/epub/bin/spec/files/biblioid.xml
new file mode 100644 (file)
index 0000000..d6522a2
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<book>
+  <bookinfo>
+    <title>Test: biblioid</title>
+    <author>
+      <firstname>Keith</firstname>
+      <surname>Fahlgren</surname>
+      <affiliation>
+        <address>
+          <email>keith@oreilly.com</email>
+        </address>
+      </affiliation>
+    </author>
+    <biblioid>thebiblioid</biblioid>
+  </bookinfo>
+  <chapter>
+    <title>Chapter One</title>
+    <para>This document has a biblioid assigned.</para>
+  </chapter>
+</book>
+
diff --git a/xsl/epub/bin/spec/files/isbn.xml b/xsl/epub/bin/spec/files/isbn.xml
new file mode 100644 (file)
index 0000000..7640b61
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<book>
+  <bookinfo>
+    <title>Test: isbn</title>
+    <author>
+      <firstname>Keith</firstname>
+      <surname>Fahlgren</surname>
+      <affiliation>
+        <address>
+          <email>keith@oreilly.com</email>
+        </address>
+      </affiliation>
+    </author>
+    <isbn>123456789X</isbn>
+  </bookinfo>
+  <chapter>
+    <title>Chapter One</title>
+    <para>This document has an ISBN assigned.</para>
+  </chapter>
+</book>
diff --git a/xsl/epub/bin/spec/files/issn.xml b/xsl/epub/bin/spec/files/issn.xml
new file mode 100644 (file)
index 0000000..c5ae537
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<article>
+  <articleinfo>
+    <title>Test: issn</title>
+    <author>
+      <firstname>Keith</firstname>
+      <surname>Fahlgren</surname>
+      <affiliation>
+        <address>
+          <email>keith@oreilly.com</email>
+        </address>
+      </affiliation>
+    </author>
+    <issn>X987654321</issn>
+  </articleinfo>
+  <section>
+    <title>Section One</title>
+    <para>This document has an issn assigned.</para>
+  </section>
+</article>
diff --git a/xsl/epub/bin/spec/files/nogoodid.xml b/xsl/epub/bin/spec/files/nogoodid.xml
new file mode 100644 (file)
index 0000000..7cfee19
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<book>
+  <chapter>
+    <title>Chapter One</title>
+    <para>This document has nothing that looks particularly attractive as a dc:identifier.</para>
+  </chapter>
+</book>
index e20786c0d076e5efb872b19a836dcb3d1a3de761..3502827aef5c455055ea7423592ebfabe2037336 100644 (file)
     <xsl:variable name="unique-id">
       <xsl:choose>
         <xsl:when test="/*/*[contains(name(.), 'info')]/biblioid"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/biblioid"/> </xsl:when>
-        <xsl:when test="/*/*[contains(name(.), 'info')]/invpartnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/invpartnumber"/> </xsl:when>
+        <xsl:when test="/*/*[contains(name(.), 'info')]/isbn"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/isbn"/> </xsl:when>
         <xsl:when test="/*/*[contains(name(.), 'info')]/issn"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/issn"/> </xsl:when>
+        <xsl:when test="/*/*[contains(name(.), 'info')]/invpartnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/invpartnumber"/> </xsl:when>
         <xsl:when test="/*/*[contains(name(.), 'info')]/issuenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/issuenum"/> </xsl:when>
         <xsl:when test="/*/*[contains(name(.), 'info')]/productnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/productnumber"/> </xsl:when>
-        <xsl:when test="/*/*[contains(name(.), 'info')]/pubsnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/pubsnumber"/> </xsl:when>
         <xsl:when test="/*/*[contains(name(.), 'info')]/seriesvolnums"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/seriesvolnums"/> </xsl:when>
         <xsl:when test="/*/*[contains(name(.), 'info')]/volumenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/volumenum"/> </xsl:when>
-        <xsl:when test="/*/*[contains(name(.), 'info')]/isbn"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/isbn"/> </xsl:when>
+        <!-- Deprecated -->
+        <xsl:when test="/*/*[contains(name(.), 'info')]/pubsnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')]/pubsnumber"/> </xsl:when>
       </xsl:choose>  
       <xsl:text>_</xsl:text>
-      <xsl:value-of select="/*/@id"/>
+      <xsl:choose>
+        <xsl:when test="/*/@id">
+          <xsl:value-of select="/*/@id"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <!-- TODO: Do UUIDs here -->
+          <xsl:value-of select="generate-id(/*)"/>
+        </xsl:otherwise>
+      </xsl:choose>
     </xsl:variable>
     <xsl:variable name="doc.title">
       <xsl:call-template name="get.doc.title" />
             <xsl:element name="dc:identifier">
               <xsl:attribute name="id"><xsl:value-of select="$package-id"/></xsl:attribute>
               <xsl:choose>
+                <xsl:when test="/appendix/appendixinfo/biblioid|
+                                /article/articleinfo/biblioid|
+                                /book/bookinfo/biblioid|
+                                /chapter/chapterinfo/biblioid|
+                                /glossary/glossaryinfo/biblioid|
+                                /part/partinfo/biblioid|
+                                /preface/prefaceinfo/biblioid|
+                                /refentry/refentryinfo/biblioid|
+                                /reference/referenceinfo/biblioid|
+                                /refsect1/refsect1info/biblioid|
+                                /refsect2/refsect2info/biblioid|
+                                /refsect3/refsect3info/biblioid|
+                                /refsection/refsectioninfo/biblioid|
+                                /refsynopsisdiv/refsynopsisdivinfo/biblioid|
+                                /sect1/sect1info/biblioid|
+                                /sect2/sect2info/biblioid|
+                                /sect3/sect3info/biblioid|
+                                /sect4/sect4info/biblioid|
+                                /sect5/sect5info/biblioid|
+                                /section/sectioninfo/biblioid|
+                                /setindex/setindexinfo/biblioid|
+                                /set/setinfo/biblioid">
+                  <xsl:if test="/*/*/biblioid[1]/@class = 'doi' or /*/*/biblioid[1]/@class = 'isbn' or /*/*/biblioid[1]/@class = 'isrn' or /*/*/biblioid[1]/@class = 'issn'">
+                    <xsl:text>urn:</xsl:text>
+                    <xsl:value-of select="/*/*/biblioid[1]/@class"/>
+                    <xsl:text>:</xsl:text>
+                  </xsl:if>
+                  <xsl:value-of select="/*/*/biblioid[1]"/>
+                </xsl:when>
                 <xsl:when test="/appendix/appendixinfo/isbn|
                                 /article/articleinfo/isbn|
                                 /book/bookinfo/isbn|
                   <xsl:text>urn:isbn:</xsl:text>
                   <xsl:value-of select="/*/*/isbn"/>
                 </xsl:when>
+                <xsl:when test="/appendix/appendixinfo/issn|
+                                /article/articleinfo/issn|
+                                /book/bookinfo/issn|
+                                /chapter/chapterinfo/issn|
+                                /glossary/glossaryinfo/issn|
+                                /part/partinfo/issn|
+                                /preface/prefaceinfo/issn|
+                                /refentry/refentryinfo/issn|
+                                /reference/referenceinfo/issn|
+                                /refsect1/refsect1info/issn|
+                                /refsect2/refsect2info/issn|
+                                /refsect3/refsect3info/issn|
+                                /refsection/refsectioninfo/issn|
+                                /refsynopsisdiv/refsynopsisdivinfo/issn|
+                                /sect1/sect1info/issn|
+                                /sect2/sect2info/issn|
+                                /sect3/sect3info/issn|
+                                /sect4/sect4info/issn|
+                                /sect5/sect5info/issn|
+                                /section/sectioninfo/issn|
+                                /setindex/setindexinfo/issn|
+                                /set/setinfo/issn">
+                  <xsl:text>urn:issn:</xsl:text>
+                  <xsl:value-of select="/*/*/issn"/>
+                </xsl:when>
                 <xsl:otherwise>
                   <xsl:value-of select="$unique-id"/>
                 </xsl:otherwise>