| 37 | |
| 38 | ---- |
| 39 | |
| 40 | '''The Overall Control-Flow''' |
| 41 | |
| 42 | [[Image(http://trac.dojotoolkit.org/raw-attachment/ticket/12924/data-handlers-flow.png)]] |
| 43 | |
| 44 | |
| 45 | 1. !ViewController accesses !FileTypeMap to get a content type (e.g. "html" or "json") by a file name suffix. |
| 46 | 2. !ViewController creates a !DataSource with the url property. |
| 47 | 3. !ViewController creates !DataHandler with the created !DataSource. |
| 48 | 4. !ViewController calls !DataHandler.processData() with the content type. |
| 49 | 5. !DataHandler accesses !ContentTypeMap to get a !ContentHandler class name by the given content type. |
| 50 | 6. !DataHandler calls !DataSource.getData(). |
| 51 | 7. !DataSource gets external content. |
| 52 | 8. !DataHandler creates the !ContentHandler class. |
| 53 | 9. !DataHandler calls !ContentHandler.parse() to parse the content. |
| 54 | 10. !ContentHandler.parse() parses the content. |
| 55 | 11. !ContentHandler.parse() creates a new view. |
| 56 | 12. !DataHandler calls a callback that is defined in !ViewController. |
| 57 | 13. The callback makes a view transition to the new view. |
| 58 | |
| 59 | |
| 60 | '''How to replace !DataHandler''' |
| 61 | |
| 62 | |
| 63 | |
| 64 | The default !DataHandler class name is "dojox/mobile/dh/!DataHandler", which is defined as the dataHandlerClass property in !ViewController. It can be overridden by adding the dataHandlerClass property to transitionOptions. Below is an example of specifying your own !DataHandler in !ListItem. |
| 65 | |
| 66 | {{{ |
| 67 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.html", |
| 68 | transitionOptions:{dataHandlerClass:"com/acme/MyDataHandler"}'> |
| 69 | External View #1 |
| 70 | </li> |
| 71 | }}} |
| 72 | |
| 73 | '''How to replace !FileTypeMap''' |
| 74 | |
| 75 | The default !FileTypeMap class name is "dojox/mobile/dh/!SuffixFileTypeMap", which is defined as the fileTypeMapClass property in !ViewController. It can be overridden by adding the fileTypeMapClass property to transitionOptions. Below is an example of specifying your own !FileTypeMap in !ListItem. |
| 76 | |
| 77 | {{{ |
| 78 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.html", |
| 79 | transitionOptions:{fileTypeMapClass:"com/acme/MyFileTypeMap"}'> |
| 80 | External View #1 |
| 81 | </li> |
| 82 | }}} |
| 83 | |
| 84 | '''How to replace !DataSource''' |
| 85 | |
| 86 | The default !DataSource class name is "dojox/mobile/dh/UrlDataSource", which is defined as the dataSourceClass property in !ViewController. It can be overridden by adding the dataSourceClass property to transitionOptions. Below is an example of specifying your own !DataSource in !ListItem. |
| 87 | |
| 88 | {{{ |
| 89 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.html", |
| 90 | transitionOptions:{dataSourceClass:"com/acme/MyDataSource"}'> |
| 91 | External View #1 |
| 92 | </li> |
| 93 | }}} |
| 94 | |
| 95 | '''How to replace !ContentTypeMap''' |
| 96 | |
| 97 | Usually, !ContentTypeMap does not need to be replaced. If you have your own !DataHandler, however, you can have your own !ContentTypeMap as well, since !DataHandler has dependency on !ContentTypeMap. |
| 98 | |
| 99 | '''How to override !ContentType''' |
| 100 | |
| 101 | Usually, content type is determined by looking up the matching entry in a !ContentTypeMap. If you want to skip the look-up, and explicitly specify a particular content type, you can give the contentType property to transitionOptions. Below is an example of specifying a content type in !ListItem. |
| 102 | |
| 103 | {{{ |
| 104 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.data", |
| 105 | transitionOptions:{contentType:"data"}'> |
| 106 | External View #1 |
| 107 | </li> |
| 108 | }}} |
| 109 | |
| 110 | '''How to register !ContentType''' |
| 111 | |
| 112 | Content type is determined by a !FileTypeMap. For example, !SuffixFileTypeMap uses the file name suffix to determine content type. For !SuffixFileTypeMap, you can register "suffix to content type" entries into the map. !SuffixFileTypeMap is a singleton module. You can simply get its module return value and use the add() method to register your entries. |
| 113 | |
| 114 | {{{ |
| 115 | require([ |
| 116 | "dojox/mobile/dh/SuffixFileTypeMap", |
| 117 | "dojox/mobile/parser", |
| 118 | "dojox/mobile", |
| 119 | "dojox/mobile/compat" |
| 120 | ], function(SuffixFileTypeMap){ |
| 121 | SuffixFileTypeMap.add("acme", "data"); // regard *.acme as "data" type |
| 122 | }); |
| 123 | }}} |
| 124 | |
| 125 | If you use the old dojo.require() API, you can register entries as follows. |
| 126 | |
| 127 | {{{ |
| 128 | dojo.require("dojox/mobile/parser"); |
| 129 | dojo.require("dojox/mobile"); |
| 130 | dojo.require("dojox/mobile/compat"); |
| 131 | dojo.require("dojox/mobile/dh/SuffixFileTypeMap"); |
| 132 | |
| 133 | dojox.mobile.dh.SuffixFileTypeMap.add("acme", "data"); |
| 134 | }}} |
| 135 | |
| 136 | If a given suffix does not match any of the entries in the map, !ViewController uses "html" as the default content type. |
| 137 | |
| 138 | '''How to register !ContentHandler''' |
| 139 | |
| 140 | Which !ContentHandler to use is managed by !ContentTypeMap. In your application, you can register "content type to content handler class" entries into the map. !ContentTypeMap is a singleton module. You can simply get its module return value and use the add() method to register your entries. |
| 141 | |
| 142 | {{{ |
| 143 | require([ |
| 144 | "dojox/mobile/dh/ContentTypeMap", |
| 145 | "dojox/mobile/parser", |
| 146 | "dojox/mobile", |
| 147 | "dojox/mobile/compat" |
| 148 | ], function(ContentTypeMap){ |
| 149 | ContentTypeMap.add("html", "dojox/mobile/dh/MyHtmlContentHandler"); |
| 150 | }); |
| 151 | }}} |
| 152 | |
| 153 | If you use the old dojo.require() API, you can register entries as follows. |
| 154 | |
| 155 | {{{ |
| 156 | dojo.require("dojox/mobile/parser"); |
| 157 | dojo.require("dojox/mobile"); |
| 158 | dojo.require("dojox/mobile/compat"); |
| 159 | dojo.require("dojox/mobile/dh/ContentTypeMap"); |
| 160 | |
| 161 | dojox.mobile.dh.ContentTypeMap.add("html", "dojox/mobile/dh/MyHtmlContentHandler"); |
| 162 | }}} |