Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 62832 invoked from network); 30 Oct 2007 17:27:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Oct 2007 17:27:50 -0000 Received: (qmail 18284 invoked by uid 500); 30 Oct 2007 17:27:07 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 18237 invoked by uid 500); 30 Oct 2007 17:27:07 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 18126 invoked by uid 99); 30 Oct 2007 17:27:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Oct 2007 10:27:06 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Oct 2007 17:27:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2B2031A9832; Tue, 30 Oct 2007 10:26:56 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r590165 - in /incubator/cxf/trunk/common/common/src: main/java/org/apache/cxf/staxutils/StaxUtils.java test/java/org/apache/cxf/staxutils/StaxUtilsTest.java Date: Tue, 30 Oct 2007 17:26:54 -0000 To: cxf-commits@incubator.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071030172656.2B2031A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Tue Oct 30 10:26:53 2007 New Revision: 590165 URL: http://svn.apache.org/viewvc?rev=590165&view=rev Log: Fix issue of default namespaces being defined twice Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=590165&r1=590164&r2=590165&view=diff ============================================================================== --- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original) +++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Tue Oct 30 10:26:53 2007 @@ -448,12 +448,13 @@ for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); - String name = attr.getNodeName(); - String attrPrefix = ""; - int prefixIndex = name.indexOf(':'); - if (prefixIndex != -1) { - attrPrefix = name.substring(0, prefixIndex); - name = name.substring(prefixIndex + 1); + String name = attr.getLocalName(); + String attrPrefix = attr.getPrefix(); + if (attrPrefix == null) { + attrPrefix = ""; + } + if (name == null) { + name = attr.getNodeName(); } if ("xmlns".equals(attrPrefix)) { @@ -467,6 +468,9 @@ if ("xmlns".equals(name) && "".equals(attrPrefix)) { writer.writeNamespace("", attr.getNodeValue()); if (attr.getNodeValue().equals(ns)) { + declareNamespace = false; + } else if (StringUtils.isEmpty(attr.getNodeValue()) + && StringUtils.isEmpty(ns)) { declareNamespace = false; } } else { Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=590165&r1=590164&r2=590165&view=diff ============================================================================== --- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java (original) +++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java Tue Oct 30 10:26:53 2007 @@ -172,4 +172,27 @@ assertTrue(output.contains("snarf")); assertTrue(output.contains("blop")); } + + @Test + public void testEmptyNamespace() throws Exception { + String testString = "" + + "abcdef"; + + StringReader reader = new StringReader(testString); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + Document doc = dbf.newDocumentBuilder().parse(new InputSource(reader)); + + StringWriter sw = new StringWriter(); + XMLStreamWriter swriter = StaxUtils.createXMLStreamWriter(sw); + //should not throw an exception + StaxUtils.writeDocument(doc, swriter, false, true); + swriter.flush(); + swriter.close(); + + String output = sw.toString(); + assertEquals(testString, output); + + } + }