From 547e9f498220268b209b28926002a74515baf281 Mon Sep 17 00:00:00 2001 From: Hector Castro Date: Fri, 30 Jan 2015 11:04:00 -0600 Subject: [PATCH 04/11] Bug 13642 [ENH] Adding new features for Dublin Core metadata Changes to marc2dcxml method in Record.pm - Update marc2dcxml() to obtain more arguments - Update the pod of marc2dcxml() - Change the use MARC::Crosswalk::DublinCore for C4::DublinCoreTransformer --- C4/Record.pm | 106 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 21 deletions(-) mode change 100644 => 100755 C4/Record.pm diff --git a/C4/Record.pm b/C4/Record.pm old mode 100644 new mode 100755 index 16d3f54..fa85ea0 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -25,7 +25,7 @@ use strict; # please specify in which methods a given module is used use MARC::Record; # marc2marcxml, marcxml2marc, changeEncoding use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding -use MARC::Crosswalk::DublinCore; # marc2dcxml +use C4::DublinCoreTransformer; # marc2dcxml use Biblio::EndnoteStyle; use Unicode::Normalize; # _entity_encode use C4::Biblio; #marc2bibtex @@ -222,16 +222,29 @@ sub marcxml2marc { Returns a DublinCore::Record object, will eventually return a Dublin Core scalar -FIXME: should return actual XML, not just an object +FIXME: should return actual XML, not just an object (C4::DublinCoreTransformer return an XML) + +C<$type> - the recommendation ( simple-dc-rdf, dc-rdf, dc-xml, oai-dc) C<$marc> - an ISO-2709 scalar or MARC::Record object -C<$qualified> - specify whether qualified Dublin Core should be used in the input or output [0] +C<$qualified> - specify whether simple or qualified Dublin Core should be used in output [0 or 1] + +C<$entities> placing entities to 0 will codify only the five basic entities e.g., <, >, ", &, and &apos. Conversely if it is encoded to 1, all entities will coded into decimal + +C<$root> root element for XML files + +C<$xsi_schemaLocation> the xsischemaLocation for XML files. + +C<$rdf_subject> Represent the main subject of RDF triples (for Koha the URI of the resource) + +C<$rdf_format> Imply multiple formats for RDF (ntriples, nquads, rdfxml, rdfjson, ntriples-canonical, turtle) =cut sub marc2dcxml { - my ($marc,$qualified) = @_; + my ( $type, $marc, $qualified, $entities, $root, $xsi_schemaLocation, $rdf_subject, + $rdf_format ) = @_; my $error; # test if it's already a MARC::Record object, if not, make it one my $marc_record_obj; @@ -245,24 +258,75 @@ sub marc2dcxml { $error .="\nCreation of MARC::Record object failed: ".$MARC::File::ERROR; } } - my $crosswalk = MARC::Crosswalk::DublinCore->new; - if ($qualified) { - $crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 1 ); - } - my $dcxml = $crosswalk->as_dublincore($marc_record_obj); - my $dcxmlfinal = "\n"; - $dcxmlfinal .= ""; - - foreach my $element ( $dcxml->elements() ) { - $dcxmlfinal.="<"."dc:".$element->name().">".$element->content()."name().">\n"; + my $dcxml; + + SWITCH: + for ($type) { + if (/^simple-dc-rdf/) { + my $objectDC = C4::DublinCoreTransformer->new({ + type => 'rdf', + qualified => 0, + get_marc_record => $marc, + }); + + $objectDC->get_rdf_data({ + rdf_subject => $rdf_subject, + rdf_format => 'rdfxml', + entities => 1, + }); + $dcxml = $objectDC->write_rdf(); + last SWITCH; + } + if (/^dc-rdf/) { + my $objectDC = C4::DublinCoreTransformer->new({ + type => 'rdf', + qualified => 1, + get_marc_record => $marc, + }); + + $objectDC->get_rdf_data({ + rdf_subject => $rdf_subject, + rdf_format => $rdf_format, + entities => 1, + }); + $dcxml = $objectDC->write_rdf(); + last SWITCH; + } + if (/^dc-xml/) { + my $objectDC = C4::DublinCoreTransformer->new({ + type => 'xml', + qualified => $qualified, + get_marc_record => $marc, + }); + + $objectDC->get_xml_data({ + root => $root, + xsi_schemaLocation => $xsi_schemaLocation, + entities => 1, + }); + $dcxml = $objectDC->write_xml(); + last SWITCH; + } + if ($type eq 'oai-dc') { + my $objectDC = C4::DublinCoreTransformer->new({ + type => 'xml', + qualified => 0, + get_marc_record => $marc, + }); + + $objectDC->get_xml_data({ + root => 'oai_dc:dc', + xsi_schemaLocation => 'http://www.openarchives.org/OAI/2.0/oai_dc/' . + ' http://www.openarchives.org/OAI/2.0/oai_dc.xsd', + entities => 0, + optional_namespace => 'oai_dc', + namespace_url => 'http://www.openarchives.org/OAI/2.0/oai_dc/', + }); + $dcxml = $objectDC->write_xml(); + last SWITCH; + } } - $dcxmlfinal .= "\n"; - return ($error,$dcxmlfinal); + return ( $error, $dcxml ); } =head2 marc2modsxml - Convert from ISO-2709 to MODS -- 1.7.10.4