├── README.md ├── fetchAnnotations.js ├── index.html ├── postNotes.js ├── index.js └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # zotero 2 | sync hypothesis <-> zotero 3 | 4 | This tool reads your Zotero library, finds items imported by URL, looks for associated Hypothesis annotations, and syncs them to Zotero as child notes. 5 | 6 | Existing annotations added to Hypothesis will sync to Zotero. 7 | 8 | If you resync with no changes in Zotero or Hypothesis, nothing will happen. 9 | 10 | If you delete a Hypothesis-synced note from Zotero, then resync, it will reappear. 11 | 12 | If you update an annotation in Hypothesis, it won't resync to Zotero unless you delete the corresponding note in Zotero. 13 | 14 | Only top-level annotations will sync, replies are ignored. 15 | -------------------------------------------------------------------------------- /fetchAnnotations.js: -------------------------------------------------------------------------------- 1 | // this web worker fetches annotations for urls of zotero items 2 | 3 | // use hlib, not hlib2, because no web components in this environment 4 | self.importScripts('https://jonudell.info/hlib/hlib.bundle.js') 5 | 6 | // listen for a request to query hypothesis for annotations on a zotero item 7 | self.addEventListener('message', e => { 8 | const url = e.data.zoteroItem.url 9 | const key = e.data.zoteroItem.key 10 | const token = e.data.token 11 | 12 | const hypothesisQuery = `https://hypothes.is/api/search?uri=${url}` 13 | 14 | const opts = { 15 | method: 'get', 16 | url: hypothesisQuery 17 | } 18 | 19 | if (token) { 20 | opts.headers = { 21 | Authorization: 'Bearer ' + e.data.token, 22 | 'Content-Type': 'application/json;charset=utf-8' 23 | } 24 | } 25 | 26 | // find hypothesis annotations for a zotero item 27 | hlib 28 | .httpRequest(opts) 29 | .then( data => { 30 | const hypothesisInfo = JSON.parse(data.response) 31 | // message the caller with zotero item info plus hypothesis search results 32 | self.postMessage({ 33 | key: key, 34 | version: e.data.zoteroItem.version, 35 | url: e.data.zoteroItem.url, 36 | title: e.data.zoteroItem.title, 37 | doi: e.data.zoteroItem.doi, 38 | hypothesisAnnos: hypothesisInfo.rows, 39 | hypothesisTotal: hypothesisInfo.total 40 | }) 41 | }) 42 | .catch( e => { 43 | const msg = `fetchAnnotations failed: ${opts.url}, ${data.response}, ${JSON.stringify(e)}` 44 | self.postMessage(msg) 45 | }) 46 | }) 47 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 33 | 34 | 35 | 36 | 37 |
38 | 39 |

40 | Sync Hypothesis annotations to Zotero 41 |

42 | 43 |
44 |
45 |
46 | 47 |
48 | 49 |
50 |
51 |

52 | This tool reads your Zotero library, finds items imported by URL, looks for 53 | associated Hypothesis annotations, and syncs them to Zotero as child notes. 54 |

55 |

Existing annotations added to Hypothesis will sync to Zotero.

56 |

If you resync with no changes in Zotero or Hypothesis, nothing will happen.

57 |

If you delete a Hypothesis-synced note from Zotero, then resync, it will reappear.

58 |

If you update an annotation in Hypothesis, it won't resync to Zotero unless you delete the corresponding 59 | note in Zotero.

60 |

Only top-level annotations will sync, replies are ignored.

61 | 62 | 63 |
64 | 65 |
66 | 67 |
68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /postNotes.js: -------------------------------------------------------------------------------- 1 | // this web worker imports hypothesis annotations into zotero as child notes 2 | // it adds a zotero tag to each imported note like 'hypothesis-BvFJGPmpRd-7d6g7_sOpFg' 3 | 4 | // use hlib, not hlib2, because no web components in this environment 5 | self.importScripts('https://jonudell.info/hlib/hlib.bundle.js') 6 | self.importScripts('https://jonudell.info/hlib/showdown.js') 7 | 8 | // import a hypothesis annnotation as a zotero child note 9 | function importAnnotation(zoteroKey, zoteroUserId, zoteroApiKey, anno) { 10 | const converter = new Showdown.converter() 11 | const quote = anno.quote != '' ? `
${anno.quote}
` : '' 12 | const body = converter.makeHtml(anno.text) 13 | 14 | const html = ` 15 |

Hypothesis annotation by ${anno.user}

