Merged with helma/master

This commit is contained in:
Tobi Schäfer 2013-04-07 17:27:18 +02:00
parent ff7bba76cf
commit 59d127e089
11 changed files with 75 additions and 241 deletions

5
.gitignore vendored
View file

@ -1,8 +1,3 @@
.*
apps
db/*
lib/ext
modules/
server.properties server.properties
classes/* classes/*
launcher.jar launcher.jar

9
.gitmodules vendored
View file

@ -1,9 +0,0 @@
[submodule "modules"]
path = modules
url = ./modules
[submodule "swarm"]
path = swarm
url = ./swarm
[submodule "apps"]
path = apps
url = ./apps

17
modules/README Normal file
View file

@ -0,0 +1,17 @@
<p>HelmaLib is organized into two groups of modules:</p>
<ul>
<li>modules/core which contains extensions to core JavaScript types such as
Object, Array, or Date.</li>
<li>modules/helma which provides new functionality to JavaScript, usually by
wrapping a Java library.</li>
</ul>
<p>To use a HelmaLib module in your Helma application, you need to add it to the
app's repositories. The simplest way to do so is by using the app.addRepository()
function:</p>
<pre> app.addRepository("modules/helma/Search.js");</pre>
<p>If you are looking for more Helma libraries, be sure to check out the
<a href="https://opensvn.csie.org/traccgi/jala/wiki">Jala project</a>!</p>

View file

@ -23,7 +23,6 @@
* @addon * @addon
*/ */
/** /**
* Check if this array contains a specific value. * Check if this array contains a specific value.
* @param {Object} val the value to check * @param {Object} val the value to check

View file

@ -17,7 +17,7 @@
/** /**
* @fileoverview Implements some useful macro filters. * @fileoverview Implements some useful macro filters.
* <br /><br /> * <br /><br />
* To use this optional module, its repository needs to be added to the * To use this optional module, its repository needs to be added to the
* application, for example by calling app.addRepository('modules/core/Filters.js') * application, for example by calling app.addRepository('modules/core/Filters.js')
*/ */
@ -65,7 +65,7 @@ function titleize_filter(input) {
/** /**
* Cuts a String at a certain position, and * Cuts a String at a certain position, and
* optionally appends a suffix, if truncation * optionally appends a suffix, if truncation
* has occurred. * has occurred.
* *
@ -118,7 +118,7 @@ function escapeXml_filter(input) {
* @see http://www.google.com/codesearch?q=escapeHtml * @see http://www.google.com/codesearch?q=escapeHtml
*/ */
function escapeHtml_filter(input) { function escapeHtml_filter(input) {
var replace = Packages.org.mortbay.util.StringUtil.replace; var replace = Packages.org.eclipse.jetty.util.StringUtil.replace;
var str = (input || "").toString(); var str = (input || "").toString();
return replace(replace(replace(replace(str, '&', '&amp;'), '"', '&quot;'), '>', '&gt;'), '<', '&lt;'); return replace(replace(replace(replace(str, '&', '&amp;'), '"', '&quot;'), '>', '&gt;'), '<', '&lt;');
} }
@ -127,7 +127,7 @@ var h_filter = escapeHtml_filter;
/** /**
* Escapes the characters in a String to be suitable * Escapes the characters in a String to be suitable
* to use as an HTTP parameter value. * to use as an HTTP parameter value.
* *
* @see http://www.google.com/codesearch?q=escapeUrl * @see http://www.google.com/codesearch?q=escapeUrl
@ -145,7 +145,7 @@ function escapeUrl_filter(input, param, charset) {
* definitions. * definitions.
*/ */
function escapeJavaScript_filter(input) { function escapeJavaScript_filter(input) {
var replace = Packages.org.mortbay.util.StringUtil.replace; var replace = Packages.org.eclipse.jetty.util.StringUtil.replace;
var str = (input || "").toString(); var str = (input || "").toString();
return replace(replace(replace(replace(replace(str, '"', '\\"'), "'", "\\'"), '\n', '\\n'), '\r', '\\r'), '\t', '\\t'); return replace(replace(replace(replace(replace(str, '"', '\\"'), "'", "\\'"), '\n', '\\n'), '\r', '\\r'), '\t', '\\t');
} }
@ -155,7 +155,7 @@ function escapeJavaScript_filter(input) {
* Replaces linebreaks with HTML linebreaks. * Replaces linebreaks with HTML linebreaks.
*/ */
function linebreakToHtml_filter(input) { function linebreakToHtml_filter(input) {
var replace = Packages.org.mortbay.util.StringUtil.replace; var replace = Packages.org.eclipse.jetty.util.StringUtil.replace;
var str = (input || "").toString(); var str = (input || "").toString();
return replace(str, '\n', '<br />'); return replace(str, '\n', '<br />');
} }
@ -171,7 +171,7 @@ function replace_filter(input, param, oldString, newString) {
var str = (input || "").toString(); var str = (input || "").toString();
var oldString = param["old"] != null ? param["old"] : oldString; var oldString = param["old"] != null ? param["old"] : oldString;
var newString = param["new"] != null ? param["new"] : newString; var newString = param["new"] != null ? param["new"] : newString;
var replace = Packages.org.mortbay.util.StringUtil.replace; var replace = Packages.org.eclipse.jetty.util.StringUtil.replace;
return replace(str, oldString, newString); return replace(str, oldString, newString);
} }

View file

@ -1,179 +1,2 @@
/* // This file intentionally left blank to prevent legacy code from
* Helma License Notice // breaking when trying to include the obsolete JSON module.
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2006 Helma Software. All Rights Reserved.
*
* $RCSfile: JSON.js,v $
* $Author$
* $Revision$
* $Date$
*/
/**
* @fileoverview Adds JSON methods to the Object, Array and String prototypes.
* <br /><br />
* To use this optional module, its repository needs to be added to the
* application, for example by calling app.addRepository('modules/core/JSON.js')
*/
/*
json.js
2006-04-28 [http://www.json.org/json.js]
This file adds these methods to JavaScript:
object.toJSON()
This method produces a JSON text from an object. The
object must not contain any cyclical references.
array.toJSON()
This method produces a JSON text from an array. The
array must not contain any cyclical references.
string.parseJSON()
This method parses a JSON text to produce an object or
array. It will return false if there is an error.
*/
(function () {
var m = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
},
s = {
/**
* @ignore
*/
array: function (x) {
var a = ['['], b, f, i, l = x.length, v;
for (i = 0; i < l; i += 1) {
v = x[i];
f = s[typeof v];
if (f) {
v = f(v);
if (typeof v == 'string') {
if (b) {
a[a.length] = ',';
}
a[a.length] = v;
b = true;
}
}
}
a[a.length] = ']';
return a.join('');
},
'boolean': function (x) {
return String(x);
},
'null': function (x) {
return "null";
},
/**
* @ignore
*/
number: function (x) {
return isFinite(x) ? String(x) : 'null';
},
/**
* @ignore
*/
object: function (x) {
if (x) {
if (x instanceof Array) {
return s.array(x);
}
var a = ['{'], b, f, i, v;
for (i in x) {
v = x[i];
f = s[typeof v];
if (f) {
v = f(v);
if (typeof v == 'string') {
if (b) {
a[a.length] = ',';
}
a.push(s.string(i), ':', v);
b = true;
}
}
}
a[a.length] = '}';
return a.join('');
}
return 'null';
},
/**
* @ignore
*/
string: function (x) {
if (/["\\\x00-\x1f]/.test(x)) {
x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
var c = m[b];
if (c) {
return c;
}
c = b.charCodeAt();
return '\\u00' +
Math.floor(c / 16).toString(16) +
(c % 16).toString(16);
});
}
return '"' + x + '"';
}
};
/**
* This method produces a JSON text from an object.
* The object must not contain any cyclical references.
*/
Object.prototype.toJSON = function () {
return s.object(this);
};
/**
* This method produces a JSON text from an array.
* The array must not contain any cyclical references.
*/
Array.prototype.toJSON = function () {
return s.array(this);
};
Object.prototype.dontEnum("toJSON");
Array.prototype.dontEnum("toJSON");
return;
})();
/**
* This method parses a JSON text to produce an object or
* array. It will return false if there is an error.
*/
String.prototype.parseJSON = function () {
try {
return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(this.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + this + ')');
} catch (e) {
return false;
}
};
String.prototype.dontEnum("parseJSON");

