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 2009/12/09 00:51:34 UTC
svn commit: r888635 - in /incubator/wookie/trunk:
src-tests/org/apache/wookie/tests/conformance/
src/org/apache/wookie/manifestmodel/impl/ src/org/apache/wookie/util/
Author: scottbw
Date: Tue Dec 8 23:51:33 2009
New Revision: 888635
URL: http://svn.apache.org/viewvc?rev=888635&view=rev
Log:
Implemented IRI attribute checking, fixing WOOKIE-60, WOOKIE-77 and WOOKIE-78
Added:
incubator/wookie/trunk/src/org/apache/wookie/util/IRIValidator.java
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/FeatureEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java?rev=888635&r1=888634&r2=888635&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java Tue Dec 8 23:51:33 2009
@@ -211,7 +211,7 @@
@Test
public void b2(){
Element widget = processWidgetNoErrors("http://dev.w3.org/2006/waf/widgets/test-suite/test-cases/ta-RawAIWHoMs/002/b2.wgt");
- assertEquals("pass:", widget.getAttributeValue("identifier"));
+ assertEquals("pass:", widget.getAttributeValue("identifier")); //Note that this test will pass on its own, but not if run in a series including b1, as it will update b1 rather than create a new widget");
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java?rev=888635&r1=888634&r2=888635&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java Tue Dec 8 23:51:33 2009
@@ -14,11 +14,9 @@
package org.apache.wookie.manifestmodel.impl;
-import java.net.URI;
-import java.net.URISyntaxException;
-
import org.apache.wookie.manifestmodel.IAuthorEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
+import org.apache.wookie.util.IRIValidator;
import org.apache.wookie.util.UnicodeUtils;
import org.apache.wookie.util.XmlUtils;
import org.jdom.Element;
@@ -77,14 +75,7 @@
fAuthorName = UnicodeUtils.normalizeWhitespace(XmlUtils.getTextContent(element));
fHref = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.HREF_ATTRIBUTE));
if (fHref.equals("")) fHref = null;
- if (fHref != null){
- try {
- @SuppressWarnings("unused")
- URI uri = new URI(fHref);
- } catch (URISyntaxException e) {
- fHref = null;
- }
- }
+ if (!IRIValidator.isValidIRI(fHref)) fHref = null;
fEmail = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.EMAIL_ATTRIBUTE));
if (fEmail.equals("")) fEmail = null;
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/FeatureEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/FeatureEntity.java?rev=888635&r1=888634&r2=888635&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/FeatureEntity.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/FeatureEntity.java Tue Dec 8 23:51:33 2009
@@ -22,6 +22,7 @@
import org.apache.wookie.manifestmodel.IFeatureEntity;
import org.apache.wookie.manifestmodel.IParamEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
+import org.apache.wookie.util.IRIValidator;
import org.apache.wookie.util.UnicodeUtils;
import org.jdom.Element;
/**
@@ -95,10 +96,18 @@
fRequired = true;
String isRequired = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.REQUIRED_ATTRIBUTE));
if(isRequired.equals("false")) fRequired = false;
-
+
if(fName.equals("")){
fName = null;
} else {
+ // Not a valid IRI?
+ if (!IRIValidator.isValidIRI(fName)){
+ if (fRequired) {
+ throw new BadManifestException();
+ } else {
+ fName = null;
+ }
+ }
// Not supported?
if (ServerFeature.findByName(fName)==null){
if (fRequired){
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=888635&r1=888634&r2=888635&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 Tue Dec 8 23:51:33 2009
@@ -37,6 +37,7 @@
import org.apache.wookie.manifestmodel.IParamEntity;
import org.apache.wookie.manifestmodel.IPreferenceEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
+import org.apache.wookie.util.IRIValidator;
import org.apache.wookie.util.NumberUtils;
import org.apache.wookie.util.RandomGUID;
import org.apache.wookie.util.UnicodeUtils;
@@ -292,13 +293,16 @@
// try the old one
fIdentifier = element.getAttributeValue(IW3CXMLConfiguration.UID_ATTRIBUTE);
}
+ // Normalize spaces
+ if(fIdentifier != null) fIdentifier = UnicodeUtils.normalizeSpaces(fIdentifier);
+ // Not a valid IRI?
+ if (!IRIValidator.isValidIRI(fIdentifier)){
+ fIdentifier = null;
+ }
if(fIdentifier == null){
//give up & generate one
RandomGUID r = new RandomGUID();
fIdentifier = "generated-uid-" + r.toString();
- } else {
- //normalize spaces
- fIdentifier = UnicodeUtils.normalizeSpaces(fIdentifier);
}
// VERSION IS OPTIONAL
fVersion = element.getAttributeValue(IW3CXMLConfiguration.VERSION_ATTRIBUTE);
Added: incubator/wookie/trunk/src/org/apache/wookie/util/IRIValidator.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/IRIValidator.java?rev=888635&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/IRIValidator.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/IRIValidator.java Tue Dec 8 23:51:33 2009
@@ -0,0 +1,46 @@
+/*
+ * 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 java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * IRI checking utility
+ * This should be replaced with a "real" IRI implementation
+ * as soon as one becomes available.
+ *
+ * @author Scott Wilson
+ *
+ */
+public class IRIValidator {
+
+ public static boolean isValidIRI(String str){
+ URI iri;
+ if (str == null) return false;
+ try {
+ iri = new URI(str);
+ if (iri.getScheme() == null) return false;
+ return true;
+ } catch (Exception e) {
+ // Scheme only is allowed for an IRI
+ try {
+ iri = new URI(str, null, null);
+ return true;
+ } catch (URISyntaxException e1) {
+ return false;
+ }
+ }
+ }
+}