incubator-wookie-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scot...@apache.org
Subject svn commit: r833405 - in /incubator/wookie/trunk: src-tests/org/apache/wookie/tests/functional/ src-tests/org/apache/wookie/tests/integration/ src/org/apache/wookie/beans/ src/org/apache/wookie/controller/ src/org/apache/wookie/helpers/ src/org/apache/...
Date Fri, 06 Nov 2009 14:22:42 GMT
Author: scottbw
Date: Fri Nov  6 14:22:42 2009
New Revision: 833405

URL: http://svn.apache.org/viewvc?rev=833405&view=rev
Log:
Fixed WOOKIE-48. This involved switching from int to Integer for representing height and width
of Widget objects, impacting a number of classes including test cases. Also extended the metadata
returned by REST API to help with testing.

Added:
    incubator/wookie/trunk/src/org/apache/wookie/util/NumberUtils.java
Modified:
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/integration/GadgetUtilsTest.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/Widget.java
    incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
    incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java
    incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IManifestModel.java
    incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java?rev=833405&r1=833404&r2=833405&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java
(original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java
Fri Nov  6 14:22:42 2009
@@ -36,7 +36,7 @@
 	        int code = get.getStatusCode();
 	        assertEquals(200,code);
 	        String response = get.getResponseBodyAsString();
-	        assertTrue(response.contains("<widget id=\"1\" identifier=\"http://www.tencompetence.org/widgets/default/notsupported\"
version=\"v1.0\">"));
+	        assertTrue(response.contains("<widget id=\"1\" identifier=\"http://www.tencompetence.org/widgets/default/notsupported\""));
 	        get.releaseConnection();
 	    }
 	    catch (Exception e) {
@@ -54,7 +54,7 @@
 	        int code = get.getStatusCode();
 	        assertEquals(200,code);
 	        String response = get.getResponseBodyAsString();
-	        assertTrue(response.contains("<widget id=\"1\" identifier=\"http://www.tencompetence.org/widgets/default/notsupported\"
version=\"v1.0\">"));
+	        assertTrue(response.contains("<widget id=\"1\" identifier=\"http://www.tencompetence.org/widgets/default/notsupported\""));
 	        get.releaseConnection();
 	    }
 	    catch (Exception e) {
@@ -88,7 +88,7 @@
 	        int code = get.getStatusCode();
 	        assertEquals(200,code);
 	        String response = get.getResponseBodyAsString();
-	        assertTrue(response.contains("<widget id=\"1\" identifier=\"http://www.tencompetence.org/widgets/default/notsupported\"
version=\"v1.0\">"));
+	        assertTrue(response.contains("<widget id=\"1\" identifier=\"http://www.tencompetence.org/widgets/default/notsupported\""));
 	        get.releaseConnection();
 	    }
 	    catch (Exception e) {

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/integration/GadgetUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/integration/GadgetUtilsTest.java?rev=833405&r1=833404&r2=833405&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/integration/GadgetUtilsTest.java
(original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/integration/GadgetUtilsTest.java
Fri Nov  6 14:22:42 2009
@@ -226,8 +226,8 @@
 		Widget widget = null;
 		try {
 			widget = GadgetUtils.getWidget(TEST_METADATA_VALID, SHINDIG);
-			assertEquals(widget.getHeight(), 200);
-			assertEquals(widget.getWidth(), 320);
+			assertEquals(widget.getHeight().intValue(), 200);
+			assertEquals(widget.getWidth().intValue(), 320);
 		} catch (Exception e) {
 			fail("Create widget from basic valid metadata - defaults not used");
 		}
@@ -239,8 +239,8 @@
 		try {
 			widget = GadgetUtils.getWidget(TEST_METADATA_SET_HEIGHT_WIDTH,
 					SHINDIG);
-			assertEquals(widget.getHeight(), 50);
-			assertEquals(widget.getWidth(), 50);
+			assertEquals(widget.getHeight().intValue(), 50);
+			assertEquals(widget.getWidth().intValue(), 50);
 		} catch (Exception e) {
 			fail("Create widget from basic valid metadata - overrides not used");
 		}

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/Widget.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/Widget.java?rev=833405&r1=833404&r2=833405&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/Widget.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/Widget.java Fri Nov  6 14:22:42 2009
@@ -40,8 +40,8 @@
 	private String widgetIconLocation;
 	private String url;
 	private String guid;	
-	private int height;
-	private int width;
+	private Integer height;
+	private Integer width;
 	private boolean maximize;	
 	@SuppressWarnings("unchecked")
 	private Set widgetTypes = new HashSet();
@@ -58,19 +58,19 @@
 		this.url = url;
 	}
 	
-	public int getHeight(){
+	public Integer getHeight(){
 		return height;
 	}
 	
-	public void setHeight(int height){
+	public void setHeight(Integer height){
 		this.height = height;
 	}
 
-	public int getWidth(){
+	public Integer getWidth(){
 		return width;
 	}
 	
-	public void setWidth(int width){
+	public void setWidth(Integer width){
 		this.width = width;
 	}
 	

Modified: incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java?rev=833405&r1=833404&r2=833405&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
Fri Nov  6 14:22:42 2009
@@ -33,6 +33,7 @@
 import org.apache.wookie.helpers.Notifier;
 import org.apache.wookie.helpers.WidgetFactory;
 import org.apache.wookie.helpers.WidgetKeyManager;
+import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
 import org.apache.wookie.server.LocaleHandler;
 import org.apache.wookie.util.HashGenerator;
 import org.apache.wookie.util.RandomGUID;
@@ -277,7 +278,14 @@
 		URL urlWidget =  new URL(request.getScheme() ,
 				request.getServerName() ,
 				request.getServerPort() , widget.getUrl());
-
+		
+		// Return a default width and height where the original value is either not provided
+		// or of an invalid range (<0)
+		String width = String.valueOf(IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE);
+		String height = String.valueOf(IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE);
+		if (widget.getWidth()!=null && widget.getWidth()>0) width = widget.getWidth().toString();
+		if (widget.getHeight()!=null && widget.getHeight()>0) height = widget.getHeight().toString();
+		
 		response.setContentType(CONTENT_TYPE);
 		PrintWriter out = response.getWriter();
 		out.println(XMLDECLARATION);			
@@ -297,8 +305,8 @@
 		out.println("</url>"); //$NON-NLS-1$
 		out.println("<identifier>"+key+"</identifier>"); //$NON-NLS-1$ //$NON-NLS-2$
 		out.println("<title>"+widget.getWidgetTitle()+"</title>"); //$NON-NLS-1$ //$NON-NLS-2$
-		out.println("<height>"+widget.getHeight()+"</height>"); //$NON-NLS-1$ //$NON-NLS-2$
-		out.println("<width>"+widget.getWidth()+"</width>"); //$NON-NLS-1$ //$NON-NLS-2$
+		out.println("<height>"+height+"</height>"); //$NON-NLS-1$ //$NON-NLS-2$
+		out.println("<width>"+width+"</width>"); //$NON-NLS-1$ //$NON-NLS-2$
 		out.println("<maximize>"+widget.isMaximize()+"</maximize>"); //$NON-NLS-1$
//$NON-NLS-2$
 		out.println("</widgetdata>"); //$NON-NLS-1$
 	}

Modified: incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java?rev=833405&r1=833404&r2=833405&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java Fri Nov  6 14:22:42
2009
@@ -65,11 +65,21 @@
 	 * @return the XML representation of the widget
 	 */
 	public static String toXml(Widget widget, String localIconPath){
+		String width = "";
+		String height = "";
+		if (widget.getWidth()!=null)  width = widget.getWidth().toString();
+		if (widget.getHeight()!=null) height = widget.getHeight().toString();
+		
 		if (widget == null) return null;
 		String out = "";
 		URL urlWidgetIcon = null;
-		out += "\t<widget id=\""+widget.getId()+"\" identifier=\"" + widget.getGuid() + "\"
version=\""
-				+ widget.getVersion() + "\">\n";
+		out += "\t<widget " +
+				"id=\""+widget.getId()
+				+"\" identifier=\"" + widget.getGuid() 
+				+"\" width=\"" + width
+				+"\" height=\"" + height
+				+ "\" version=\"" + widget.getVersion() 
+				+ "\">\n";
 		out += "\t\t<title short=\""+widget.getWidgetShortName()+"\">" + widget.getWidgetTitle()
+ "</title>\n";
 		out += "\t\t<description>" + widget.getWidgetDescription()
 				+ "</description>\n";

Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IManifestModel.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IManifestModel.java?rev=833405&r1=833404&r2=833405&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IManifestModel.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IManifestModel.java Fri Nov
 6 14:22:42 2009
@@ -40,9 +40,9 @@
 
 	public String getLocalDescription(String locale);
 
-	public int getHeight();
+	public Integer getHeight();
 
-	public int getWidth();
+	public Integer getWidth();
 
 	public String getAuthor();
 

Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java?rev=833405&r1=833404&r2=833405&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
Fri Nov  6 14:22:42 2009
@@ -31,6 +31,7 @@
 import org.apache.wookie.manifestmodel.INameEntity;
 import org.apache.wookie.manifestmodel.IPreferenceEntity;
 import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
+import org.apache.wookie.util.NumberUtils;
 import org.apache.wookie.util.RandomGUID;
 import org.apache.wookie.util.UnicodeUtils;
 import org.jdom.Element;
@@ -45,8 +46,8 @@
 	
 	private String fIdentifier;
 	private String fVersion;
-	private int fHeight;
-	private int fWidth;
+	private Integer fHeight;
+	private Integer fWidth;
 	private String fViewModes;
 	private String fLang;
 	private List<INameEntity> fNamesList;
@@ -167,7 +168,7 @@
 		fContent = content;
 	}
 
-	public int getHeight() {
+	public Integer getHeight() {
 		return fHeight;
 	}
 
@@ -175,7 +176,7 @@
 		fHeight = height;
 	}
 	
-	public int getWidth() {
+	public Integer getWidth() {
 		return fWidth;
 	}
 
@@ -223,24 +224,26 @@
 		} else {
 			fVersion = UnicodeUtils.normalizeSpaces(fVersion);
 		}
-		// HEIGHT IS OPTIONAL		
+		// HEIGHT IS OPTIONAL	
 		String height  = element.getAttributeValue(IW3CXMLConfiguration.HEIGHT_ATTRIBUTE);
 		if(height != null){
-			fHeight  = Integer.valueOf(height);
-		}
-		else{ 
-			// give up
-			fHeight = IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE;
+			try { 
+				fHeight = NumberUtils.processNonNegativeInteger(height); 
+			} catch (NumberFormatException e) { 
+				// Not a valid number - pass through without setting 
+			} 
 		}
+
 		// WIDTH IS OPTIONAL		
 		String width  = element.getAttributeValue(IW3CXMLConfiguration.WIDTH_ATTRIBUTE);
 		if(width != null){
-			fWidth = Integer.valueOf(width);
-		}
-		else{
-			// give up
-			fWidth = IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE;
+			try { 
+				fWidth = NumberUtils.processNonNegativeInteger(width); 
+			} catch (NumberFormatException e) { 
+				// Not a valid number - pass through without setting 
+			} 
 		}
+
 		// VIEWMODES IS OPTIONAL	
 		fViewModes = element.getAttributeValue(IW3CXMLConfiguration.MODE_ATTRIBUTE);
 		if(fViewModes == null){

Added: incubator/wookie/trunk/src/org/apache/wookie/util/NumberUtils.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/NumberUtils.java?rev=833405&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/NumberUtils.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/NumberUtils.java Fri Nov  6 14:22:42
2009
@@ -0,0 +1,47 @@
+/*
+ *  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.
+ */
+package org.apache.wookie.util;
+
+import antlr.StringUtils;
+
+/**
+ * Utility for handling numbers according to W3C processing rules
+ * @author scott
+ *
+ */
+public class NumberUtils {
+	
+	public static int processNonNegativeInteger(String in) throws NumberFormatException {
+		int result = 0;
+		in = UnicodeUtils.normalizeSpaces(in);
+		StringUtils.stripFront(in, " ");
+		
+		if (in.length() == 0) throw new NumberFormatException("no non-space characters");
+
+		for (int pos=0;pos<in.length();pos++){
+			String nextchar = in.substring(pos, pos+1);
+			// If the nextchar is not one of U+0030 (0) .. U+0039 (9), then return result.
+			try {
+				int i = Integer.parseInt(nextchar);
+				result = result * 10 + i;
+			} catch (Exception e) {
+				return result;
+			}
+		}
+		
+		return result;
+		
+	}
+
+}



Mime
View raw message