You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2006/07/07 18:12:49 UTC

svn commit: r419943 - in /incubator/xap/trunk: WebContent/examples/example1/ src/xap/ src/xap/macro/ src/xap/session/ src/xap/util/ src/xap/xml/ src/xap/xml/dom/ src/xap/xml/dom/events/ testsrc/ testsrc/xap/util/

Author: jmargaris
Date: Fri Jul  7 11:12:47 2006
New Revision: 419943

URL: http://svn.apache.org/viewvc?rev=419943&view=rev
Log:
parameterized macros, cleaned up a bunch of exception stuff

Added:
    incubator/xap/trunk/src/xap/util/EscapeSyntaxParser.js   (with props)
    incubator/xap/trunk/src/xap/util/Exception.js
      - copied, changed from r417619, incubator/xap/trunk/src/xap/util/BaseException.js
    incubator/xap/trunk/src/xap/util/MessageFormat.js   (with props)
    incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.html   (with props)
    incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.js   (with props)
    incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.html   (with props)
    incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js   (with props)
Removed:
    incubator/xap/trunk/src/xap/util/BaseException.js
    incubator/xap/trunk/src/xap/util/IllegalArgumentException.js
    incubator/xap/trunk/src/xap/util/IllegalStateException.js
Modified:
    incubator/xap/trunk/WebContent/examples/example1/index.xal
    incubator/xap/trunk/src/xap/Xap.js
    incubator/xap/trunk/src/xap/macro/Macro.js
    incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js
    incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js
    incubator/xap/trunk/src/xap/util/Hashtable.js
    incubator/xap/trunk/src/xap/util/ResourceDictionary.js
    incubator/xap/trunk/src/xap/util/XapException.js
    incubator/xap/trunk/src/xap/util/__package__.js
    incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js
    incubator/xap/trunk/src/xap/xml/dom/Document.js
    incubator/xap/trunk/src/xap/xml/dom/XapElement.js
    incubator/xap/trunk/src/xap/xml/dom/events/AttributeChangeEvent.js
    incubator/xap/trunk/src/xap/xml/dom/events/StructureChangeEvent.js
    incubator/xap/trunk/testsrc/XapUnitTestSuite.html

Modified: incubator/xap/trunk/WebContent/examples/example1/index.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/example1/index.xal?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/example1/index.xal (original)
+++ incubator/xap/trunk/WebContent/examples/example1/index.xal Fri Jul  7 11:12:47 2006
@@ -9,7 +9,7 @@
 	<macro:macro id="mymacro">
 		<xm:modifications>
 			<xm:append select="id('myPanel')">
-    			<xal:button text="A new button from a macro" y="60%"/>
+    			<xal:button text="{0}" y="60%"/>
    		</xm:append>
 		</xm:modifications>
 	</macro:macro>
@@ -40,7 +40,7 @@
 	 			<left>
 		 			<panel width="100%" height="100%" id="myPanel">
 		 				<button text="url event" width="100%" height="20%" onCommand="index2.xal"/>
