Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:api_user_docs [2010/04/03 18:59] – kd | dev:api_user_docs [2017/11/12 19:53] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Zotero | + | < |
+ | in the process of updating the documentation for | ||
+ | <a href=" | ||
+ | may be outdated in the meantime. Thanks for your understanding.</ | ||
- | This documentation is a work in progress, and at this stage you see many TODO entries in the list. There are also things I haven' | ||
- | |||
- | ===== Setting up a simplified development environment ===== | ||
- | |||
- | The two easiest ways to set up a development environment for Zotero is either with an interactive javascript environment, | ||
- | |||
- | An example of getting POW to interact with Zotero is available as a [[http:// | ||
- | |||
- | There are a number of suitable interactive javascript environments for interacting with Firefox' | ||
- | |||
- | - [[http:// | ||
- | - A Firefox plugin to provide MozRepl access [[http:// | ||
- | - The [[https:// | ||
- | |||
- | My feeling is that the easiest way to get some kind of working application up is to use the Plain old Webserver and server side javascript. | ||
- | |||
- | Setting up a Firefox development environment is beyond the scope of this | ||
- | document. | ||
- | |||
- | Perl programmers should be aware of the [[http:// | ||
- | related [[http:// | ||
- | from inside perl programs. | ||
- | |||
- | **A problem with MozREPL**: With a longer script I've had trouble with MozRepl timing out on me for no apparent reason. | ||
- | |||
- | ===== Zotero API Howtos ===== | ||
- | |||
- | The Zotero API is under-documented, | ||
- | |||
- | ==== Create new Zotero object ==== | ||
- | |||
- | This is the first thing that you need to do when interacting with zotero' | ||
- | internals. | ||
- | |||
- | <code javascript> | ||
- | var Zotero = Components.classes[" | ||
- | </ | ||
- | |||
- | ==== Setup a Zotero search ==== | ||
- | |||
- | If you are focused on data access, then the first thing you will want to do | ||
- | will be to retrieve items from your zotero. | ||
- | good start. | ||
- | |||
- | <code javascript> | ||
- | |||
- | ==== Search for items containing a specific tag ==== | ||
- | |||
- | Starting with the code from "Setup a Zotero search" | ||
- | code to retrieve items with a particular tag: | ||
- | |||
- | <code javascript> | ||
- | |||
- | ==== Zotero Collection Operations ==== | ||
- | |||
- | === Get the collection tree and display as a series of nested ordered lists === | ||
- | |||
- | This code was developed in the firefox extension Plain Old Webserver server side javascript. | ||
- | |||
- | <code javascript> | ||
- | var Zotero = Components.classes[" | ||
- | |||
- | var render_collection = function(coll) { | ||
- | if (!coll) { | ||
- | coll = null; | ||
- | } | ||
- | var collections = Zotero.getCollections(coll); | ||
- | document.writeln("< | ||
- | for (c in collections) { | ||
- | document.writeln('< | ||
- | if (collections[c].hasChildCollections) { | ||
- | var childCol = render_collection(collections[c].id); | ||
- | } | ||
- | } | ||
- | document.writeln("</ | ||
- | } | ||
- | |||
- | render_collection(); | ||
- | </ | ||
- | |||
- | === Get the items for a particular collection === | ||
- | |||
- | <code javascript> | ||
- | var Zotero = Components.classes[" | ||
- | var collectionid = pow_server.GET.id; | ||
- | var collection = z.Collections.get(collectionid); | ||
- | var items = collection.getChildItems(); | ||
- | // or you can obtain an array of itemIDs instead: | ||
- | var itemids = collection.getChildItems(true); | ||
- | </ | ||
- | |||
- | ==== Select a Zotero saved search ==== | ||
- | |||
- | TODO | ||
- | |||
- | ==== Search term operators ==== | ||
- | |||
- | TODO | ||
- | |||
- | ==== Combining search terms ==== | ||
- | |||
- | TODO | ||
- | |||
- | ==== Complete list of search operators ==== | ||
- | |||
- | TODO (should be pretty easy) | ||
- | |||
- | ==== Complete list of search fields ==== | ||
- | |||
- | TODO (with description of what the more obscure fields mean - e.g. abstractNote for | ||
- | abstract, and how do we search the fulltext archive?) | ||
- | |||
- | ==== Executing the search ==== | ||
- | |||
- | Once the search conditions have been set up, then it's time to execute the | ||
- | results: | ||
- | |||
- | <code javascript> | ||
- | |||
- | This returns the item ids in the search as an array [I could be wrong ... ]. | ||
- | The next thing to do is to get the Zotero items for the array of IDs: | ||
- | |||
- | <code javascript> | ||
- | |||
- | ==== Getting a bibliography for an array of items: ==== | ||
- | |||
- | Here we use zotero' | ||
- | specified in Zotero' | ||
- | |||
- | First we start with a list of as in the previous entry. | ||
- | |||
- | <code javascript> | ||
- | var biblio = qc.getContentFromItems(new Array(item), | ||
- | z.Prefs.get(" | ||
- | var biblio_html_format = cite.html; | ||
- | var biblio_txt | ||
- | </ | ||
- | |||
- | TODO: get citations. | ||
- | especially RTF | ||
- | |||
- | ==== Get information about an item. ==== | ||
- | |||
- | TODO: need to list all the possible fields here, and what kind of entry they | ||
- | belong to. | ||
- | |||
- | To get an item's abstract, we get the ' | ||
- | |||
- | <code javascript> | ||
- | |||
- | ==== Get fulltext for an item. ==== | ||
- | |||
- | TODO | ||
- | |||
- | ==== Get stored attachements for an item ==== | ||
- | |||
- | TODO | ||
- | |||
- | ==== Get child notes for an item ==== | ||
- | |||
- | To get the child notes for an item, we use the following code: | ||
- | |||
- | <code javascript> | ||
- | |||
- | This returns an array of notes. | ||
- | in turn we just iterate through the array: | ||
- | |||
- | <code javascript> | ||
- | for (var j=0; | ||
- | var note = z.Items.get(notes[j]); | ||
- | var note_html = note.getNote; | ||
- | } | ||
- | </ | ||
- | |||
- | ==== Get an item's related items ==== | ||
- | |||
- | This technique works for anything that can have related items attached within | ||
- | the zotero database. | ||
- | |||
- | <code javascript> | ||
- | |||
- | This returns a list of items just like in the search examples. | ||
- | |||
- | ===== Generic XUL Javascript to provide support functions ===== | ||
- | |||
- | ==== Writing out a file: ==== | ||
- | |||
- | This function will write out a file to a specified filename. | ||
- | already exists it will be silently overwritten. | ||
- | be cleaned up, talk about append mode as well, and failure if file already | ||
- | exists ...] | ||
- | |||
- | Note that Plain Old Webserver contains quite a few simplified support functions for reading, writing and deleting files, including new bits of javascript, and generally making things nice and easy. | ||
- | |||
- | |||
- | <code javascript> | ||
- | function writeFile(filename, | ||
- | var file = Components.classes[" | ||
- | var foStream = Components.classes[" | ||
- | file.initWithPath(filename); | ||
- | foStream.init(file, | ||
- | foStream.write(data, | ||
- | foStream.close(); | ||
- | }; | ||
- | |||
- | writeFile("/ | ||
- | </ | ||
- | |||
- | ==== TODO ==== | ||
- | |||
- | many other things :) | ||
+ | See [[dev/ |