You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by al...@apache.org on 2010/11/28 00:54:04 UTC

svn commit: r1039794 - in /myfaces/gsoc/html5-comp-lib/trunk: html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/ html5-comp-lib-core/src/main/resources/META-INF/resources/myfaces.apache.org/ html5-comp-lib-examples/src/main/...

Author: aliok
Date: Sat Nov 27 23:54:04 2010
New Revision: 1039794

URL: http://svn.apache.org/viewvc?rev=1039794&view=rev
Log:
Html5
DropTarget behavior to recognize "*" as accept all mime types

Modified:
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/DropTargetBehaviorRenderer.java
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/resources/myfaces.apache.org/html5.js
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/dnd/dnd03.xhtml

Modified: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/DropTargetBehaviorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/DropTargetBehaviorRenderer.java?rev=1039794&r1=1039793&r2=1039794&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/DropTargetBehaviorRenderer.java (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/DropTargetBehaviorRenderer.java Sat Nov 27 23:54:04 2010
@@ -34,6 +34,7 @@ import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseId;
 import javax.faces.render.ClientBehaviorRenderer;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.myfaces.html5.behavior.DropTargetBehavior;
 import org.apache.myfaces.html5.event.DropEvent;
 import org.apache.myfaces.html5.renderkit.util.BehaviorScriptUtils;
@@ -71,6 +72,8 @@ public class DropTargetBehaviorRenderer 
     private static Set<String> ALLOWED_ACTIONS = new HashSet<String>(Arrays.asList("copy", "move", "link", "copyLink",
             "copyMove", "linkMove", "all", "none"));
 
+    private static final String ACCEPT_ALL_MIME_TYPES = "*";
+
     @Override
     public void decode(FacesContext context, UIComponent component, ClientBehavior behavior)
     {
@@ -180,10 +183,7 @@ public class DropTargetBehaviorRenderer 
     {
         String action = behavior.getAction() != null ? behavior.getAction().toString() : null;
         String[] types = Html5RendererUtils.resolveStrings(behavior.getTypes());
-        String[] acceptMimeTypes = Html5RendererUtils.resolveStrings(behavior.getAcceptMimeTypes(), new String[]
-        {
-            DEFAULT_MYFACES_MIME_TYPE
-        });
+        String[] acceptMimeTypes = _resolveAcceptMimeTypes(behavior);
 
         // it is better to check the action is one of allowed, isn't it? So, if user types 'cpy' instead of 'copy',
         // he/she will easily understand what is wrong. Other way, he/she has to watch the browser's javascript console.
@@ -200,27 +200,12 @@ public class DropTargetBehaviorRenderer 
         return script;
     }
 
-    private void _checkAction(String action)
-    {
-        if (action == null || action.isEmpty())
-            return;
-
-        if (ALLOWED_ACTIONS.contains(action))
-            return;
-        else
-            throw new FacesException("Action of dropTarget is not one of allowed values "
-                    + Arrays.toString(ALLOWED_ACTIONS.toArray(new String[0])) + " but " + action);
-    }
-
     private String _getDropScript(ClientBehaviorContext behaviorContext, DropTargetBehavior behavior)
     {
 
         String sourceId = behaviorContext.getSourceId();
         String[] rerender = Html5RendererUtils.resolveStrings(behavior.getRerender());
-        String[] acceptMimeTypes = Html5RendererUtils.resolveStrings(behavior.getAcceptMimeTypes(), new String[]
-        {
-            DEFAULT_MYFACES_MIME_TYPE
-        });
+        String[] acceptMimeTypes = _resolveAcceptMimeTypes(behavior);
 
         String jsSourceId = (sourceId == null) ? "this" : BehaviorScriptUtils.convertToSafeJavascriptLiteral(sourceId);
         String jsAcceptMimeTypes = BehaviorScriptUtils.convertToSafeJavascriptLiteralArray(acceptMimeTypes);
@@ -234,4 +219,31 @@ public class DropTargetBehaviorRenderer 
         return script;
     }
 
+    private String[] _resolveAcceptMimeTypes(DropTargetBehavior behavior) {
+        String[] acceptMimeTypes;
+        if(behavior.getAcceptMimeTypes()!=null && ACCEPT_ALL_MIME_TYPES.equals(behavior.getAcceptMimeTypes())){
+            acceptMimeTypes = new String[]{ACCEPT_ALL_MIME_TYPES};
+        }
+        else
+        {
+            acceptMimeTypes = Html5RendererUtils.resolveStrings(behavior.getAcceptMimeTypes(), new String[]
+            {
+                DEFAULT_MYFACES_MIME_TYPE
+            });
+        }
+        return acceptMimeTypes;
+    }
+
+    private void _checkAction(String action)
+    {
+        if (action == null || action.isEmpty())
+            return;
+
+        if (ALLOWED_ACTIONS.contains(action))
+            return;
+        else
+            throw new FacesException("Action of dropTarget is not one of allowed values "
+                    + Arrays.toString(ALLOWED_ACTIONS.toArray(new String[0])) + " but " + action);
+    }
+
 }

Modified: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/resources/myfaces.apache.org/html5.js
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/resources/myfaces.apache.org/html5.js?rev=1039794&r1=1039793&r2=1039794&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/resources/myfaces.apache.org/html5.js (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/resources/myfaces.apache.org/html5.js Sat Nov 27 23:54:04 2010
@@ -28,6 +28,7 @@ myfaces.html5.PARAM_MIME_TYPE 				= 'tex
 myfaces.html5.COMPONENT_SOURCE_MIME_TYPE 	= 'text/x-myfaces-html5-dnd-source';
 myfaces.html5.DROP_TARGETS_MIME_TYPE 		= 'text/x-myfaces-html5-drop-target-type';
 myfaces.html5.COMPONENT_SOURCE 				= 'org.apache.myfaces';
+myfaces.html5.ACCEPT_ALL_MIME_TYPES 	    = '*';
 
 //myfaces.html5.COMPONENT_SOURCE_MIME_TYPE 	= 'text/x-myfaces-html5-dnd-source';
 
@@ -54,13 +55,16 @@ myfaces.html5.dragStart = function(event
 }
  
 myfaces.html5.dragEnterOrOver = function(event, allowedEffect, dropTargetTypes, acceptedMimeTypes) {
-	//check allowed mime types first
-    var foundMimeTypes = acceptedMimeTypes.filter(function (mimeType){return event.dataTransfer.types.contains(mimeType)});
-    //if even one of the event mime types are not allowed, stop DnD 
-    if(foundMimeTypes == null || foundMimeTypes.length == 0)
-    {
-        return true; //don't cancel the event, thus stop DnD
+	//check allowed mime types first. if its "*", then accept all (do not check it)
+    if(acceptedMimeTypes.length!=1 || acceptedMimeTypes[0]!=myfaces.html5.ACCEPT_ALL_MIME_TYPES){
+        var foundMimeTypes = acceptedMimeTypes.filter(function (mimeType){return event.dataTransfer.types.contains(mimeType)});
+        //if even one of the event mime types are not allowed, stop DnD
+        if(foundMimeTypes == null || foundMimeTypes.length == 0)
+        {
+            return true; //don't cancel the event, thus stop DnD
+        }
     }
+
     
     //if allowed effect is specified, set it. so the browser can decide whether continue or stop dnd operation.
     if(allowedEffect){
@@ -112,17 +116,26 @@ myfaces.html5.drop = function(event, sou
 
     //set the data according to acceptedMimeTypes
     if(acceptedMimeTypes){
-	    var foundMimeTypes = acceptedMimeTypes.filter(function (mimeType){return event.dataTransfer.types.contains(mimeType)});
-	    if(foundMimeTypes.length > 0){
-	    	 options["org.apache.myfaces.dnd.foundMimeTypes"] = myfaces.html5._getArrayAsString(acceptedMimeTypes);
-	    	 for(var i=0; i< foundMimeTypes.length; i++){
-	    		 var mimeType = foundMimeTypes[i];
-	    		 var data = event.dataTransfer.getData(mimeType);
-	    		 if(data){
-	    			 options[mimeType] = data;
-	    		 }
-	    	 }
-	    }
+	    var foundMimeTypes;
+        if(acceptedMimeTypes.length==1 && acceptedMimeTypes[0]==myfaces.html5.ACCEPT_ALL_MIME_TYPES){
+            foundMimeTypes = new Array(event.dataTransfer.types.length);
+            for(var i=0; i<event.dataTransfer.types.length; i++){
+                foundMimeTypes[i] =  event.dataTransfer.types.item(i);
+            }
+        }
+        else {
+            foundMimeTypes = acceptedMimeTypes.filter(function (mimeType) {return event.dataTransfer.types.contains(mimeType)});
+        }
+        if(foundMimeTypes.length > 0){
+             options["org.apache.myfaces.dnd.foundMimeTypes"] = myfaces.html5._getArrayAsString(foundMimeTypes);
+             for(var i=0; i< foundMimeTypes.length; i++){
+                 var mimeType = foundMimeTypes[i];
+                 var data = event.dataTransfer.getData(mimeType);
+                 if(data){
+                     options[mimeType] = data;
+                 }
+             }
+        }
     }
     
     //set event

Modified: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/dnd/dnd03.xhtml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/dnd/dnd03.xhtml?rev=1039794&r1=1039793&r2=1039794&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/dnd/dnd03.xhtml (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/dnd/dnd03.xhtml Sat Nov 27 23:54:04 2010
@@ -65,7 +65,7 @@
 						<td>
 						
 							<hx:div id="drop_zone">
-								<fx:dropTarget acceptMimeTypes="text/x-myfaces-html5-dnd-source, text/plain" 
+								<fx:dropTarget acceptMimeTypes="*" 
 									dropListener="#{dndBean.processDropBehavior}" rerender="someParamOT"/>
 								<h:outputText value="DROP TARGET" />
 							</hx:div>