-		 				<button text="macro event" width="100%" y="20%" height="20%" onCommand="macro:mymacro.execute()"/>
+		 				<button text="macro event" width="100%" y="20%" height="20%" onCommand="macro:mymacro.execute('some text')"/>
 		 			</panel>
 	 			</left>
  			

Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Fri Jul  7 11:12:47 2006
@@ -84,16 +84,15 @@
 
 Xap.loadXap = function( sourceRootDir ) {
 	//xap.util
-	Xap.loadUri( sourceRootDir + "/src/xap/util/LogFactory.js");	
-	Xap.loadUri( sourceRootDir + "/src/xap/util/XmlUtils.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/HttpUtils.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/UidProvider.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/Hashtable.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/ResourceDictionary.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/XapException.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/BaseException.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/IllegalArgumentException.js" );
-	Xap.loadUri( sourceRootDir + "/src/xap/util/Profiler.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/LogFactory.js");	
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/XmlUtils.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/HttpUtils.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/UidProvider.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/Hashtable.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/ResourceDictionary.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/XapException.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/Exception.js" );
+	dojo.hostenv.loadUri(  sourceRootDir + "/src/xap/util/Profiler.js" );
 	
 
 	//xap.session

Modified: incubator/xap/trunk/src/xap/macro/Macro.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/macro/Macro.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/macro/Macro.js (original)
+++ incubator/xap/trunk/src/xap/macro/Macro.js Fri Jul  7 11:12:47 2006
@@ -15,6 +15,7 @@
  *
  */
  
+Xap.require("xap.util.MessageFormat");
 /**
  * @fileoverview A macro is a segment of stored xml that can be run from the client
  * as if it came from the server in a retrieveAndProcess()
@@ -40,11 +41,25 @@
 }
 
 
+//TODO need to finalize the escape syntax for messageformat/macros,
+//currently there isn't one at all!
+
 //-----------------------------------------------------------------------
 // Public Methods.
 //-----------------------------------------------------------------------
 Macro.prototype.execute = function() {
+	
+	var finalText = this._macroText;
+	
+	//if there are arguments here plug them into the message format
+	if (arguments && arguments.length>0){
+		var args = new Array(arguments.length);
+		for (var i=0; i<arguments.length; i++){
+			args[i] = arguments[i];
+		}		
+		finalText = xap.util.MessageFormat.format( this._macroText, args);
+	}
 	//TODO allow arguments that plug into message format style string
 	var parser = new SaxParser( new SaxContentHandler() );
-	this._session.processDocument( parser.parse( this._macroText ) );
+	this._session.processDocument( parser.parse( finalText ) );
 }

Modified: incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js Fri Jul  7 11:12:47 2006
@@ -69,6 +69,7 @@
 	 
 	//TODO we really need to clarify whether or not XAP is a generic wrapping
 	//tag or something with more meaning
+	//TODO what if the original macro is malformed?
 	var macro = new Macro( "<xap>" + element.childNodes[0].toXmlWithoutAutoAssignedIds() + "</xap>", this.getSession() );
 	 
 	//TODO if we are replacing and existing one should probably

Modified: incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js (original)
+++ incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js Fri Jul  7 11:12:47 2006
@@ -126,7 +126,7 @@
  * @param {XapElement} sourceElement The current element that 'this' should refer to
  * @param {ClientEvent} clientEvent The current event that 'event' should refer to.
  * @return {ParseResult} A ParseResult object that wraps the argument we resolved.
- * @throws BaseException if something goes wrong..
+ * @throws xap.util.Exception if something goes wrong..
  */
  
 
@@ -161,7 +161,7 @@
 			}
 			else{
 				DeclarativeArgumentParser.s_log.debug("Hit a character after the full arg:" + arg);
-				throw new BaseException("Bad parameter trailing characters");
+				throw new xap.util.Exception("Bad parameter trailing characters");
 				//TODO
 			}
 		}
@@ -175,7 +175,7 @@
 			if ( (c=='\"' || c=='\'') && arg.trim().length==0){
 				DeclarativeArgumentParser.s_log.debug("Hit an open string char, parsing string");
 				parseResult =  this._parseString(args,nextChar, c);
-				nextChar = this._parseResult._terminatingIndex;
+				nextChar = parseResult._terminatingIndex;
 			}
 			
 			//if we get an '(' anywhere it means this must be an 'mco' call of some sort
@@ -201,7 +201,7 @@
 				var containerName = null;
 				
 				if (containerIndex==-1){
-					throw new BaseException("Mmissing colon :" + mco);
+					throw new xap.util.Exception("Mmissing colon :" + mco);
 				}
 
 				containerName = mco.substring(0,containerIndex);
@@ -210,7 +210,7 @@
 				var periodIndex = mco.lastIndexOf(".");
 				    
 				if (periodIndex==-1 || periodIndex==0 || periodIndex==mco.length-1){
-					throw new BaseException("Mmissing period:" + mco);
+					throw new xap.util.Exception("Mmissing period:" + mco);
 			    }
 				    
 				var mcoName = mco.substring(0,periodIndex);
@@ -323,7 +323,7 @@
 		else{
 			if (result._parseStatus!=ParseResult.CLOSING_PAREN){
 				//TODO
-				throw new BaseException("Bad paramter string " + argumentsString);
+				throw new xap.util.Exception("Bad paramter string " + argumentsString);
 			}
 			break;
 		}
@@ -355,7 +355,7 @@
  * TODO our use of MCO everywhere is bad, this is really any object
  * call. Also "stringToMcoArg" should be "literalToArg?"
  * 
- * @throws BaseException if something goes wrong.
+ * @throws xap.util.Exception if something goes wrong.
  * 
  * @private
  */
@@ -372,13 +372,13 @@
 		var container = this._session.getContainer(containerName);
 		if (container==null){
 			//TODO
-			throw new BaseException("No container with name: " + containerName);
+			throw new xap.util.Exception("No container with name: " + containerName);
 		}
 		
 		var bean = container.get(mcoName);
 	  	if (bean==null){
 	  		//TODO
-			throw new BaseException("No bean with name: " + mcoName);
+			throw new xap.util.Exception("No bean with name: " + mcoName);
 	  	}
 		return bean;
 	    //note that this RETURNS a macro and does not RUN it!
@@ -439,7 +439,7 @@
 	}
 	
 	//TODO include element for more info
