[teiid-commits] teiid SVN: r3383 - in branches/7.4.x/engine/src: main/java/org/teiid/query/xquery/saxon and 3 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Aug 16 10:25:22 EDT 2011


Author: shawkins
Date: 2011-08-16 10:25:21 -0400 (Tue, 16 Aug 2011)
New Revision: 3383

Modified:
   branches/7.4.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java
   branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties
   branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
   branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1713 fix for not using the default namespace

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java	2011-08-15 18:31:49 UTC (rev 3382)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java	2011-08-16 14:25:21 UTC (rev 3383)
@@ -1337,6 +1337,8 @@
 			if (item.getPrefix() != null) {
 				if (item.getPrefix().equals("xml") || item.getPrefix().equals("xmlns")) { //$NON-NLS-1$ //$NON-NLS-2$
 					handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.xml_namespaces_reserved"), obj); //$NON-NLS-1$
+				} else if (!Name11Checker.getInstance().isValidNCName(item.getPrefix())) {
+					handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.xml_namespaces_invalid", item.getPrefix()), obj); //$NON-NLS-1$
 				}
 				if (item.getUri().length() == 0) {
 					handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.xml_namespaces_null_uri"), obj); //$NON-NLS-1$

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java	2011-08-15 18:31:49 UTC (rev 3382)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java	2011-08-16 14:25:21 UTC (rev 3383)
@@ -90,6 +90,9 @@
 @SuppressWarnings("serial")
 public class SaxonXQueryExpression {
 	
+	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+	static final String DEFAULT_PREFIX = "-"; //$NON-NLS-1$
+
 	public static final Properties DEFAULT_OUTPUT_PROPERTIES = new Properties();
 	{
 		DEFAULT_OUTPUT_PROPERTIES.setProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
@@ -170,17 +173,17 @@
         this.xQueryString = xQueryString;
         StaticQueryContext context = new StaticQueryContext(config);
         IndependentContext ic = new IndependentContext(config);
-        namespaceMap.put("", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        namespaceMap.put(EMPTY_STRING, EMPTY_STRING);
         if (namespaces != null) {
         	for (NamespaceItem item : namespaces.getNamespaceItems()) {
         		if (item.getPrefix() == null) {
         			if (item.getUri() == null) {
-        				context.setDefaultElementNamespace(""); //$NON-NLS-1$
-        				ic.setDefaultElementNamespace(""); //$NON-NLS-1$
+        				context.setDefaultElementNamespace(EMPTY_STRING); 
+        				ic.setDefaultElementNamespace(EMPTY_STRING);
         			} else {
         				context.setDefaultElementNamespace(item.getUri());
         				ic.setDefaultElementNamespace(item.getUri());
-        				namespaceMap.put("", item.getUri()); //$NON-NLS-1$
+        				namespaceMap.put(EMPTY_STRING, item.getUri());
         			}
         		} else {
     				context.declareNamespace(item.getPrefix(), item.getUri());
@@ -189,6 +192,7 @@
         		}
 			}
         }
+        namespaceMap.put(DEFAULT_PREFIX, namespaceMap.get(EMPTY_STRING));
         for (DerivedColumn derivedColumn : passing) {
         	if (derivedColumn.getAlias() == null) {
         		continue;

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java	2011-08-15 18:31:49 UTC (rev 3382)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java	2011-08-16 14:25:21 UTC (rev 3383)
@@ -82,7 +82,7 @@
 					"QName must not contain more than one colon: " //$NON-NLS-1$
 					+ "qname='" + localNames[i] + "', path='" + path + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 			if (k <= 0) {
-				fixedPath += " :"; //$NON-NLS-1$
+				fixedPath += SaxonXQueryExpression.DEFAULT_PREFIX+":"; //$NON-NLS-1$
 			} else {
 				String prefix = localNames[i].substring(0, k).trim();
 				if (k >= localNames[i].length() - 1)

Modified: branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties	2011-08-15 18:31:49 UTC (rev 3382)
+++ branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties	2011-08-16 14:25:21 UTC (rev 3383)
@@ -709,6 +709,7 @@
 ValidationVisitor.xml_namespaces=At most only one NO DEFAULT or DEFAULT namespace may be specified.
 ValidationVisitor.xml_namespaces_reserved=The namespaces xmlns and xml are reserved.
 ValidationVisitor.xml_namespaces_null_uri=The null uri, or empty string, is not allowed as the uri value.
+ValidationVisitor.xml_namespaces_invalid=The namespace prefix {0} is not a valid NCName
 ValidationVisitor.xml_attributes_reserved=The namespace xmlns is reserved.
 ValidationVisitor.xml_content_type=The expression "{0}" is of OBJECT or BLOB type, which cannot be used as an XML or TEXT content value.
 ValidationVisitor.xml_invalid_qname=The qname "{0}" is invalid.

Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2011-08-15 18:31:49 UTC (rev 3382)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2011-08-16 14:25:21 UTC (rev 3383)
@@ -474,5 +474,17 @@
 	public static BlobType blobFromFile(final String file) {
 		return new BlobType(new BlobImpl(new InputStreamFactory.FileInputStreamFactory(UnitTestUtil.getTestDataFile(file))));
 	}
+	
+    @Test public void testXmlTableWithDefault() throws Exception {
+        String sql = "select * from xmltable(XMLNAMESPACES(default 'http://x.y.com'), '/a/b' passing convert('<a xmlns=\"http://x.y.com\"><b>first</b><b x=\"attr\">second</b></a>', xml) columns x string path '@x', val string path '/.') as x"; //$NON-NLS-1$
+        
+        List<?>[] expected = new List<?>[] {
+        		Arrays.asList(null, "first"),
+        		Arrays.asList("attr", "second"),
+        };    
+    
+        process(sql, expected);
+    }
 
+
 }

Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java	2011-08-15 18:31:49 UTC (rev 3382)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java	2011-08-16 14:25:21 UTC (rev 3383)
@@ -1735,6 +1735,10 @@
     @Test public void testXMLNamespaces() {
     	helpValidate("select xmlforest(xmlnamespaces(no default, default 'http://foo'), e1 as \"table\") from pm1.g1", new String[] {"XMLNAMESPACES(NO DEFAULT, DEFAULT 'http://foo')"}, RealMetadataFactory.example1Cached());
     }
+    
+    @Test public void testXMLNamespacesInvalid() {
+    	helpValidate("select xmlforest(xmlnamespaces('http://foo' as \"1\"), e1 as \"table\") from pm1.g1", new String[] {"XMLNAMESPACES('http://foo' AS \"1\")"}, RealMetadataFactory.example1Cached());
+    }
 
     @Test public void testXMLNamespacesReserved() {
     	helpValidate("select xmlforest(xmlnamespaces('http://foo' as xmlns), e1 as \"table\") from pm1.g1", new String[] {"XMLNAMESPACES('http://foo' AS xmlns)"}, RealMetadataFactory.example1Cached());



More information about the teiid-commits mailing list