1 if (Garmin == undefined) var Garmin = {};
  2 /**
  3  * Copyright � 2007 Garmin Ltd. or its subsidiaries.
  4  *
  5  * Licensed under the Apache License, Version 2.0 (the 'License')
  6  * you may not use this file except in compliance with the License.
  7  * You may obtain a copy of the License at
  8  *
  9  *    http://www.apache.org/licenses/LICENSE-2.0
 10  *
 11  * Unless required by applicable law or agreed to in writing, software
 12  * distributed under the License is distributed on an 'AS IS' BASIS,
 13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  * See the License for the specific language governing permissions and
 15  * limitations under the License.
 16  * 
 17  * @fileoverview Garmin.File A data structure representing a file
 18  * 
 19  * @author Diana Chow diana.chow at garmin.com
 20  * @version 1.0
 21  */
 22 /**A data structure for storing data commonly found in file
 23  * formats supported by various gps devices.
 24  * @class Garmin.File
 25  * @constructor 
 26  */
 27 Garmin.File = function(){};
 28 Garmin.File = Class.create();
 29 Garmin.File.prototype = {
 30 	
 31 	initialize: function() {
 32 		this.attributes = new Hash();
 33 		this.id = new Garmin.FileId();
 34 	},
 35 	
 36 	getAttributes: function() {
 37 		return this.attributes;
 38 	},
 39 	
 40 	getAttribute: function(aKey) {
 41 		return this.attributes[aKey];
 42 	},
 43 	
 44 	setAttribute: function(aKey, aValue) {
 45 		this.attributes[aKey] = aValue;
 46 	},
 47 	
 48 	getId: function() {
 49 		return this.id;
 50 	},
 51 	
 52 	getIdValue: function(iKey) {
 53 		return this.id.getValue(iKey);
 54 	},
 55 	
 56 	setIdValue: function(iKey, iValue) {
 57 		this.id.setValue(iKey, iValue);
 58 	},
 59 	
 60 	setId: function(id) {
 61 	    this.id = id;
 62 	},
 63 	
 64 //	getEndTime: function() {
 65 //		return this.getSummaryValue(Garmin.File.SUMMARY_KEYS.endTime).getValue();
 66 //	},	
 67 
 68     getCreationTime: function() {
 69         return this.getAttribute(Garmin.File.ATTRIBUTE_KEYS.creationTime); 
 70     },
 71 	
 72 	getIdString: function() {
 73 		return this.getIdValue(Garmin.FileId.KEYS.id).getValue();
 74 	},
 75 	
 76 	printMe: function(tabs) {
 77 		var output = "";
 78 		output += tabs + "\n\n[File]\n";
 79 		
 80 		output += tabs + "  attributes:\n";
 81 		var attKeys = this.attributes.keys();
 82 		for (var i = 0; i < attKeys.length; i++) {
 83 			output += tabs + "    " + attKeys[i] + ": " + this.attributes[attKeys[i]] + "\n"; 
 84 		}
 85 		
 86 		output += tabs + "  id:\n";
 87 		output += this.id.printMe(tabs + "  ");
 88 
 89 		return output;
 90 	},
 91 	
 92 	toString: function() {
 93 		return "[Garmin.File]"
 94 	}
 95 };
 96 
 97 Garmin.File.ATTRIBUTE_KEYS = {
 98 	isDirectory:		"IsDirectory", // 5/7/09 this guy isn't used by the API yet
 99 	path:		        "Path",
100 	type:		        "Type",
101 	creationTime:		"CreationTime",
102 	dom:				"documentObjectModel"
103 };
104 
105 Garmin.FileId = function(){};
106 Garmin.FileId = Class.create();
107 Garmin.FileId.prototype = {
108 	
109 	initialize: function() {
110 	    this.values = new Hash();
111 	},
112 	
113 	getValue: function(key) {
114 	    return this.values[key];
115 	},
116 	
117 	setValue: function(key, value){
118 	    this.values[key] = value;
119 	},
120 	
121 	toString: function() {
122 		return "[Garmin.FileId]"
123 	}
124 };
125 
126 Garmin.FileId.KEYS = {
127 	id:                         "Id",
128 	fileType:                   "FileType",
129     manufacturer:               "Manufacturer",
130     product:                    "Product",
131     serialNumber:               "SerialNumber"
132 };
133 
134 /**
135  * Mapping of fitness file type to FIT identifier, provided by dynastream.
136  */
137 Garmin.FileId.FILE_TYPE_MAP = {
138     activities:                 "4",
139     goals:                      "11",
140     locations:                  "8",
141     monitoring:                 "9",
142     profiles:                   "2",
143     schedules:                  "7",
144     sports:                     "3",
145     totals:                     "10"
146 };