16 | ${quote} 17 | ${body}` 18 | 19 | // params for the zotero api call to create a hypothesis-derived child note 20 | const tags = [ { tag: `hypothesis-${anno.id}` } ] 21 | for (let tag of anno.tags) { 22 | tags.push({ tag: tag }) 23 | } 24 | const params = [ 25 | { 26 | parentItem: zoteroKey, 27 | itemType: 'note', 28 | note: html, 29 | tags: tags, 30 | collections: [], 31 | relations: {} 32 | } 33 | ] 34 | 35 | const zoteroApiCall = `https://www.zotero.org/api/users/${zoteroUserId}/items/` 36 | 37 | const opts = { 38 | method: 'post', 39 | url: zoteroApiCall, 40 | params: JSON.stringify(params), 41 | headers: { 42 | 'Zotero-API-Key': `${zoteroApiKey}` 43 | } 44 | } 45 | 46 | // call zotero api to import a hypothesis-derived child note 47 | return hlib.httpRequest(opts) 48 | } 49 | 50 | function delaySeconds(seconds) { 51 | return new Promise((resolve) => setTimeout(resolve, seconds * 1000)) 52 | } 53 | 54 | // listen for a request to import one or more hypothesis annotations for a zotero item 55 | self.addEventListener('message', e => { 56 | const zoteroUserId = e.data.zoteroUserId 57 | const zoteroApiKey = e.data.zoteroApiKey 58 | const zoteroKey = e.data.annotationsToImport.key 59 | const rows = e.data.annotationsToImport.hypothesisAnnos 60 | processRows(rows) 61 | 62 | async function processRows(rows) { 63 | for (let i = 0; i < rows.length; i++) { 64 | await delaySeconds(.1) 65 | const anno = hlib.parseAnnotation(rows[i]) 66 | const result = await(importAnnotation(zoteroKey, zoteroUserId, zoteroApiKey, anno)) 67 | const user = `${anno.user}`.replace('acct:', '').replace('@hypothes.is', '') 68 | self.postMessage( 69 | `imported ${anno.id} 70 | by ${user} on ${anno.url}` 71 | ) 72 | self.postMessage({ 73 | zoteroKey: zoteroKey // echo back the zotero key so caller can track progress 74 | }) 75 | } 76 | } 77 | 78 | }) -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | function logWrite(msg) { 2 | console.log(msg) 3 | hlib.getById('viewer').innerHTML = `
${msg}
` 4 | } 5 | 6 | function logAppend(msg) { 7 | console.log(msg) 8 | hlib.getById('viewer').innerHTML += `
${msg}
` 9 | } 10 | 11 | function setZoteroApiKey() { 12 | hlib.setLocalStorageFromForm('zoteroApiKeyForm', 'h_zoteroApiKey') 13 | } 14 | 15 | function getZoteroApiKey() { 16 | return localStorage.getItem('h_zoteroApiKey') 17 | } 18 | 19 | function setZoteroUserId() { 20 | hlib.setLocalStorageFromForm('zoteroUserIdForm', 'h_zoteroUserId') 21 | } 22 | 23 | function getZoteroUserId() { 24 | return localStorage.getItem('h_zoteroUserId') 25 | } 26 | 27 | // necessary because hlib now uses fetch, which does not allow access to custom headers, 28 | // and zotero returns total-results in a custom header 29 | 30 | function _httpRequest(method, url, headers) { 31 | return new Promise(function(resolve, reject) { 32 | const xhr = new XMLHttpRequest() 33 | xhr.open(method, url) 34 | for (let header of headers) { 35 | const key = Object.keys(header)[0] 36 | xhr.setRequestHeader(key, header[key]) 37 | } 38 | xhr.onload = function() { 39 | if (this.status >= 200 && this.status < 300) { 40 | resolve({ 41 | response: xhr.response, 42 | total: xhr.getResponseHeader('total-results') 43 | }) 44 | } else { 45 | reject({ 46 | status: this.status, 47 | statusText: xhr.statusText 48 | }) 49 | } 50 | } 51 | xhr.onerror = function() { 52 | reject({ 53 | url: url, 54 | status: this.status, 55 | statusText: xhr.statusText 56 | }) 57 | } 58 | xhr.send() 59 | }) 60 | } 61 | 62 | // main entry point, wired to sync button 63 | function sync() { 64 | const offset = 0 65 | collectZoteroItems(offset, [], [], processZoteroItems) 66 | } 67 | 68 | // offset: for zotero api paging 69 | // zoteroItems: accumulator for items in the zotero library 70 | // hypothesisNotes: subset of items that are notes imported from hypothesis 71 | // processZoteroItems: handler called when all items collected 72 | function collectZoteroItems(offset, zoteroItems, hypothesisNotes, processZoteroItems) { 73 | const url = `https://www.zotero.org/api/users/${getZoteroUserId()}/items?start=${offset}&limit=50` 74 | const headers = [ { 'Zotero-API-Key': `${getZoteroApiKey()}` }, { Authorization: `Bearer ${hlib.getToken()}` } ] 75 | _httpRequest('get', url, headers) 76 | .then(function(data) { 77 | const items = JSON.parse(data.response) 78 | const total = parseInt(data.total) 79 | // summarize results and accumulate them into the array zoteroItems 80 | items.forEach(item => { 81 | const result = { 82 | key: item.key, 83 | version: item.version, 84 | doi: item.data.DOI ? item.data.DOI : null, 85 | title: item.data.title, 86 | url: item.data.url, 87 | itemType: item.data.itemType, 88 | tags: item.data.tags 89 | } 90 | zoteroItems.push(result) 91 | }) 92 | logWrite(`fetched ${zoteroItems.length} of ${total} zotero items`) 93 | if (total && zoteroItems.length >= total) { 94 | logWrite('') 95 | // we have all the items in the zotero library 96 | // we need to query hypothesis for items that have urls, looking for annotations on them 97 | zoteroItems = zoteroItems.filter(x => { 98 | let r = true 99 | if (x.itemType === 'attachment') { 100 | r = false // skip attachments, which have urls but are duplicative of primary types (newspaper article, blog post, etc.) 101 | } 102 | if (!x.url && x.itemType !== 'note') { 103 | r = false // skip other items with no url, but keep notes so we can avoid duplicate imports 104 | } 105 | return r 106 | }) 107 | // collect zotero notes that represent imported hypothesis annotations 108 | // it's the subset of notes with tags prefixed like 'hypothesis-BvFJGPmpRd-7d6g7_sOpFg 109 | // and suffixed with hypothesis ids that are in zotero and won't be reimported 110 | let _hypothesisNotes = zoteroItems.filter(x => { 111 | return x.itemType === 'note' && x.tags.length > 0 && hasHypothesisTag(x) // only zotero notes with hypothesis tags 112 | }) 113 | hypothesisNotes = hypothesisNotes.concat(_hypothesisNotes) 114 | let _hypothesisNoteKeys = _hypothesisNotes.map(x => { 115 | return x.key // capture zotero keys 116 | }) 117 | zoteroItems = zoteroItems.filter(x => { 118 | return _hypothesisNoteKeys.indexOf(x.key) == -1 // exclude _hypothesisNotes 119 | }) 120 | zoteroItems = zoteroItems.filter(x => { 121 | return x.url // exclude items with no url 122 | }) 123 | processZoteroItems(hypothesisNotes, zoteroItems) 124 | } else { 125 | // continue collecting until all pages of zotero api results are processed 126 | offset += 50 127 | collectZoteroItems(offset, zoteroItems, hypothesisNotes, processZoteroItems) 128 | } 129 | }) 130 | .catch((e) => { 131 | logAppend(JSON.stringify(e)) 132 | }) 133 | } 134 | 135 | // hypothesisNotes: zoteroItems that are child notes from hypothesis 136 | // zoteroItems: zoteroItems that are not child notes from hypothesis 137 | function processZoteroItems(hypothesisNotes, zoteroItems) { 138 | logAppend(`zotero items that could be annotated: ${zoteroItems.length}`) 139 | // spawn a worker to fetch hypothesis annotations for zotero items 140 | const annotationFetcher = new Worker('fetchAnnotations.js') 141 | 142 | const annotationFetchResults = {} 143 | 144 | // listen for messages from the annotation fetcher 145 | annotationFetcher.addEventListener('message', function(e) { 146 | annotationFetchResults[e.data.key] = e.data 147 | let fetchedCount = Object.keys(annotationFetchResults).length 148 | //logWrite(`fetchWorker got response #${fetchedCount} of ${zoteroItems.length} expected`) 149 | // expect as many messages as zotero items, if fewer, the app will time out 150 | if (fetchedCount == zoteroItems.length) { 151 | //logAppend(`all ${fetchedCount} messages received from annotation fetcher, calling importer`) 152 | annotationFetcher.terminate() 153 | 154 | // get the ids of imported hypothesis notes 155 | let excludedIds = hypothesisNotes.map(x => { 156 | let id = 'NoHypothesisId' 157 | x.tags.forEach(tag => { 158 | if (isHypothesisTag(tag)) { 159 | id = getHypothesisIdFromZoteroTag(tag) 160 | } 161 | }) 162 | return id 163 | }) 164 | 165 | let resultsToImport = [] 166 | 167 | const zoteroKeys = Object.keys(annotationFetchResults) 168 | for (let i = 0; i < zoteroKeys.length; i++) { 169 | const fetchedResultForZoteroKey = annotationFetchResults[zoteroKeys[i]] 170 | if (fetchedResultForZoteroKey.hypothesisTotal == 0) { 171 | continue 172 | } 173 | let candidateAnnos = fetchedResultForZoteroKey.hypothesisAnnos 174 | // exclude replies 175 | candidateAnnos = candidateAnnos.filter(x => { 176 | return !x.references 177 | }) 178 | // filter out the excluded rows 179 | const importAnnos = candidateAnnos.filter(x => { 180 | return excludedIds.indexOf(x.id) == -1 181 | }) 182 | fetchedResultForZoteroKey.hypothesisAnnos = importAnnos 183 | if (importAnnos.length) { 184 | resultsToImport.push(fetchedResultForZoteroKey) 185 | } 186 | } 187 | logAppend(`zotero items with new annotations to import: ${resultsToImport.length}`) 188 | if (resultsToImport.length) { 189 | importer(resultsToImport) 190 | } else { 191 | logAppend('done') 192 | } 193 | } 194 | }) 195 | 196 | // message the worker once per zotero item 197 | zoteroItems.forEach(zoteroItem => { 198 | annotationFetcher.postMessage({ 199 | zoteroItem: zoteroItem, 200 | token: hlib.getToken() // hypothesis api token so worker can read private/group annotations 201 | }) 202 | }) 203 | } 204 | 205 | function getHypothesisIdFromZoteroTag(tag) { 206 | return tag['tag'].slice(11) 207 | } 208 | function isHypothesisTag(tag) { 209 | return tag['tag'].slice(0, 11) === 'hypothesis-' 210 | } 211 | 212 | function hasHypothesisTag(zoteroItem) { 213 | let hasHypothesisTag = false 214 | zoteroItem.tags.forEach(tag => { 215 | if (isHypothesisTag(tag)) { 216 | hasHypothesisTag = true 217 | } 218 | }) 219 | return hasHypothesisTag 220 | } 221 | 222 | // a web worker called with a list of objects that contain a merge of 223 | // zotero item info and hypothesis api search results 224 | function importer(resultsToImport) { 225 | const importWorker = new Worker('postNotes.js') 226 | const objectKeys = Object.keys(resultsToImport) 227 | 228 | const expectedResponses = {} 229 | 230 | objectKeys.forEach(key => { 231 | const resultToImport = resultsToImport[key] 232 | expectedResponses[resultToImport.key] = resultToImport.hypothesisAnnos.length 233 | }) 234 | 235 | importWorker.addEventListener('message', function(e) { 236 | if (e.data.zoteroKey) { 237 | expectedResponses[e.data.zoteroKey] -= 1 238 | } else { 239 | logAppend(e.data) 240 | } 241 | let done = true 242 | Object.keys(expectedResponses).forEach(zoteroKey => { 243 | if (expectedResponses[zoteroKey]) { 244 | done = false // we haven't yet received all the messages for this key 245 | } 246 | }) 247 | if (done) { 248 | logAppend('done') 249 | importWorker.terminate() 250 | } 251 | }) 252 | 253 | objectKeys.forEach(key => { 254 | // ask the worker to import annotations for a zotero item 255 | importWorker.postMessage({ 256 | zoteroUserId: getZoteroUserId(), 257 | zoteroApiKey: getZoteroApiKey(), 258 | zoteroItemKey: key, 259 | annotationsToImport: resultsToImport[key] 260 | }) 261 | }) 262 | } 263 | 264 | const tokenContainer = hlib.getById('tokenContainer') 265 | hlib.createApiTokenInputForm(tokenContainer) 266 | 267 | const userArgs = { 268 | element: hlib.getById('zoteroUserContainer'), 269 | name: 'Zotero numeric user ID', 270 | id: 'zoteroUserId', 271 | value: getZoteroUserId(), 272 | onchange: setZoteroUserId, 273 | type: '', 274 | msg: `Zotero numeric user id from 275 | https://www.zotero.org/settings/keys` 276 | } 277 | 278 | hlib.createNamedInputForm(userArgs) 279 | 280 | const apiKeyArgs = { 281 | element: hlib.getById('zoteroApiKeyContainer'), 282 | name: 'Zotero API key', 283 | id: 'zoteroApiKey', 284 | value: getZoteroApiKey(), 285 | onchange: setZoteroApiKey, 286 | type: 'password', 287 | msg: `Zotero API key from 288 | https://www.zotero.org/settings/keys` 289 | } 290 | 291 | hlib.createNamedInputForm(apiKeyArgs) 292 | 293 | const viewer = document.getElementById('viewer') 294 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------