You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2010/04/24 01:45:48 UTC

svn commit: r937553 - in /incubator/wookie/trunk: parser/java/src-test/org/apache/wookie/w3c/test/ parser/java/src/org/apache/wookie/w3c/ parser/java/src/org/apache/wookie/w3c/impl/ parser/java/src/org/apache/wookie/w3c/updates/ src/org/apache/wookie/u...

Author: scottbw
Date: Fri Apr 23 23:45:47 2010
New Revision: 937553

URL: http://svn.apache.org/viewvc?rev=937553&view=rev
Log:
Added support for the W3C <update-description> element in the parser (see WOOKIE-103); however this is not yet exposed in the server's Widget bean class. (Also removed some manual testing code that is no longer necessary)

Added:
    incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/UpdateDescriptionTest.java
    incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/
    incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java
Modified:
    incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidget.java
    incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java
    incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java

Added: incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/UpdateDescriptionTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/UpdateDescriptionTest.java?rev=937553&view=auto
==============================================================================
--- incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/UpdateDescriptionTest.java (added)
+++ incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/UpdateDescriptionTest.java Fri Apr 23 23:45:47 2010
@@ -0,0 +1,58 @@
+/*
+ *  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.w3c.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.apache.wookie.w3c.IW3CXMLConfiguration;
+import org.apache.wookie.w3c.exceptions.BadManifestException;
+import org.apache.wookie.w3c.updates.UpdateDescription;
+import org.jdom.Element;
+import org.jdom.Namespace;
+import org.junit.Test;
+
+/**
+ * Tests for Update Description. These should be replaced at some point by official W3C test cases.
+ */
+public class UpdateDescriptionTest {
+	
+	@Test
+	public void create(){
+		UpdateDescription desc = new UpdateDescription();
+		Element update = new Element("update-description", Namespace.getNamespace(IW3CXMLConfiguration.MANIFEST_NAMESPACE));
+		update.setAttribute("href", "http://localhost");
+		try {
+			desc.fromXML(update);
+		} catch (BadManifestException e) {
+			fail();
+		}
+		assertEquals("http://localhost", desc.getHref());
+	}
+	
+	@Test
+	public void createInvalidURL(){
+		UpdateDescription desc = new UpdateDescription();
+		Element update = new Element("update-description", Namespace.getNamespace(IW3CXMLConfiguration.MANIFEST_NAMESPACE));
+		update.setAttribute("href", "notavalidurl!");
+		try {
+			desc.fromXML(update);
+		} catch (BadManifestException e) {
+			fail();
+		}
+		assertNull(desc.getHref());
+	}
+
+}

Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidget.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidget.java?rev=937553&r1=937552&r2=937553&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidget.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidget.java Fri Apr 23 23:45:47 2010
@@ -107,4 +107,9 @@ public interface W3CWidget extends IElem
 	 */
 	public String getLocalName(String locale);
 	
+	/**
+	 * @return the update description document URL for the widget, or null if no valid update URL has been set
+	 */
+	public String getUpdate();
+	
 }

Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java?rev=937553&r1=937552&r2=937553&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java Fri Apr 23 23:45:47 2010
@@ -22,6 +22,7 @@ import java.util.List;
 import org.apache.commons.compress.archivers.zip.ZipFile;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
+import org.apache.wookie.w3c.updates.UpdateDescription;
 import org.apache.wookie.w3c.util.LocalizationUtils;
 import org.apache.wookie.w3c.IAccessEntity;
 import org.apache.wookie.w3c.IAuthorEntity;
@@ -33,7 +34,6 @@ import org.apache.wookie.w3c.ILicenseEnt
 import org.apache.wookie.w3c.ILocalizedEntity;
 import org.apache.wookie.w3c.W3CWidget;
 import org.apache.wookie.w3c.INameEntity;
-import org.apache.wookie.w3c.IParamEntity;
 import org.apache.wookie.w3c.IPreferenceEntity;
 import org.apache.wookie.w3c.IW3CXMLConfiguration;
 import org.apache.wookie.w3c.exceptions.BadManifestException;
