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 mt...@apache.org on 2006/09/07 21:44:55 UTC

svn commit: r441241 - in /incubator/xap/trunk/src/xap: resolver/AttributeResolutionHandler.js session/ClientSession.js taghandling/AbstractTagImpl.js

Author: mturyn
Date: Thu Sep  7 14:44:54 2006
New Revision: 441241

URL: http://svn.apache.org/viewvc?view=rev&rev=441241
Log:
Added AttributeResolutionHandler, attach one now to each session, ABstractTagImpl inheritors will use it to (you guessed it) resolve attributes---less vaguely, these are attributes that resolve to objects or primitives in the context of their namespaces (e.g., "mco");

Added:
    incubator/xap/trunk/src/xap/resolver/AttributeResolutionHandler.js   (with props)
Modified:
    incubator/xap/trunk/src/xap/session/ClientSession.js
    incubator/xap/trunk/src/xap/taghandling/AbstractTagImpl.js

Added: incubator/xap/trunk/src/xap/resolver/AttributeResolutionHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/resolver/AttributeResolutionHandler.js?view=auto&rev=441241
==============================================================================
--- incubator/xap/trunk/src/xap/resolver/AttributeResolutionHandler.js (added)
+++ incubator/xap/trunk/src/xap/resolver/AttributeResolutionHandler.js Thu Sep  7 14:44:54 2006
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ *
+ */
+
+//Let Dojo know what to expect from this file:
+Xap.provide("xap.resolver.AttributeResolutionHandler"); 
+
+Xap.require("xap.session.ClientEvent");
+Xap.require("xap.session.EventHandler") ;
+
+/**
+ * @param session{xap.session.ClientSession}
+ * @constructor
+ *
+**/ 
+xap.resolver.AttributeResolutionHandler = function(session){		
+	this._session = session ;
+}
+
+
+Xap.setupClassAsSubclassOf("xap.resolver.AttributeResolutionHandler","Object") ;
+
+
+
+xap.resolver.AttributeResolutionHandler.prototype.resolveAttribute = function(event,xapElement){
+	
+	var attributeValue=event.getNewValue() ;
+	
+	if ( !this.mightNeedResolution(attributeValue) ){
+		return ;
+	}
+
+	// If we've reached this point, we've got brackets
+	// fore and aft, so remove them:
+	attributeValue = attributeValue.substring(1,attributeValue.length-1) ;
+
+	if ( !this.isHandledObjectValuedAttribute(attributeValue) ){
+		return ;
+	}
+
+	// We know that this is of the form xyz:str,
+	// where "xyz" is a known handler:
+
+	// Lifting code from AbstractTagImpl.fireEvent() 
+	// and EventHandler.fireEvent():
+	var handler = this._session.getEventHandler() ;
+
+	try{
+		// This will go to a more complete unescaping method later:
+		attributeValue = attributeValue.replace(/\\}/g,"}") ;
+		//Compactor needs this l-bracket escaped
+		attributeValue = attributeValue.replace(/\\\{/g,"{") ; 
+
+		var clientEvent = new xap.session.ClientEvent( 
+													xapElement, 
+													this._session
+														);	
+
+			
+		// we use parseArgument here because technically an object 
+		// event is just an argument as they can be imbedded in other 
+		// arguments etc  TODO: understand this
+		var parser = this._session.getDeclarativeArgumentParser() ;
+		var parseResult = parser.parseArgument(
+												attributeValue,
+												0,
+												xapElement, 
+												clientEvent
+												);		
+
+		if( typeof parseResult._resultObject != "undefined"){
+			event.setNewValue(parseResult._resultObject);		
+		}
+	} catch(anException){
+		this._session.handleException(anException);
+	}
+}
+
+
+
+xap.resolver.AttributeResolutionHandler.prototype.mightNeedResolution =function(attributeValue){ 
+	return !( attributeValue == null 
+				// Must have at least two brackets:
+				|| attributeValue.length < 2
+				|| attributeValue.charAt(0) != "{"
+				|| attributeValue.charAt(attributeValue.length - 1) != "}"
+			) ;
+}
+	
+// Replace this a.s.a.p. with something hooked into the handler
+// manager:
+xap.resolver.AttributeResolutionHandler.allowedHandlers = 
+{javascript:true,mco:true,data:true}
+
+xap.resolver.AttributeResolutionHandler.prototype.isHandledObjectValuedAttribute = function(str){
+	var result = false ;
+	var firstColon = str.indexOf(":") ;
+	if ( firstColon != -1){
+		var possibleHandler = str.substring(0,firstColon) ;
+		result = this.constructor.allowedHandlers[possibleHandler] ;
+		result = (typeof result != "undefined") ;
+	}
+	return result ;
+}
+
+		
\ No newline at end of file

