1 /**
  2  * The Render Engine
  3  * XMLLoader
  4  *
  5  * @fileoverview A resource loader for XML files.
  6  *
  7  * @author: Brett Fattori (brettf@renderengine.com)
  8  * @author: $Author: bfattori $
  9  * @version: $Revision: 1555 $
 10  *
 11  * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com)
 12  *
 13  * Permission is hereby granted, free of charge, to any person obtaining a copy
 14  * of this software and associated documentation files (the "Software"), to deal
 15  * in the Software without restriction, including without limitation the rights
 16  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 17  * copies of the Software, and to permit persons to whom the Software is
 18  * furnished to do so, subject to the following conditions:
 19  *
 20  * The above copyright notice and this permission notice shall be included in
 21  * all copies or substantial portions of the Software.
 22  *
 23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 28  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 29  * THE SOFTWARE.
 30  *
 31  */
 32 
 33 // The class this file defines and its required classes
 34 R.Engine.define({
 35     "class":"R.resources.loaders.XMLLoader",
 36     "requires":[
 37         "R.resources.loaders.RemoteLoader"
 38     ]
 39 });
 40 
 41 /**
 42  * @class Loads XML files from a specified URL.
 43  *
 44  * @constructor
 45  * @param name {String=XMLLoader} The name of the resource loader
 46  * @extends R.resources.loaders.RemoteLoader
 47  */
 48 R.resources.loaders.XMLLoader = function () {
 49     return R.resources.loaders.RemoteLoader.extend(/** @scope R.resources.loaders.XMLLoader.prototype */{
 50 
 51         objects:null,
 52 
 53         /** private */
 54         constructor:function (name) {
 55             this.base(name || "XMLLoader");
 56             this.objects = {};
 57         },
 58 
 59         /**
 60          * Load an XML file from a URL.
 61          *
 62          * @param name {String} The name of the resource
 63          * @param url {String} The URL where the resource is located
 64          */
 65         load:function (name, url /*, doc */) {
 66 
 67             if (!arguments[2]) {
 68                 Assert(url.indexOf("http") == -1, "XML must be located relative to this server");
 69                 var thisObj = this;
 70 
 71                 // Get the file from the server
 72                 $.get(url, function (data) {
 73                     // 2nd pass - store the XML
 74                     thisObj.load(name, url, data);
 75                 }, "xml");
 76             }
 77             else {
 78                 // The object has been loaded and is ready for use
 79                 this.setReady(name);
 80                 this.base(name, url, arguments[2]);
 81             }
 82         },
 83 
 84         /**
 85          * The name of the resource this loader will get.
 86          * @returns {String} The string "object"
 87          */
 88         getResourceType:function () {
 89             return "xml";
 90         }
 91 
 92     }, /** @scope R.resources.loaders.XMLLoader.prototype */ {
 93         /**
 94          * Get the class name of this object.
 95          * @return {String} The string "R.resources.loaders.XMLLoader"
 96          */
 97         getClassName:function () {
 98             return "R.resources.loaders.XMLLoader";
 99         }
100     });
101 
102 }
103