@@ -71,6 +71,7 @@ public class WidgetManifestModel impleme
 	private List<IContentEntity> fContentList;
 	private List<IFeatureEntity> fFeaturesList;
 	private List<IPreferenceEntity> fPreferencesList;
+	private String fUpdate;
 	
 	private String[] supportedEncodings;
 	
@@ -138,40 +139,8 @@ public class WidgetManifestModel impleme
 				}
 			}
 		}
-		//Uncomment this when performing conformance testing
-		//outputFeatureList();
-		//outputEncodings();
 	}
-	
-	/**
-	 * Used to check output during conformance testing
-	 */
-	private void outputFeatureList(){
-		if (fFeaturesList.size()==0) return;
-		String out = "";
-		out+=("id:"+this.fIdentifier+":"+this.getLocalName("en"));
-		for (IFeatureEntity feature: fFeaturesList){
-			String params = "";
-			for (IParamEntity param:feature.getParams()){
-				params+="["+param.getName()+":"+param.getValue()+"]";
-			}
-			out+=("feature:"+feature.getName()+"required="+feature.isRequired()+"{"+params+"}");
-		}
-		System.out.println(out);
-	}
-	
-	/**
-	 * Used to check output during conformance testing
-	 */
-	private void outputEncodings(){
-		String out = "";
-		out+=("id:"+this.fIdentifier+":"+this.getLocalName("en"));
-		for (IContentEntity startFile:getContentList()){
-			out+=startFile.getSrc()+" "+startFile.getCharSet();
-		}
-		System.out.println(out);
-	}
-	
+
 	public String getViewModes() {
 		return fViewModes;
 	}
@@ -239,6 +208,10 @@ public class WidgetManifestModel impleme
 		return fWidth;
 	}
 	
+	public String getUpdate(){
+		return fUpdate;
+	}
+	
 	public void fromXML(Element element) throws BadManifestException{
 		fLogger.warn("WidgetManifestModel.fromXML() called with no locales");
 		fromXML(element, new String[]{"en"});
@@ -345,7 +318,15 @@ public class WidgetManifestModel impleme
 			if(tag.equals(IW3CXMLConfiguration.AUTHOR_ELEMENT) && fAuthor == null) {
 				fAuthor = new AuthorEntity();
 				fAuthor.fromXML(child);
-			}		
+			}	
+			
+			// UDPATE DESCRIPTION IS OPTONAL - can only be one, ignore subsequent repetitions
+			if(tag.equals(IW3CXMLConfiguration.UPDATE_ELEMENT) && fUpdate == null) {
+				UpdateDescription update = new UpdateDescription();
+				update.fromXML(child);
+				// It must have a valid HREF attribute, or it is ignored
+				if (update.getHref() != null) fUpdate = update.getHref();
+			}	
 		
 			// LICENSE IS OPTIONAL - can be many
 			if(tag.equals(IW3CXMLConfiguration.LICENSE_ELEMENT)) {				

Added: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java?rev=937553&view=auto
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java (added)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java Fri Apr 23 23:45:47 2010
@@ -0,0 +1,40 @@
+/*
+ *  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.w3c.updates;
+import org.apache.wookie.w3c.exceptions.BadManifestException;
+import org.apache.wookie.w3c.util.IRIValidator;
+import org.jdom.Element;
+
+/**
+ * An UpdateDescription for a Widget
+ */
+public class UpdateDescription{
+	
+	private String _href;
+	
+	public UpdateDescription(){	
+	}
+
+	public String getHref() {
+		return _href;
+	}
+
+	public void fromXML(Element element) throws BadManifestException {
+		String href = element.getAttributeValue("href");
+		if (href != null && href != "" && IRIValidator.isValidIRI(href)){
+			_href = href;
+		}
+	}
+
+}

Modified: incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java?rev=937553&r1=937552&r2=937553&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java Fri Apr 23 23:45:47 2010
@@ -211,4 +211,10 @@ public class GadgetAdapter implements W3
 		return IW3CXMLConfiguration.UNKNOWN;
 	}
 
+	public String getUpdate() {
+		return null;
+	}
+	
+	
+
 }