From 306aed5b8a559aad2fb944a946ffdda9713f07ec Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 6 Mar 2010 09:47:55 -0500 Subject: introducing version 2, major patch, (version 1 libraries retained) --- lib/sisu/v2/shared_metadata.rb | 759 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 759 insertions(+) create mode 100644 lib/sisu/v2/shared_metadata.rb (limited to 'lib/sisu/v2/shared_metadata.rb') diff --git a/lib/sisu/v2/shared_metadata.rb b/lib/sisu/v2/shared_metadata.rb new file mode 100644 index 00000000..7c8cc971 --- /dev/null +++ b/lib/sisu/v2/shared_metadata.rb @@ -0,0 +1,759 @@ +# coding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2010, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module Metadata + class Summary + attr_accessor :tag,:inf,:class,:attrib + def initialize(md,display_heading=false) + @md,@display_heading=md,display_heading + @tag,@inf,@class,@attrib=nil + end + def metadata_base + meta,tag=[],[] + dir=SiSU_Env::Info_env.new(@md.fns) + base_html="#{dir.url.root}/#{@md.fnb}" + l=SiSU_Env::Standardise_language.new.file_to_language(@md.fns) + language=l[:l] + tr=SiSU_Translate::Source.new(@md,language) + @attrib='md' + if @display_heading + @tag,@inf=%{Document Metadata},'' + meta << self.meta_para + end + if defined? @md.title.full \ + and @md.title.full=~/\S+/ + @tag,@inf,@class=tr.full_title,@md.title.full,'dc' #1 + meta << self.meta_para + end + if defined? @md.creator.author \ + and @md.creator.author=~/\S+/ + @tag,@inf,@class=tr.author,@md.creator.author,'dc' #2 + meta << self.meta_para + end + if defined? @md.creator.translator \ + and @md.creator.translator=~/\S+/ + @tag,@inf,@class=tr.translator,@md.creator.translator,'ext' + meta << self.meta_para + end + if defined? @md.creator.illustrator \ + and @md.creator.illustrator=~/\S+/ + @tag,@inf,@class=tr.illustrator,@md.creator.illustrator,'ext' + meta << self.meta_para + end + if defined? @md.creator.prepared_by \ + and @md.creator.prepared_by=~/\S+/ + @tag,@inf,@class=tr.prepared_by,@md.creator.prepared_by,'ext' + meta << self.meta_para + end + if defined? @md.creator.digitized_by \ + and @md.creator.digitized_by=~/\S+/ + @tag,@inf,@class=tr.digitized_by,@md.creator.digitized_by,'ext' + meta << self.meta_para + end + if defined? @md.rights.all \ + and @md.rights.all=~/\S+/ + @tag,@inf,@class=tr.rights,@md.rights.all,'dc' #15 + meta << self.meta_para + end + if defined? @md.classify.subject \ + and @md.classify.subject=~/\S+/ + @tag,@inf,@class=tr.subject,@md.classify.subject,'dc' #3 + meta << self.meta_para + end + if defined? @md.notes.description \ + and @md.notes.description=~/\S+/ + @tag,@inf,@class=tr.description,@md.notes.description,'dc' #4 + meta << self.meta_para + end + if defined? @md.publisher \ + and @md.publisher=~/\S+/ + @tag,@inf,@class=tr.publisher,@md.publisher,'dc' #5 + meta << self.meta_para + end + if defined? @md.creator.contributor \ + and @md.creator.contributor=~/\S+/ + @tag,@inf,@class=tr.contributor,@md.creator.contributor,'dc' #6 + meta << self.meta_para + end + if defined? @md.notes.abstract \ + and @md.notes.abstract=~/\S+/ + @tag,@inf,@class=tr.abstract,@md.notes.abstract,'ext' + meta << self.meta_para + end + if defined? @md.date.created \ + and @md.date.created=~/\S+/ + @tag,@inf,@class=tr.date_created,@md.date.created,'dc' #7 + meta << self.meta_para + end + if defined? @md.date.issued \ + and @md.date.issued=~/\S+/ + @tag,@inf,@class=tr.date_issued,@md.date.issued,'dc' #7 + meta << self.meta_para + end + if defined? @md.date.available \ + and @md.date.available=~/\S+/ + @tag,@inf,@class=tr.date_available,@md.date.available,'dc' #7 + meta << self.meta_para + end + if defined? @md.date.modified \ + and @md.date.modified=~/\S+/ + @tag,@inf,@class=tr.date_modified,@md.date.modified,'dc' #7 + meta << self.meta_para + end + if defined? @md.date.valid \ + and @md.date.valid=~/\S+/ + @tag,@inf,@class=tr.date_valid,@md.date.valid,'dc' #7 + meta << self.meta_para + end + if defined? @md.date.published \ + and @md.date.published=~/\S+/ + @tag,@inf,@class=tr.date,@md.date.published,'dc' #7 + meta << self.meta_para + end + if defined? @md.type \ + and @md.date=~/\S+/ + @tag,@inf,@class=tr.type,@md.type,'dc' #8 + meta << self.meta_para + end + if defined? @md.classify.loc \ + and @md.classify.loc=~/\S+/ + @tag,@inf,@class=tr.cls_loc,@md.classify.loc,'id' + meta << self.meta_para + end + if defined? @md.classify.dewey \ + and @md.classify.dewey=~/\S+/ + @tag,@inf,@class=tr.cls_dewey,@md.classify.dewey,'id' + meta << self.meta_para + end + if defined? @md.classify.pg \ + and @md.classify.pg=~/\S+/ + @tag,@inf,@class=tr.cls_gutenberg,@md.classify.pg,'id' + meta << self.meta_para + end + if defined? @md.classify.isbn \ + and @md.classify.isbn=~/\S+/ + @tag,@inf,@class=tr.cls_isbn,@md.classify.isbn,'id' + meta << self.meta_para + end + if defined? @md.notes.comment \ + and @md.notes.comment=~/\S+/ + @tag,@inf,@class=tr.comments,@md.notes.comments,'ext' + meta << self.meta_para + end + if defined? @md.notes.prefix_a \ + and @md.notes.prefix_a=~/\S+/ + @tag,@inf,@class=tr.prefix_a,@md.notes.prefix_a,'inf' + meta << self.meta_para + end + if defined? @md.notes.prefix_b \ + and @md.notes.prefix_b=~/\S+/ + @tag,@inf,@class=tr.prefix_b,@md.notes.prefix_b,'inf' + meta << self.meta_para + end + if defined? @md.classify.identifier \ + and @md.classify.identifier=~/\S+/ + @tag,@inf,@class=tr.identifier,@md.classify.identifier,'dc' #10 + meta << self.meta_para + end + if defined? @md.original.source \ + and @md.original.source=~/\S+/ + @tag,@inf,@class=tr.source,@md.original.source,'dc' #11 + meta << self.meta_para + end + if defined? @md.title.language \ + and @md.title.language=~/\S+/ + @tag,@inf,@class=tr.language,@md.title.language,'dc' #12 + meta << self.meta_para + end + if defined? @md.original.language \ + and @md.original.language=~/\S+/ + @tag,@inf,@class=tr.language_original,@md.original.language,'ext' + meta << self.meta_para + end + if defined? @md.classify.format \ + and @md.classify.format=~/\S+/ + @tag,@inf,@class=tr.format,@md.classify.format,'dc' #9 + meta << self.meta_para + end + if defined? @md.classify.relation \ + and @md.classify.relation=~/\S+/ + @tag,@inf,@class=tr.relation,@md.classify.relation,'dc' #13 + meta << self.meta_para + end + if defined? @md.classify.coverage \ + and @md.classify.coverage=~/\S+/ + @tag,@inf,@class=tr.coverage,@md.classify.coverage,'dc' #14 + meta << self.meta_para + end + if defined? @md.classify.keywords \ + and @md.classify.keywords=~/\S+/ + @tag,@inf,@class=tr.keywords,@md.classify.keywords,'ext' + meta << self.meta_para + end + if @display_heading + @tag,@inf=%{Version Information},'' + meta << self.meta_para + end + if defined? @md.fns \ + and @md.fns=~/\S+/ + @tag,@inf,@class=tr.sourcefile,@md.fns,'src' + meta << self.meta_para + end + if defined? @md.file_encoding \ + and @md.file_encoding=~/\S+/ + @tag,@inf,@class='Filetype',@md.file_encoding,'src' + meta << self.meta_para + end + if defined? @md.dgst \ + and @md.dgst.class==Array + @tag,@inf,@class='Source Digest',"#{@md.dgst[0]} #{@md.dgst[1]}",'src' + meta << self.meta_para + end + if defined? @md.dgst_skin \ + and @md.dgst_skin.class==Array + @tag,@inf,@class='Skin Digest',"#{@md.dgst_skin[0]} #{@md.dgst_skin[1]}",'src' + meta << self.meta_para + end + if @display_heading + @tag,@inf=%{Generated},'' + meta << self.meta_para + end + if defined? @md.sisu_version \ + and @md.sisu_version[:version]=~/\S+/ + v="#{tr.sisu_version}: " + + "#{@md.sisu_version[:project]} " + + "#{@md.sisu_version[:version]} " + + "of #{@md.sisu_version[:date_stamp]} " + + "(#{@md.sisu_version[:date]})" + @tag,@inf,@class='Generated by',v,'ver' + meta << self.meta_para + end + if defined? @md.ruby_version \ + and @md.ruby_version=~/\S+/ + @tag,@inf,@class=tr.ruby_version,@md.ruby_version,'ver' + meta << self.meta_para + end + if defined? @md.generated \ + and @md.generated.class==Time + @tag,@inf,@class=tr.last_generated,@md.generated,'date' + meta << self.meta_para + end + meta + end + def char_enc(str) + @s=str + def utf8 + if @s \ + and @s.class==String + @s.gsub!(//u,Mx[:br_paragraph]) + @s.gsub!(//um,'>') # '>' # > + @s.gsub!(/¢/um,'¢') # '¢' # ¢ + @s.gsub!(/£/um,'£') # '£' # £ + @s.gsub!(/¥/um,'¥') # '¥' # ¥ + @s.gsub!(/§/um,'§') # '§' # § + @s.gsub!(/©/um,'©') # '©' # © + @s.gsub!(/ª/um,'ª') # 'ª' # ª + @s.gsub!(/«/um,'«') # '«' # « + @s.gsub!(/®/um,'®') # '®' # ® + @s.gsub!(/°/um,'°') # '°' # ° + @s.gsub!(/±/um,'±') # '±' # ± + @s.gsub!(/²/um,'²') # '²' # ² + @s.gsub!(/³/um,'³') # '³' # ³ + @s.gsub!(/µ/um,'µ') # 'µ' # µ + @s.gsub!(/¶/um,'¶') # '¶' # ¶ + @s.gsub!(/¹/um,'¹') # '¹' # ¹ + @s.gsub!(/º/um,'º') # 'º' # º + @s.gsub!(/»/um,'»') # '»' # » + @s.gsub!(/¼/um,'¼') # '¼' # ¼ + @s.gsub!(/½/um,'½') # '½' # ½ + @s.gsub!(/¾/um,'¾') # '¾' # ¾ + @s.gsub!(/×/um,'×') # '×' # × + @s.gsub!(/÷/um,'÷') # '÷' # ÷ + @s.gsub!(/¿/um,'¿') # '¿' # ¿ + @s.gsub!(/À/um,'À') # 'À' # À + @s.gsub!(/Á/um,'Á') # 'Á' # Á + @s.gsub!(/Â/um,'Â') # 'Â' # Â + @s.gsub!(/Ã/um,'Ã') # 'Ã' # Ã + @s.gsub!(/Ä/um,'Ä') # 'Ä' # Ä + @s.gsub!(/Å/um,'Å') # 'Å' # Å + @s.gsub!(/Æ/um,'Æ') # 'Æ' # Æ + @s.gsub!(/Ç/um,'Ç') # 'Ç' # Ç + @s.gsub!(/È/um,'È') # 'È' # È + @s.gsub!(/É/um,'É') # 'É' # É + @s.gsub!(/Ê/um,'Ê') # 'Ê' # Ê + @s.gsub!(/Ë/um,'Ë') # 'Ë' # Ë + @s.gsub!(/Ì/um,'Ì') # 'Ì' # Ì + @s.gsub!(/Í/um,'Í') # 'Í' # Í + @s.gsub!(/Î/um,'Î') # 'Î' # Î + @s.gsub!(/Ï/um,'Ï') # 'Ï' # Ï + @s.gsub!(/Ð/um,'Ð') # 'Ð' # Ð + @s.gsub!(/Ñ/um,'Ñ') # 'Ñ' # Ñ + @s.gsub!(/Ò/um,'Ò') # 'Ò' # Ò + @s.gsub!(/Ó/um,'Ó') # 'Ó' # Ó + @s.gsub!(/Ô/um,'Ô') # 'Ô' # Ô + @s.gsub!(/Õ/um,'Õ') # 'Õ' # Õ + @s.gsub!(/Ö/um,'Ö') # 'Ö' # Ö + @s.gsub!(/Ø/um,'Ø') # 'Ø' # Ø + @s.gsub!(/Ù/um,'Ù') # 'Ù' # Ù + @s.gsub!(/Ú/um,'Ú') # 'Ú' # Ú + @s.gsub!(/Û/um,'Û') # 'Û' # Û + @s.gsub!(/Ü/um,'Ü') # 'Ü' # Ü + @s.gsub!(/Ý/um,'Ý') # 'Ý' # Ý + @s.gsub!(/Þ/um,'Þ') # 'Þ' # Þ + @s.gsub!(/ß/um,'ß') # 'ß' # ß + @s.gsub!(/à/um,'à') # 'à' # à + @s.gsub!(/á/um,'á') # 'á' # á + @s.gsub!(/â/um,'â') # 'â' # â + @s.gsub!(/ã/um,'ã') # 'ã' # ã + @s.gsub!(/ä/um,'ä') # 'ä' # ä + @s.gsub!(/å/um,'å') # 'å' # å + @s.gsub!(/æ/um,'æ') # 'æ' # æ + @s.gsub!(/ç/um,'ç') # 'ç' # ç + @s.gsub!(/è/um,'è') # 'è' # è + @s.gsub!(/é/um,'é') # '´' # é + @s.gsub!(/ê/um,'ê') # 'ˆ' # ê + @s.gsub!(/ë/um,'ë') # 'ë' # ë + @s.gsub!(/ì/um,'ì') # 'ì' # ì + @s.gsub!(/í/um,'í') # '´' # í + @s.gsub!(/î/um,'î') # 'î' # î + @s.gsub!(/ï/um,'ï') # 'ï' # ï + @s.gsub!(/ð/um,'ð') # 'ð' # ð + @s.gsub!(/ñ/um,'ñ') # 'ñ' # ñ + @s.gsub!(/ò/um,'ò') # 'ò' # ò + @s.gsub!(/ó/um,'ó') # 'ó' # ó + @s.gsub!(/ô/um,'ô') # 'ô' # ô + @s.gsub!(/õ/um,'õ') # 'õ' # õ + @s.gsub!(/ö/um,'ö') # 'ö' # ö + @s.gsub!(/ø/um,'ø') # 'ø' # ø + @s.gsub!(/ù/um,'ú') # 'ù' # ú + @s.gsub!(/ú/um,'û') # 'ú' # û + @s.gsub!(/û/um,'ü') # 'û' # ü + @s.gsub!(/ü/um,'ý') # 'ü' # ý + @s.gsub!(/þ/um,'þ') # 'þ' # þ + @s.gsub!(/ÿ/um,'ÿ') # 'ÿ' # ÿ + @s.gsub!(/‘/um,'‘') # '‘' # ‘ + @s.gsub!(/’/um,'’') # '’' # ’ + @s.gsub!(/“/um,'“') # “ # “ + @s.gsub!(/”/um,'”') # ” # ” + @s.gsub!(/–/um,'–') # – # – + @s.gsub!(/—/um,'—') # — # — + @s.gsub!(/∝/um,'∝') # ∝ # ∝ + @s.gsub!(/∞/um,'∞') # ∞ # ∞ + @s.gsub!(/™/um,'™') # ™ # ™ + @s.gsub!(/✠/um,'✠') # ✗ # ✠ + @s.gsub!(/ /um,' ') # space identify + @s.gsub!(/ /um,' ') # space identify + @s.gsub!(/#{Mx[:br_paragraph]}/u,'
') + end + @s + end + self + end + def xml_sax + def meta_para + inf_xml=char_enc(@inf).utf8 + < +#{Ax[:tab]}#{@tag.capitalize}: +#{Ax[:tab]} +#{Ax[:tab]*2}#{inf_xml} +#{Ax[:tab]} + +WOK + end + def metadata + Metadata::Summary.new(@md).metadata_base + end + self + end + def xml_dom + def meta_para + inf_xml=char_enc(@inf).utf8 + < +#{Ax[:tab]*2}#{@tag.capitalize}: +#{Ax[:tab]*2}<#{@attrib}> +#{Ax[:tab]*3}#{inf_xml} +#{Ax[:tab]*2} +#{Ax[:tab]} +WOK + end + def metadata + Metadata::Summary.new(@md).metadata_base + end + self + end + def xhtml_scroll + def meta_para + inf_xml=char_enc(@inf).utf8 + < +#{Ax[:tab]}#{@tag.capitalize}: +#{Ax[:tab]}<#{@attrib} class="#{@class}"> +#{Ax[:tab]*2}#{inf_xml} +#{Ax[:tab]} +#{Ax[:tab]} +
+WOK + end + def metadata + Metadata::Summary.new(@md).metadata_base + end + self + end + def xhtml_display + def meta_para + inf_xml=char_enc(@inf).utf8 + %{

+ #{@tag}: #{inf_xml} +

} + end + def metadata + Metadata::Summary.new(@md,true).metadata_base + end + self + end + def odf + def meta_para + url_brace=SiSU_Viz::Skin.new.url_decoration + if @inf.class==String + @inf.gsub!(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1') #http ftp matches escaped, no decoration + @inf.gsub!(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + '\1\2') #special case \{ e.g. \}http://url + @inf.gsub!(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) #http ftp matches with decoration + @inf.gsub!(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+)/, + %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) if @inf !~/http:\/\// # improve upon, document crash where url contains '@' symbol + end + <#{@tag.capitalize}: #{@inf}} +WOK + end + def metadata + Metadata::Summary.new(@md).metadata_base + end + self + end + def plaintext + def meta_para + <