portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smi...@apache.org
Subject svn commit: r588424 - /portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceLib.java
Date Fri, 26 Oct 2007 00:01:31 GMT
Author: smilek
Date: Thu Oct 25 17:01:30 2007
New Revision: 588424

URL: http://svn.apache.org/viewvc?rev=588424&view=rev
Log:
added makeJSONObject() method with overloads

Modified:
    portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceLib.java

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceLib.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceLib.java?rev=588424&r1=588423&r2=588424&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceLib.java
(original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceLib.java
Thu Oct 25 17:01:30 2007
@@ -18,6 +18,7 @@
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Collection;
 
 import javax.servlet.http.HttpServletRequest;
@@ -296,6 +297,70 @@
         return relativePath;
     }
     
+    public static StringBuffer makeJSONObject( Map objectMap, boolean whenEmptyReturnNewObject
)
+    {
+    	return makeJSONObject( null, new Map[] { objectMap }, whenEmptyReturnNewObject );
+    }
+    public static StringBuffer makeJSONObject( Map[] objectMaps, boolean whenEmptyReturnNewObject
)
+    {
+    	return makeJSONObject( null, objectMaps, whenEmptyReturnNewObject );
+    }
+    public static StringBuffer makeJSONObject( StringBuffer jsonBuffer, Map objectMap, boolean
whenEmptyReturnNewObject )
+    {
+    	return makeJSONObject( jsonBuffer, new Map[] { objectMap }, whenEmptyReturnNewObject
);
+    }
+    public static StringBuffer makeJSONObject( StringBuffer jsonBuffer, Map[] objectMaps,
boolean whenEmptyReturnNewObject )
+    {
+    	if ( jsonBuffer == null )
+    		jsonBuffer = new StringBuffer();
+    	
+    	int added = 0;
+    	int objMapsLen = ( objectMaps == null ? 0 : objectMaps.length );
+    	if ( objMapsLen > 0 )
+    	{
+    		for ( int i = 0 ; i < objMapsLen ; i++ )
+    		{
+    			Map objectMap = objectMaps[i];
+    			if ( objectMap != null && objectMap.size() > 0 )
+    	        {
+    				if ( added == 0 )
+    					jsonBuffer.append( "{" );
+    	        	Map.Entry objEntry;
+    	        	Object objKey, objVal;
+    	        	Iterator objMapIter = objectMap.entrySet().iterator();
+    	        	while ( objMapIter.hasNext() )
+    	        	{
+    	        		objEntry = (Map.Entry)objMapIter.next();
+    	        		objKey = objEntry.getKey();
+    	        		if ( objKey != null )
+    	        		{
+    	        			if ( added > 0 )
+    	        				jsonBuffer.append( ", " );
+    	        			jsonBuffer.append( "\"" ).append( objKey.toString() ).append( "\":" );
+    	            		objVal = objEntry.getValue();
+    	            		if ( objVal == null )
+    	            			objVal = "";
+    	            		jsonBuffer.append( "\"" ).append( objVal.toString() ).append( "\"" );
+    	            		added++;
+    	        		}
+    	        	}
+    	        }
+    		}
+    	}
+    	if ( added > 0 )
+    	{
+			jsonBuffer.append( "}" );
+    	}
+		else if ( whenEmptyReturnNewObject )
+        {
+        	jsonBuffer.append( "{}" );
+        }
+        else
+        {
+        	return null;
+        }
+    	return jsonBuffer;
+    }
     
     public static String makeJavascriptStatement( String statement, String indent, boolean
addEOL )
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message