-	throw new BaseException("Could not convert to mco arg:" + arg);
+	throw new xap.util.Exception("Could not convert to mco arg:" + arg);
 }
 
 
@@ -451,7 +451,7 @@
  * @param methodName Name of the method
  * @param args array of args
  * @return The result of the method call.
- * @throws BaseException If something bad happens...
+ * @throws xap.util.Exception If something bad happens...
  * 
  * @private
  */
@@ -463,21 +463,21 @@
 	if (container==null){
 		
 		//TODO
-		throw new BaseException("Could not find container " + containerName);
+		throw new xap.util.Exception("Could not find container " + containerName);
 		
 	}
 
 	var o  = container.get(mcoName);
  	if (o==null){
 		//TODO
-		throw new BaseException("Could not find bean " + mcoName);
+		throw new xap.util.Exception("Could not find bean " + mcoName);
     }
     
 	
     //see if the method with that name exists
 	if (!o[methodName]){
 		//TODO
-		throw new BaseException("Could not find method :" + methodName);
+		throw new xap.util.Exception("Could not find method :" + methodName);
     	
 	}
 	
@@ -487,7 +487,7 @@
 		return o[methodName].apply(o,args);
 	}
 	catch( exception ){
-		throw new BaseException("Error calling method :" + methodName, exception);
+		throw new xap.util.Exception("Error calling method :" + methodName, exception);
 	}
 
 	return null;
