| 1 |
// Bedework x-property functions |
|---|
| 2 |
|
|---|
| 3 |
/* ********************************************************************** |
|---|
| 4 |
Copyright 2007 Rensselaer Polytechnic Institute. All worldwide rights reserved. |
|---|
| 5 |
|
|---|
| 6 |
Redistribution and use of this distribution in source and binary forms, |
|---|
| 7 |
with or without modification, are permitted provided that: |
|---|
| 8 |
The above copyright notice and this permission notice appear in all |
|---|
| 9 |
copies and supporting documentation; |
|---|
| 10 |
|
|---|
| 11 |
The name, identifiers, and trademarks of Rensselaer Polytechnic |
|---|
| 12 |
Institute are not used in advertising or publicity without the |
|---|
| 13 |
express prior written permission of Rensselaer Polytechnic Institute; |
|---|
| 14 |
|
|---|
| 15 |
DISCLAIMER: The software is distributed" AS IS" without any express or |
|---|
| 16 |
implied warranty, including but not limited to, any implied warranties |
|---|
| 17 |
of merchantability or fitness for a particular purpose or any warrant)' |
|---|
| 18 |
of non-infringement of any current or pending patent rights. The authors |
|---|
| 19 |
of the software make no representations about the suitability of this |
|---|
| 20 |
software for any particular purpose. The entire risk as to the quality |
|---|
| 21 |
and performance of the software is with the user. Should the software |
|---|
| 22 |
prove defective, the user assumes the cost of all necessary servicing, |
|---|
| 23 |
repair or correction. In particular, neither Rensselaer Polytechnic |
|---|
| 24 |
Institute, nor the authors of the software are liable for any indirect, |
|---|
| 25 |
special, consequential, or incidental damages related to the software, |
|---|
| 26 |
to the maximum extent the law permits. */ |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
// ======================================================================== |
|---|
| 30 |
// Bedework specific x-properties |
|---|
| 31 |
// ======================================================================== |
|---|
| 32 |
|
|---|
| 33 |
var bwXPropertyImage = "X-BEDEWORK-IMAGE"; |
|---|
| 34 |
var bwXPropertySubmittedBy = "X-BEDEWORK-SUBMITTEDBY"; |
|---|
| 35 |
var bwXPropertyLocation = "X-BEDEWORK-LOCATION"; |
|---|
| 36 |
var bwXPropertyContact = "X-BEDEWORK-CONTACT"; |
|---|
| 37 |
var bwXPropertyCategories = "X-BEDEWORK-CATEGORIES"; |
|---|
| 38 |
var bwXPropertySubmitComment = "X-BEDEWORK-SUBMIT-COMMENT"; |
|---|
| 39 |
|
|---|
| 40 |
var bwXParamDescription = "X-BEDEWORK-PARAM-DESCRIPTION"; |
|---|
| 41 |
var bwXParamWidth = "X-BEDEWORK-PARAM-WIDTH"; |
|---|
| 42 |
var bwXParamHeight = "X-BEDEWORK-PARAM-HEIGHT"; |
|---|
| 43 |
var bwXParamSubAddress = "X-BEDEWORK-PARAM-SUBADDRESS"; |
|---|
| 44 |
var bwXParamURL = "X-BEDEWORK-PARAM-URL"; |
|---|
| 45 |
var bwXParamPhone = "X-BEDEWORK-PARAM-PHONE"; |
|---|
| 46 |
var bwXParamEmail = "X-BEDEWORK-PARAM-EMAIL"; |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
// ======================================================================== |
|---|
| 50 |
// x-property functions |
|---|
| 51 |
// ======================================================================== |
|---|
| 52 |
|
|---|
| 53 |
var bwXProps = new BwXProperties(); |
|---|
| 54 |
|
|---|
| 55 |
/* An xproperty |
|---|
| 56 |
* name: String - name of x-property, e.g. "X-BEDEWORK-IMAGE" |
|---|
| 57 |
* params: 2-D Array of parameter name/value pairs, |
|---|
| 58 |
* e.g. params[0] = ["X-BEDEWORK-PARAM-DESCRIPTION","a lovely image"] |
|---|
| 59 |
* value: String - value of x-property |
|---|
| 60 |
*/ |
|---|
| 61 |
function BwXProperty(name, params, value) { |
|---|
| 62 |
this.name = name; |
|---|
| 63 |
this.params = params; |
|---|
| 64 |
this.value = value; |
|---|
| 65 |
|
|---|
| 66 |
this.format = function() { |
|---|
| 67 |
var curXparams = ""; |
|---|
| 68 |
if (this.params.length) { |
|---|
| 69 |
for (var i = 0; i < this.params.length; i++) { |
|---|
| 70 |
if (this.params[i][1] != "") { |
|---|
| 71 |
curXparams += ";" + this.params[i][0]; |
|---|
| 72 |
// if parameter values contain ";" or ":" or "," they must be quoted |
|---|
| 73 |
if (this.params[i][1].indexOf(":") != -1 || this.params[i][1].indexOf(";") != -1 || this.params[i][1].indexOf(",") != -1) { |
|---|
| 74 |
curXparams += "=\"" + this.params[i][1] + "\""; |
|---|
| 75 |
} else { |
|---|
| 76 |
curXparams += "=" + this.params[i][1]; |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
return this.name + curXparams + ":" + this.value; |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
function BwXProperties() { |
|---|
| 86 |
var xproperties = new Array(); |
|---|
| 87 |
|
|---|
| 88 |
this.init = function(name, params, value) { |
|---|
| 89 |
var xprop = new BwXProperty(name, params, value); |
|---|
| 90 |
xproperties.push(xprop); |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
this.update = function(name, params, value, isUnique) { |
|---|
| 94 |
// strip out any double quotes in the parameter values: |
|---|
| 95 |
if (params.length) { |
|---|
| 96 |
for (var i = 0; i < params.length; i++) { |
|---|
| 97 |
var strippedParamValue = ""; |
|---|
| 98 |
for (var j = 0; j < params[i][1].length; j++) { |
|---|
| 99 |
var c = params[i][1][j]; |
|---|
| 100 |
if (c != '"') { |
|---|
| 101 |
strippedParamValue += c; |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
params[i][1] = strippedParamValue; |
|---|
| 105 |
} |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
// add or update the xproperty: |
|---|
| 109 |
var xprop = new BwXProperty(name, params, value); |
|---|
| 110 |
if (isUnique) { |
|---|
| 111 |
index = this.getIndex(name); |
|---|
| 112 |
if (index < 0) { |
|---|
| 113 |
xproperties.push(xprop); |
|---|
| 114 |
} else { |
|---|
| 115 |
xproperties.splice(index,1,xprop); |
|---|
| 116 |
} |
|---|
| 117 |
} else { |
|---|
| 118 |
xproperties.push(xprop); |
|---|
| 119 |
} |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
this.getIndex = function(name) { |
|---|
| 123 |
for (var i = 0; i < xproperties.length; i++) { |
|---|
| 124 |
var curXprop = xproperties[i]; |
|---|
| 125 |
if (curXprop.name == name) { |
|---|
| 126 |
return i; |
|---|
| 127 |
} |
|---|
| 128 |
} |
|---|
| 129 |
return -1; |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
this.generate = function(formObj) { |
|---|
| 134 |
for (var i = 0; i < xproperties.length; i++) { |
|---|
| 135 |
var xpropField = formObj.appendChild(document.createElement("input")); |
|---|
| 136 |
xpropField.type = "hidden"; |
|---|
| 137 |
xpropField.name = "xproperty"; |
|---|
| 138 |
xpropField.value = xproperties[i].format(); |
|---|
| 139 |
// alert(xproperties[i].format()); |
|---|
| 140 |
} |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
} |
|---|