Propchange: incubator/xap/trunk/src/xap/resolver/AttributeResolutionHandler.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/xap/trunk/src/xap/session/ClientSession.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/session/ClientSession.js?view=diff&rev=441241&r1=441240&r2=441241
==============================================================================
--- incubator/xap/trunk/src/xap/session/ClientSession.js (original)
+++ incubator/xap/trunk/src/xap/session/ClientSession.js Thu Sep  7 14:44:54 2006
@@ -25,6 +25,7 @@
 Xap.require("xap.util.Hashtable");
 Xap.require("xap.taghandling.PluginRegistryImpl");
 Xap.require("xap.taghandling.PluginDocumentHandler");
+Xap.require("xap.resolver.AttributeResolutionHandler");
 Xap.require("xap.taghandling.AbstractTagImpl");
 Xap.require("xap.session.EventHandler");
 Xap.require("xap.session.DeclarativeArgumentParser");
@@ -69,6 +70,8 @@
 	
 	this._namespaceHandlerManager = new xap.xml.NamespaceHandlerManager( this );
 	
+	this._attributeResolver = new xap.resolver.AttributeResolutionHandler( this ) ;
+	
 	//set up a plugin document handler for the UI document
 	
 	var uiDocument =  this._documentContainer.getUiDocument();
@@ -93,6 +96,10 @@
 
 xap.session.ClientSession.prototype.getNamespaceHandlerManager = function() {
 	return this._namespaceHandlerManager;
+}
+
+xap.session.ClientSession.prototype.getAttributeResolver = function() {
+	return this._attributeResolver;
 }
 
 /**

Modified: incubator/xap/trunk/src/xap/taghandling/AbstractTagImpl.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/taghandling/AbstractTagImpl.js?view=diff&rev=441241&r1=441240&r2=441241
==============================================================================
--- incubator/xap/trunk/src/xap/taghandling/AbstractTagImpl.js (original)
+++ incubator/xap/trunk/src/xap/taghandling/AbstractTagImpl.js Thu Sep  7 14:44:54 2006
@@ -489,35 +489,28 @@
 //	
 //
 //	
-	/**
-	 * This method can be used to write values back into the document.
-	 * For example, if a user enters text into a textField and we want the 
-	 * "text" attribute to reflect the text, we can call 
-	 * writeBackAttribute("text",getText()).
-	 * <br><br>
-	 * This will not signal the tag-handler that an attribute has changed. The assumption
-	 * is that the tag-handler is what initiated the write back. Other AttributeChangeListeners
-	 * will be called.
-	 * 
-	 * @param name The name of the attribute to write.
-	 * @param value The new value.
-	 */
+/**
+ * This method can be used to write values back into the document.
+ * For example, if a user enters text into a textField and we want the 
+ * "text" attribute to reflect the text, we can call 
+ * writeBackAttribute("text",getText()).
+ * <br><br>
+ * This will not signal the tag-handler that an attribute has changed. The assumption
+ * is that the tag-handler is what initiated the write back. Other AttributeChangeListeners
+ * will be called.
+ * 
+ * @param name The name of the attribute to write.
+ * @param value The new value.
+ */
 	 
 xap.taghandling.AbstractTagImpl.prototype.writeBackAttribute = function(name, value) {
 	this.getElement().removeAttributeChangeListener(this);
 	this.getElement().setAttribute(name,value);
 	this.getElement().addAttributeChangeListener(this);
 }
-//	
-//	private void writeBackAttribute(Element e, String name, String value){
-//		synchronized(getUiDocument().getDomSynchronizationObject()){
-//			e.removeAttributeChangeListener(this);
-//			e.setAttribute(name,value);
-//			e.addAttributeChangeListener(this);
-//		}
-//	}
-//
-//	
+
+
+
 /**
  * This method can be used to remove values the document.
  * For example, if a user deletes all text from a textField and we want the 
@@ -655,11 +648,18 @@
 xap.taghandling.AbstractTagImpl.prototype.onAttributeRemoved = function( e ) {}
 
 /**
- * @param e The AttributeChangeEvent
- */
-xap.taghandling.AbstractTagImpl.prototype.beforeAttributeSet = function( e ){	
-
+ * If an attribute change event looks like xyz:blah,
+ * tries to resolve "blah" in the "xyz" namespace.
+ * Subclasses may do n=more, but they definitely should 
+ * do this.
+ * @param event{xap.xml.dom.events.AttributeChangeEvent}
+ * @throw exception if resolver has a problem parsing the new event's value 
+ */
+xap.taghandling.AbstractTagImpl.prototype.beforeAttributeSet = function( event ){	
+	var resolver  = this.getSession().getAttributeResolver() ;
+	resolver.resolveAttribute(event,this.getElement())
 }
+
 
 
 //	/**