Author: darran.lofthouse(a)jboss.com
Date: 2010-03-11 12:06:09 -0500 (Thu, 11 Mar 2010)
New Revision: 11765
Removed:
common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCase.java
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java
Log:
[JBWS-2885] Revert changes.
Modified: common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java 2010-03-11 12:56:34
UTC (rev 11764)
+++ common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java 2010-03-11 17:06:09
UTC (rev 11765)
@@ -28,18 +28,13 @@
*
* @author <a href="mailto:mvecera@redhat.com">Martin Vecera</a>
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio
Soldano</a>
-* @author <a href="mailto:darran.lofthouse@jboss.com">Darran
Lofthouse</a>
-*
* @since 09-Dic-2009
+*
*/
final public class Normalizer
{
private static final Pattern PATTERN =
Pattern.compile("[&<>'\"\r\n]");
- private static final String CDATA_START = "<![CDATA[";
-
- private static final String CDATA_END = "]]>";
-
public static String normalize(String strValue)
{
return normalize(strValue, false);
@@ -50,57 +45,11 @@
Matcher m = PATTERN.matcher(strValue);
if (m.find())
{
- int len = strValue.length();
- StringBuilder sb = new StringBuilder(len * 3); // faster than StringBuffer, not
thread safe
- int start = 0;
-
- while (start < len)
- {
- int cdataStart = strValue.indexOf(CDATA_START, start);
- if (cdataStart > -1)
- {
- int cdataEnd = strValue.indexOf(CDATA_END, cdataStart);
- // If a valid start and end to a <![CDATA[ ]]> section are
- // identified exclude from normalisation.
- if (cdataEnd > -1)
- {
- if (cdataStart > start)
- {
- normalize(strValue.substring(start, cdataStart), canonical, sb);
- }
- sb.append(strValue.subSequence(cdataStart, cdataEnd + 3));
- start = cdataEnd + 3;
- }
- else
- {
- normalize(strValue.substring(start, len), canonical, sb);
- start = len;
- }
- }
- else
- {
- normalize(strValue.substring(start, len), canonical, sb);
- start = len;
- }
- }
-
- return sb.toString();
- }
- else
- {
- return strValue;
- }
- }
-
- private static void normalize(String strValue, boolean canonical, StringBuilder sb)
- {
- Matcher m = PATTERN.matcher(strValue);
- if (m.find())
- {
int pos = m.start(); // we can use previous match to skip some part at the
string beginning
int len = strValue.length(); // just a single call to length()
char[] input = new char[len]; // this is to ommit calls to String.charAt()
strValue.getChars(0, len, input, 0);
+ StringBuilder sb = new StringBuilder(len * 3); // faster than StringBuffer, not
thread safe
int copyStart = 0;
@@ -170,10 +119,12 @@
{
sb.append(input, copyStart, len - copyStart);
}
+
+ return sb.toString();
}
else
{
- sb.append(strValue);
+ return strValue;
}
}
}
Deleted: common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCase.java
===================================================================
--- common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCase.java 2010-03-11
12:56:34 UTC (rev 11764)
+++ common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCase.java 2010-03-11
17:06:09 UTC (rev 11765)
@@ -1,104 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.ws.common;
-
-import org.jboss.wsf.common.Normalizer;
-
-import junit.framework.TestCase;
-
-/**
- * [JBWS-2885]
http://jira.jboss.com/jira/browse/JBWS-2885
- *
- * Test case to test <![CDATA[ ]]> sections are skipped in the
- * normalization process.
- *
- * @author darran.lofthouse(a)jboss.com
- * @since Mar 10, 2010
- */
-public class NormalizerTestCase extends TestCase
-{
-
- private static final String CDATA_STRING = "<![CDATA[ABC]]>";
-
- public void testCDATAOnly()
- {
- String normalized = Normalizer.normalize(CDATA_STRING);
-
- assertEquals("Normalized String", CDATA_STRING, normalized);
- }
-
- public void testCDATABegin()
- {
- String normalized = Normalizer.normalize(CDATA_STRING + "ABC");
-
- assertEquals("Normalized String", CDATA_STRING + "ABC",
normalized);
- }
-
- public void testCDATAEnd()
- {
- String normalized = Normalizer.normalize("ABD" + CDATA_STRING);
-
- assertEquals("Normalized String", "ABD" + CDATA_STRING,
normalized);
- }
-
- public void testCDATAMid()
- {
- String normalized = Normalizer.normalize("ABD" + CDATA_STRING +
"EFG");
-
- assertEquals("Normalized String", "ABD" + CDATA_STRING +
"EFG", normalized);
- }
-
- public void testCDATADouble()
- {
- String normalized = Normalizer.normalize("ABD" + CDATA_STRING +
"EFG" + CDATA_STRING + "HIJ");
-
- assertEquals("Normalized String", "ABD" + CDATA_STRING +
"EFG" + CDATA_STRING + "HIJ", normalized);
- }
-
- public void testCDATABegin_Replace()
- {
- String normalized = Normalizer.normalize(CDATA_STRING + "<>");
-
- assertEquals("Normalized String", CDATA_STRING +
"<>", normalized);
- }
-
- public void testCDATAEnd_Replace()
- {
- String normalized = Normalizer.normalize("<>" + CDATA_STRING);
-
- assertEquals("Normalized String", "<>" +
CDATA_STRING, normalized);
- }
-
- public void testCDATAMid_Replace()
- {
- String normalized = Normalizer.normalize("<>" + CDATA_STRING +
"<>");
-
- assertEquals("Normalized String", "<>" +
CDATA_STRING + "<>", normalized);
- }
-
- public void testCDATADouble_Replace()
- {
- String normalized = Normalizer.normalize("<>" + CDATA_STRING +
"<>" + CDATA_STRING + "<>");
-
- assertEquals("Normalized String", "<>" +
CDATA_STRING + "<>" + CDATA_STRING + "<>",
normalized);
- }
-}