2012-03-29 03:09:03 +09:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
|
|
|
2012-03-29 03:07:37 +09:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Metadata = PDFJS.Metadata = (function MetadataClosure() {
|
2012-03-25 03:59:51 +09:00
|
|
|
function Metadata(meta) {
|
|
|
|
if (typeof meta === 'string') {
|
|
|
|
var parser = new DOMParser();
|
|
|
|
meta = parser.parseFromString(meta, 'application/xml');
|
|
|
|
} else if (!(meta instanceof Document)) {
|
|
|
|
error('Metadata: Invalid metadata object');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.metaDocument = meta;
|
|
|
|
this.metadata = {};
|
|
|
|
this.parse();
|
|
|
|
}
|
|
|
|
|
|
|
|
Metadata.prototype = {
|
|
|
|
parse: function() {
|
|
|
|
var doc = this.metaDocument;
|
|
|
|
var rdf = doc.documentElement;
|
2012-03-29 02:15:59 +09:00
|
|
|
|
|
|
|
if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
|
2012-03-25 03:59:51 +09:00
|
|
|
rdf = rdf.firstChild;
|
2012-03-29 02:15:59 +09:00
|
|
|
while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf')
|
2012-03-25 03:59:51 +09:00
|
|
|
rdf = rdf.nextSibling;
|
|
|
|
}
|
2012-03-28 05:37:02 +09:00
|
|
|
|
2012-03-29 02:15:59 +09:00
|
|
|
var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
|
|
|
|
if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes())
|
2012-03-25 03:59:51 +09:00
|
|
|
return;
|
|
|
|
|
|
|
|
var childNodes = rdf.childNodes, desc, namespace, entries, entry;
|
|
|
|
|
|
|
|
for (var i = 0, length = childNodes.length; i < length; i++) {
|
|
|
|
desc = childNodes[i];
|
2012-03-28 05:37:02 +09:00
|
|
|
if (desc.nodeName.toLowerCase() !== 'rdf:description')
|
2012-03-25 03:59:51 +09:00
|
|
|
continue;
|
|
|
|
|
|
|
|
entries = [];
|
|
|
|
for (var ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
|
2012-03-28 05:37:02 +09:00
|
|
|
if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text')
|
2012-03-25 03:59:51 +09:00
|
|
|
entries.push(desc.childNodes[ii]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ii = 0, iLength = entries.length; ii < iLength; ii++) {
|
|
|
|
var entry = entries[ii];
|
|
|
|
var name = entry.nodeName.toLowerCase();
|
2012-03-27 06:48:04 +09:00
|
|
|
this.metadata[name] = entry.textContent.trim();
|
2012-03-25 03:59:51 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function(name) {
|
|
|
|
return this.metadata[name] || null;
|
|
|
|
},
|
|
|
|
|
|
|
|
has: function(name) {
|
|
|
|
return typeof this.metadata[name] !== 'undefined';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Metadata;
|
|
|
|
})();
|