Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 16208200BBD for ; Mon, 3 Oct 2016 17:49:32 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 14990160ADC; Mon, 3 Oct 2016 15:49:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6FBD1160AF7 for ; Mon, 3 Oct 2016 17:49:29 +0200 (CEST) Received: (qmail 46627 invoked by uid 500); 3 Oct 2016 15:49:28 -0000 Mailing-List: contact commits-help@clerezza.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@clerezza.apache.org Delivered-To: mailing list commits@clerezza.apache.org Received: (qmail 45919 invoked by uid 99); 3 Oct 2016 15:49:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2016 15:49:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F1237E0BD9; Mon, 3 Oct 2016 15:49:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: reto@apache.org To: commits@clerezza.apache.org Date: Mon, 03 Oct 2016 15:49:39 -0000 Message-Id: <2bdfddbd16214b00b3dc96558eb3f739@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [13/51] [partial] clerezza git commit: CLEREZZA-1012: reduced clerezza to core components, the rest stays in legacy-branch archived-at: Mon, 03 Oct 2016 15:49:32 -0000 http://git-wip-us.apache.org/repos/asf/clerezza/blob/14575ea3/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/rdf-ext.js ---------------------------------------------------------------------- diff --git a/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/rdf-ext.js b/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/rdf-ext.js deleted file mode 100644 index d32c520..0000000 --- a/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/rdf-ext.js +++ /dev/null @@ -1,19324 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 200 && statusCode < 300); - }; - - self.graph = function (iri, callback, options) { - options = options || {}; - - self.request('GET', iri, {'Accept': buildAccept()}, null, - function (statusCode, headers, content, error) { - // error during request - if (error) { - return callback(null, 'request error: ' + error); - } - - // http status code != success - if (!httpSuccess(statusCode)) { - // in case of GET allow statusCode of 0 for browser local load - if (statusCode !== 0) { - return callback(null, 'status code error: ' + statusCode); - } - } - - // use default parser... - var contentType = self.defaultParser; - - // ...if content-type is not given or unknown - if ('content-type' in headers && headers['content-type'] in self.parsers) { - contentType = headers['content-type']; - } - - // and override if set in options - if ('forceContentType' in options && options.forceContentType in self.parsers) { - contentType = options.forceContentType; - } - - self.parsers[contentType](content, function (graph, error) { - // parser error - if (error) { - return callback(null, 'parser error: ' + error); - } - - // copy etag header to Graph object - if ('useEtag' in options && options.useEtag && 'etag' in headers) { - graph.etag = headers.etag; - } - - callback(graph); - }, iri); - } - ); - }; - - self.match = function (iri, subject, predicate, object, callback, limit) { - self.graph(iri, function (graph, error) { - // forward error - if (error) { - return callback(null, error); - } - - callback(graph.match(subject, predicate, object, limit)); - }); - }; - - self.add = function (iri, graph, callback, options) { - var - method = 'PUT', - contentType = self.defaultSerializer, - headers = {}; - - options = options || {}; - - headers['Content-Type'] = contentType; - - if ('method' in options) { - method = options.method; - } - - if ('etag' in options) { - headers['If-Match'] = options.etag; - } - - if ('useEtag' in options && options.useEtag && 'etag' in graph) { - headers['If-Match'] = graph.etag; - } - - self.serializers[contentType](graph, function (data, error) { - // serializer error - if (error) { - return callback(null, error); - } - - self.request(method, iri, headers, data, function (statusCode, headers, content, error) { - // error during request - if (error) { - return callback(null, error); - } - - // http status code != success - if (!httpSuccess(statusCode)) { - return callback(null, 'status code error: ' + statusCode); - } - - callback(graph); - }); - }); - }; - - self.merge = function (iri, graph, callback, options) { - var - contentType = self.defaultPatchSerializer, - headers = {}; - - options = options || {}; - - headers['Content-Type'] = contentType; - - if ('etag' in options) { - headers['If-Match'] = options.etag; - } - - if ('useEtag' in options && options.useEtag && 'etag' in graph) { - headers['If-Match'] = graph.etag; - } - - self.serializers[contentType](graph, function (data, error) { - // serializer error - if (error) { - return callback(null, error); - } - - self.request('PATCH', iri, headers, data, function (statusCode, headers, content, error) { - // error during request - if (error) { - return callback(null, error); - } - - // http status code != success - if (!httpSuccess(statusCode)) { - return callback(null, 'status code error: ' + statusCode); - } - - callback(graph); - } - ); - }); - }; - - self.remove = function (iri, graph, callback) { - //TODO: implement me - }; - - self.removeMatches = function (iri, subject, predicate, object, callback) { - //TODO: implement me - }; - - self.delete = function (iri, callback) { - self.request('DELETE', iri, {}, null, - function (statusCode, headers, content, error) { - // error during request - if (error) { - return callback(false, 'request error: ' + error); - } - - // http status code != success - if (!httpSuccess(statusCode)) { - return callback(false, 'status code error: ' + statusCode); - } - - callback(true); - } - ); - }; -}; - - -LdpStore.serializeSparqlUpdate = function (rdf, graph, callback) { - rdf.serializeNTriples(graph, function (nTriples, error) { - if (error) { - return callback(null, error); - } - - callback('INSERT DATA { ' + nTriples + ' }'); - }); -}; - - -LdpStore.defaultParsers = function(rdf) { - return { - 'application/ld+json': rdf.parseJsonLd, - 'application/n-triples': rdf.parseTurtle, - 'text/turtle': rdf.parseTurtle - }; -}; - - -LdpStore.defaultSerializers = function (rdf) { - return { - 'application/ld+json': rdf.serializeJsonLd, - 'application/n-triples': rdf.serializeNTriples, - 'application/sparql-update': LdpStore.serializeSparqlUpdate.bind(null, rdf), - 'text/turtle': rdf.serializeNTriples - }; -}; - - -module.exports = function (rdf) { - rdf.LdpStore = LdpStore.bind(null, rdf); -}; - -},{}],6:[function(require,module,exports){ -/* global rdf */ -'use strict'; - - -var - URIResolver = require('./uri-resolver'); - - -var MicrodataProcessor = function () { - this.blankCounter = 0; - - this.vocabularies = [{ - namespaceURI: 'http://schema.org/', - isMember: function (uri) { - return uri.indexOf(this.namespaceURI) === 0; - }, - getProperty: function (name) { - return this.namespaceURI + name; - } - }]; -}; - -MicrodataProcessor.prototype = new URIResolver(); -MicrodataProcessor.prototype.constructor = MicrodataProcessor; - -MicrodataProcessor.typeNode = rdf.createNamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'); -MicrodataProcessor.integerNode = rdf.createNamedNode('http://www.w3.org/2001/XMLSchema#integer'); -MicrodataProcessor.doubleNode = rdf.createNamedNode('http://www.w3.org/2001/XMLSchema#double'); -MicrodataProcessor.timeNode = rdf.createNamedNode('http://www.w3.org/2001/XMLSchema#time'); -MicrodataProcessor.dateTimeNode = rdf.createNamedNode('http://www.w3.org/2001/XMLSchema#dateTime'); -MicrodataProcessor.durationNode = rdf.createNamedNode('http://www.w3.org/2001/XMLSchema#duration'); - -MicrodataProcessor.absoluteURIRE = /[\w\_\-]+:\S+/; - -MicrodataProcessor.prototype.resolve = function (uri) { - return uri; -}; - -MicrodataProcessor.trim = function (str) { - str = str || ''; - - return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); -}; - -MicrodataProcessor.tokenize = function (str) { - return MicrodataProcessor - .trim(str) - .split(/\s+/) - .reduce(function (tokens, token) { - if (token) { - tokens.push(token); - } - - return tokens; - }, []); -}; - -MicrodataProcessor.prototype.getVocabulary = function (uri) { - for (var i=0; i= 0) { - return makeVocab(uri.substring(0,hash+1)); - } - - var lastSlash = uri.lastIndexOf('/'); - - if (lastSlash >= 0) { - return makeVocab(uri.substring(0,lastSlash+1)); - } - - return makeVocab(uri); -}; - -MicrodataProcessor.prototype.getProperty = function (value, vocabulary) { - if (MicrodataProcessor.absoluteURIRE.exec(value)) { - return value; - } - - return vocabulary ? vocabulary.getProperty(value) : base.resolve('#' + value); -}; - -MicrodataProcessor.valueMappings = { - link: function(node,base) { - return rdf.createNamedNode(base.resolve(node.getAttribute('href'))); - }, - media: function (node, base) { - return rdf.createNamedNode(base.resolve(node.getAttribute('src'))); - }, - meta: function (node) { - var - value = node.getAttribute('content'), - lang = node.getAttribute('lang'); - - return rdf.createLiteral(value, lang ? lang : null); - }, - number: function (node) { - var value = node.getAttribute('value'); - - if (value === parseInt(value).toString()) { - return rdf.createLiteral(value, null, MicrodataProcessor.integerNode); - } else if (value === parseFloat(value).toString()) { - return rdf.createLiteral(value, null, MicrodataProcessor.doubleNode); - } else { - return rdf.createLiteral(value); - } - }, - object: function (node, base) { - return rdf.createNamedNode(base.resolve(node.getAttribute('data'))); - }, - time: function(node) { - var - value = node.getAttribute('datetime'), - lang = node.getAttribute('lang'); - - //TODO: add http://www.w3.org/2001/XMLSchema#gYearMonth. - //TODO: add http://www.w3.org/2001/XMLSchema#gYear. - //TODO: use RegExp - if (value.length === 9) { - return rdf.createLiteral(value, null, MicrodataProcessor.timeNode); - } else if (value.length === 20) { - return rdf.createLiteral(value, null, MicrodataProcessor.dateTimeNode); - } else if (value.substr(0, 1) === 'P') { - return rdf.createLiteral(value, null, MicrodataProcessor.durationNode); - } else { - return rdf.createLiteral(value, lang ? lang : null); - } - } -}; - -MicrodataProcessor.valueMappings.a = MicrodataProcessor.valueMappings.link; -MicrodataProcessor.valueMappings.area = MicrodataProcessor.valueMappings.a; -MicrodataProcessor.valueMappings.audio = MicrodataProcessor.valueMappings.media; -MicrodataProcessor.valueMappings.data = MicrodataProcessor.valueMappings.number; -MicrodataProcessor.valueMappings.embed = MicrodataProcessor.valueMappings.media; -MicrodataProcessor.valueMappings.iframe = MicrodataProcessor.valueMappings.media; -MicrodataProcessor.valueMappings.img = MicrodataProcessor.valueMappings.media; -MicrodataProcessor.valueMappings.meter = MicrodataProcessor.valueMappings.number; -MicrodataProcessor.valueMappings.source = MicrodataProcessor.valueMappings.media; -MicrodataProcessor.valueMappings.track = MicrodataProcessor.valueMappings.media; -MicrodataProcessor.valueMappings.video = MicrodataProcessor.valueMappings.media; - -MicrodataProcessor.prototype.getValue = function(node, base) { - var converter = MicrodataProcessor.valueMappings[node.localName]; - - if (converter) { - return converter(node, base); - } - - return rdf.createLiteral(node.textContent); -}; - -MicrodataProcessor.prototype.process = function (node, callback, base) { - var - self = this; - - if (node.nodeType === node.DOCUMENT_NODE) { - node = node.documentElement; - } - - base = self.parseURI(base); - - var createContext = function (memory, subject, type, vocabulary) { - return { - memory: memory ? memory : {}, - subject: subject, - type: type, - vocabulary: vocabulary - }; - }; - - var processChildren = function (current, type) { - var - context, - itemProp, - itemScope, - predicate, - subject, - value; - - for (var child = current.item.firstChild; child; child = child.nextSibling) { - if (child.nodeType !== child.ELEMENT_NODE) { - continue; - } - - itemProp = child.getAttribute('itemprop'); - itemScope = child.hasAttribute('itemscope'); - - // spec 6.3.9.1.1 - context = createContext(current.context.memory, current.context.subject, type, current.context.vocabulary); - - subject = generateTriple({item: child, context: context}); - - if (itemProp) { - // spec 6.3.9.1 - MicrodataProcessor.tokenize(itemProp).forEach(function (token) { - // spec 6.3.9.1.2 - //TODO: Let predicate be the result of generate predicate URI using context and name - if (MicrodataProcessor.absoluteURIRE.test(token)) { - predicate = rdf.createNamedNode(token); - } else if (context.vocabulary) { - predicate = rdf.createNamedNode(context.vocabulary + token); - } else { - predicate = rdf.createNamedNode(base.resolve('#' + token)); - } - - // spec 6.3.9.1.3 - //TODO: Let value be the property value of element - value = self.getValue(child, base); - - // spec 6.3.9.1.4 - //TODO: If value is an item, then generate the triples for value using context. Replace value by the subject returned from those steps - if (itemScope) { - value = subject; - } - - // spec 6.3.9.1.5 - - callback(rdf.createTriple( - current.context.subject, - predicate, - value - )); - - // spec 6.3.9.1.6 - //TODO: If an entry exists in the registry for name in the vocabulary associated with vocab having the key subPropertyOf or equivalentProperty, for each such value equiv, generate the following triple: - }); - } - } - }; - - var processSubject = function (current) { - var - itemType = current.item.getAttribute('itemtype'), - type, - vocab; - - // spec 6.3.3 - MicrodataProcessor.tokenize(itemType).forEach(function (token) { - if (!MicrodataProcessor.absoluteURIRE.test(token)) { - return; - } - - // spec 6.3.4 - if (!type) { - type = token; - } - - callback(rdf.createTriple( - current.context.subject, - MicrodataProcessor.typeNode, - rdf.createNamedNode(base.resolve(token)))); - }); - - // spec 6.3.5 - if (!type) { - type = current.context.type; - } - - // spec 6.3.6 - //TODO: If the registry contains a URI prefix that is a character for character match of type up to the length of the URI prefix, set vocab as that URI prefix - // spec 6.3.7 - //TODO: Otherwise, if type is not empty, construct vocab by removing everything following the last SOLIDUS U+002F ("/") or NUMBER SIGN U+0023 ("#") from the path component of type - if (type) { - vocab = self.getVocabulary(type); //TODO: return only uri string - vocab = vocab ? vocab.namespaceURI : null; - } - - // spec 6.3.8 - //TODO: Update evaluation context setting current vocabulary to vocab - if (vocab) { - current.context.vocabulary = vocab; - } - - // spec 6.3.9 - processChildren(current, type); - }; - - var generateTriple = function (current) { - var - id = current.item.getAttribute('id'), - itemId = current.item.getAttribute('itemid'), - itemRef = current.item.getAttribute('itemref'), - itemScope = current.item.hasAttribute('itemscope'); - - // spec 6.3.1 - if (id in current.context.memory) { - current.context.memory[id].forEach(function (context) { - processSubject({item: current.item, context: context}); - }); - } else { - if (itemScope) { - if (itemId) { - current.context.subject = rdf.createNamedNode(base.resolve(itemId)); - } else { - current.context.subject = rdf.createBlankNode(); - } - - // spec 6.3.2 - //TODO: Add a mapping from item to subject in memory - MicrodataProcessor.tokenize(itemRef).forEach(function (token) { - if (!(token in current.context.memory)) { - current.context.memory[token] = []; - } - - current.context.memory[token].push(current.context); - }); - } - - processSubject(current); - } - - return current.context.subject; - }; - - generateTriple({item: node, context: createContext(null, null, null, null)}); -}; - -var MicrodataParser = function (rdf) { - var processor = new MicrodataProcessor(); - - this.process = function (data, callback, base, filter, done) { - base = base || ''; - filter = filter || function () { return true; }; - done = done || function () {}; - - processor.process(rdf.parseHtml(data, base), callback, base); - - done(true); - - return true; - }; - - this.parse = function (data, callback, base, filter, graph) { - graph = graph || rdf.createGraph(); - - return this.process( - data, - function (triple) { graph.add(triple); }, - base, - filter, - function (success) { callback(success ? graph : null); }); - }; -}; - - -module.exports = function (rdf) { - rdf.MicrodataParser = MicrodataParser.bind(null, rdf); - - var parser = new MicrodataParser(rdf); - rdf.parseMicrodata = parser.parse.bind(parser); -}; - -},{"./uri-resolver":14}],7:[function(require,module,exports){ -/* global rdf:true */ -'use strict'; - - -var NTriplesSerializer = function (rdf) { - this.serialize = function (graph, callback) { - callback = callback || function () {}; - - var nTriples = rdf.Graph.toString(graph); - - callback(nTriples); - - return nTriples; - }; -}; - - -module.exports = function (rdf) { - rdf.NTriplesSerializer = NTriplesSerializer.bind(null, rdf); - - var serializer = new NTriplesSerializer(rdf); - rdf.serializeNTriples = serializer.serialize.bind(serializer); -}; - -},{}],8:[function(require,module,exports){ -/* global rdf:true, Promise:false */ -'use strict'; - - -var funcTemplate = function (func, PromiseClass) { - return function () { - var args = arguments; - - return new PromiseClass(function (resolve, reject) { - var callback = function (result, error) { - if (error) { - reject(error); - } else { - resolve(result); - } - }; - - func(args, callback); - }); - }; -}; - - -var ParserPromiseWrapper = function (p, parser) { - this.process = funcTemplate(function (args, callback) { parser.process(args[0], args[1], args[2], args[3], callback); }, p); - this.parse = funcTemplate(function (args, callback) { parser.parse(args[0], callback, args[1], args[2], args[3]); }, p); - this.parser = function () { return parser; }; -}; - - -var SerializerPromiseWrapper = function (p, serializer) { - this.serialize = funcTemplate(function (args, callback) { serializer.serialize(args[0], callback); }, p); - this.serializer = function () { return serializer; }; -}; - - -var StorePromiseWrapper = function (p, store) { - this.graph = funcTemplate(function (args, callback) { store.graph(args[0], callback); }, p); - this.match = funcTemplate(function (args, callback) { store.match(args[0], args[1], args[2], args[3], callback, args[5]); }, p); - this.add = funcTemplate(function (args, callback) { store.add(args[0], args[1], callback); }, p); - this.merge = funcTemplate(function (args, callback) { store.merge(args[0], args[1], callback); }, p); - this.remove = funcTemplate(function (args, callback) { store.remove(args[0], args[1], callback); }, p); - this.removeMatches = funcTemplate(function (args, callback) { store.removeMatches(args[0], args[1], args[2], args[3], callback); }, p); - this.delete = funcTemplate(function (args, callback) { store.delete(args[0], callback); }, p); - this.store = function () { return store; }; -}; - - -module.exports = function (rdf) { - rdf.promise = {}; - rdf.promise.Parser = ParserPromiseWrapper.bind(null, rdf.Promise); - rdf.promise.Serializer = SerializerPromiseWrapper.bind(null, rdf.Promise); - rdf.promise.Store = StorePromiseWrapper.bind(null, rdf.Promise); -}; - -},{}],9:[function(require,module,exports){ -/* global rdf:true */ -'use strict'; - - -var RdfstoreStore = function (store) { - var - self = this, - rdf = store.rdf; - - self.graph = function (iri, callback) { - store.graph(iri, function (success, graph) { - if (success) { - callback(graph); - } else { - callback(null); - } - }); - }; - - self.match = function (iri, subject, predicate, object, callback, limit) { - self.graph(iri, function (graph) { - if (!graph) { - callback(null); - } else { - callback(graph.match(subject, predicate, object, limit)); - } - }); - }; - - self.add = function (iri, graph, callback) { - store.clear(iri, function () { - store.insert(graph, iri, function (success) { - if (success) { - callback(graph); - } else { - callback(null, 'couldn\'n insert graph'); - } - }); - }); - }; - - self.merge = function (iri, graph, callback) { - store.insert(graph, iri, function (success) { - if (success) { - callback(graph); - } else { - callback(null, 'couldn\'n insert graph'); - } - }); - }; - - self.remove = function (iri, graph, callback) { - self.graph(iri, function (oldGraph) { - var newGraph = rdf.Graph.difference(oldGraph, graph); - - self.add(iri, newGraph, function (addedGraph) { - callback(!!addedGraph); - }); - }); - }; - - self.removeMatches = function (iri, subject, predicate, object, callback) { - self.graph(iri, function (oldGraph) { - var newGraph = oldGraph.removeMatches(subject, predicate, object); - - self.add(iri, newGraph, function (addedGraph) { - callback(!!addedGraph); - }); - }); - }; - - self.delete = function (iri, callback) { - store.clear(iri, function (success) { - if (success) { - callback(true); - } else { - callback(null, 'couldn\'n delete graph'); - } - }); - }; -}; - - -module.exports = function (rdf) { - rdf.RdfstoreStore = RdfstoreStore; -}; - -},{}],10:[function(require,module,exports){ -/** - * @fileoverview - * RDF/XML PARSER - * - * Version 0.1 - * Parser believed to be in full positive RDF/XML parsing compliance - * with the possible exception of handling deprecated RDF attributes - * appropriately. Parser is believed to comply fully with other W3C - * and industry standards where appropriate (DOM, ECMAScript, &c.) - * - * Author: David Sheets - * - * W3C� SOFTWARE NOTICE AND LICENSE - * http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - * This work (and included software, documentation such as READMEs, or - * other related items) is being provided by the copyright holders under - * the following license. By obtaining, using and/or copying this work, - * you (the licensee) agree that you have read, understood, and will - * comply with the following terms and conditions. - * - * Permission to copy, modify, and distribute this software and its - * documentation, with or without modification, for any purpose and - * without fee or royalty is hereby granted, provided that you include - * the following on ALL copies of the software and documentation or - * portions thereof, including modifications: - * - * 1. The full text of this NOTICE in a location viewable to users of - * the redistributed or derivative work. - * 2. Any pre-existing intellectual property disclaimers, notices, or terms and - * conditions. If none exist, the W3C Software Short Notice should be - * included (hypertext is preferred, text is permitted) within the body - * of any redistributed or derivative code. - * 3. Notice of any changes or modifications to the files, including the - * date changes were made. (We recommend you provide URIs to the location - * from which the code is derived.) - * - * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT - * HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS - * FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR - * DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, - * TRADEMARKS OR OTHER RIGHTS. - * - * COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL - * OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR - * DOCUMENTATION. - * - * The name and trademarks of copyright holders may NOT be used in - * advertising or publicity pertaining to the software without specific, - * written prior permission. Title to copyright in this software and any - * associated documentation will at all times remain with copyright - * holders. - */ -/** - * @class Class defining an RDFParser resource object tied to an RDFStore - * - * @author David Sheets - * @version 0.1 - * - * @constructor - * @param {RDFStore} store An RDFStore object - */ - -var RdfLibParser = function(store){ - var RDFParser = {}; - - /** Standard namespaces that we know how to handle @final - * @member RDFParser - */ - RDFParser.ns = {'RDF': "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 'RDFS': "http://www.w3.org/2000/01/rdf-schema#"}; - - /** DOM Level 2 node type magic numbers @final - * @member RDFParser - */ - RDFParser.nodeType = {'ELEMENT': 1, 'ATTRIBUTE': 2, 'TEXT': 3, - 'CDATA_SECTION': 4, 'ENTITY_REFERENCE': 5, - 'ENTITY': 6, 'PROCESSING_INSTRUCTION': 7, - 'COMMENT': 8, 'DOCUMENT': 9, 'DOCUMENT_TYPE': 10, - 'DOCUMENT_FRAGMENT': 11, 'NOTATION': 12}; - - /** - * Frame class for namespace and base URI lookups - * Base lookups will always resolve because the parser knows - * the default base. - * - * @private - */ - - this.frameFactory = function(parser, parent, element){ - return {'NODE': 1, 'ARC': 2, 'parent': parent, 'parser': parser, 'store': parser.store, 'element': element, - 'lastChild': 0, 'base': null, 'lang': null, 'node': null, 'nodeType': null, 'listIndex': 1, 'rdfid': null, 'datatype': null, 'collection': false, /** Terminate the frame and notify the store that we're done */ - 'terminateFrame': function(){ - if (this.collection){ - - this.node.close(); - } - } - , /** Add a symbol of a certain type to the this frame */'addSymbol': function(type, uri){ - uri = uriJoin(uri, this.base); - this.node = this.store.sym(uri); - - this.nodeType = type; - } - , /** Load any constructed triples into the store */'loadTriple': function(){ - if (this.parent.parent.collection){ - this.parent.parent.node.append(this.node); - } - else { - this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why); - } - if (this.parent.rdfid != null){ - // reify - var triple = this.store.sym(uriJoin("#" + this.parent.rdfid, this.base)); - this.store.add(triple, this.store.sym(RDFParser.ns.RDF + "type"), this.store.sym(RDFParser.ns.RDF + "Statement"), this.parser.why); - this.store.add(triple, this.store.sym(RDFParser.ns.RDF + "subject"), this.parent.parent.node, this.parser.why); - this.store.add(triple, this.store.sym(RDFParser.ns.RDF + "predicate"), this.parent.node, this.parser.why); - - this.store.add(triple, this.store.sym(RDFParser.ns.RDF + "object"), this.node, this.parser.why); - } - } - , /** Check if it's OK to load a triple */'isTripleToLoad': function(){ - - return (this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === - this.ARC && this.parent.parent.nodeType === this.NODE); - } - , /** Add a symbolic node to this frame */'addNode': function(uri){ - this.addSymbol(this.NODE, uri); - if (this.isTripleToLoad()){ - - this.loadTriple(); - } - } - , /** Add a collection node to this frame */'addCollection': function(){ - this.nodeType = this.NODE; - this.node = this.store.collection(); - this.collection = true; - if (this.isTripleToLoad()){ - - this.loadTriple(); - } - } - , /** Add a collection arc to this frame */'addCollectionArc': function(){ - - this.nodeType = this.ARC; - } - , /** Add a bnode to this frame */'addBNode': function(id){ - if (id != null){ - if (this.parser.bnodes[id] != null){ - this.node = this.parser.bnodes[id]; - } - else { - this.node = this.parser.bnodes[id] = this.store.bnode(); - } - } - else { - this.node = this.store.bnode(); - } - this.nodeType = this.NODE; - if (this.isTripleToLoad()){ - - this.loadTriple(); - } - } - , /** Add an arc or property to this frame */'addArc': function(uri){ - if (uri === RDFParser.ns.RDF + "li"){ - uri = RDFParser.ns.RDF + "_" + this.parent.listIndex; - this.parent.listIndex++; - } - - this.addSymbol(this.ARC, uri); - } - , /** Add a literal to this frame */'addLiteral': function(value){ - if (this.parent.datatype){ - this.node = this.store.literal(value, "", this.store.sym(this.parent.datatype)); - } - else { - this.node = this.store.literal(value, this.lang); - } - this.nodeType = this.NODE; - if (this.isTripleToLoad()){ - this.loadTriple(); - } - } - }; - }; - - //from the OpenLayers source .. needed to get around IE problems. - this.getAttributeNodeNS = function(node, uri, name){ - var attributeNode = null; - if (node.getAttributeNodeNS){ - attributeNode = node.getAttributeNodeNS(uri, name); - } - else { - var attributes = node.attributes; - var potentialNode, fullName; - for (var i = 0;i < attributes.length; ++ i){ - potentialNode = attributes[i]; - if (potentialNode.namespaceURI === uri){ - fullName = (potentialNode.prefix) ? (potentialNode.prefix +":" + name): name; - if (fullName === potentialNode.nodeName){ - attributeNode = potentialNode; - break; - } - } - } - } - return attributeNode; - }; - - - /** Our triple store reference @private */ - - this.store = store;/** Our identified blank nodes @private */ - this.bnodes = {};/** A context for context-aware stores @private */ - this.why = null;/** Reification flag */ - this.reify = false; - - /** - * Build our initial scope frame and parse the DOM into triples - * @param {DOMTree} document The DOM to parse - * @param {String} base The base URL to use - * @param {Object} why The context to which this resource belongs - */ - - this.parse = function(document, base, why){ - var children = document.childNodes;// clean up for the next run - this.cleanParser();// figure out the root element - var root; - if (document.nodeType === RDFParser.nodeType.DOCUMENT){ - for (var c = 0;c < children.length;c++){ - if (children[c].nodeType === RDFParser.nodeType.ELEMENT){ - root = children[c]; - break; - } - } - } - else if (document.nodeType === RDFParser.nodeType.ELEMENT){ - root = document; - } - else { - throw new Error("RDFParser: can't find root in " + base +". Halting. "); - // return false; - } - this.why = why;// our topmost frame - var f = this.frameFactory(this); - this.base = base; - f.base = base; - f.lang = ''; - this.parseDOM(this.buildFrame(f, root)); - return true; - }; - - this.parseDOM = function(frame){ - // a DOM utility function used in parsing - var rdfid; - var elementURI = function(el){ - var result = ""; - if (el.namespaceURI == null){ - throw new Error("RDF/XML syntax error: No namespace for " + el.localName + " in " + this.base); - } - if (el.namespaceURI){ - result = result + el.namespaceURI; - } - if (el.localName){ - result = result + el.localName; - } - else if (el.nodeName){ - if (el.nodeName.indexOf(":") >= 0)result = result + el.nodeName.split(":")[1]; - else result = result + el.nodeName; - } - return result; - }.bind(this); - var dig = true;// if we'll dig down in the tree on the next iter - while (frame.parent){ - var dom = frame.element; - var attrs = dom.attributes; - if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION){ - //we have a literal - if(frame.parent.nodeType == frame.NODE) { - //must have had attributes, store as rdf:value - frame.addArc(RDFParser.ns.RDF + 'value'); - frame = this.buildFrame(frame); - } - frame.addLiteral(dom.nodeValue); - } - else if (elementURI(dom)!== RDFParser.ns.RDF + "RDF"){ - // not root - if (frame.parent && frame.parent.collection){ - // we're a collection element - frame.addCollectionArc(); - frame = this.buildFrame(frame, frame.element); - frame.parent.element = null; - } - if ( ! frame.parent || ! frame.parent.nodeType || frame.parent.nodeType === frame.ARC){ - // we need a node - var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "about"); - rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "ID"); - if (about && rdfid){ - throw new Error("RDFParser: " + dom.nodeName + " has both rdf:id and rdf:about." + - " Halting. Only one of these" + " properties may be specified on a" + " node."); - } - if (!about && rdfid){ - frame.addNode("#" + rdfid.nodeValue); - dom.removeAttributeNode(rdfid); - } - else if (about == null && rdfid == null){ - var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "nodeID"); - if (bnid){ - frame.addBNode(bnid.nodeValue); - dom.removeAttributeNode(bnid); - } - else { - frame.addBNode(); - } - } - else { - frame.addNode(about.nodeValue); - dom.removeAttributeNode(about); - } - // Typed nodes - var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "type"); - if (RDFParser.ns.RDF + "Description" !== elementURI(dom)){ - rdftype = {'nodeValue': elementURI(dom)}; - } - if (rdftype != null){ - this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + "type"), this.store.sym(uriJoin(rdftype.nodeValue, - frame.base)), this.why); - if (rdftype.nodeName){ - dom.removeAttributeNode(rdftype); - } - } - // Property Attributes - for (var x = attrs.length - 1;x >= 0;x--){ - this.store.add(frame.node, this.store.sym(elementURI(attrs[x])), this.store.literal(attrs[x].nodeValue, - frame.lang), this.why); - } - } - else { - // we should add an arc (or implicit bnode+arc) - frame.addArc(elementURI(dom));// save the arc's rdf:ID if it has one - if (this.reify){ - rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "ID"); - if (rdfid){ - frame.rdfid = rdfid.nodeValue; - dom.removeAttributeNode(rdfid); - } - } - var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "parseType"); - var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "datatype"); - if (datatype){ - frame.datatype = datatype.nodeValue; - dom.removeAttributeNode(datatype); - } - if (parsetype){ - var nv = parsetype.nodeValue; - if (nv === "Literal"){ - frame.datatype = RDFParser.ns.RDF + "XMLLiteral";// (this.buildFrame(frame)).addLiteral(dom) - // should work but doesn't - frame = this.buildFrame(frame); - frame.addLiteral(dom); - dig = false; - } - else if (nv === "Resource"){ - frame = this.buildFrame(frame, frame.element); - frame.parent.element = null; - frame.addBNode(); - } - else if (nv === "Collection"){ - frame = this.buildFrame(frame, frame.element); - frame.parent.element = null; - frame.addCollection(); - } - dom.removeAttributeNode(parsetype); - } - if (attrs.length !== 0){ - var resource = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "resource"); - var bnid2 = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, "nodeID"); - frame = this.buildFrame(frame); - if (resource){ - frame.addNode(resource.nodeValue); - dom.removeAttributeNode(resource); - } - else { - if (bnid2){ - frame.addBNode(bnid2.nodeValue); - dom.removeAttributeNode(bnid2); - } - else { - frame.addBNode(); - } - } - for (var x1 = attrs.length - 1; x1 >= 0; x1--){ - var f = this.buildFrame(frame); - f.addArc(elementURI(attrs[x1])); - if (elementURI(attrs[x1])=== RDFParser.ns.RDF + "type"){ - (this.buildFrame(f)).addNode(attrs[x1].nodeValue); - } - else { - (this.buildFrame(f)).addLiteral(attrs[x1].nodeValue); - } - } - } - else if (dom.childNodes.length === 0){ - (this.buildFrame(frame)).addLiteral(""); - } - } - }// rdf:RDF - // dig dug - dom = frame.element; - while (frame.parent){ - var pframe = frame; - while (dom == null){ - frame = frame.parent; - dom = frame.element; - } - var candidate = dom.childNodes && dom.childNodes[frame.lastChild]; - if (!candidate || ! dig){ - frame.terminateFrame(); - if ( ! (frame = frame.parent)){ - break; - }// done - dom = frame.element; - dig = true; - } - else if ((candidate.nodeType !== RDFParser.nodeType.ELEMENT && - candidate.nodeType !== RDFParser.nodeType.TEXT && - candidate.nodeType !== RDFParser.nodeType.CDATA_SECTION) || - ((candidate.nodeType === RDFParser.nodeType.TEXT || - candidate.nodeType === RDFParser.nodeType.CDATA_SECTION) && - dom.childNodes.length !== 1)){ - frame.lastChild++; - } - else { - // not a leaf - frame.lastChild++; - frame = this.buildFrame(pframe, dom.childNodes[frame.lastChild - 1]); - break; - } - } - }// while - }; - - /** - * Cleans out state from a previous parse run - * @private - */ - this.cleanParser = function(){ - this.bnodes = {}; - this.why = null; - }; - - /** - * Builds scope frame - * @private - */ - this.buildFrame = function(parent, element){ - var frame = this.frameFactory(this, parent, element); - if (parent){ - frame.base = parent.base; - frame.lang = parent.lang; - } - if (!element || element.nodeType === RDFParser.nodeType.TEXT || - element.nodeType === RDFParser.nodeType.CDATA_SECTION){ - return frame; - } - var attrs = element.attributes; - var base = element.getAttributeNode("xml:base"); - if (base != null){ - frame.base = base.nodeValue; - element.removeAttribute("xml:base"); - } - var lang = element.getAttributeNode("xml:lang"); - if (lang != null){ - frame.lang = lang.nodeValue; - element.removeAttribute("xml:lang"); - } - // remove all extraneous xml and xmlns attributes - for (var x = attrs.length - 1;x >= 0;x--){ - if (attrs[x].nodeName.substr(0, 3) === "xml"){ - if (attrs[x].name.slice(0, 6) === 'xmlns:'){ - var uri = attrs[x].nodeValue;// alert('base for namespac attr:'+this.base); - if (this.base) uri = uriJoin(uri, this.base); - this.store.setPrefixForURI(attrs[x].name.slice(6), uri); - } - // alert('rdfparser: xml atribute: '+attrs[x].name) //@@ - element.removeAttributeNode(attrs[x]); - } - } - return frame; - }; -}; - - -// taken from rdflib/uri.coffee -var uriJoin = function(given, base) { - var baseColon, baseHash, baseScheme, baseSingle, colon, lastSlash, path; - baseHash = base.indexOf('#'); - if (baseHash > 0) { - base = base.slice(0, baseHash); - } - if (given.length === 0) { - return base; - } - if (given.indexOf('#') === 0) { - return base + given; - } - colon = given.indexOf(':'); - if (colon >= 0) { - return given; - } - baseColon = base.indexOf(':'); - if (base.length === 0) { - return given; - } - if (baseColon < 0) { - alert("Invalid base: " + base + " in join with given: " + given); - return given; - } - baseScheme = base.slice(0, +baseColon + 1 || 9e9); - if (given.indexOf('//') === 0) { - return baseScheme + given; - } - if (base.indexOf('//', baseColon) === baseColon + 1) { - baseSingle = base.indexOf('/', baseColon + 3); - if (baseSingle < 0) { - if (base.length - baseColon - 3 > 0) { - return base + '/' + given; - } else { - return baseScheme + given; - } - } - } else { - baseSingle = base.indexOf('/', baseColon + 1); - if (baseSingle < 0) { - if (base.length - baseColon - 1 > 0) { - return base + '/' + given; - } else { - return baseScheme + given; - } - } - } - if (given.indexOf('/') === 0) { - return base.slice(0, baseSingle) + given; - } - path = base.slice(baseSingle); - lastSlash = path.lastIndexOf('/'); - if (lastSlash < 0) { - return baseScheme + given; - } - if (lastSlash >= 0 && lastSlash < path.length - 1) { - path = path.slice(0, +lastSlash + 1 || 9e9); - } - path += given; - while (path.match(/[^\/]*\/\.\.\//)) { - path = path.replace(/[^\/]*\/\.\.\//, ''); - } - path = path.replace(/\.\//g, ''); - path = path.replace(/\/\.$/, '/'); - return base.slice(0, baseSingle) + path; -}; - - -// RDF-Interface API -var RdfXmlParser = function (rdf) { - this.process = function (toparse, callback, base, filter, done) { - if (typeof toparse === 'string') { - toparse = rdf.parseXml(toparse); - } - - base = base || ''; - filter = filter || function() { return true; }; - - // convert an array of DOM nodes to a XML string - var domNodesToString = function (nodes) { - var xmlString = ''; - - for(var i=0; i= 200 && statusCode < 300); - }; - - var buildMatch = function (subject, predicate, object) { - var match = ''; - - var nodeToNT = function (node) { - if (typeof node === 'string') { - if (node.substr(0, 2) === '_:') { - return node; - } else { - return '<' + node + '>'; - } - } - - return node.toNT(); - }; - - match += subject ? nodeToNT(subject) : '?s'; - match += predicate ? ' ' + nodeToNT(predicate) : ' ?p'; - match += object ? ' ' + nodeToNT(object) : ' ?o'; - - return match; - }; - - self.graph = function (graphIri, callback) { - self.match(graphIri, null, null, null, callback); - }; - - self.match = function (graphIri, subject, predicate, object, callback, limit) { - var - filter = buildMatch(subject, predicate, object), - query = 'CONSTRUCT { ' + filter + ' } { GRAPH <' + graphIri + '> {' + filter + ' }}', - url = self.endpointUrl + '?query=' + encodeURIComponent(query); - - self.request('GET', url, { 'Accept': self.mimeType }, null, - function (statusCode, headers, resContent, error) { - // error during request - if (error) { - return callback(null, 'request error: ' + error); - } - - // http status code != success - if (!httpSuccess(statusCode)) { - return callback(null, 'status code error: ' + statusCode); - } - - // TODO: use limit parameters - self.parse(resContent, callback); - } - ); - }; - - var updateRequest = function (content, callbackValue, callback) { - self.request('POST', self.updateUrl, { 'Content-Type': 'application/sparql-update' }, content, - function (statusCode, headers, resContent, error) { - // error during request - if (error) { - return callback(null, 'request error: ' + error); - } - - // http status code != success - if (!httpSuccess(statusCode)) { - return callback(null, 'status code error: ' + statusCode); - } - - callback(callbackValue); - } - ); - }; - - self.add = function (graphIri, graph, callback) { - var content = - 'DROP SILENT GRAPH <' + graphIri + '>;' + - 'INSERT DATA { GRAPH <' + graphIri + '> { ' + self.serialize(graph) + ' } }'; - - updateRequest(content, graph, callback); - }; - - self.merge = function (graphIri, graph, callback) { - var content = - 'INSERT DATA { GRAPH <' + graphIri + '> { ' + self.serialize(graph) + ' } }'; - - updateRequest(content, graph, callback); - }; - - self.remove = function (graphIri, graph, callback) { - var content = - 'DELETE DATA FROM <' + graphIri + '> { ' + self.serialize(graph) + ' }'; - - updateRequest(content, true, callback); - }; - - self.removeMatches = function (graphIri, subject, predicate, object, callback) { - var content = - 'DELETE FROM GRAPH <' + graphIri + '> WHERE { ' + - buildMatch(subject, predicate, object) + ' }'; - - updateRequest(content, true, callback); - }; - - self.delete = function (graphIri, callback) { - var content = 'CLEAR GRAPH <' + graphIri + '>'; - - updateRequest(content, true, callback); - }; -}; - - -module.exports = function (rdf) { - rdf.SparqlStore = SparqlStore.bind(null, rdf); -}; - -},{}],12:[function(require,module,exports){ -'use strict'; - - -var - N3 = require('n3'); - - -var TurtleParser = function (rdf, options) { - options = options || {}; - - options.importPrefixMap = options.importPrefixMap || true; - - this.process = function (data, callback, base, filter, done) { - var config = {}; - - config.documentIRI = base; - filter = filter || function () { return true; }; - done = done || function () {}; - - var - parser = N3.Parser(config), - blankNodes = {}; - - parser.parse(data, function (error, n3Triple, n3Prefixes) { - if (error) { - return done(false, error); - } - - if (options.importPrefixMap && n3Prefixes) { - Object.keys(n3Prefixes).forEach(function (prefix) { - rdf.prefixes[prefix] = n3Prefixes[prefix]; - }); - } - - if (!n3Triple) { - return done(true); - } - - var toRdfNode = function (n3Node) { - if (N3.Util.isIRI(n3Node)) { - return rdf.createNamedNode(n3Node); - } else if (N3.Util.isBlank(n3Node)) { - if (n3Node in blankNodes) { - return blankNodes[n3Node]; - } else { - return (blankNodes[n3Node] = rdf.createBlankNode()); - } - } else { - var - lang = N3.Util.getLiteralLanguage(n3Node), - type = N3.Util.getLiteralType(n3Node); - - if (lang === '') { - lang = null; - } - - if (type === 'http://www.w3.org/2001/XMLSchema#string') { - type = null; - } - - return rdf.createLiteral( - N3.Util.getLiteralValue(n3Node), - lang, - type ? rdf.createNamedNode(type) : null); - } - }; - - var pushTriple = function (n3Triple) { - var triple = rdf.createTriple( - toRdfNode(n3Triple.subject), - toRdfNode(n3Triple.predicate), - toRdfNode(n3Triple.object)); - - if (filter(triple)) { - callback(triple); - } - }; - - pushTriple(n3Triple); - }); - - return true; - }; - - this.parse = function (data, callback, base, filter, graph) { - graph = graph || rdf.createGraph(); - - return this.process( - data, - function (triple) { graph.add(triple); }, - base, - filter, - function (success, error) { callback(success ? graph : null, error); }); - }; -}; - - -module.exports = function (rdf) { - rdf.TurtleParser = TurtleParser.bind(null, rdf); - rdf.NTriplesParser = TurtleParser.bind(null, rdf); - - var parser = new TurtleParser(rdf); - rdf.parseTurtle = parser.parse.bind(parser); - rdf.parseNTriples = parser.parse.bind(parser); -}; - -},{"n3":47}],13:[function(require,module,exports){ -'use strict'; - - -var - N3 = require('n3'); - - -var TurtleSerializer = function (rdf, options) { - options = options || {}; - - options.usePrefixMap = options.usePrefixMap || true; - - this.serialize = function (graph, callback) { - var - writerOptions = {}, - writer; - - callback = callback || function () {}; - - if (options.usePrefixMap) { - writerOptions.prefixes = {}; - - Object.keys(rdf.prefixes).forEach(function (prefix) { - if (typeof rdf.prefixes[prefix] !== 'string') { - return; - } - - writerOptions.prefixes[prefix] = rdf.prefixes[prefix]; - }); - } - - writer = N3.Writer(writerOptions); - - var createN3Node = function (node) { - if (node.interfaceName.toString() === 'NamedNode') { - return node.nominalValue; - } else if (node.interfaceName.toString() === 'BlankNode') { - return '_:' + node.nominalValue; - } else { - if (node.datatype) { - return '"' + node.nominalValue + '"^^' + node.datatype.nominalValue; - } else if (node.language) { - return '"' + node.nominalValue + '"@' + node.language; - } else { - return '"' + node.nominalValue + '"'; - } - } - }; - - graph.forEach(function (triple) { - writer.addTriple( - createN3Node(triple.subject), - createN3Node(triple.predicate), - createN3Node(triple.object)); - }); - - writer.end(function (error, result) { - if (error) { - callback(null, error); - } else { - callback(result); - } - }); - - return true; - }; -}; - - -module.exports = function (rdf) { - rdf.TurtleSerializer = TurtleSerializer.bind(null, rdf); - - var serializer = new TurtleSerializer(rdf); - rdf.serializeTurtle = serializer.serialize.bind(serializer); -}; - -},{"n3":47}],14:[function(require,module,exports){ -/* global rdf:true */ -'use strict'; - - -var URIResolver = function() {}; - -URIResolver.SCHEME = /^[A-Za-z][A-Za-z0-9\+\-\.]*\:/; - -URIResolver.prototype.parseURI = function(uri) { - var match = URIResolver.SCHEME.exec(uri); - if (!match) { - throw "Bad URI value, no scheme: "+uri; - } - var parsed = { spec: uri }; - parsed.scheme = match[0].substring(0,match[0].length-1); - parsed.schemeSpecificPart = parsed.spec.substring(match[0].length); - if (parsed.schemeSpecificPart.charAt(0)=='/' && parsed.schemeSpecificPart.charAt(1)=='/') { - this.parseGeneric(parsed); - } else { - parsed.isGeneric = false; - } - parsed.normalize = function() { - if (!this.isGeneric) { - return; - } - if (this.segments.length==0) { - return; - } - // edge case of ending in "/." - if (this.path.length>1 && this.path.substring(this.path.length-2)=="/.") { - this.path = this.path.substring(0,this.path.length-1); - this.segments.splice(this.segments.length-1,1); - this.schemeSpecificPart = "//"+this.authority+this.path; - if (typeof this.query != "undefined") { - this.schemeSpecificPart += "?" + this.query; - } - if (typeof this.fragment != "undefined") { - this.schemeSpecificPart += "#" + this.fragment; - } - this.spec = this.scheme+":"+this.schemeSpecificPart; - return; - } - var end = this.path.charAt(this.path.length-1); - if (end!="/") { - end = ""; - } - for (var i=0; i0 && this.segments[i]=="..") { - this.segments.splice(i-1,2); - i -= 2; - } - if (this.segments[i]==".") { - this.segments.splice(i,1); - i--; - } - } - this.path = this.segments.length==0 ? "/" : "/"+this.segments.join("/")+end; - this.schemeSpecificPart = "//"+this.authority+this.path; - if (typeof this.query != "undefined") { - this.schemeSpecificPart += "?" + this.query; - } - if (typeof this.fragment != "undefined") { - this.schemeSpecificPart += "#" + this.fragment; - } - this.spec = this.scheme+":"+this.schemeSpecificPart; - } - parsed.resolve = function(href) { - if (!href) { - return this.spec; - } - if (href.charAt(0)=='#') { - var lastHash = this.spec.lastIndexOf('#'); - return lastHash<0 ? this.spec+href : this.spec.substring(0,lastHash)+href; - } - if (!this.isGeneric) { - throw "Cannot resolve uri against non-generic URI: "+this.spec; - } - var colon = href.indexOf(':'); - if (href.charAt(0)=='/') { - return this.scheme+"://"+this.authority+href; - } else if (href.charAt(0)=='.' && href.charAt(1)=='/') { - if (this.path.charAt(this.path.length-1)=='/') { - return this.scheme+"://"+this.authority+this.path+href.substring(2); - } else { - var last = this.path.lastIndexOf('/'); - return this.scheme+"://"+this.authority+this.path.substring(0,last)+href.substring(1); - } - } else if (URIResolver.SCHEME.test(href)) { - return href; - } else if (href.charAt(0)=="?") { - return this.scheme+"://"+this.authority+this.path+href; - } else { - if (this.path.charAt(this.path.length-1)=='/') { - return this.scheme+"://"+this.authority+this.path+href; - } else { - var last = this.path.lastIndexOf('/'); - return this.scheme+"://"+this.authority+this.path.substring(0,last+1)+href; - } - } - }; - parsed.relativeTo = function(otherURI) { - if (otherURI.scheme!=this.scheme) { - return this.spec; - } - if (!this.isGeneric) { - throw "A non generic URI cannot be made relative: "+this.spec; - } - if (!otherURI.isGeneric) { - throw "Cannot make a relative URI against a non-generic URI: "+otherURI.spec; - } - if (otherURI.authority!=this.authority) { - return this.spec; - } - var i=0; - for (; i=0) { - parsed.fragment = parsed.path.substring(hash+1); - parsed.path = parsed.path.substring(0,hash); - } - var questionMark = parsed.path.indexOf('?'); - if (questionMark>=0) { - parsed.query = parsed.path.substring(questionMark+1); - parsed.path = parsed.path.substring(0,questionMark); - } - if (parsed.path=="/" || parsed.path=="") { - parsed.segments = []; - } else { - parsed.segments = parsed.path.split(/\//); - if (parsed.segments.length>0 && parsed.segments[0]=='' && parsed.path.length>1 && parsed.path.charAt(1)!='/') { - // empty segment at the start, remove it - parsed.segments.shift(); - } - if (parsed.segments.length>0 && parsed.path.length>0 && parsed.path.charAt(parsed.path.length-1)=='/' && parsed.segments[parsed.segments.length-1]=='') { - // we may have an empty the end - // check to see if it is legimate - if (parsed.path.length>1 && parsed.path.charAt(parsed.path.length-2)!='/') { - parsed.segments.pop(); - } - } - // check for non-escaped characters - for (var i=0; i0) { - throw "Unecaped character "+check[j].charAt(0)+" ("+check[j].charCodeAt(0)+") in URI "+parsed.spec; - } - } - } - } - parsed.isGeneric = true; -}; - - -module.exports = URIResolver; - -},{}],15:[function(require,module,exports){ -/* global DOMParser, XMLHttpRequest */ -'use strict'; - - -var utils = {}; - - -utils.defaultRequest = function (method, requestUrl, headers, content, callback) { - var xhr = new XMLHttpRequest(); - - xhr.onreadystatechange = function () { - if (xhr.readyState === xhr.DONE) { - var - headerLines = xhr.getAllResponseHeaders().split('\r\n'), - resHeaders = {}; - - for (var i = 0; i < headerLines.length; i++) { - var headerLine = headerLines[i].split(': ', 2); - resHeaders[headerLine[0].toLowerCase()] = headerLine[1]; - } - - callback(xhr.status, resHeaders, xhr.responseText); - } - }; - - xhr.open(method, requestUrl, true); - - for (var header in headers) { - xhr.setRequestHeader(header, headers[header]); - } - - xhr.send(content); -}; - -utils.corsProxyRequest = function (proxyUrl, method, requestUrl, headers, content, callback) { - var url = proxyUrl + '?url=' + encodeURIComponent(requestUrl); - - utils.defaultRequest(method, url, headers, content, callback); -}; - -utils.parseHtml = function (toparse, base) { - var parser = new DOMParser(); - - return parser.parseFromString(toparse, 'text/html'); -}; - -utils.parseXml = function (toparse, base) { - var parser = new DOMParser(); - - return parser.parseFromString(toparse, 'application/xml'); -}; - -utils.mixin = function (rdf) { - rdf.defaultRequest = utils.defaultRequest; - rdf.corsProxyRequest = utils.corsProxyRequest; - rdf.parseHtml = utils.parseHtml; - rdf.parseXml = utils.parseXml; -}; - - -module.exports = utils.mixin; - -},{}],16:[function(require,module,exports){ -'use strict'; - - -var utils = {}; - - -/* - * generic filters - */ -utils.filter = {}; - -utils.filter.namedNode = function (node) { - return node.interfaceName === 'NamedNode'; -}; - -utils.filter.blankNode = function (node) { - return node.interfaceName === 'BlankNode'; -}; - -utils.filter.literal = function (node) { - return node.interfaceName === 'Literal'; -}; - -utils.filter.namedNodeSubject = function (subject) { - return function (triple) { - return triple.subject.interfaceName !== 'NamedNode' || triple.subject.equals(subject); - }; -}; - - -/* - * list triple parts - */ -utils.list = {}; - -utils.list.tripleParts = function (graph, part, filter) { - var nodes = {}; - - filter = filter || function () { return true; }; - - graph.forEach(function (triple) { - nodes[triple[part].toNT()] = triple[part]; - }); - - nodes = Object.keys(nodes) - .map(function (key) { - return nodes[key]; - }) - .filter(function (node) { - return filter(node); - }); - - return nodes; -}; - -utils.list.subjects = function (graph, filter) { - return utils.list.tripleParts(graph, 'subject', filter); -}; - -utils.list.predicates = function (graph, filter) { - return utils.list.tripleParts(graph, 'predicate', filter); -}; - -utils.list.objects = function (graph, filter) { - return utils.list.tripleParts(graph, 'object', filter); -}; - - -/* - * Creates a subgraph by traversing a graph with filter support - */ -utils.createSubGraph = function (rdf, graph, entry, filter) { - var - processedEntries = {}, - subGraph = rdf.createGraph(); - - var processSubject = function (entries) { - if (entries.length === 0) { - return; - } - - var - newEntries = [], - matches = rdf.createGraph(); - - entries.forEach(function (entry) { - matches.addAll(graph.match(entry)); - }); - - if (filter) { - matches = matches.filter(filter); - } - - matches.forEach(function (match) { - var key = match.object.toNT(); - - if (!(key in processedEntries)) { - newEntries.push(match.object); - processedEntries[key] = true; - } - }); - - subGraph.addAll(matches); - - processSubject(newEntries); - }; - - processSubject([entry]); - - return subGraph; -}; - - -/* - * Create a subgraph based on a named node subject without crossing named node borders - */ -utils.createSubGraphByNamedNodeSubject = function (rdf, graph, subject) { - return rdf.utils.createSubGraph(graph, subject, utils.filter.namedNodeSubject(subject)); -}; - -/* - * Fills a store based on createSubGraphByNamedNodeSubject for all named node subjects - */ -utils.splitGraphByNamedNodeSubject = function (rdf, graph, store) { - store = store || new rdf.promise.Store(rdf.createStore()); - - var adds = []; - - utils.list.subjects(graph, utils.filter.namedNode).forEach(function (subject) { - adds.push(store.add(subject, utils.createSubGraphByNamedNodeSubject(rdf, graph, subject))); - }); - - return Promise.all(adds).then(function () { - return store; - }); -}; - - -/* - * namespace mapping - */ -utils.mapNamespaceNode = function (rdf, node, search, replace) { - // process only named nodes... - if (node.interfaceName !== 'NamedNode') { - return node; - } - - // ...that start with search - if (node.nominalValue.toString().indexOf(search) !== 0) { - return node; - } - - // create new named node with replace + original node without search - return rdf.createNamedNode(replace + node.nominalValue.toString().substr(search.length)); -}; - -utils.mapNamespaceTriple = function (rdf, triple, search, replace) { - return rdf.createTriple( - utils.mapNamespaceNode(rdf, triple.subject, search, replace), - utils.mapNamespaceNode(rdf, triple.predicate, search, replace), - utils.mapNamespaceNode(rdf, triple.object, search, replace) - ); -}; - -utils.mapNamespaceGraph = function (rdf, graph, search, replace) { - var mappedGraph = rdf.createGraph(); - - graph.forEach(function (triple) { - mappedGraph.add(utils.mapNamespaceTriple(rdf, triple, search, replace)); - }); - - return mappedGraph; -}; - - -utils.mixin = function (rdf) { - rdf.utils = {}; - rdf.utils.filter = utils.filter; - rdf.utils.list = utils.list; - rdf.utils.createSubGraph = utils.createSubGraph.bind(null, rdf); - rdf.utils.createSubGraphByNamedNodeSubject = utils.createSubGraphByNamedNodeSubject.bind(null, rdf); - rdf.utils.splitGraphByNamedNodeSubject = utils.splitGraphByNamedNodeSubject.bind(null, rdf); - rdf.utils.mapNamespaceNode = utils.mapNamespaceNode.bind(null, rdf); - rdf.utils.mapNamespaceTriple = utils.mapNamespaceTriple.bind(null, rdf); - rdf.utils.mapNamespaceGraph = utils.mapNamespaceGraph.bind(null, rdf); -}; - - -module.exports = utils.mixin; - -},{}],17:[function(require,module,exports){ - -},{}],18:[function(require,module,exports){ -arguments[4][17][0].apply(exports,arguments) -},{"dup":17}],19:[function(require,module,exports){ -/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - -var base64 = require('base64-js') -var ieee754 = require('ieee754') -var isArray = require('is-array') - -exports.Buffer = Buffer -exports.SlowBuffer = SlowBuffer -exports.INSPECT_MAX_BYTES = 50 -Buffer.poolSize = 8192 // not used by this implementation - -var kMaxLength = 0x3fffffff -var rootParent = {} - -/** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Note: - * - * - Implementation must support adding new properties to `Uint8Array` instances. - * Firefox 4-29 lacked support, fixed in Firefox 30+. - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - * - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will - * get the Object implementation, which is slower but will work correctly. - */ -Buffer.TYPED_ARRAY_SUPPORT = (function () { - try { - var buf = new ArrayBuffer(0) - var arr = new Uint8Array(buf) - arr.foo = function () { return 42 } - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` - } catch (e) { - return false - } -})() - -/** - * Class: Buffer - * ============= - * - * The Buffer constructor returns instances of `Uint8Array` that are augmented - * with function properties for all the node `Buffer` API functions. We use - * `Uint8Array` so that square bracket notation works as expected -- it returns - * a single octet. - * - * By augmenting the instances, we can avoid modifying the `Uint8Array` - * prototype. - */ -function Buffer (subject, encoding) { - var self = this - if (!(self instanceof Buffer)) return new Buffer(subject, encoding) - - var type = typeof subject - var length - - if (type === 'number') { - length = +subject - } else if (type === 'string') { - length = Buffer.byteLength(subject, encoding) - } else if (type === 'object' && subject !== null) { - // assume object is array-like - if (subject.type === 'Buffer' && isArray(subject.data)) subject = subject.data - length = +subject.length - } else { - throw new TypeError('must start with number, buffer, array or string') - } - - if (length > kMaxLength) { - throw new RangeError('Attempt to allocate Buffer larger than maximum size: 0x' + - kMaxLength.toString(16) + ' bytes') - } - - if (length < 0) length = 0 - else length >>>= 0 // coerce to uint32 - - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Preferred: Return an augmented `Uint8Array` instance for best performance - self = Buffer._augment(new Uint8Array(length)) // eslint-disable-line consistent-this - } else { - // Fallback: Return THIS instance of Buffer (created by `new`) - self.length = length - self._isBuffer = true - } - - var i - if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') { - // Speed optimization -- use set if we're copying from a typed array - self._set(subject) - } else if (isArrayish(subject)) { - /