View file

@ -17,7 +17,7 @@
/** /**
* @fileoverview Adds useful methods to the JavaScript Object type. * @fileoverview Adds useful methods to the JavaScript Object type.
* <br /><br /> * <br /><br />
* To use this optional module, its repository needs to be added to the * To use this optional module, its repository needs to be added to the
* application, for example by calling app.addRepository('modules/core/Object.js') * application, for example by calling app.addRepository('modules/core/Object.js')
*/ */
@ -30,42 +30,43 @@
*/ */
Object.prototype.clone = function(clone, recursive) { Object.prototype.clone = function(clone, recursive) {
var getValue = function(value, recursive) { var getValue = function(value, recursive) {
if ((value == null || typeof(value) !== "object") || recursive !== true) { if (recursive !== true || value == null
return value; || (typeof (value) !== "object" && typeof (value) !== "function")) {
} return value;
return value.clone(null, recursive); }
}; return value.clone(null, recursive);
};
if (typeof(this) === "object") { if (typeof (this) === "object") {
switch (this.constructor) { if (this === null) {
case Array: return null;
return this.map(function(value) { }
return getValue(value, recursive); switch (this.constructor) {
}); case String:
case Number:
case Boolean:
case Date:
return new this.constructor(this.valueOf());
case null: // e.g. macro parameter objects case Array:
if (clone == null) { return this.map(function(value) {
clone = {}; return getValue(value, recursive);
} });
// continue below
case Object:
case HopObject:
if (clone == null) {
clone = new this.constructor();
}
for (var propName in this) {
clone[propName] = getValue(this[propName], recursive);
}
return clone;
default: default:
return new this.constructor(this.valueOf()); if (clone == null) {
} clone = new this.constructor();
} else if (typeof(this) === "function" && this.constructor === RegExp) { }
return new RegExp(this.valueOf()); for ( var propName in this) {
} clone[propName] = getValue(this[propName], recursive);
return this; }
return clone;
}
} else if (typeof (this) === "function" && this.constructor === RegExp) {
return new RegExp(this.valueOf());
}
return this;
}; };
@ -78,11 +79,10 @@ Object.prototype.clone = function(clone, recursive) {
Object.prototype.reduce = function(recursive) { Object.prototype.reduce = function(recursive) {
var result = {}; var result = {};
for (var i in this) { for (var i in this) {
if (this[i] instanceof HopObject == false) { if (this[i] instanceof HopObject == false)
result[i] = this[i]; result[i] = this[i];
} else if (recursive) { else if (recursive)
result[i] = this.reduce(true); result[i] = this.reduce(true);
}
} }
return result; return result;
}; };

View file

@ -14,7 +14,7 @@
* $Date$ * $Date$
*/ */
// convenience SingleFileRepository to load all the // convenience SingleFileRepository to load all the
// Javascript library files in ./modules/core // Javascript library files in ./modules/core
app.addRepository('modules/core/Array.js'); app.addRepository('modules/core/Array.js');
@ -24,5 +24,4 @@ app.addRepository('modules/core/Object.js');
app.addRepository('modules/core/String.js'); app.addRepository('modules/core/String.js');
app.addRepository('modules/core/HopObject.js'); app.addRepository('modules/core/HopObject.js');
app.addRepository('modules/core/Global.js'); app.addRepository('modules/core/Global.js');
app.addRepository('modules/core/JSON.js');
app.addRepository('modules/core/Filters.js'); app.addRepository('modules/core/Filters.js');

View file

@ -477,7 +477,13 @@ helma.Html.prototype.dropDown = function(param, options, selectedValue, firstOpt
this.closeTag("option"); this.closeTag("option");
res.write("\n "); res.write("\n ");
} }
var hasOpenGroup = false;
for (var i in options) { for (var i in options) {
if (options[i].group) {
hasOpenGroup && html.closeTag("optgroup");
html.openTag("optgroup", {label: options[i].group});
hasOpenGroup = true;
}
var attr = new Object(); var attr = new Object();
var display = ""; var display = "";
if ((options[i] instanceof Array) && options[i].length > 0) { if ((options[i] instanceof Array) && options[i].length > 0) {
@ -503,6 +509,7 @@ helma.Html.prototype.dropDown = function(param, options, selectedValue, firstOpt
this.closeTag("option"); this.closeTag("option");
res.write("\n "); res.write("\n ");
} }
hasOpenGroup && html.closeTag("optgroup");
this.closeTag("select"); this.closeTag("select");
res.write("\n "); res.write("\n ");
return; return;

View file

@ -61,7 +61,9 @@ helma.Http = function() {
var responseHandler = function(connection, result) { var responseHandler = function(connection, result) {
var input; var input;
try { try {
input = new java.io.BufferedInputStream(connection.getInputStream()); if (method !== 'DELETE') {
input = new java.io.BufferedInputStream(connection.getInputStream());
}
} catch (error) { } catch (error) {
input = new java.io.BufferedInputStream(connection.getErrorStream()); input = new java.io.BufferedInputStream(connection.getErrorStream());
} }

1
modules/lib3k Symbolic link
View file

@ -0,0 +1 @@
/Users/tobi/Projects/helma/modules/lib3k