You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by dk...@apache.org on 2012/07/24 19:37:29 UTC

svn commit: r1365187 - in /webservices/xmlschema/trunk/xmlschema-core/src: main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java test/java/org/apache/ws/commons/schema/XMLSerializerTest.java

Author: dkulp
Date: Tue Jul 24 17:37:28 2012
New Revision: 1365187

URL: http://svn.apache.org/viewvc?rev=1365187&view=rev
Log:
[XMLSCHEMA-25] Fix for potential never ending loop
Patch from Dmitry Repchevsky applied

Added:
    webservices/xmlschema/trunk/xmlschema-core/src/test/java/org/apache/ws/commons/schema/XMLSerializerTest.java
Modified:
    webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java

Modified: webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?rev=1365187&r1=1365186&r2=1365187&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java (original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java Tue Jul 24 17:37:28 2012
@@ -2430,11 +2430,11 @@ public class XmlSchemaSerializer {
         if (xsdPrefix == null) {
             //find a prefix to use
             xsdPrefix = "";
-            if (ctx != null && ctx.getNamespaceURI(xsdPrefix) != null) {
+            if (ctx != null && ctx.getNamespaceURI(xsdPrefix).length() > 0) {
                 xsdPrefix = "xsd";
             }
             int count = 0;
-            while (ctx != null && ctx.getNamespaceURI(xsdPrefix) != null) {
+            while (ctx != null && ctx.getNamespaceURI(xsdPrefix).length() > 0) {
                 xsdPrefix = "xsd" + ++count;
             }
         }
@@ -2448,14 +2448,16 @@ public class XmlSchemaSerializer {
             String[] prefixes = ctx.getDeclaredPrefixes();
             for (int i = 0;  i < prefixes.length;  i++) {
                 String prefix = prefixes[i];
-                String uri = ctx.getNamespaceURI(prefix);
-                if (uri != null && prefix != null) {
-                    if ("".equals(prefix) || !schemaNamespace.containsKey(uri)) {
-                        schemaNamespace.put(uri, prefix);
+                if (prefix != null) {
+                    String uri = ctx.getNamespaceURI(prefix);
+                    if (uri.length() > 0) {
+                        if ("".equals(prefix) || !schemaNamespace.containsKey(uri)) {
+                            schemaNamespace.put(uri, prefix);
+                        }
+                        prefix = (prefix.length() > 0) ? "xmlns:" + prefix : "xmlns";
+                        schemaEl.setAttributeNS(XMLNS_NAMESPACE_URI,
+                                                prefix, uri);
                     }
-                    prefix = (prefix.length() > 0) ? "xmlns:" + prefix : "xmlns";
-                    schemaEl.setAttributeNS(XMLNS_NAMESPACE_URI,
-                                            prefix, uri);
                 }
             }
         }

Added: webservices/xmlschema/trunk/xmlschema-core/src/test/java/org/apache/ws/commons/schema/XMLSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/java/org/apache/ws/commons/schema/XMLSerializerTest.java?rev=1365187&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/java/org/apache/ws/commons/schema/XMLSerializerTest.java (added)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/java/org/apache/ws/commons/schema/XMLSerializerTest.java Tue Jul 24 17:37:28 2012
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.ws.commons.schema;
+
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.apache.ws.commons.schema.utils.NodeNamespaceContext;
+import org.junit.Test;
+
+public class XMLSerializerTest {
+    @Test
+    public void test() throws Exception {
+        XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
+        XmlSchema xmlSchema = new XmlSchema("", xmlSchemaCollection);
+        NamespacePrefixList ctx = NodeNamespaceContext.getNamespaceContext(xmlSchema.getSchemaDocument());
+        xmlSchema.setNamespaceContext(ctx);
+        xmlSchema.getSchemaDocument();
+    }
+}
\ No newline at end of file