Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
dev:translator_coding [2011/04/05 03:53] – adding framework ajlyondev:translator_coding [2011/04/10 17:41] – [Saving Multiple Items] ajlyon
Line 88: Line 88:
   }</code>   }</code>
  
-For compatibility with Zotero Connectors, ''Zotero.selectItems'' should preferably be called with a callback function as the second parameter. This callback function receives the object with the selected items.+For compatibility with Zotero Connectors, ''Zotero.selectItems'' should preferably be called with a callback function as the second parameter. This callback function receives the object with the selected items. FIXME We need an example of a translator that does this.
  
 === Batch Saving === === Batch Saving ===
Line 99: Line 99:
 ''Zotero.Utilities.doPost(url, postdata, callback, charset)'' sends a POST request to the specified URL (not an array), with the POST string defined in ''postdata'' and then calls function ''callback'' with two arguments: response string, and the response object. The optional ''charset'' argument forces the response to be interpreted in the specified character set. ''Zotero.Utilities.doPost(url, postdata, callback, charset)'' sends a POST request to the specified URL (not an array), with the POST string defined in ''postdata'' and then calls function ''callback'' with two arguments: response string, and the response object. The optional ''charset'' argument forces the response to be interpreted in the specified character set.
  
-(Need documentation on the xmlhttp object-- link to MDC.)+''Zotero.Utilities.processDocuments(url, callback, onDone, charset)'' sends a GET request to the specified URL or to each in an array of URLs, and then calls the function ''callback'' with XXXXX arguments: DOM document object, URL, and XXXX. FIXME the optional ''charset'' argument forces the response to be interpreted in the specified character set. This is approximately the equivalent of ''doGet'', except that it returns DOM document objects instead of strings.
  
-''Zotero.Utilities.processDocuments(url, callback, onDone, charset)''+**Note:** The response objects passed to the callbacks above are [[https://developer.mozilla.org/en/XMLHttpRequest|described in detail in the MDC Documentation]].
  
-''Zotero.Utilities.processAsync(sets, callbacks, onDone)'' can be used from translators to make it easier to correctly chain sets of asynchronous callbacks, since many translators that require multiple callbacks do it incorrectly [text from commit message, r4262]+''Zotero.Utilities.processAsync(sets, callbacks, onDone)'' can be used from translators to make it easier to correctly chain sets of asynchronous callbacks, since many translators that require multiple callbacks do it incorrectly [text from commit message, r4262] 
  
 == Synchronous == == Synchronous ==
Line 120: Line 120:
 <code javascript>var bibtexData = Zotero.Utilities.retrieveSource(this.bibtexLink);</code> <code javascript>var bibtexData = Zotero.Utilities.retrieveSource(this.bibtexLink);</code>
  
-===== Translator Framework ===== +====== Import Translators ====== 
-Many web translators can be written in a simplified form by using the [[dev/translator_framework|Translator Framework]], a library for translator developmentTranslators written in this way consist of simple sets of rules for scraping item metadata from specified portions of the page. See the [[dev/translator_framework|Translator Framework]] page for details+====== Export Translators ====== 
 +====== Search Translators ====== 
 +====== Utility functions ====== 
 +Zotero provides several utility functions for translators to useSome of them are used for asynchronous and synchronous HTTP requests; those are [[#batch_saving|discussed above]]. In addition to those HTTP functions and the many standard functions provided by JavaScript, Zotero provides: 
 +  * ''Zotero.Utilities.capitalizeTitle(title, ignorePreference)'' 
 +  * ''Zotero.Utilities.cleanAuthor(author, creatorType, hasComma)'' 
 +  * ''Zotero.Utilities.trimInternal(text)''
  
-====== The Translator Object ======+====== Working with the Translator object ====== 
 +=== Methods ===
   * ''Zotero.loadTranslator(type)''   * ''Zotero.loadTranslator(type)''
   * ''translator.setSearch(OpenURL ContextObject)''   * ''translator.setSearch(OpenURL ContextObject)''
 +For search translators. Takes a skeleton item object and ... FIXME
   * ''translator.setString(string)''   * ''translator.setString(string)''
 +For import translators. Sets the string that the translator will import from.
   * ''translator.getTranslators()''   * ''translator.getTranslators()''
 +Returns an array of translators that should be able to run on the given data. That is, those translators that return a non-false value for ''detectImport'', ''detectSearch'' or ''detectWeb'' when passed the input given with ''setString'', ''setSearch'', etc.
   * ''translator.setTranslator(translator)'' Takes translator object (returned by ''getTranslators(..)'', or the UUID of a translator.   * ''translator.setTranslator(translator)'' Takes translator object (returned by ''getTranslators(..)'', or the UUID of a translator.
   * ''translator.setHandler(event, callback)''   * ''translator.setHandler(event, callback)''
Line 151: Line 161:
 search.translate(); search.translate();
 </code> </code>
 +===== Translator Framework =====
 +Many web translators can be written in a simplified form by using the [[dev/translator_framework|Translator Framework]], a library for translator development. Translators written in this way consist of simple sets of rules for scraping item metadata from specified portions of the page. See the [[dev/translator_framework|Translator Framework]] page for details. 
dev/translator_coding.txt · Last modified: 2017/11/12 19:53 by 127.0.0.1