Author: vgritsenko
Date: Tue May  3 11:15:04 2005
New Revision: 167949

URL: http://svn.apache.org/viewcvs?rev=167949&view=rev
Log:
replace while() with easier to read for() loop, reduce count of local 
variables, reduce count of get() calls.

Modified:
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java?rev=167949&r1=167948&r2=167949&view=diff
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
 Tue May  3 11:15:04 2005
@@ -56,7 +56,6 @@
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.helpers.AttributesImpl;
 
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.TransformerFactory;
@@ -515,7 +514,7 @@
 
     /**
      * Stop recording of text and return the recorded information.
-     * @return The String.
+     * @return The String, trimmed.
      */
     public String endTextRecording()
     throws SAXException {
@@ -936,42 +935,35 @@
     throws SAXException {
 
         if (prefix != null) {
-            // search the namespace prefix
+            // Find and remove the namespace prefix
             boolean found = false;
-            int l = this.namespaces.size();
-            int i = l-1;
-            while (!found && i >= 0) {
-                String currentPrefix = ((String[])this.namespaces.get(i))[0];
-                if (currentPrefix.equals(prefix)) {
+            for (int i = this.namespaces.size() - 1; i >= 0; i--) {
+                final String[] prefixAndUri = (String[]) 
this.namespaces.get(i);
+                if (prefixAndUri[0].equals(prefix)) {
+                    this.namespaces.remove(i);
                     found = true;
-                } else {
-                    i--;
+                    break;
                 }
             }
             if (!found) {
-                throw new SAXException("Namespace for prefix '"+ prefix + "' 
not found.");
+                throw new SAXException("Namespace for prefix '" + prefix + "' 
not found.");
             }
 
-            this.namespaces.remove(i);
             if (prefix.equals(this.ourPrefix)) {
+                // Reset our current prefix
                 this.ourPrefix = null;
-                // now search if we have a different prefix for our namespace
-                found = false;
-                l = this.namespaces.size();
-                i = l-1;
-                while (!found && i >= 0) {
-                    String currentNS = ((String[])this.namespaces.get(i))[1];
-                    if (namespaceURI.equals(currentNS)) {
-                        found = true;
-                    } else {
-                        i--;
+
+                // Now search if we have a different prefix for our namespace
+                for (int i = this.namespaces.size() - 1; i >= 0; i--) {
+                    final String[] prefixAndUri = (String[]) 
this.namespaces.get(i);
+                    if (namespaceURI.equals(prefixAndUri[1])) {
+                        this.ourPrefix = prefixAndUri[0];
+                        break;
                     }
                 }
-                if (found) {
-                    this.ourPrefix = ((String[])this.namespaces.get(i))[0];
-                }
             }
         }
+
         if (this.ignoreEventsCount == 0) {
             super.endPrefixMapping(prefix);
         }


Reply via email to