@@ -500,7 +500,7 @@
  * @param args The string we look into to find this string in question.
  * @param startIndex The index where this argument starts
  * @param terminatingCharacter The character ( " or ') that starts and ends the string
- * @throws BaseException if something bad happens...
+ * @throws xap.util.Exception if something bad happens...
  * @private
  */
  
@@ -547,7 +547,7 @@
 	//2: we reached the end of the args string, which means our args
 	//string is mis-formatted, in which case result._result will be null.	
 	if (result._resultObject==null){
-		throw new BaseException("Bad string that we parsed: " + args + " at index " + startIndex--);
+		throw new xap.util.Exception("Bad string that we parsed: " + args + " at index " + startIndex--);
 	}
 	
 	return result;

Added: incubator/xap/trunk/src/xap/util/EscapeSyntaxParser.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/EscapeSyntaxParser.js?rev=419943&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/util/EscapeSyntaxParser.js (added)
+++ incubator/xap/trunk/src/xap/util/EscapeSyntaxParser.js Fri Jul  7 11:12:47 2006
@@ -0,0 +1,181 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+ 
+Xap.require("xap.util.Exception");
+Xap.provide("xap.util.EscapeSyntaxParser");
+
+//TODO docs here need help, mostly ported over unchanged.
+
+/**
+ * @fileoverview A parser for escaping/unescaping strings based on
+ * escape sequences.
+ * 
+ * @author jmargaris
+ */
+ 
+/**
+ * Creates a new EscapeSyntaxParser.
+ * 
+ * @class This class is used for escaping/unescaping strings that have single-character
+ * escape sequences in them. An escape syntax parser maps escape sequences
+ * of the form 'Xa' to 'b' where 'X' is the escape lead (typically a \),
+ * 'a' is the character being escaped and 'b' is the resulting character.
+ * <br><br>
+ * For example take the following EscapeSyntaxParser: <br><br>
+ * <code>
+ * new xap.util.EscapeSyntaxParser('\\', ['\\', '{', '}'], ['\\', '{', '}'], false);
+ * </code>
+ * <br><br>
+ * In this case '\' is the escape sequence starter. '\\' is mapped to '\', 
+ * '\{' is mapped to '{', and '\}' is mapped to '}'<br><br>
+ * Now consider the following alernate parser:<br>
+ * <code>
+ * new xap.util.EscapeSyntaxParser('x', ['\\', '{', '}'], ['a', 'b', 'c'], false);
+ * </code><br><br>
+ * In this case 'x' is the escape sequence starter. 'x\' is mapped to 'a', 
+ * 'x{' is mapped to 'b', and 'x}' is mapped to 'c'
+ * 
+ * 
+ * 
+ * @param {Character} escapeLead The character that signifies an escape sequence, typically \
+ * @param {Array} escapeChars An array of characters to escape
+ * @param {Array} resolvedChars A parallel array of characters to resolve to
+ * @param {Boolean} strict If true report all unrecognized escape sequences as errors
+ */
+xap.util.EscapeSyntaxParser = function( escapeLead, escapeChars, resolvedChars, strict ){
+	this._escapeLead = escapeLead;
+	this._escapeSequenceCharacters = escapeChars;
+	this._resolvedCharacters = resolvedChars;
+	this._reportUnknownEscapeSequencesAsErrors = strict;
+	
+}
+
+xap.util.EscapeSyntaxParser.UNRESOLVED_CHARACTER = new Object();
+
+
+/**
+ * Returns the resolved character at the given index in the given string.
+ * If the escapeSequenceIndex does not point to the start of an escape
+ * sequence UNRESOLVED_CHARACTER is returned, NOT the original character. This method
+ * exists for complex parsing operations such as parsing a comma separated
+ * list of parameters which may each have different escape sequences.
+ * 
+ * @param s
+ * @param escapeSequenceIndex
+ * @return TODO
+ * @throws RuntimeException
+ */	
+xap.util.EscapeSyntaxParser.prototype.getResolvedCharacter = function( s, index){
+	var c = s.charAt(index);
+
+	//if we don't start with the escape sequence starter we are done
+	if (c!=this._escapeLead){
+		return xap.util.EscapeSyntaxParser.UNRESOLVED_CHARACTER;
+	}	
+	//if \ was the last character that's not valid
+	if (index+1>=s.length && this._reportUnknownEscapeSequencesAsErrors){
+		throw new xap.util.Exception("Invalid escape sequence: " + this._escapeLead +
+			" at index " + index + " in string: " + s);
+	}
+		
+	//get the next character after the \ and check it against our list
+	//if we find it, return the corresponding resolved character
+	var keyCharacter = s.charAt(index+1);
+	for (var i = 0 ; i<this._escapeSequenceCharacters.length; i++){
+		if (keyCharacter==this._escapeSequenceCharacters[i]){
+			return this._resolvedCharacters[i];
+		}
+	}
+		
+	if (this._reportUnknownEscapeSequencesAsErrors){
+		throw new xap.util.Exception("Invalid escape sequence: " + this._escapeLead + keyCharacter +
+			" at index " + index + " in string: " + s);
+	}
+		
+	//if we got here it means we had \x where that is not a valid
+	//escape sequence AND we are not reporting that as error so 
+	//just say we didn't need to do any resolution which should make
+	//the caller just accept the \ as a normal character
+	return xap.util.EscapeSyntaxParser.UNRESOLVED_CHARACTER;
+}
+
+	/**
+	 * Given an unescaped string, convert it into an escaped one that
+	 * fits this escape syntax. For example given the string
+	 * "hello\there" turn it into "hello\\there".
+	 * @param s The string to escape.
+	 * @return A properly escaped string
+	 */
+xap.util.EscapeSyntaxParser.prototype.escape = function( s ){
+	var b = new String();
+	for (var i =0; i<s.length; i++){
+		var c = s.charAt(i);
+		var neededReplace = false;
+		for (var j=0; j<this._resolvedCharacters.length; j++ ){	
+			//replace character with an escape sequence
+			if (c==this._resolvedCharacters[j]){
+				b += this._escapeLead;
+				b += this._escapeSequenceCharacters[j];
+				neededReplace = true;
+				break;
+			}
+		}
+			
+		//if we didn't replace the character
+		//with an escape sequence just append it directly.
+		if (!neededReplace){
+			b += c;
+		}
+	}
+	return b;
+}
+	
+/**
+ * Parses the string and returns a new string with escape sequences
+ * replaced with resolved values if any resolution was needed. If not
+ * the original string is returned. 
+ */
+xap.util.EscapeSyntaxParser.prototype.parse = function( s ){
+	var buffer = null;
+	for (var i =0; i<s.length; i++){
+		var c = this.getResolvedCharacter(s,i);
+		
+		//if c==UNRESOLVED_CHARACTER it means no resolution was needed, so just
+		//apend on the original character
+		if (c==xap.util.EscapeSyntaxParser.UNRESOLVED_CHARACTER){
+			
+			//if we are building up a resolved string append to it
+			if (buffer!=null){
+				buffer += s.charAt(i);
+			}
+		}
+		
+		//if we got some value back, that is what we should use and we
+		//also need to SKIP over the next character!
+		else{
+			//if we don't have a buffer yet we need to make one now
+			//that has all the content we've skipped over so far
+			if (buffer==null){
+				buffer = s.substring(0,i);
+			}
+			buffer+=c;
+			i++;
+		}
+	}
+	return buffer==null?s:buffer;
+}
+

Propchange: incubator/xap/trunk/src/xap/util/EscapeSyntaxParser.js
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/xap/trunk/src/xap/util/Exception.js (from r417619, incubator/xap/trunk/src/xap/util/BaseException.js)
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/Exception.js?p2=incubator/xap/trunk/src/xap/util/Exception.js&p1=incubator/xap/trunk/src/xap/util/BaseException.js&r1=417619&r2=419943&rev=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/util/BaseException.js (original)
+++ incubator/xap/trunk/src/xap/util/Exception.js Fri Jul  7 11:12:47 2006
@@ -15,10 +15,14 @@
  *
  */
  
- /**
+ 
+Xap.provide("xap.util.Exception");
+ 
+/**
  * @fileoverview Base class for non-internationalized exceptions
  * 
  * @author ikaplansky
+ * @author jmargaris
  */
  
  
@@ -30,25 +34,25 @@
  * @param message The message
  * @param cause The cause of the message, typically another exception
  */
-BaseException = function( message, cause, location ) {
+xap.util.Exception = function( message, cause, location ) {
 	this._message = message;
 	this._cause = cause;
 	this._location = location;
 }
 
-BaseException.prototype.getLocation = function() {
+xap.util.Exception .prototype.getLocation = function() {
 	return this._location;
 }
 
-BaseException.prototype.getMessage = function() {
+xap.util.Exception .prototype.getMessage = function() {
 	return this._message;
 }
 
-BaseException.prototype.getCause = function() {
+xap.util.Exception .prototype.getCause = function() {
 	return this._cause;
 }
 
-BaseException.prototype.toString = function() {
+xap.util.Exception .prototype.toString = function() {
 	var buf = "Message:" + this._message;
 	if( this._cause != null ){
 		buf += "\nCause:" + this._cause.toString();

Modified: incubator/xap/trunk/src/xap/util/Hashtable.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/Hashtable.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/util/Hashtable.js (original)
+++ incubator/xap/trunk/src/xap/util/Hashtable.js Fri Jul  7 11:12:47 2006
@@ -60,7 +60,7 @@
  */
 Hashtable.prototype.containsKey = function( key ) {
 	if (key===null){
-		throw new IllegalArgumentException( "key cannot be null at Hashtable.containsKey" );
+		throw new xap.util.Exception( "key cannot be null in Hashtable.containsKey()" );
 	}
 	key = this._computeKey(key);
 	return this._hashtable[key]!=null;
@@ -72,7 +72,7 @@
  */
 Hashtable.prototype.containsValue = function( value ) {
 	if (value==null){
-		throw new IllegalArgumentException( "value cannot be null at Hashtable.containsValue" );
+		throw new xap.util.Exception( "value cannot be null at Hashtable.containsValue()" );
 	}
 	for ( var i in this._hashtable ) {
 		if ( this._hashtable[i] == value ) {
@@ -88,7 +88,7 @@
  */
 Hashtable.prototype.get = function ( key ) {
 	if (key==null){
-		throw new IllegalArgumentException( "Key cannot be null at Hashtable.get" );
+		throw new xap.util.Exception( "key cannot be null at Hashtable.get()" );
 	}
 	key = this._computeKey(key);
 	return this._hashtable[key];
@@ -100,10 +100,10 @@
  */
 Hashtable.prototype.put = function( key, value ) {
     if ( key == null ) {
-        throw new IllegalArgumentException( "Key cannot be null at Hashtable.put" );
+        throw new xap.util.Exception( "key cannot be null at Hashtable.put()" );
     }
     if( value == null ) {
-        throw new IllegalArgumentException( "Value cannot be null at Hashtable.put" );
+        throw new xap.util.Exception( "value cannot be null at Hashtable.put()" );
     }
     key = this._computeKey(key);
     if( this._hashtable[key] == null ) {
@@ -121,7 +121,7 @@
  */
 Hashtable.prototype.remove = function( key ) {
 	if (key==null){
-		throw new IllegalArgumentException( "key cannot be null at Hashtable.remove" );
+		throw new xap.util.Exception( "key cannot be null at Hashtable.remove()" );
 	}
 	key = this._computeKey(key);
 	var rtn = this._hashtable[key];

Added: incubator/xap/trunk/src/xap/util/MessageFormat.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/MessageFormat.js?rev=419943&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/util/MessageFormat.js (added)
+++ incubator/xap/trunk/src/xap/util/MessageFormat.js Fri Jul  7 11:12:47 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+
+Xap.provide("xa.util.MessageFormat");
+Xap.require("xap.util.EscapeSyntaxParser")
+
+/**
+ * @fileoverview Provides an approximation of Java message format.
+ * @author jmargaris
+ * 
+ */
+ 
+/**
+ * @class Provides an approximation of Java message format.
+ */ 
+xap.util.MessageFormat = function() {}
+
+
+/**
+ * A simple approximation of Java message format,
+ * takes a string like "aaa{0} bbb{1} ccc{2}" and plugs
+ * in arguments in that order. Currently there is no escape syntax at all. TODO
+ * 
+ * @param {String} formatString The string message format.
+ * @param {Array} args An array of arguments to plug into the message format.
+ */
+xap.util.MessageFormat.format = function( formatString, args ){
+	if (!formatString){
+		return null;
+	}
+	
+	//TODO escaping syntax??
+	for (var i =0; args && i<args.length; i++){	
+		var replacementString = "\\{" + i + "\\}";
+		var regEx = new RegExp(replacementString, "gm");
+		
+		formatString = formatString.replace(regEx, ""+args[i]);
+	}
+	return formatString;
+}
+
+

Propchange: incubator/xap/trunk/src/xap/util/MessageFormat.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/xap/trunk/src/xap/util/ResourceDictionary.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/ResourceDictionary.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/util/ResourceDictionary.js (original)
+++ incubator/xap/trunk/src/xap/util/ResourceDictionary.js Fri Jul  7 11:12:47 2006
@@ -23,6 +23,8 @@
  * @author ikaplansky
  */
 
+Xap.require("xap.util.MessageFormat");
+
 ResourceDictionary = function() {}
 
 //-------------------------------------------------------------------
@@ -48,10 +50,8 @@
 		}
 	}
 	if( resourceObject != null ) {
-		var messagePattern = resourceObject.messages[msgId];
-		if( messagePattern != null ) {
-			return AjxMessageFormat.format( messagePattern, args );
-		}
+		var messagePattern = resourceObject.messages[msgId];	
+		return xap.util.MessageFormat.format( messagePattern, args);
 	}
 	return "MsgId:" + msgId + ",class:" + className + ",args:" + args;
 }

Modified: incubator/xap/trunk/src/xap/util/XapException.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/XapException.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/util/XapException.js (original)
+++ incubator/xap/trunk/src/xap/util/XapException.js Fri Jul  7 11:12:47 2006
@@ -98,7 +98,7 @@
 
 /**
  * Converts an exception to a string. This should work for
- * XapException, BaseException and built-in JS exceptions
+ * XapException, xap.util.Exception and built-in JS exceptions
  */
 XapException.exceptionToString = function(exception){
 	var s = new String();

Modified: incubator/xap/trunk/src/xap/util/__package__.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/__package__.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/util/__package__.js (original)
+++ incubator/xap/trunk/src/xap/util/__package__.js Fri Jul  7 11:12:47 2006
@@ -18,7 +18,9 @@
 
 Xap.kwCompoundRequire({
 	common:	[
-				"xap.util.Character"
+				"xap.util.Character",
+				"xap.util.ArrayHelper",
+				"xap.util.Exception"
 				]
 });
 

Modified: incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js (original)
+++ incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js Fri Jul  7 11:12:47 2006
@@ -79,7 +79,7 @@
 NamespaceHandlerManager.prototype.dispatch = function( element ) {
 	if( ! this.isNamespaceRegistered( element.getNamespaceUri() )) {
         // TODO - internationalize
-		throw new IllegalArgumentException( "The namespace supplied [" + 
+		throw new xap.util.Exception( "The namespace supplied [" + 
 				element.getNamespaceUri() + "] is not valid." );
 	}
 	var handler = this._namespaceToHandlersMap.get(

Modified: incubator/xap/trunk/src/xap/xml/dom/Document.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/Document.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/Document.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/Document.js Fri Jul  7 11:12:47 2006
@@ -364,11 +364,11 @@
 /**
  * This method will register the supplied prefix/namespace pair.  If the 
  * prefix is already registered with a different namespace value, an
- * IllegalStateException is thrown.
+ * Exception is thrown.
  * 
  * @param prefix The prefix to register
  * @param ns The namespace to register for the prefix
- * @throws IllegalStateException if the prefix supplied is already
+ * @throws Exception if the prefix supplied is already
  * registered with a different namespace.
  * @private
  */

Modified: incubator/xap/trunk/src/xap/xml/dom/XapElement.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/XapElement.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/XapElement.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/XapElement.js Fri Jul  7 11:12:47 2006
@@ -196,7 +196,7 @@
 	if( "id" == name ) {
 		isIdAttribute = true;
  		if ( doc != null ) {
- 			throw new IllegalStateException
+ 			throw new xap.util.Exception
       		( ResourceDictionary.getMessage
 	    		( XapElement.CANNOT_SET_ID_ATTRIBUTE_WHEN_PART_OF_DOCUMENT, 
 	      		XapElement.CLASSNAME ) );
@@ -296,7 +296,7 @@
 	
 	//TODO what if o is not a child?  
 	if(child == null){
-//		throw new IllegalArgumentException
+//		throw new xap.util.Exception
 //                ( ResourceDictionary.getMessage
 //                  ( CANNOT_REMOVE_NULL_CHILD, ElementImpl.class ) );
 //	    }

Modified: incubator/xap/trunk/src/xap/xml/dom/events/AttributeChangeEvent.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/events/AttributeChangeEvent.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/events/AttributeChangeEvent.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/events/AttributeChangeEvent.js Fri Jul  7 11:12:47 2006
@@ -100,13 +100,13 @@
 AttributeChangeEvent.prototype.setNewValue = function( value ) {
 	if ( value == null ) {
 		// TODO - internationalize
-		throw new IllegalArgumentException
+		throw new xap.util.Exception
 			("Can't set the attribute value as null");
 	}
 	var elementValue = this.getSourceElement().getAttribute( this.getName() );
 	if ( elementValue != null && elementValue != this._oldValue ) {
 		// TODO - internationalize
-		throw new IllegalStateException
+		throw new xap.util.Exception
 			("You may only change the new value of attributes " +
 			"before the change has been committed (accepted by " +
 			"all registered AttributeChangeListener objects)");

Modified: incubator/xap/trunk/src/xap/xml/dom/events/StructureChangeEvent.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/events/StructureChangeEvent.js?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/events/StructureChangeEvent.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/events/StructureChangeEvent.js Fri Jul  7 11:12:47 2006
@@ -132,7 +132,7 @@
 		if ( newChange.nodeType != google.DOM_ELEMENT_NODE ) {
 			
 			//TODO i18n
-			throw new IllegalArgumentException
+			throw new xap.util.Exception
 				( "The root element of Documents must be of type Element" );
 		} 
 	}

Modified: incubator/xap/trunk/testsrc/XapUnitTestSuite.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/XapUnitTestSuite.html?rev=419943&r1=419942&r2=419943&view=diff
==============================================================================
--- incubator/xap/trunk/testsrc/XapUnitTestSuite.html (original)
+++ incubator/xap/trunk/testsrc/XapUnitTestSuite.html Fri Jul  7 11:12:47 2006
@@ -10,6 +10,8 @@
 
 	    function utilSuite( webappContext ) {
             var result = new top.jsUnitTestSuite();
+            result.addTestPage( webappContext + "/testsrc/xap/util/_TestEscapeSyntaxParser.html" );
+            result.addTestPage( webappContext + "/testsrc/xap/util/_TestMessageFormat.html" );
             result.addTestPage( webappContext + "/testsrc/xap/util/_TestHashtable.html" );
             result.addTestPage( webappContext + "/testsrc/xap/util/_TestLogFactory.html" );
             result.addTestPage( webappContext + "/testsrc/xap/util/_TestCharacter.html" );

Added: incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.html?rev=419943&view=auto
==============================================================================
--- incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.html (added)
+++ incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.html Fri Jul  7 11:12:47 2006
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
+	"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+	<title>Element Unit Tests</title>
+	<link rel="stylesheet" type="text/css" href="/jsunit/jsunit/css/jsUnitStyle.css">
+	<script language="JavaScript" type="text/javascript" src="/jsunit/jsunit/app/jsUnitCore.js"></script>
+	<script language="JavaScript" type="text/javascript" src="/jsunit/src/dojo/dojo.js"></script>
+	<script language="JavaScript" type="text/javascript" src="/jsunit/src/xap/util/Utils.js"></script>
+	<script language="JavaScript" type="text/javascript" src="/jsunit/src/xap/Xap.js"></script>
+	
+	<script language="JavaScript" type="text/javascript" src="_TestEscapeSyntaxParser.js"></script>
+	
+	<script language="JavaScript" type="text/javascript">
+		Xap.bootstrap( "/jsunit" );
+  	</script>
+</head>
+
+<body>
+  		
+</body>
+</html>
\ No newline at end of file

Propchange: incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.js?rev=419943&view=auto
==============================================================================
--- incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.js (added)
+++ incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.js Fri Jul  7 11:12:47 2006
@@ -0,0 +1,85 @@
+
+Xap.require("xap.util.EscapeSyntaxParser");
+
+function exposeTestFunctionNames(){
+	 return ["testEscapeSyntax", "testStrictEscapeSyntax"];
+}	
+
+var argumentParser = new xap.util.EscapeSyntaxParser('\\', 
+	['\\', '{', '}'], ['\\', '{', '}'], false);
+	
+var strictArgumentParser = new xap.util.EscapeSyntaxParser('\\', 
+	['\\', '{', '}'], ['\\', '{', '}'], true);
+		
+var VALID_INPUT_STRINGS = [
+		"hello",
+		"\\{hello",
+		"\\{hello\\}",
+		"\\{he\\\\llo\\}"
+];
+	
+var VALID_OUTPUT_STRINGS = [
+		"hello",
+		"{hello",
+		"{hello}",
+		"{he\\llo}"
+];
+	
+var INVALID_INPUT_STRINGS = [
+		"hello\\",
+		"hello\\h"
+];
+	
+	
+	
+	
+testEscapeSyntax = function(){
+	var outputString = null;
+	for (var i =0; i<VALID_INPUT_STRINGS.length; i++){
+		try{
+			outputString = argumentParser.parse(VALID_INPUT_STRINGS[i]);
+		}
+		catch(e){
+			assertTrue("Got unexpected exception on string" + VALID_INPUT_STRINGS[i] + " : "  + XapException.exceptionToString(e), false);
+		}
+		assertTrue(outputString + "==" + VALID_OUTPUT_STRINGS[i],
+			outputString == VALID_OUTPUT_STRINGS[i]);
+	}
+
+	
+	for (var i =0; i<INVALID_INPUT_STRINGS.length; i++){
+		try{
+			outputString  = argumentParser.parse(INVALID_INPUT_STRINGS[i]);
+		}
+		catch(e){
+			assertTrue("Got unexpected exception on string : " +   INVALID_INPUT_STRINGS[i] + " : " + XapException.exceptionToString(e), false);
+		}	
+		assertTrue(outputString + "==" + INVALID_INPUT_STRINGS[i],
+			outputString == INVALID_INPUT_STRINGS[i]);
+	}
+}
+
+testStrictEscapeSyntax = function(){
+	var outputString = null
+	for (var i =0; i<VALID_INPUT_STRINGS.length; i++){
+		try{
+			outputString = strictArgumentParser.parse(VALID_INPUT_STRINGS[i]);
+		}
+		catch(e){
+			assertTrue("Got unexpected exception on string" + VALID_INPUT_STRINGS[i] + " : "  + XapException.exceptionToString(e), false);
+		}
+		assertTrue(outputString + "==" + VALID_OUTPUT_STRINGS[i],
+			outputString == VALID_OUTPUT_STRINGS[i]);
+	}
+	
+	for (var i =0; i<INVALID_INPUT_STRINGS.length; i++){
+		var exception = null;
+		try{
+			outputString = strictArgumentParser.parse(INVALID_INPUT_STRINGS[i]);
+		}
+		catch(e){
+			exception = e;
+		}	
+		assertTrue("Expected an exception parsing:" + INVALID_INPUT_STRINGS[i], exception!=null);
+	}
+}

Propchange: incubator/xap/trunk/testsrc/xap/util/_TestEscapeSyntaxParser.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.html?rev=419943&view=auto
==============================================================================
--- incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.html (added)
+++ incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.html Fri Jul  7 11:12:47 2006
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
+	"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+	<title>Element Unit Tests</title>
+	<link rel="stylesheet" type="text/css" href="/jsunit/jsunit/css/jsUnitStyle.css">
+	<script language="JavaScript" type="text/javascript" src="/jsunit/jsunit/app/jsUnitCore.js"></script>
+	<script language="JavaScript" type="text/javascript" src="/jsunit/src/dojo/dojo.js"></script>
+	<script language="JavaScript" type="text/javascript" src="/jsunit/src/xap/util/Utils.js"></script>
+	<script language="JavaScript" type="text/javascript" src="/jsunit/src/xap/Xap.js"></script>
+	
+	<script language="JavaScript" type="text/javascript" src="_TestMessageFormat.js"></script>
+	
+	<script language="JavaScript" type="text/javascript">
+		Xap.bootstrap( "/jsunit" );
+  	</script>
+</head>
+
+<body>
+  		
+</body>
+</html>
\ No newline at end of file

Propchange: incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js?rev=419943&view=auto
==============================================================================
--- incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js (added)
+++ incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js Fri Jul  7 11:12:47 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+Xap.require("xap.util.MessageFormat");
+
+function exposeTestFunctionNames(){
+	 return ["testMessageFormat"];
+}
+	
+ function testMessageFormat() {
+	var formatString = "Arg 1: {0}   arg 2: {1}";
+	var values = ["ARG1", "ARG2"];
+	var returnValue = xap.util.MessageFormat.format(formatString, values);
+	assertTrue("First message format failed", 
+		returnValue=="Arg 1: ARG1   arg 2: ARG2");
+		
+	formatString = "Arg 1: {0}   arg 2: {1} arg3: {2}";
+	values = ["ARG1", "ARG2"];
+	returnValue = xap.util.MessageFormat.format(formatString, values);
+	assertTrue("Second message format failed", 
+		returnValue=="Arg 1: ARG1   arg 2: ARG2 arg3: {2}");
+		
+	formatString = "Arg 1: {0}   arg 2: {1} arg1: {0}";
+	values = ["ARG1", "ARG2"];
+	returnValue = xap.util.MessageFormat.format(formatString, values);
+	assertTrue("Third message format failed", 
+		returnValue=="Arg 1: ARG1   arg 2: ARG2 arg1: ARG1");
+}

Propchange: incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js
------------------------------------------------------------------------------
    svn:eol-style = native