You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2005/12/06 20:30:51 UTC
svn commit: r354516 [6/15] - in /portals/jetspeed-2/trunk:
applications/j2-admin/src/java/org/apache/jetspeed/portlets/customizer/
applications/j2-admin/src/webapp/WEB-INF/
applications/j2-admin/src/webapp/WEB-INF/view/customizer/
applications/j2-admin...
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/json.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/json.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/json.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/json.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,115 @@
+dojo.provide("dojo.json");
+dojo.require("dojo.lang");
+
+dojo.json = {
+ jsonRegistry: new dojo.AdapterRegistry(),
+
+ register: function(name, check, wrap, /*optional*/ override){
+ /***
+
+ Register a JSON serialization function. JSON serialization
+ functions should take one argument and return an object
+ suitable for JSON serialization:
+
+ - string
+ - number
+ - boolean
+ - undefined
+ - object
+ - null
+ - Array-like (length property that is a number)
+ - Objects with a "json" method will have this method called
+ - Any other object will be used as {key:value, ...} pairs
+
+ If override is given, it is used as the highest priority
+ JSON serialization, otherwise it will be used as the lowest.
+ ***/
+
+ dojo.json.jsonRegistry.register(name, check, wrap, override);
+ },
+
+ evalJSON: function(){
+ // FIXME: should this accept mozilla's optional second arg?
+ return eval("(" + arguments[0] + ")");
+ },
+
+ serialize: function(o){
+ /***
+ Create a JSON serialization of an object, note that this doesn't
+ check for infinite recursion, so don't do that!
+ ***/
+
+ var objtype = typeof(o);
+ if(objtype == "undefined"){
+ return "undefined";
+ }else if((objtype == "number")||(objtype == "boolean")){
+ return o + "";
+ }else if(o === null){
+ return "null";
+ }
+ var m = dojo.lang;
+ if(objtype == "string"){
+ return m.reprString(o);
+ }
+ // recurse
+ var me = arguments.callee;
+ // short-circuit for objects that support "json" serialization
+ // if they return "self" then just pass-through...
+ var newObj;
+ if(typeof(o.__json__) == "function"){
+ newObj = o.__json__();
+ if(o !== newObj){
+ return me(newObj);
+ }
+ }
+ if(typeof(o.json) == "function"){
+ newObj = o.json();
+ if (o !== newObj) {
+ return me(newObj);
+ }
+ }
+ // array
+ if (objtype != "function" && typeof(o.length) == "number") {
+ var res = [];
+ for (var i = 0; i < o.length; i++) {
+ var val = me(o[i]);
+ if (typeof(val) != "string") {
+ val = "undefined";
+ }
+ res.push(val);
+ }
+ return "[" + res.join(",") + "]";
+ }
+ // look in the registry
+ try {
+ newObj = dojo.json.jsonRegistry.match(o);
+ return me(newObj);
+ }catch(e){
+ dojo.debug(e);
+ }
+ // it's a function with no adapter, bad
+ if (objtype == "function") {
+ return null;
+ }
+ // generic object code path
+ res = [];
+ for (var k in o) {
+ var useKey;
+ if (typeof(k) == "number") {
+ useKey = '"' + k + '"';
+ } else if (typeof(k) == "string") {
+ useKey = m.reprString(k);
+ } else {
+ // skip non-string or number keys
+ continue;
+ }
+ val = me(o[k]);
+ if (typeof(val) != "string") {
+ // skip non-serializable values
+ continue;
+ }
+ res.push(useKey + ":" + val);
+ }
+ return "{" + res.join(",") + "}";
+ }
+};
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,592 @@
+dojo.provide("dojo.lang");
+dojo.provide("dojo.AdapterRegistry");
+dojo.provide("dojo.lang.Lang");
+
+dojo.lang.mixin = function(obj, props){
+ var tobj = [];
+ for(var x in props){
+ if(typeof tobj[x] == "undefined" || tobj[x] != props[x]) {
+ obj[x] = props[x];
+ }
+ }
+ return obj;
+}
+
+dojo.lang.extend = function(ctor, props){
+ this.mixin(ctor.prototype, props);
+}
+
+dojo.lang.extendPrototype = function(obj, props){
+ this.extend(obj.constructor, props);
+}
+
+dojo.lang.anonCtr = 0;
+dojo.lang.anon = {};
+dojo.lang.nameAnonFunc = function(anonFuncPtr, namespaceObj){
+ var nso = (namespaceObj || dojo.lang.anon);
+ if((dj_global["djConfig"])&&(djConfig["slowAnonFuncLookups"] == true)){
+ for(var x in nso){
+ if(nso[x] === anonFuncPtr){
+ return x;
+ }
+ }
+ }
+ var ret = "__"+dojo.lang.anonCtr++;
+ while(typeof nso[ret] != "undefined"){
+ ret = "__"+dojo.lang.anonCtr++;
+ }
+ nso[ret] = anonFuncPtr;
+ return ret;
+}
+
+/**
+ * Runs a function in a given scope (thisObject), can
+ * also be used to preserve scope.
+ *
+ * hitch(foo, "bar"); // runs foo.bar() in the scope of foo
+ * hitch(foo, myFunction); // runs myFunction in the scope of foo
+ */
+dojo.lang.hitch = function(thisObject, method) {
+ if(dojo.lang.isString(method)) {
+ var fcn = thisObject[method];
+ } else {
+ var fcn = method;
+ }
+
+ return function() {
+ return fcn.apply(thisObject, arguments);
+ }
+}
+
+/**
+ * Sets a timeout in milliseconds to execute a function in a given context
+ * with optional arguments.
+ *
+ * setTimeout (Object context, function func, number delay[, arg1[, ...]]);
+ * setTimeout (function func, number delay[, arg1[, ...]]);
+ */
+dojo.lang.setTimeout = function(func, delay){
+ var context = window, argsStart = 2;
+ if(!dojo.lang.isFunction(func)){
+ context = func;
+ func = delay;
+ delay = arguments[2];
+ argsStart++;
+ }
+
+ if(dojo.lang.isString(func)){
+ func = context[func];
+ }
+
+ var args = [];
+ for (var i = argsStart; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+ return setTimeout(function () { func.apply(context, args); }, delay);
+}
+
+/**
+ * Partial implmentation of is* functions from
+ * http://www.crockford.com/javascript/recommend.html
+ * NOTE: some of these may not be the best thing to use in all situations
+ * as they aren't part of core JS and therefore can't work in every case.
+ * See WARNING messages inline for tips.
+ *
+ * The following is* functions are fairly "safe"
+ */
+
+dojo.lang.isObject = function(wh) {
+ return typeof wh == "object" || dojo.lang.isArray(wh) || dojo.lang.isFunction(wh);
+}
+
+dojo.lang.isArray = function(wh) {
+ return (wh instanceof Array || typeof wh == "array");
+}
+
+dojo.lang.isArrayLike = function(wh) {
+ if(dojo.lang.isString(wh)){ return false; }
+ if(dojo.lang.isArray(wh)){ return true; }
+ if(dojo.lang.isNumber(wh.length) && isFinite(wh)){ return true; }
+ return false;
+}
+
+dojo.lang.isFunction = function(wh) {
+ return (wh instanceof Function || typeof wh == "function");
+}
+
+dojo.lang.isString = function(wh) {
+ return (wh instanceof String || typeof wh == "string");
+}
+
+dojo.lang.isAlien = function(wh) {
+ return !dojo.lang.isFunction() && /\{\s*\[native code\]\s*\}/.test(String(wh));
+}
+
+dojo.lang.isBoolean = function(wh) {
+ return (wh instanceof Boolean || typeof wh == "boolean");
+}
+
+/**
+ * The following is***() functions are somewhat "unsafe". Fortunately,
+ * there are workarounds the the language provides and are mentioned
+ * in the WARNING messages.
+ *
+ * WARNING: In most cases, isNaN(wh) is sufficient to determine whether or not
+ * something is a number or can be used as such. For example, a number or string
+ * can be used interchangably when accessing array items (arr["1"] is the same as
+ * arr[1]) and isNaN will return false for both values ("1" and 1). Should you
+ * use isNumber("1"), that will return false, which is generally not too useful.
+ * Also, isNumber(NaN) returns true, again, this isn't generally useful, but there
+ * are corner cases (like when you want to make sure that two things are really
+ * the same type of thing). That is really where isNumber "shines".
+ *
+ * RECOMMENDATION: Use isNaN(wh) when possible
+ */
+dojo.lang.isNumber = function(wh) {
+ return (wh instanceof Number || typeof wh == "number");
+}
+
+/**
+ * WARNING: In some cases, isUndefined will not behave as you
+ * might expect. If you do isUndefined(foo) and there is no earlier
+ * reference to foo, an error will be thrown before isUndefined is
+ * called. It behaves correctly if you scope yor object first, i.e.
+ * isUndefined(foo.bar) where foo is an object and bar isn't a
+ * property of the object.
+ *
+ * RECOMMENDATION: Use `typeof foo == "undefined"` when possible
+ *
+ * FIXME: Should isUndefined go away since it is error prone?
+ */
+dojo.lang.isUndefined = function(wh) {
+ return ((wh == undefined)&&(typeof wh == "undefined"));
+}
+
+// end Crockford functions
+
+dojo.lang.whatAmI = function(wh) {
+ try {
+ if(dojo.lang.isArray(wh)) { return "array"; }
+ if(dojo.lang.isFunction(wh)) { return "function"; }
+ if(dojo.lang.isString(wh)) { return "string"; }
+ if(dojo.lang.isNumber(wh)) { return "number"; }
+ if(dojo.lang.isBoolean(wh)) { return "boolean"; }
+ if(dojo.lang.isAlien(wh)) { return "alien"; }
+ if(dojo.lang.isUndefined(wh)) { return "undefined"; }
+ // FIXME: should this go first?
+ for(var name in dojo.lang.whatAmI.custom) {
+ if(dojo.lang.whatAmI.custom[name](wh)) {
+ return name;
+ }
+ }
+ if(dojo.lang.isObject(wh)) { return "object"; }
+ } catch(E) {}
+ return "unknown";
+}
+/*
+ * dojo.lang.whatAmI.custom[typeName] = someFunction
+ * will return typeName is someFunction(wh) returns true
+ */
+dojo.lang.whatAmI.custom = {};
+
+dojo.lang.find = function(arr, val, identity){
+ // support both (arr, val) and (val, arr)
+ if(!dojo.lang.isArray(arr) && dojo.lang.isArray(val)) {
+ var a = arr;
+ arr = val;
+ val = a;
+ }
+ var isString = dojo.lang.isString(arr);
+ if(isString) { arr = arr.split(""); }
+ if(identity){
+ for(var i=0;i<arr.length;++i){
+ if(arr[i] === val){ return i; }
+ }
+ }else{
+ for(var i=0;i<arr.length;++i){
+ if(arr[i] == val){ return i; }
+ }
+ }
+ return -1;
+}
+
+dojo.lang.indexOf = dojo.lang.find;
+
+dojo.lang.findLast = function(arr, val, identity) {
+ // support both (arr, val) and (val, arr)
+ if(!dojo.lang.isArray(arr) && dojo.lang.isArray(val)) {
+ var a = arr;
+ arr = val;
+ val = a;
+ }
+ var isString = dojo.lang.isString(arr);
+ if(isString) { arr = arr.split(""); }
+ if(identity){
+ for(var i = arr.length-1; i >= 0; i--) {
+ if(arr[i] === val){ return i; }
+ }
+ }else{
+ for(var i = arr.length-1; i >= 0; i--) {
+ if(arr[i] == val){ return i; }
+ }
+ }
+ return -1;
+}
+
+dojo.lang.lastIndexOf = dojo.lang.findLast;
+
+dojo.lang.inArray = function(arr, val){
+ return dojo.lang.find(arr, val) > -1;
+}
+
+dojo.lang.getNameInObj = function(ns, item){
+ if(!ns){ ns = dj_global; }
+
+ for(var x in ns){
+ if(ns[x] === item){
+ return new String(x);
+ }
+ }
+ return null;
+}
+
+// FIXME: Is this worthless since you can do: if(name in obj)
+// is this the right place for this?
+dojo.lang.has = function(obj, name){
+ return (typeof obj[name] !== 'undefined');
+}
+
+dojo.lang.isEmpty = function(obj) {
+ if(dojo.lang.isObject(obj)) {
+ var tmp = {};
+ var count = 0;
+ for(var x in obj){
+ if(obj[x] && (!tmp[x])){
+ count++;
+ break;
+ }
+ }
+ return (count == 0);
+ } else if(dojo.lang.isArray(obj) || dojo.lang.isString(obj)) {
+ return obj.length == 0;
+ }
+}
+
+dojo.lang.forEach = function(arr, unary_func, fix_length){
+ var isString = dojo.lang.isString(arr);
+ if(isString) { arr = arr.split(""); }
+ var il = arr.length;
+ for(var i=0; i< ((fix_length) ? il : arr.length); i++){
+ if(unary_func(arr[i], i, arr) == "break"){
+ break;
+ }
+ }
+}
+
+dojo.lang.map = function(arr, obj, unary_func){
+ var isString = dojo.lang.isString(arr);
+ if(isString){
+ arr = arr.split("");
+ }
+ if(dojo.lang.isFunction(obj)&&(!unary_func)){
+ unary_func = obj;
+ obj = dj_global;
+ }else if(dojo.lang.isFunction(obj) && unary_func){
+ // ff 1.5 compat
+ var tmpObj = obj;
+ obj = unary_func;
+ unary_func = tmpObj;
+ }
+
+ if(Array.map){
+ var outArr = Array.map(arr, unary_func, obj);
+ }else{
+ var outArr = [];
+ for(var i=0;i<arr.length;++i){
+ outArr.push(unary_func.call(obj, arr[i]));
+ }
+ }
+
+ if(isString) {
+ return outArr.join("");
+ } else {
+ return outArr;
+ }
+}
+
+dojo.lang.tryThese = function(){
+ for(var x=0; x<arguments.length; x++){
+ try{
+ if(typeof arguments[x] == "function"){
+ var ret = (arguments[x]());
+ if(ret){
+ return ret;
+ }
+ }
+ }catch(e){
+ dojo.debug(e);
+ }
+ }
+}
+
+dojo.lang.delayThese = function(farr, cb, delay, onend){
+ /**
+ * alternate: (array funcArray, function callback, function onend)
+ * alternate: (array funcArray, function callback)
+ * alternate: (array funcArray)
+ */
+ if(!farr.length){
+ if(typeof onend == "function"){
+ onend();
+ }
+ return;
+ }
+ if((typeof delay == "undefined")&&(typeof cb == "number")){
+ delay = cb;
+ cb = function(){};
+ }else if(!cb){
+ cb = function(){};
+ if(!delay){ delay = 0; }
+ }
+ setTimeout(function(){
+ (farr.shift())();
+ cb();
+ dojo.lang.delayThese(farr, cb, delay, onend);
+ }, delay);
+}
+
+dojo.lang.shallowCopy = function(obj) {
+ var ret = {}, key;
+ for(key in obj) {
+ if(dojo.lang.isUndefined(ret[key])) {
+ ret[key] = obj[key];
+ }
+ }
+ return ret;
+}
+
+dojo.lang.every = function(arr, callback, thisObject) {
+ var isString = dojo.lang.isString(arr);
+ if(isString) { arr = arr.split(""); }
+ if(Array.every) {
+ return Array.every(arr, callback, thisObject);
+ } else {
+ if(!thisObject) {
+ if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); }
+ thisObject = dj_global;
+ }
+
+ for(var i = 0; i < arr.length; i++) {
+ if(!callback.call(thisObject, arr[i], i, arr)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+
+dojo.lang.some = function(arr, callback, thisObject) {
+ var isString = dojo.lang.isString(arr);
+ if(isString) { arr = arr.split(""); }
+ if(Array.some) {
+ return Array.some(arr, callback, thisObject);
+ } else {
+ if(!thisObject) {
+ if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); }
+ thisObject = dj_global;
+ }
+
+ for(var i = 0; i < arr.length; i++) {
+ if(callback.call(thisObject, arr[i], i, arr)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
+dojo.lang.filter = function(arr, callback, thisObject) {
+ var isString = dojo.lang.isString(arr);
+ if(isString) { arr = arr.split(""); }
+ if(Array.filter) {
+ var outArr = Array.filter(arr, callback, thisObject);
+ } else {
+ if(!thisObject) {
+ if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); }
+ thisObject = dj_global;
+ }
+
+ var outArr = [];
+ for(var i = 0; i < arr.length; i++) {
+ if(callback.call(thisObject, arr[i], i, arr)) {
+ outArr.push(arr[i]);
+ }
+ }
+ }
+ if(isString) {
+ return outArr.join("");
+ } else {
+ return outArr;
+ }
+}
+
+dojo.AdapterRegistry = function(){
+ /***
+ A registry to facilitate adaptation.
+
+ Pairs is an array of [name, check, wrap] triples
+
+ All check/wrap functions in this registry should be of the same arity.
+ ***/
+ this.pairs = [];
+}
+
+dojo.lang.extend(dojo.AdapterRegistry, {
+ register: function (name, check, wrap, /* optional */ override) {
+ /***
+ The check function should return true if the given arguments are
+ appropriate for the wrap function.
+
+ If override is given and true, the check function will be given
+ highest priority. Otherwise, it will be the lowest priority
+ adapter.
+ ***/
+
+ if (override) {
+ this.pairs.unshift([name, check, wrap]);
+ } else {
+ this.pairs.push([name, check, wrap]);
+ }
+ },
+
+ match: function (/* ... */) {
+ /***
+ Find an adapter for the given arguments.
+
+ If no suitable adapter is found, throws NotFound.
+ ***/
+ for(var i = 0; i < this.pairs.length; i++){
+ var pair = this.pairs[i];
+ if(pair[1].apply(this, arguments)){
+ return pair[2].apply(this, arguments);
+ }
+ }
+ dojo.raise("No match found");
+ },
+
+ unregister: function (name) {
+ /***
+
+ Remove a named adapter from the registry
+
+ ***/
+ for (var i = 0; i < this.pairs.length; i++) {
+ var pair = this.pairs[i];
+ if (pair[0] == name) {
+ this.pairs.splice(i, 1);
+ return true;
+ }
+ }
+ return false;
+ }
+});
+
+dojo.lang.reprRegistry = new dojo.AdapterRegistry();
+dojo.lang.registerRepr = function(name, check, wrap, /*optional*/ override) {
+ /***
+ Register a repr function. repr functions should take
+ one argument and return a string representation of it
+ suitable for developers, primarily used when debugging.
+
+ If override is given, it is used as the highest priority
+ repr, otherwise it will be used as the lowest.
+ ***/
+ dojo.lang.reprRegistry.register(name, check, wrap, override);
+ };
+
+dojo.lang.repr = function(obj){
+ /***
+ Return a "programmer representation" for an object
+ ***/
+
+ if(typeof(obj) == "undefined"){
+ return "undefined";
+ }else if(obj === null){
+ return "null";
+ }
+
+ try{
+ if(typeof(obj["__repr__"]) == 'function'){
+ return obj["__repr__"]();
+ }else if((typeof(obj["repr"]) == 'function')&&(obj.repr != arguments.callee)){
+ return obj["repr"]();
+ }
+ return dojo.lang.reprRegistry.match(obj);
+ }catch(e){
+ if(typeof(obj.NAME) == 'string' && (
+ obj.toString == Function.prototype.toString ||
+ obj.toString == Object.prototype.toString
+ )){
+ return o.NAME;
+ }
+ }
+
+ if(typeof(obj) == "function"){
+ obj = (obj + "").replace(/^\s+/, "");
+ var idx = obj.indexOf("{");
+ if(idx != -1){
+ obj = obj.substr(0, idx) + "{...}";
+ }
+ }
+ return obj + "";
+}
+
+dojo.lang.reprArrayLike = function(arr){
+ try{
+ var na = dojo.lang.map(arr, dojo.lang.repr);
+ return "[" + na.join(", ") + "]";
+ }catch(e){ }
+};
+
+dojo.lang.reprString = function(str){
+ return ('"' + str.replace(/(["\\])/g, '\\$1') + '"'
+ ).replace(/[\f]/g, "\\f"
+ ).replace(/[\b]/g, "\\b"
+ ).replace(/[\n]/g, "\\n"
+ ).replace(/[\t]/g, "\\t"
+ ).replace(/[\r]/g, "\\r");
+};
+
+dojo.lang.reprNumber = function(num){
+ return num + "";
+};
+
+(function(){
+ var m = dojo.lang;
+ m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike);
+ m.registerRepr("string", m.isString, m.reprString);
+ m.registerRepr("numbers", m.isNumber, m.reprNumber);
+ m.registerRepr("boolean", m.isBoolean, m.reprNumber);
+ // m.registerRepr("numbers", m.typeMatcher("number", "boolean"), m.reprNumber);
+})();
+
+/**
+ * Creates a 1-D array out of all the arguments passed,
+ * unravelling any array-like objects in the process
+ *
+ * Ex:
+ * unnest(1, 2, 3) ==> [1, 2, 3]
+ * unnest(1, [2, [3], [[[4]]]]) ==> [1, 2, 3, 4]
+ */
+dojo.lang.unnest = function(/* ... */) {
+ var out = [];
+ for(var i = 0; i < arguments.length; i++) {
+ if(dojo.lang.isArrayLike(arguments[i])) {
+ var add = dojo.lang.unnest.apply(this, arguments[i]);
+ out = out.concat(add);
+ } else {
+ out.push(arguments[i]);
+ }
+ }
+ return out;
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/Lang.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/Lang.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/Lang.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/Lang.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,2 @@
+dojo.require("dojo.lang");
+dj_deprecated("dojo.lang.Lang is deprecated, use dojo.lang instead");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/__package__.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/__package__.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/__package__.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/lang/__package__.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,4 @@
+dojo.hostenv.conditionalLoadModule({
+ common: ["dojo.lang"]
+});
+dojo.hostenv.moduleLoaded("dojo.lang.*");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/Logger.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/Logger.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/Logger.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/Logger.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,398 @@
+/* This is the dojo logging facility, which is stolen from nWidgets, which
+ is patterned on the Python logging module, which in turn has been
+ heavily influenced by log4j (execpt with some more pythonic choices,
+ which we adopt as well).
+
+ While the dojo logging facilities do provide a set of familiar
+ interfaces, many of the details are changed to reflect the constraints
+ of the browser environment. Mainly, file and syslog-style logging
+ facilites are not provided, with HTTP POST and GET requests being the
+ only ways of getting data from the browser back to a server. Minimal
+ support for this (and XML serialization of logs) is provided, but may
+ not be of practical use in a deployment environment.
+
+ The Dojo logging classes are agnostic of any environment, and while
+ default loggers are provided for browser-based interpreter
+ environments, this file and the classes it define are explicitly
+ designed to be portable to command-line interpreters and other
+ ECMA-262v3 envrionments.
+
+ the logger needs to accomidate:
+ log "levels"
+ type identifiers
+ file?
+ message
+ tic/toc?
+
+ The logger should ALWAYS record:
+ time/date logged
+ message
+ type
+ level
+*/
+// TODO: conver documentation to javadoc style once we confirm that is our choice
+// TODO: define DTD for XML-formatted log messages
+// TODO: write XML Formatter class
+// TODO: write HTTP Handler which uses POST to send log lines/sections
+
+// Filename: LogCore.js
+// Purpose: a common logging infrastructure for dojo
+// Classes: dojo.logging, dojo.logging.Logger, dojo.logging.Record, dojo.logging.LogFilter
+// Global Objects: dojo.logging
+// Dependencies: none
+
+dojo.provide("dojo.logging.Logger");
+dojo.provide("dojo.log");
+dojo.require("dojo.lang");
+
+/*
+ A simple data structure class that stores information for and about
+ a logged event. Objects of this type are created automatically when
+ an event is logged and are the internal format in which information
+ about log events is kept.
+*/
+
+dojo.logging.Record = function(lvl, msg){
+ this.level = lvl;
+ this.message = msg;
+ this.time = new Date();
+ // FIXME: what other information can we receive/discover here?
+}
+
+// an empty parent (abstract) class which concrete filters should inherit from.
+dojo.logging.LogFilter = function(loggerChain){
+ this.passChain = loggerChain || "";
+ this.filter = function(record){
+ // FIXME: need to figure out a way to enforce the loggerChain
+ // restriction
+ return true; // pass all records
+ }
+}
+
+dojo.logging.Logger = function(){
+ this.cutOffLevel = 0;
+ this.propagate = true;
+ this.parent = null;
+ // storage for dojo.logging.Record objects seen and accepted by this logger
+ this.data = [];
+ this.filters = [];
+ this.handlers = [];
+}
+
+dojo.lang.extend(dojo.logging.Logger, {
+ argsToArr: function(args){
+ // utility function, reproduced from __util__ here to remove dependency
+ var ret = [];
+ for(var x=0; x<args.length; x++){
+ ret.push(args[x]);
+ }
+ return ret;
+ },
+
+ setLevel: function(lvl){
+ this.cutOffLevel = parseInt(lvl);
+ },
+
+ isEnabledFor: function(lvl){
+ return parseInt(lvl) >= this.cutOffLevel;
+ },
+
+ getEffectiveLevel: function(){
+ if((this.cutOffLevel==0)&&(this.parent)){
+ return this.parent.getEffectiveLevel();
+ }
+ return this.cutOffLevel;
+ },
+
+ addFilter: function(flt){
+ this.filters.push(flt);
+ return this.filters.length-1;
+ },
+
+ removeFilterByIndex: function(fltIndex){
+ if(this.filters[fltIndex]){
+ delete this.filters[fltIndex];
+ return true;
+ }
+ return false;
+ },
+
+ removeFilter: function(fltRef){
+ for(var x=0; x<this.filters.length; x++){
+ if(this.filters[x]===fltRef){
+ delete this.filters[x];
+ return true;
+ }
+ }
+ return false;
+ },
+
+ removeAllFilters: function(){
+ this.filters = []; // clobber all of them
+ },
+
+ filter: function(rec){
+ for(var x=0; x<this.filters.length; x++){
+ if((this.filters[x]["filter"])&&
+ (!this.filters[x].filter(rec))||
+ (rec.level<this.cutOffLevel)){
+ return false;
+ }
+ }
+ return true;
+ },
+
+ addHandler: function(hdlr){
+ this.handlers.push(hdlr);
+ return this.handlers.length-1;
+ },
+
+ handle: function(rec){
+ if((!this.filter(rec))||(rec.level<this.cutOffLevel)){ return false; }
+ for(var x=0; x<this.handlers.length; x++){
+ if(this.handlers[x]["handle"]){
+ this.handlers[x].handle(rec);
+ }
+ }
+ // FIXME: not sure what to do about records to be propagated that may have
+ // been modified by the handlers or the filters at this logger. Should
+ // parents always have pristine copies? or is passing the modified record
+ // OK?
+ // if((this.propagate)&&(this.parent)){ this.parent.handle(rec); }
+ return true;
+ },
+
+ // the heart and soul of the logging system
+ log: function(lvl, msg){
+ if( (this.propagate)&&(this.parent)&&
+ (this.parent.rec.level>=this.cutOffLevel)){
+ this.parent.log(lvl, msg);
+ return false;
+ }
+ // FIXME: need to call logging providers here!
+ this.handle(new dojo.logging.Record(lvl, msg));
+ return true;
+ },
+
+ // logger helpers
+ debug:function(msg){
+ return this.logType("DEBUG", this.argsToArr(arguments));
+ },
+
+ info: function(msg){
+ return this.logType("INFO", this.argsToArr(arguments));
+ },
+
+ warning: function(msg){
+ return this.logType("WARNING", this.argsToArr(arguments));
+ },
+
+ error: function(msg){
+ return this.logType("ERROR", this.argsToArr(arguments));
+ },
+
+ critical: function(msg){
+ return this.logType("CRITICAL", this.argsToArr(arguments));
+ },
+
+ exception: function(msg, e, squelch){
+ // FIXME: this needs to be modified to put the exception in the msg
+ // if we're on Moz, we can get the following from the exception object:
+ // lineNumber
+ // message
+ // fileName
+ // stack
+ // name
+ // on IE, we get:
+ // name
+ // message (from MDA?)
+ // number
+ // description (same as message!)
+ if(e){
+ var eparts = [e.name, (e.description||e.message)];
+ if(e.fileName){
+ eparts.push(e.fileName);
+ eparts.push("line "+e.lineNumber);
+ // eparts.push(e.stack);
+ }
+ msg += " "+eparts.join(" : ");
+ }
+
+ this.logType("ERROR", msg);
+ if(!squelch){
+ throw e;
+ }
+ },
+
+ logType: function(type, args){
+ var na = [dojo.logging.log.getLevel(type)];
+ if(typeof args == "array"){
+ na = na.concat(args);
+ }else if((typeof args == "object")&&(args["length"])){
+ na = na.concat(this.argsToArr(args));
+ /* for(var x=0; x<args.length; x++){
+ na.push(args[x]);
+ } */
+ }else{
+ na = na.concat(this.argsToArr(arguments).slice(1));
+ /* for(var x=1; x<arguments.length; x++){
+ na.push(arguments[x]);
+ } */
+ }
+ return this.log.apply(this, na);
+ }
+});
+
+void(function(){
+ var ptype = dojo.logging.Logger.prototype;
+ ptype.warn = ptype.warning;
+ ptype.err = ptype.error;
+ ptype.crit = ptype.critical;
+})();
+
+// the Handler class
+dojo.logging.LogHandler = function(level){
+ this.cutOffLevel = (level) ? level : 0;
+ this.formatter = null; // FIXME: default formatter?
+ this.data = [];
+ this.filters = [];
+}
+
+dojo.logging.LogHandler.prototype.setFormatter = function(fmtr){
+ // FIXME: need to vet that it is indeed a formatter object
+ dj_unimplemented("setFormatter");
+}
+
+dojo.logging.LogHandler.prototype.flush = function(){
+ dj_unimplemented("flush");
+}
+
+dojo.logging.LogHandler.prototype.close = function(){
+ dj_unimplemented("close");
+}
+
+dojo.logging.LogHandler.prototype.handleError = function(){
+ dj_unimplemented("handleError");
+}
+
+dojo.logging.LogHandler.prototype.handle = function(record){
+ // emits the passed record if it passes this object's filters
+ if((this.filter(record))&&(record.level>=this.cutOffLevel)){
+ this.emit(record);
+ }
+}
+
+dojo.logging.LogHandler.prototype.emit = function(record){
+ // do whatever is necessaray to actually log the record
+ dj_unimplemented("emit");
+}
+
+// set aliases since we don't want to inherit from dojo.logging.Logger
+void(function(){ // begin globals protection closure
+ var names = [
+ "setLevel", "addFilter", "removeFilterByIndex", "removeFilter",
+ "removeAllFilters", "filter"
+ ];
+ var tgt = dojo.logging.LogHandler.prototype;
+ var src = dojo.logging.Logger.prototype;
+ for(var x=0; x<names.length; x++){
+ tgt[names[x]] = src[names[x]];
+ }
+})(); // end globals protection closure
+
+dojo.logging.log = new dojo.logging.Logger();
+
+// an associative array of logger objects. This object inherits from
+// a list of level names with their associated numeric levels
+dojo.logging.log.levels = [ {"name": "DEBUG", "level": 1},
+ {"name": "INFO", "level": 2},
+ {"name": "WARNING", "level": 3},
+ {"name": "ERROR", "level": 4},
+ {"name": "CRITICAL", "level": 5} ];
+
+dojo.logging.log.loggers = {};
+
+dojo.logging.log.getLogger = function(name){
+ if(!this.loggers[name]){
+ this.loggers[name] = new dojo.logging.Logger();
+ this.loggers[name].parent = this;
+ }
+ return this.loggers[name];
+}
+
+dojo.logging.log.getLevelName = function(lvl){
+ for(var x=0; x<this.levels.length; x++){
+ if(this.levels[x].level == lvl){
+ return this.levels[x].name;
+ }
+ }
+ return null;
+}
+
+dojo.logging.log.addLevelName = function(name, lvl){
+ if(this.getLevelName(name)){
+ this.err("could not add log level "+name+" because a level with that name already exists");
+ return false;
+ }
+ this.levels.append({"name": name, "level": parseInt(lvl)});
+ return true;
+}
+
+dojo.logging.log.getLevel = function(name){
+ for(var x=0; x<this.levels.length; x++){
+ if(this.levels[x].name.toUpperCase() == name.toUpperCase()){
+ return this.levels[x].level;
+ }
+ }
+ return null;
+}
+
+// a default handler class, it simply saves all of the handle()'d records in
+// memory. Useful for attaching to with dojo.event.connect()
+dojo.logging.MemoryLogHandler = function(level, recordsToKeep, postType, postInterval){
+ // mixin style inheritance
+ dojo.logging.LogHandler.call(this, level);
+ // default is unlimited
+ this.numRecords = (typeof djConfig['loggingNumRecords'] != 'undefined') ? djConfig['loggingNumRecords'] : ((recordsToKeep) ? recordsToKeep : -1);
+ // 0=count, 1=time, -1=don't post TODO: move this to a better location for prefs
+ this.postType = (typeof djConfig['loggingPostType'] != 'undefined') ? djConfig['loggingPostType'] : ( postType || -1);
+ // milliseconds for time, interger for number of records, -1 for non-posting,
+ this.postInterval = (typeof djConfig['loggingPostInterval'] != 'undefined') ? djConfig['loggingPostInterval'] : ( postType || -1);
+
+}
+// prototype inheritance
+dojo.logging.MemoryLogHandler.prototype = new dojo.logging.LogHandler();
+
+// FIXME
+// dj_inherits(dojo.logging.MemoryLogHandler,
+
+// over-ride base-class
+dojo.logging.MemoryLogHandler.prototype.emit = function(record){
+ this.data.push(record);
+ if(this.numRecords != -1){
+ while(this.data.length>this.numRecords){
+ this.data.shift();
+ }
+ }
+}
+
+dojo.logging.logQueueHandler = new dojo.logging.MemoryLogHandler(0,50,0,10000);
+// actual logging event handler
+dojo.logging.logQueueHandler.emit = function(record){
+ // we should probably abstract this in the future
+ var logStr = String(dojo.log.getLevelName(record.level)+": "+record.time.toLocaleTimeString())+": "+record.message;
+ if(!dj_undef("debug", dj_global)){
+ dojo.debug(logStr);
+ }else if((typeof dj_global["print"] == "function")&&(!dojo.render.html.capable)){
+ print(logStr);
+ }
+ this.data.push(record);
+ if(this.numRecords != -1){
+ while(this.data.length>this.numRecords){
+ this.data.shift();
+ }
+ }
+}
+
+dojo.logging.log.addHandler(dojo.logging.logQueueHandler);
+dojo.log = dojo.logging.log;
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/__package__.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/__package__.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/__package__.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/logging/__package__.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,5 @@
+dojo.hostenv.conditionalLoadModule({
+ common: ["dojo.logging.Logger", false, false],
+ rhino: ["dojo.logging.RhinoLogger"]
+});
+dojo.hostenv.moduleLoaded("dojo.logging.*");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,99 @@
+dojo.provide("dojo.math");
+
+dojo.math.degToRad = function (x) { return (x*Math.PI) / 180; }
+dojo.math.radToDeg = function (x) { return (x*180) / Math.PI; }
+
+dojo.math.factorial = function (n) {
+ if(n<1){ return 0; }
+ var retVal = 1;
+ for(var i=1;i<=n;i++){ retVal *= i; }
+ return retVal;
+}
+
+//The number of ways of obtaining an ordered subset of k elements from a set of n elements
+dojo.math.permutations = function (n,k) {
+ if(n==0 || k==0) return 1;
+ return (dojo.math.factorial(n) / dojo.math.factorial(n-k));
+}
+
+//The number of ways of picking n unordered outcomes from r possibilities
+dojo.math.combinations = function (n,r) {
+ if(n==0 || r==0) return 1;
+ return (dojo.math.factorial(n) / (dojo.math.factorial(n-r) * dojo.math.factorial(r)));
+}
+
+dojo.math.bernstein = function (t,n,i) {
+ return (dojo.math.combinations(n,i) * Math.pow(t,i) * Math.pow(1-t,n-i));
+}
+
+/**
+ * Returns random numbers with a Gaussian distribution, with the mean set at
+ * 0 and the variance set at 1.
+ *
+ * @return A random number from a Gaussian distribution
+ */
+ // FIXME: this doesn't always range from -1 to 1 (fails ant test sometimes!)
+dojo.math.gaussianRandom = function () {
+ var k = 2;
+ do {
+ var i = 2 * Math.random() - 1;
+ var j = 2 * Math.random() - 1;
+ k = i * i + j * j;
+ } while (k >= 1);
+ k = Math.sqrt((-2 * Math.log(k)) / k);
+ return i * k;
+}
+
+/**
+ * Calculates the mean of an Array of numbers.
+ *
+ * @return The mean of the numbers in the Array
+ */
+dojo.math.mean = function () {
+ var array = dojo.lang.isArray(arguments[0]) ? arguments[0] : arguments;
+ var mean = 0;
+ for (var i = 0; i < array.length; i++) { mean += array[i]; }
+ return mean / array.length;
+}
+
+/**
+ * Extends Math.round by adding a second argument specifying the number of
+ * decimal places to round to.
+ *
+ * @param number The number to round
+ * @param places The number of decimal places to round to
+ * @return The rounded number
+ */
+// TODO: add support for significant figures
+dojo.math.round = function (number, places) {
+ if (!places) { var shift = 1; }
+ else { var shift = Math.pow(10, places); }
+ return Math.round(number * shift) / shift;
+}
+
+/**
+ * Calculates the standard deviation of an Array of numbers
+ *
+ * @return The standard deviation of the numbers
+ */
+dojo.math.sd = function () {
+ var array = dojo.lang.isArray(arguments[0]) ? arguments[0] : arguments;
+ return Math.sqrt(dojo.math.variance(array));
+}
+
+/**
+ * Calculates the variance of an Array of numbers
+ *
+ * @return The variance of the numbers
+ */
+dojo.math.variance = function () {
+ var array = dojo.lang.isArray(arguments[0]) ? arguments[0] : arguments;
+ var mean = 0, squares = 0;
+ for (var i = 0; i < array.length; i++) {
+ mean += array[i];
+ squares += Math.pow(array[i], 2);
+ }
+ return (squares / array.length)
+ - Math.pow(mean / array.length, 2);
+}
+
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/Math.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/Math.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/Math.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/Math.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,2 @@
+dj_deprecated("dojo.math.Math does not exist, include dojo.math");
+dojo.require("dojo.math");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/__package__.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/__package__.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/__package__.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/__package__.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,8 @@
+dojo.hostenv.conditionalLoadModule({
+ common: [
+ ["dojo.math", false, false],
+ ["dojo.math.curves", false, false],
+ ["dojo.math.points", false, false]
+ ]
+});
+dojo.hostenv.moduleLoaded("dojo.math.*");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/curves.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/curves.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/curves.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/curves.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,212 @@
+dojo.provide("dojo.math.curves");
+
+dojo.require("dojo.math");
+
+/* Curves from Dan's 13th lib stuff.
+ * See: http://pupius.co.uk/js/Toolkit.Drawing.js
+ * http://pupius.co.uk/dump/dojo/Dojo.Math.js
+ */
+
+dojo.math.curves = {
+ //Creates a straight line object
+ Line: function(start, end) {
+ this.start = start;
+ this.end = end;
+ this.dimensions = start.length;
+
+ for(var i = 0; i < start.length; i++) {
+ start[i] = Number(start[i]);
+ }
+
+ for(var i = 0; i < end.length; i++) {
+ end[i] = Number(end[i]);
+ }
+
+ //simple function to find point on an n-dimensional, straight line
+ this.getValue = function(n) {
+ var retVal = new Array(this.dimensions);
+ for(var i=0;i<this.dimensions;i++)
+ retVal[i] = ((this.end[i] - this.start[i]) * n) + this.start[i];
+ return retVal;
+ }
+
+ return this;
+ },
+
+
+ //Takes an array of points, the first is the start point, the last is end point and the ones in
+ //between are the Bezier control points.
+ Bezier: function(pnts) {
+ this.getValue = function(step) {
+ if(step >= 1) return this.p[this.p.length-1]; // if step>=1 we must be at the end of the curve
+ if(step <= 0) return this.p[0]; // if step<=0 we must be at the start of the curve
+ var retVal = new Array(this.p[0].length);
+ for(var k=0;j<this.p[0].length;k++) { retVal[k]=0; }
+ for(var j=0;j<this.p[0].length;j++) {
+ var C=0; var D=0;
+ for(var i=0;i<this.p.length;i++) {
+ C += this.p[i][j] * this.p[this.p.length-1][0]
+ * dojo.math.bernstein(step,this.p.length,i);
+ }
+ for(var l=0;l<this.p.length;l++) {
+ D += this.p[this.p.length-1][0] * dojo.math.bernstein(step,this.p.length,l);
+ }
+ retVal[j] = C/D;
+ }
+ return retVal;
+ }
+ this.p = pnts;
+ return this;
+ },
+
+
+ //Catmull-Rom Spline - allows you to interpolate a smooth curve through a set of points in n-dimensional space
+ CatmullRom : function(pnts,c) {
+ this.getValue = function(step) {
+ var percent = step * (this.p.length-1);
+ var node = Math.floor(percent);
+ var progress = percent - node;
+
+ var i0 = node-1; if(i0 < 0) i0 = 0;
+ var i = node;
+ var i1 = node+1; if(i1 >= this.p.length) i1 = this.p.length-1;
+ var i2 = node+2; if(i2 >= this.p.length) i2 = this.p.length-1;
+
+ var u = progress;
+ var u2 = progress*progress;
+ var u3 = progress*progress*progress;
+
+ var retVal = new Array(this.p[0].length);
+ for(var k=0;k<this.p[0].length;k++) {
+ var x1 = ( -this.c * this.p[i0][k] ) + ( (2 - this.c) * this.p[i][k] ) + ( (this.c-2) * this.p[i1][k] ) + ( this.c * this.p[i2][k] );
+ var x2 = ( 2 * this.c * this.p[i0][k] ) + ( (this.c-3) * this.p[i][k] ) + ( (3 - 2 * this.c) * this.p[i1][k] ) + ( -this.c * this.p[i2][k] );
+ var x3 = ( -this.c * this.p[i0][k] ) + ( this.c * this.p[i1][k] );
+ var x4 = this.p[i][k];
+
+ retVal[k] = x1*u3 + x2*u2 + x3*u + x4;
+ }
+ return retVal;
+
+ }
+
+
+ if(!c) this.c = 0.7;
+ else this.c = c;
+ this.p = pnts;
+
+ return this;
+ },
+
+ // FIXME: This is the bad way to do a partial-arc with 2 points. We need to have the user
+ // supply the radius, otherwise we always get a half-circle between the two points.
+ Arc : function(start, end, ccw) {
+ var center = dojo.math.points.midpoint(start, end);
+ var sides = dojo.math.points.translate(dojo.math.points.invert(center), start);
+ var rad = Math.sqrt(Math.pow(sides[0], 2) + Math.pow(sides[1], 2));
+ var theta = dojo.math.radToDeg(Math.atan(sides[1]/sides[0]));
+ if( sides[0] < 0 ) {
+ theta -= 90;
+ } else {
+ theta += 90;
+ }
+ dojo.math.curves.CenteredArc.call(this, center, rad, theta, theta+(ccw?-180:180));
+ },
+
+ // Creates an arc object, with center and radius (Top of arc = 0 degrees, increments clockwise)
+ // center => 2D point for center of arc
+ // radius => scalar quantity for radius of arc
+ // start => to define an arc specify start angle (default: 0)
+ // end => to define an arc specify start angle
+ CenteredArc : function(center, radius, start, end) {
+ this.center = center;
+ this.radius = radius;
+ this.start = start || 0;
+ this.end = end;
+
+ this.getValue = function(n) {
+ var retVal = new Array(2);
+ var theta = dojo.math.degToRad(this.start+((this.end-this.start)*n));
+
+ retVal[0] = this.center[0] + this.radius*Math.sin(theta);
+ retVal[1] = this.center[1] - this.radius*Math.cos(theta);
+
+ return retVal;
+ }
+
+ return this;
+ },
+
+ // Special case of Arc (start = 0, end = 360)
+ Circle : function(center, radius) {
+ dojo.math.curves.CenteredArc.call(this, center, radius, 0, 360);
+ return this;
+ },
+
+ Path : function() {
+ var curves = [];
+ var weights = [];
+ var ranges = [];
+ var totalWeight = 0;
+
+ this.add = function(curve, weight) {
+ if( weight < 0 ) { dojo.raise("dojo.math.curves.Path.add: weight cannot be less than 0"); }
+ curves.push(curve);
+ weights.push(weight);
+ totalWeight += weight;
+ computeRanges();
+ }
+
+ this.remove = function(curve) {
+ for(var i = 0; i < curves.length; i++) {
+ if( curves[i] == curve ) {
+ curves.splice(i, 1);
+ totalWeight -= weights.splice(i, 1)[0];
+ break;
+ }
+ }
+ computeRanges();
+ }
+
+ this.removeAll = function() {
+ curves = [];
+ weights = [];
+ totalWeight = 0;
+ }
+
+ this.getValue = function(n) {
+ var found = false, value = 0;
+ for(var i = 0; i < ranges.length; i++) {
+ var r = ranges[i];
+ //w(r.join(" ... "));
+ if( n >= r[0] && n < r[1] ) {
+ var subN = (n - r[0]) / r[2];
+ value = curves[i].getValue(subN);
+ found = true;
+ break;
+ }
+ }
+
+ // FIXME: Do we want to assume we're at the end?
+ if( !found ) {
+ value = curves[curves.length-1].getValue(1);
+ }
+
+ for(j = 0; j < i; j++) {
+ value = dojo.math.points.translate(value, curves[j].getValue(1));
+ }
+ return value;
+ }
+
+ function computeRanges() {
+ var start = 0;
+ for(var i = 0; i < weights.length; i++) {
+ var end = start + weights[i] / totalWeight;
+ var len = end - start;
+ ranges[i] = [start, end, len];
+ start = end;
+ }
+ }
+
+ return this;
+ }
+};
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/matrix.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/matrix.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/matrix.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/matrix.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,295 @@
+dojo.provide("dojo.math.matrix");
+
+//
+// some of this code is based on
+// http://www.mkaz.com/math/MatrixCalculator.java
+// (published under a BSD Open Source License)
+//
+// the rest is from my vague memory of matricies in school [cal]
+//
+// the copying of arguments is a little excessive, and could be trimmed back in
+// the case where a function doesn't modify them at all (but some do!)
+//
+
+dojo.math.matrix.iDF = 0;
+
+dojo.math.matrix.multiply = function(a, b){
+
+ a = dojo.math.matrix.copy(a);
+ b = dojo.math.matrix.copy(b);
+
+ var ax = a[0].length;
+ var ay = a.length;
+ var bx = b[0].length;
+ var by = b.length;
+
+ if (ax != by){
+ dojo.debug("Can't multiply matricies of sizes "+ax+','+ay+' and '+bx+','+by);
+ return [[0]];
+ }
+
+ var c = [];
+
+ for(var k=0; k<ay; k++){
+ c[k] = [];
+ for(var i=0; i<bx; i++){
+
+ c[k][i] = 0;
+
+ for(var m=0; m<ax; m++){
+
+ c[k][i] += a[k][m]*b[m][i];
+ }
+ }
+ }
+
+ return c;
+}
+
+dojo.math.matrix.inverse = function(a){
+
+ a = dojo.math.matrix.copy(a);
+
+ // Formula used to Calculate Inverse:
+ // inv(A) = 1/det(A) * adj(A)
+
+ var tms = a.length;
+
+ var m = dojo.math.matrix.create(tms, tms);
+ var mm = dojo.math.matrix.adjoint(a);
+
+ var det = dojo.math.matrix.determinant(a);
+ var dd = 0;
+
+ if (det == 0){
+ dojo.debug("Determinant Equals 0, Not Invertible.");
+ return [[0]];
+ }else{
+ dd = 1 / det;
+ }
+
+ for (var i = 0; i < tms; i++)
+ for (var j = 0; j < tms; j++) {
+ m[i][j] = dd * mm[i][j];
+ }
+
+ return m;
+}
+
+dojo.math.matrix.determinant = function(a){
+
+ a = dojo.math.matrix.copy(a);
+
+ if (a.length != a[0].length){
+ dojo.debug("Can't calculate the determiant of a non-squre matrix!");
+ return 0;
+ }
+
+ var tms = a.length;
+ var det = 1;
+
+ var b = dojo.math.matrix.upperTriangle(a);
+
+ for (var i=0; i < tms; i++){
+ det *= b[i][i];
+ }
+
+ det = det * dojo.math.matrix.iDF;
+
+ return det;
+}
+
+dojo.math.matrix.upperTriangle = function(m){
+
+ m = dojo.math.matrix.copy(m);
+
+ var f1 = 0;
+ var temp = 0;
+ var tms = m.length;
+ var v = 1;
+
+ dojo.math.matrix.iDF = 1;
+
+ for (var col = 0; col < tms - 1; col++) {
+ for (var row = col + 1; row < tms; row++) {
+ v = 1;
+
+ var stop_loop = 0;
+
+ // check if 0 in diagonal
+ while ((m[col][col] == 0) && !stop_loop){
+
+ // if so switch until not
+ if (col + v >= tms){
+
+ // check if switched all rows
+ dojo.math.matrix.iDF = 0;
+ stop_loop = 1;
+ }else{
+ for (var c = 0; c < tms; c++) {
+ temp = m[col][c];
+ m[col][c] = m[col + v][c]; // switch rows
+ m[col + v][c] = temp;
+ }
+ v++; // count row switchs
+ dojo.math.matrix.iDF *= -1; // each switch changes determinant factor
+ }
+ }
+
+ if (m[col][col] != 0) {
+ f1 = (-1) * m[row][col] / m[col][col];
+ for (var i = col; i < tms; i++) {
+ m[row][i] = f1 * m[col][i] + m[row][i];
+ }
+ }
+ }
+ }
+
+ return m;
+}
+
+dojo.math.matrix.create = function(a, b){
+ var m = [];
+ for(var i=0; i<b; i++){
+ m[i] = [];
+ for(var j=0; j<a; j++){
+ m[i][j] = 0;
+ }
+ }
+ return m;
+}
+
+dojo.math.matrix.adjoint = function(a){
+
+ a = dojo.math.matrix.copy(a);
+
+ var tms = a.length;
+
+ if (a.length != a[0].length){
+ dojo.debug("Can't find the adjoint of a non-square matrix");
+ return [[0]];
+ }
+
+ if (tms == 1){
+ dojo.debug("Can't find the adjoint of a 1x1 matrix");
+ return [[0]];
+ }
+
+ var m = dojo.math.matrix.create(tms, tms);
+
+ var ii = 0;
+ var jj = 0;
+ var ia = 0;
+ var ja = 0;
+ var det = 0;
+
+ for (var i = 0; i < tms; i++){
+ for (var j = 0; j < tms; j++){
+
+ ia = 0;
+ ja = 0;
+
+ var ap = dojo.math.matrix.create(tms-1, tms-1);
+
+ for (ii = 0; ii < tms; ii++) {
+ for (jj = 0; jj < tms; jj++) {
+
+ if ((ii != i) && (jj != j)) {
+ ap[ia][ja] = a[ii][jj];
+ ja++;
+ }
+
+ }
+
+ if ((ii != i) && (jj != j)) {
+ ia++;
+ }
+ ja = 0;
+ }
+
+ det = dojo.math.matrix.determinant(ap);
+ m[i][j] = Math.pow(-1 , (i + j)) * det;
+ }
+ }
+
+ m = dojo.math.matrix.transpose(m);
+
+ return m;
+}
+
+dojo.math.matrix.transpose = function(a){
+
+ a = dojo.math.matrix.copy(a);
+
+ var m = dojo.math.matrix.create(a.length, a[0].length);
+
+ for (var i = 0; i < a.length; i++)
+ for (var j = 0; j < a[i].length; j++)
+ m[j][i] = a[i][j];
+ return m;
+}
+
+dojo.math.matrix.format = function(a){
+
+ function format_int(x){
+ var dp = 5;
+ var fac = Math.pow(10 , dp);
+ var a = Math.round(x*fac)/fac;
+ var b = a.toString();
+ if (b.charAt(0) != '-'){ b = ' ' + b;}
+ var has_dp = 0;
+ for(var i=1; i<b.length; i++){
+ if (b.charAt(i) == '.'){ has_dp = 1; }
+ }
+ if (!has_dp){ b += '.'; }
+ while(b.length < dp+3){ b += '0'; }
+ return b;
+ }
+
+ var ya = a.length;
+ var xa = a[0].length;
+
+ var buffer = '';
+
+ for (var y=0; y<ya; y++){
+ buffer += '| ';
+ for (var x=0; x<xa; x++){
+ buffer += format_int(a[y][x]) + ' ';
+ }
+ buffer += '|\n';
+ }
+
+ return buffer;
+}
+
+dojo.math.matrix.copy = function(a){
+
+ var ya = a.length;
+ var xa = a[0].length;
+
+ var m = dojo.math.matrix.create(xa, ya);
+
+ for (var y=0; y<ya; y++){
+ for (var x=0; x<xa; x++){
+ m[y][x] = a[y][x];
+ }
+ }
+
+ return m;
+}
+
+dojo.math.matrix.scale = function(k, a){
+
+ a = dojo.math.matrix.copy(a);
+
+ var ya = a.length;
+ var xa = a[0].length;
+
+ for (var y=0; y<ya; y++){
+ for (var x=0; x<xa; x++){
+ a[y][x] *= k;
+ }
+ }
+
+ return a;
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/points.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/points.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/points.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/math/points.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,37 @@
+dojo.provide("dojo.math.points");
+dojo.require("dojo.math");
+
+// TODO: add a Point class?
+dojo.math.points = {
+ translate: function(a, b) {
+ if( a.length != b.length ) {
+ dojo.raise("dojo.math.translate: points not same size (a:[" + a + "], b:[" + b + "])");
+ }
+ var c = new Array(a.length);
+ for(var i = 0; i < a.length; i++) {
+ c[i] = a[i] + b[i];
+ }
+ return c;
+ },
+
+ midpoint: function(a, b) {
+ if( a.length != b.length ) {
+ dojo.raise("dojo.math.midpoint: points not same size (a:[" + a + "], b:[" + b + "])");
+ }
+ var c = new Array(a.length);
+ for(var i = 0; i < a.length; i++) {
+ c[i] = (a[i] + b[i]) / 2;
+ }
+ return c;
+ },
+
+ invert: function(a) {
+ var b = new Array(a.length);
+ for(var i = 0; i < a.length; i++) { b[i] = -a[i]; }
+ return b;
+ },
+
+ distance: function(a, b) {
+ return Math.sqrt(Math.pow(b[0]-a[0], 2) + Math.pow(b[1]-a[1], 2));
+ }
+};
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,107 @@
+dojo.provide("dojo.profile");
+
+dojo.profile = new function(){
+ var profiles = {};
+ var pns = [];
+
+ this.start = function(name){
+ if(!profiles[name]){
+ profiles[name] = {iters: 0, total: 0};
+ pns[pns.length] = name;
+ }else{
+ if(profiles[name]["start"]){
+ this.end(name);
+ }
+ }
+ profiles[name].end = null;
+ profiles[name].start = new Date();
+ }
+
+ this.end = function(name){
+ var ed = new Date();
+ if((profiles[name])&&(profiles[name]["start"])){
+ with(profiles[name]){
+ end = ed;
+ total += (end - start);
+ start = null;
+ iters++;
+ }
+ }else{
+ // oops! bad call to end(), what should we do here?
+ return true;
+ }
+ }
+
+ this.stop = this.end;
+
+ this.dump = function(appendToDoc){
+ var tbl = document.createElement("table");
+ with(tbl.style){
+ border = "1px solid black";
+ borderCollapse = "collapse";
+ }
+ var hdr = tbl.createTHead();
+ var hdrtr = hdr.insertRow(0);
+ // document.createElement("tr");
+ var cols = ["Identifier","Calls","Total","Avg"];
+ for(var x=0; x<cols.length; x++){
+ var ntd = hdrtr.insertCell(x);
+ with(ntd.style){
+ backgroundColor = "#225d94";
+ color = "white";
+ borderBottom = "1px solid black";
+ borderRight = "1px solid black";
+ fontFamily = "tahoma";
+ fontWeight = "bolder";
+ paddingLeft = paddingRight = "5px";
+ }
+ ntd.appendChild(document.createTextNode(cols[x]));
+ }
+
+ for(var x=0; x < pns.length; x++){
+ var prf = profiles[pns[x]];
+ this.end(pns[x]);
+ if(prf.iters>0){
+ var bdytr = tbl.insertRow(true);
+ var vals = [pns[x], prf.iters, prf.total, parseInt(prf.total/prf.iters)];
+ for(var y=0; y<vals.length; y++){
+ var cc = bdytr.insertCell(y);
+ cc.appendChild(document.createTextNode(vals[y]));
+ with(cc.style){
+ borderBottom = "1px solid gray";
+ paddingLeft = paddingRight = "5px";
+ if(x%2){
+ backgroundColor = "#e1f1ff";
+ }
+ if(y>0){
+ textAlign = "right";
+ borderRight = "1px solid gray";
+ }else{
+ borderRight = "1px solid black";
+ }
+ }
+ }
+ }
+ }
+
+ if(appendToDoc){
+ var ne = document.createElement("div");
+ ne.id = "profileOutputTable";
+ with(ne.style){
+ fontFamily = "Courier New, monospace";
+ fontSize = "12px";
+ lineHeight = "16px";
+ borderTop = "1px solid black";
+ padding = "10px";
+ }
+ if(document.getElementById("profileOutputTable")){
+ document.body.replaceChild(ne, document.getElementById("profileOutputTable"));
+ }else{
+ document.body.appendChild(ne);
+ }
+ ne.appendChild(tbl);
+ }
+
+ return tbl;
+ }
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile/__package__.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile/__package__.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile/__package__.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/profile/__package__.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,5 @@
+dojo.profile = null;
+dojo.hostenv.conditionalLoadModule({
+ common: [ "dojo.profile" ]
+});
+dojo.hostenv.moduleLoaded("dojo.profile.*");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/__package__.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/__package__.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/__package__.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/__package__.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,4 @@
+dojo.hostenv.conditionalLoadModule({
+ common: ["dojo.reflect.reflection"]
+});
+dojo.hostenv.moduleLoaded("dojo.reflect.*");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/reflection.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/reflection.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/reflection.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/reflect/reflection.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,187 @@
+dojo.provide("dojo.reflect");
+
+/*****************************************************************
+ reflect.js
+ v.1.5.0
+ (c) 2003-2004 Thomas R. Trenka, Ph.D.
+
+ Derived from the reflection functions of f(m).
+ http://dojotoolkit.org
+ http://fm.dept-z.com
+
+ There is a dependency on the variable dJ_global, which
+ should always refer to the global object.
+******************************************************************/
+if(!dj_global){ var dj_global = this; }
+
+dojo.reflect = {} ;
+dojo.reflect.$unknownType = function(){ } ;
+dojo.reflect.ParameterInfo = function(name, type){
+ this.name = name ;
+ this.type = (type) ? type : dojo.reflect.$unknownType ;
+} ;
+dojo.reflect.PropertyInfo = function(name, type) {
+ this.name = name ;
+ this.type = (type) ? type : dojo.reflect.$unknownType ;
+} ;
+dojo.reflect.MethodInfo = function(name, fn){
+ var parse = function(f) {
+ var o = {} ;
+ var s = f.toString() ;
+ var param = ((s.substring(s.indexOf('(')+1, s.indexOf(')'))).replace(/\s+/g, "")).split(",") ;
+ o.parameters = [] ;
+ for (var i = 0; i < param.length; i++) {
+ o.parameters.push(new dojo.reflect.ParameterInfo(param[i])) ;
+ }
+ o.body = (s.substring(s.indexOf('{')+1, s.lastIndexOf('}'))).replace(/(^\s*)|(\s*$)/g, "") ;
+ return o ;
+ } ;
+
+ var tmp = parse(fn) ;
+ var p = tmp.parameters ;
+ var body = tmp.body ;
+
+ this.name = (name) ? name : "anonymous" ;
+ this.getParameters = function(){ return p ; } ;
+ this.getNullArgumentsObject = function() {
+ var a = [] ;
+ for (var i = 0; i < p.length; i++){
+ a.push(null);
+ }
+ return a ;
+ } ;
+ this.getBody = function() { return body ; } ;
+ this.type = Function ;
+ this.invoke = function(src, args){ return fn.apply(src, args) ; } ;
+} ;
+
+// Static object that can activate instances of the passed type.
+dojo.reflect.Activator = new (function(){
+ this.createInstance = function(type, args) {
+ switch (typeof(type)) {
+ case "function" : {
+ var o = {} ;
+ type.apply(o, args) ;
+ return o ;
+ } ;
+ case "string" : {
+ var o = {} ;
+ (dojo.reflect.Reflector.getTypeFromString(type)).apply(o, args) ;
+ return o ;
+ } ;
+ }
+ throw new Error("dojo.reflect.Activator.createInstance(): no such type exists.");
+ }
+})() ;
+
+dojo.reflect.Reflector = new (function(){
+ this.getTypeFromString = function(s) {
+ var parts = s.split("."), i = 0, obj = dj_global ;
+ do { obj = obj[parts[i++]] ; } while (i < parts.length && obj) ;
+ return (obj != dj_global) ? obj : null ;
+ };
+
+ this.typeExists = function(s) {
+ var parts = s.split("."), i = 0, obj = dj_global ;
+ do { obj = obj[parts[i++]] ; } while (i < parts.length && obj) ;
+ return (obj && obj != dj_global) ;
+ };
+
+ this.getFieldsFromType = function(s) {
+ var type = s ;
+ if (typeof(s) == "string") {
+ type = this.getTypeFromString(s) ;
+ }
+ var nullArgs = (new dojo.reflect.MethodInfo(type)).getNullArgumentsObject() ;
+ return this.getFields(dojo.reflect.Activator.createInstance(s, nullArgs)) ;
+ };
+
+ this.getPropertiesFromType = function(s) {
+ var type = s ;
+ if (typeof(s) == "string") {
+ type = this.getTypeFromString(s);
+ }
+ var nullArgs = (new dojo.reflect.MethodInfo(type)).getNullArgumentsObject() ;
+ return this.getProperties(dojo.reflect.Activator.createInstance(s, nullArgs)) ;
+ };
+
+ this.getMethodsFromType = function(s) {
+ var type = s ;
+ if (typeof(s) == "string") {
+ type = this.getTypeFromString(s) ;
+ }
+ var nullArgs = (new dojo.reflect.MethodInfo(type)).getNullArgumentsObject() ;
+ return this.getMethods(dojo.reflect.Activator.createInstance(s, nullArgs)) ;
+ };
+
+ this.getType = function(o) { return o.constructor ; } ;
+
+ this.getFields = function(obj) {
+ var arr = [] ;
+ for (var p in obj) {
+ if(this.getType(obj[p]) != Function){
+ arr.push(new dojo.reflect.PropertyInfo(p, this.getType(obj[p]))) ;
+ }else{
+ arr.push(new dojo.reflect.MethodInfo(p, obj[p]));
+ }
+ }
+ return arr ;
+ };
+
+ this.getProperties = function(obj) {
+ var arr = [] ;
+ var fi = this.getFields(obj) ;
+ for (var i = 0; i < fi.length; i++){
+ if (this.isInstanceOf(fi[i], dojo.reflect.PropertyInfo)){
+ arr.push(fi[i]) ;
+ }
+ }
+ return arr ;
+ };
+
+ this.getMethods = function(obj) {
+ var arr = [] ;
+ var fi = this.getFields(obj) ;
+ for (var i = 0; i < fi.length; i++){
+ if (this.isInstanceOf(fi[i], dojo.reflect.MethodInfo)){
+ arr.push(fi[i]) ;
+ }
+ }
+ return arr ;
+ };
+
+ /*
+ this.implements = function(o, type) {
+ if (this.isSubTypeOf(o, type)) return false ;
+ var f = this.getFieldsFromType(type) ;
+ for (var i = 0; i < f.length; i++) {
+ if (typeof(o[(f[i].name)]) == "undefined"){
+ return false;
+ }
+ }
+ return true ;
+ };
+ */
+
+ this.getBaseClass = function(o) {
+ if (o.getType().prototype.prototype.constructor){
+ return (o.getType()).prototype.prototype.constructor ;
+ }
+ return Object ;
+ } ;
+
+ this.isInstanceOf = function(o, type) {
+ return (this.getType(o) == type) ;
+ };
+
+ this.isSubTypeOf = function(o, type) {
+ return (o instanceof type) ;
+ };
+
+ this.isBaseTypeOf = function(o, type) {
+ return (type instanceof o);
+ };
+})();
+
+// back-compat
+dojo.provide("dojo.reflect.reflection");
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/regexp.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/regexp.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/regexp.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/regexp.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,556 @@
+dojo.provide("dojo.regexp");
+dojo.provide("dojo.regexp.us");
+
+// *** Regular Expression Generators ***
+
+/**
+ Builds a RE that matches a top-level domain.
+
+ @param flags An object.
+ flags.allowCC Include 2 letter country code domains. Default is true.
+ flags.allowGeneric Include the generic domains. Default is true.
+ flags.allowInfra Include infrastructure domains. Default is true.
+
+ @return A string for a regular expression for a top-level domain.
+*/
+dojo.regexp.tld = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.allowCC != "boolean") { flags.allowCC = true; }
+ if (typeof flags.allowInfra != "boolean") { flags.allowInfra = true; }
+ if (typeof flags.allowGeneric != "boolean") { flags.allowGeneric = true; }
+
+ // Infrastructure top-level domain - only one at present
+ var infraRE = "arpa";
+
+ // Generic top-level domains RE.
+ var genericRE =
+ "aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|xxx|jobs|mobi|post";
+
+ // Country Code top-level domains RE
+ var ccRE =
+ "ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|" +
+ "bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|" +
+ "ec|ee|eg|er|es|et|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|" +
+ "hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|" +
+ "lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|" +
+ "mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|" +
+ "ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sk|sl|sm|sn|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|" +
+ "to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw";
+
+ // Build top-level domain RE
+ var a = [];
+ if (flags.allowCC) { a.push(ccRE); }
+ if (flags.allowInfra) { a.push(infraRE); }
+ if (flags.allowGeneric) { a.push(genericRE); }
+
+ var tldRE = "";
+ if (a.length > 0) {
+ tldRE = "(" + a.join("|") + ")";
+ }
+
+ return tldRE;
+}
+
+/**
+ Builds a RE that matches an IP Address.
+ Supports 5 formats for IPv4: dotted decimal, dotted hex, dotted octal, decimal and hexadecimal.
+ Supports 2 formats for Ipv6.
+
+ @param flags An object. All flags are boolean with default = true.
+ flags.allowDottedDecimal Example, 207.142.131.235. No zero padding.
+ flags.allowDottedHex Example, 0x18.0x11.0x9b.0x28. Case insensitive. Zero padding allowed.
+ flags.allowDottedOctal Example, 0030.0021.0233.0050. Zero padding allowed.
+ flags.allowDecimal Example, 3482223595. A decimal number between 0-4294967295.
+ flags.allowHex Example, 0xCF8E83EB. Hexadecimal number between 0x0-0xFFFFFFFF.
+ Case insensitive. Zero padding allowed.
+ flags.allowIPv6 IPv6 address written as eight groups of four hexadecimal digits.
+ flags.allowHybrid IPv6 address written as six groups of four hexadecimal digits
+ followed by the usual 4 dotted decimal digit notation of IPv4. x:x:x:x:x:x:d.d.d.d
+
+ @return A string for a regular expression for an IP address.
+*/
+dojo.regexp.ipAddress = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.allowDottedDecimal != "boolean") { flags.allowDottedDecimal = true; }
+ if (typeof flags.allowDottedHex != "boolean") { flags.allowDottedHex = true; }
+ if (typeof flags.allowDottedOctal != "boolean") { flags.allowDottedOctal = true; }
+ if (typeof flags.allowDecimal != "boolean") { flags.allowDecimal = true; }
+ if (typeof flags.allowHex != "boolean") { flags.allowHex = true; }
+ if (typeof flags.allowIPv6 != "boolean") { flags.allowIPv6 = true; }
+ if (typeof flags.allowHybrid != "boolean") { flags.allowHybrid = true; }
+
+ // decimal-dotted IP address RE.
+ var dottedDecimalRE =
+ // Each number is between 0-255. Zero padding is not allowed.
+ "((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])";
+
+ // dotted hex IP address RE. Each number is between 0x0-0xff. Zero padding is allowed, e.g. 0x00.
+ var dottedHexRE = "(0[xX]0*[\\da-fA-F]?[\\da-fA-F]\\.){3}0[xX]0*[\\da-fA-F]?[\\da-fA-F]";
+
+ // dotted octal IP address RE. Each number is between 0000-0377.
+ // Zero padding is allowed, but each number must have at least 4 characters.
+ var dottedOctalRE = "(0+[0-3][0-7][0-7]\\.){3}0+[0-3][0-7][0-7]";
+
+ // decimal IP address RE. A decimal number between 0-4294967295.
+ var decimalRE = "(0|[1-9]\\d{0,8}|[1-3]\\d{9}|4[01]\\d{8}|42[0-8]\\d{7}|429[0-3]\\d{6}|" +
+ "4294[0-8]\\d{5}|42949[0-5]\\d{4}|429496[0-6]\\d{3}|4294967[01]\\d{2}|42949672[0-8]\\d|429496729[0-5])";
+
+ // hexadecimal IP address RE.
+ // A hexadecimal number between 0x0-0xFFFFFFFF. Case insensitive. Zero padding is allowed.
+ var hexRE = "0[xX]0*[\\da-fA-F]{1,8}";
+
+ // IPv6 address RE.
+ // The format is written as eight groups of four hexadecimal digits, x:x:x:x:x:x:x:x,
+ // where x is between 0000-ffff. Zero padding is optional. Case insensitive.
+ var ipv6RE = "([\\da-fA-F]{1,4}\\:){7}[\\da-fA-F]{1,4}";
+
+ // IPv6/IPv4 Hybrid address RE.
+ // The format is written as six groups of four hexadecimal digits,
+ // followed by the 4 dotted decimal IPv4 format. x:x:x:x:x:x:d.d.d.d
+ var hybridRE = "([\\da-fA-F]{1,4}\\:){6}" +
+ "((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])";
+
+ // Build IP Address RE
+ var a = [];
+ if (flags.allowDottedDecimal) { a.push(dottedDecimalRE); }
+ if (flags.allowDottedHex) { a.push(dottedHexRE); }
+ if (flags.allowDottedOctal) { a.push(dottedOctalRE); }
+ if (flags.allowDecimal) { a.push(decimalRE); }
+ if (flags.allowHex) { a.push(hexRE); }
+ if (flags.allowIPv6) { a.push(ipv6RE); }
+ if (flags.allowHybrid) { a.push(hybridRE); }
+
+ var ipAddressRE = "";
+ if (a.length > 0) {
+ ipAddressRE = "(" + a.join("|") + ")";
+ }
+
+ return ipAddressRE;
+}
+
+/**
+ Builds a RE that matches a host.
+ A host is a domain name or an IP address, possibly followed by a port number.
+
+ @param flags An object.
+ flags.allowIP Allow an IP address for hostname. Default is true.
+ flags.allowLocal Allow the host to be "localhost". Default is false.
+ flags.allowPort Allow a port number to be present. Default is true.
+ flags in regexp.ipAddress can be applied.
+ flags in regexp.tld can be applied.
+
+ @return A string for a regular expression for a host.
+*/
+dojo.regexp.host = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.allowIP != "boolean") { flags.allowIP = true; }
+ if (typeof flags.allowLocal != "boolean") { flags.allowLocal = false; }
+ if (typeof flags.allowPort != "boolean") { flags.allowPort = true; }
+
+ // Domain names must start with letter and can not end with a dash.
+ var domainNameRE = "([a-zA-Z]([-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?\\.)+" + dojo.regexp.tld(flags);
+
+ // port number RE
+ portRE = ( flags.allowPort ) ? "(\\:" + dojo.regexp.integer({allowSign: false}) + ")?" : "";
+
+ // build host RE
+ var hostNameRE = domainNameRE;
+ if (flags.allowIP) { hostNameRE += "|" + dojo.regexp.ipAddress(flags); }
+ if (flags.allowLocal) { hostNameRE += "|localhost"; }
+
+ return "(" + hostNameRE + ")" + portRE;
+}
+
+/**
+ Builds a regular expression that matches a URL.
+
+ @param flags An object.
+ flags.scheme Can be true, false, or [true, false].
+ This means: required, not allowed, or match either one.
+ flags in regexp.host can be applied.
+ flags in regexp.ipAddress can be applied.
+ flags in regexp.tld can be applied.
+
+ @return A string for a regular expression for a URL.
+*/
+dojo.regexp.url = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.scheme == "undefined") { flags.scheme = [true, false]; }
+
+ // Scheme RE
+ var protocalRE = dojo.regexp.buildGroupRE(flags.scheme,
+ function(q) { if (q) { return "(https?|ftps?)\\://"; } return ""; }
+ );
+
+ // Path and query RE
+ var pathRE = "(/[^\\s/]+)*(\\?\\S*)?";
+
+ return (protocalRE + dojo.regexp.host(flags) + pathRE);
+}
+
+/**
+ Builds a regular expression that matches an email address.
+
+ @param flags An object.
+ flags.allowCruft Allow address like <ma...@yahoo.com>. Default is false.
+ flags in regexp.host can be applied.
+ flags in regexp.ipAddress can be applied.
+ flags in regexp.tld can be applied.
+
+ @return A string for a regular expression for an email address.
+*/
+dojo.regexp.emailAddress = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.allowCruft != "boolean") { flags.allowCruft = false; }
+ flags.allowPort = false; // invalid in email addresses
+
+ // user name RE - apostrophes are valid if there's not 2 in a row
+ var usernameRE = "([\\da-z]+[-._+&'])*[\\da-z]+";
+
+ // build emailAddress RE
+ var emailAddressRE = usernameRE + "@" + dojo.regexp.host(flags);
+
+ // Allow email addresses with cruft
+ if ( flags.allowCruft ) {
+ emailAddressRE = "<?(mailto\\:)?" + emailAddressRE + ">?";
+ }
+
+ return emailAddressRE;
+}
+
+/**
+ Builds a regular expression that matches a list of email addresses.
+
+ @param flags An object.
+ flags.listSeparator The character used to separate email addresses. Default is newline, "\n".
+ flags in regexp.emailAddress can be applied.
+ flags in regexp.host can be applied.
+ flags in regexp.ipAddress can be applied.
+ flags in regexp.tld can be applied.
+
+ @return A string for a regular expression for an email address list.
+*/
+dojo.regexp.emailAddressList = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.listSeparator != "string") { flags.listSeparator = "\\n"; }
+
+ // build a RE for an Email Address List
+ var emailAddressRE = dojo.regexp.emailAddress(flags);
+ var emailAddressListRE = "(" + emailAddressRE + "\\s*[" + flags.listSeparator + "]\\s*)*" +
+ emailAddressRE + "\\s*[" + flags.listSeparator + "]?\\s*";
+
+ return emailAddressListRE;
+}
+
+/**
+ Builds a regular expression that matches an integer.
+
+ @param flags An object.
+ flags.signed The leading plus-or-minus sign. Can be true, false, or [true, false].
+ Default is [true, false], (i.e. will match if it is signed or unsigned).
+ flags.separator The character used as the thousands separator. Default is no separator.
+ For more than one symbol use an array, e.g. [",", ""], makes ',' optional.
+
+ @return A string for a regular expression for an integer.
+*/
+dojo.regexp.integer = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.signed == "undefined") { flags.signed = [true, false]; }
+ if (typeof flags.separator == "undefined") { flags.separator = ""; }
+
+ // build sign RE
+ var signRE = dojo.regexp.buildGroupRE(flags.signed,
+ function(q) { if (q) { return "[-+]"; } return ""; }
+ );
+
+ // number RE
+ var numberRE = dojo.regexp.buildGroupRE(flags.separator,
+ function(sep) {
+ if ( sep == "" ) {
+ return "(0|[1-9]\\d*)";
+ }
+ return "(0|[1-9]\\d{0,2}([" + sep + "]\\d{3})*)";
+ }
+ );
+ var numberRE;
+
+ // integer RE
+ return (signRE + numberRE);
+}
+
+/**
+ Builds a regular expression to match a real number in exponential notation.
+
+ @param flags An object.
+ flags.places The integer number of decimal places.
+ If not given, the decimal part is optional and the number of places is unlimited.
+ flags.decimal A string for the character used as the decimal point. Default is ".".
+ flags.exponent Express in exponential notation. Can be true, false, or [true, false].
+ Default is [true, false], (i.e. will match if the exponential part is present are not).
+ flags.eSigned The leading plus-or-minus sign on the exponent. Can be true, false,
+ or [true, false]. Default is [true, false], (i.e. will match if it is signed or unsigned).
+ flags in regexp.integer can be applied.
+
+ @return A string for a regular expression for a real number.
+*/
+dojo.regexp.realNumber = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.places != "number") { flags.places = Infinity; }
+ if (typeof flags.decimal != "string") { flags.decimal = "."; }
+ if (typeof flags.exponent == "undefined") { flags.exponent = [true, false]; }
+ if (typeof flags.eSigned == "undefined") { flags.eSigned = [true, false]; }
+
+ // integer RE
+ var integerRE = dojo.regexp.integer(flags);
+
+ // decimal RE
+ var decimalRE = "";
+ if ( flags.places == Infinity) {
+ decimalRE = "(\\" + flags.decimal + "\\d+)?";
+ }
+ else if ( flags.places > 0) {
+ decimalRE = "\\" + flags.decimal + "\\d{" + flags.places + "}";
+ }
+
+ // exponent RE
+ var exponentRE = dojo.regexp.buildGroupRE(flags.exponent,
+ function(q) {
+ if (q) { return "([eE]" + dojo.regexp.integer({signed: flags.eSigned}) + ")"; }
+ return "";
+ }
+ );
+
+ // real number RE
+ return (integerRE + decimalRE + exponentRE);
+}
+
+/**
+ Builds a regular expression to match a monetary value.
+
+ @param flags An object.
+ flags.signed The leading plus-or-minus sign. Can be true, false, or [true, false].
+ Default is [true, false], (i.e. will match if it is signed or unsigned).
+ flags.symbol A currency symbol such as Yen "¥", Pound "£", or the Euro sign "".
+ Default is "$". For more than one symbol use an array, e.g. ["$", ""], makes $ optional.
+ flags.placement The symbol can come "before" the number or "after". Default is "before".
+ flags.separator The character used as the thousands separator. The default is ",".
+ flags.cents The two decimal places for cents. Can be true, false, or [true, false].
+ Default is [true, false], (i.e. will match if cents are present are not).
+ flags.decimal A string for the character used as the decimal point. Default is ".".
+
+ @return A string for a regular expression for a monetary value.
+*/
+dojo.regexp.currency = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.signed == "undefined") { flags.signed = [true, false]; }
+ if (typeof flags.symbol == "undefined") { flags.symbol = "$"; }
+ if (typeof flags.placement != "string") { flags.placement = "before"; }
+ if (typeof flags.separator != "string") { flags.separator = ","; }
+ if (typeof flags.cents == "undefined") { flags.cents = [true, false]; }
+ if (typeof flags.decimal != "string") { flags.decimal = "."; }
+
+ // build sign RE
+ var signRE = dojo.regexp.buildGroupRE(flags.signed,
+ function(q) { if (q) { return "[-+]"; } return ""; }
+ );
+
+ // build symbol RE
+ var symbolRE = dojo.regexp.buildGroupRE(flags.symbol,
+ function(symbol) {
+ // escape all special characters
+ return "\\s?" + symbol.replace( /([.$?*!=:|\\\/^])/g, "\\$1") + "\\s?";
+ }
+ );
+
+ // number RE
+ var numberRE = dojo.regexp.integer( {signed: false, separator: flags.separator} );
+
+ // build cents RE
+ var centsRE = dojo.regexp.buildGroupRE(flags.cents,
+ function(q) { if (q) { return "(\\" + flags.decimal + "\\d\\d)"; } return ""; }
+ );
+
+ // build currency RE
+ var currencyRE;
+ if (flags.placement == "before") {
+ currencyRE = signRE + symbolRE + numberRE + centsRE;
+ }
+ else {
+ currencyRE = signRE + numberRE + centsRE + symbolRE;
+ }
+
+ return currencyRE;
+}
+
+/**
+ A regular expression to match US state and territory abbreviations.
+
+ @param flags An object.
+ flags.allowTerritories Allow Guam, Puerto Rico, etc. Default is true.
+ flags.allowMilitary Allow military 'states', e.g. Armed Forces Europe (AE). Default is true.
+
+ @return A string for a regular expression for a US state.
+*/
+dojo.regexp.us.state = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.allowTerritories != "boolean") { flags.allowTerritories = true; }
+ if (typeof flags.allowMilitary != "boolean") { flags.allowMilitary = true; }
+
+ // state RE
+ var statesRE =
+ "AL|AK|AZ|AR|CA|CO|CT|DE|DC|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|" +
+ "NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY";
+
+ // territories RE
+ var territoriesRE = "AS|FM|GU|MH|MP|PW|PR|VI";
+
+ // military states RE
+ var militaryRE = "AA|AE|AP";
+
+ // Build states and territories RE
+ if (flags.allowTerritories) { statesRE += "|" + territoriesRE; }
+ if (flags.allowMilitary) { statesRE += "|" + militaryRE; }
+
+ return "(" + statesRE + ")";
+}
+
+/**
+ Builds a regular expression to match any International format for time.
+ The RE can match one format or one of multiple formats.
+
+ Format
+ h 12 hour, no zero padding.
+ hh 12 hour, has leading zero.
+ H 24 hour, no zero padding.
+ HH 24 hour, has leading zero.
+ m minutes, no zero padding.
+ mm minutes, has leading zero.
+ s seconds, no zero padding.
+ ss seconds, has leading zero.
+ t am or pm, case insensitive.
+ All other characters must appear literally in the expression.
+
+ Example
+ "h:m:s t" -> 2:5:33 PM
+ "HH:mm:ss" -> 14:05:33
+
+ @param flags An object.
+ flags.format A string or an array of strings. Default is "h:mm:ss t".
+ flags.amSymbol The symbol used for AM. Default is "AM".
+ flags.pmSymbol The symbol used for PM. Default is "PM".
+
+ @return A string for a regular expression for a time value.
+*/
+dojo.regexp.time = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.format == "undefined") { flags.format = "h:mm:ss t"; }
+ if (typeof flags.amSymbol != "string") { flags.amSymbol = "AM"; }
+ if (typeof flags.pmSymbol != "string") { flags.pmSymbol = "PM"; }
+
+ // Converts a time format to a RE
+ var timeRE = function(format) {
+ // escape all special characters
+ format = format.replace( /([.$?*!=:|{}\(\)\[\]\\\/^])/g, "\\$1");
+ var amRE = flags.amSymbol.replace( /([.$?*!=:|{}\(\)\[\]\\\/^])/g, "\\$1");
+ var pmRE = flags.pmSymbol.replace( /([.$?*!=:|{}\(\)\[\]\\\/^])/g, "\\$1");
+
+ // replace tokens with Regular Expressions
+ format = format.replace("hh", "(0[1-9]|1[0-2])");
+ format = format.replace("h", "([1-9]|1[0-2])");
+ format = format.replace("HH", "([01][0-9]|2[0-3])");
+ format = format.replace("H", "([0-9]|1[0-9]|2[0-3])");
+ format = format.replace("mm", "([0-5][0-9])");
+ format = format.replace("m", "([1-5][0-9]|[0-9])");
+ format = format.replace("ss", "([0-5][0-9])");
+ format = format.replace("s", "([1-5][0-9]|[0-9])");
+ format = format.replace("t", "\\s?(" + amRE + "|" + pmRE + ")\\s?" );
+
+ return format;
+ };
+
+ // build RE for multiple time formats
+ return dojo.regexp.buildGroupRE(flags.format, timeRE);
+}
+
+/**
+ Builds a regular expression to match any sort of number based format.
+ Use it for phone numbers, social security numbers, zip-codes, etc.
+ The RE can match one format or one of multiple formats.
+
+ Format
+ # Stands for a digit, 0-9.
+ ? Stands for an optional digit, 0-9 or nothing.
+ All other characters must appear literally in the expression.
+
+ Example
+ "(###) ###-####" -> (510) 542-9742
+ "(###) ###-#### x#???" -> (510) 542-9742 x153
+ "###-##-####" -> 506-82-1089 i.e. social security number
+ "#####-####" -> 98225-1649 i.e. zip code
+
+ @param flags An object.
+ flags.format A string or an Array of strings for multiple formats.
+ @return A string for a regular expression for the number format(s).
+*/
+dojo.regexp.numberFormat = function(flags) {
+ // assign default values to missing paramters
+ flags = (typeof flags == "object") ? flags : {};
+ if (typeof flags.format == "undefined") { flags.format = "###-###-####"; }
+
+ // Converts a number format to RE.
+ var digitRE = function(format) {
+ // escape all special characters, except '?'
+ format = format.replace( /([.$*!=:|{}\(\)\[\]\\\/^])/g, "\\$1");
+
+ // Now replace '?' with Regular Expression
+ format = format.replace(/\?/g, "\\d?");
+
+ // replace # with Regular Expression
+ format = format.replace(/#/g, "\\d");
+
+ return format;
+ };
+
+ // build RE for multiple number formats
+ return dojo.regexp.buildGroupRE(flags.format, digitRE);
+}
+
+
+/**
+ This is basically a utility function used by some of the RE generators.
+ Builds a regular expression that groups subexpressions.
+ The subexpressions are constructed by the function, re, in the second parameter.
+ re builds one subexpression for each elem in the array a, in the first parameter.
+
+ @param a A single value or an array of values.
+ @param re A function. Takes one parameter and converts it to a regular expression.
+ @return A string for a regular expression that groups all the subexpressions.
+*/
+dojo.regexp.buildGroupRE = function(a, re) {
+
+ // case 1: a is a single value.
+ if ( !( a instanceof Array ) ) {
+ return re(a);
+ }
+
+ // case 2: a is an array
+ var b = [];
+ for (var i = 0; i < a.length; i++) {
+ // convert each elem to a RE
+ b.push(re(a[i]));
+ }
+
+ // join the REs as alternatives in a RE group.
+ return "(" + b.join("|") + ")";
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/storage.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/storage.js?rev=354516&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/storage.js (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/dojo/src/storage.js Tue Dec 6 11:29:56 2005
@@ -0,0 +1,62 @@
+// FIXME: should we require JSON here?
+dojo.require("dojo.lang.*");
+dojo.provide("dojo.storage");
+dojo.provide("dojo.storage.StorageProvider");
+
+dojo.storage = new function(){
+ this.provider = null;
+
+ // similar API as with dojo.io.addTransport()
+ this.setProvider = function(obj){
+ this.provider = obj;
+ }
+
+ this.set = function(key, value, namespace){
+ // FIXME: not very expressive, doesn't have a way of indicating queuing
+ if(!this.provider){
+ return false;
+ }
+ return this.provider.set(key, value, namespace);
+ }
+
+ this.get = function(key, namespace){
+ if(!this.provider){
+ return false;
+ }
+ return this.provider.get(key, namespace);
+ }
+
+ this.remove = function(key, namespace){
+ return this.provider.remove(key, namespace);
+ }
+}
+
+dojo.storage.StorageProvider = function(){
+}
+
+dojo.lang.extend(dojo.storage.StorageProvider, {
+ namespace: "*",
+ initialized: false,
+
+ free: function(){
+ dojo.unimplemented("dojo.storage.StorageProvider.free");
+ return 0;
+ },
+
+ freeK: function(){
+ return dojo.math.round(this.free()/1024, 0);
+ },
+
+ set: function(key, value, namespace){
+ dojo.unimplemented("dojo.storage.StorageProvider.set");
+ },
+
+ get: function(key, namespace){
+ dojo.unimplemented("dojo.storage.StorageProvider.get");
+ },
+
+ remove: function(key, value, namespace){
+ dojo.unimplemented("dojo.storage.StorageProvider.set");
+ },
+
+});
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org