You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/02/10 22:05:41 UTC

svn commit: r1444616 - /manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/XMLFuzzyHierarchicalParseState.java

Author: kwright
Date: Sun Feb 10 21:05:41 2013
New Revision: 1444616

URL: http://svn.apache.org/r1444616
Log:
Make sure we don't accumulate indefinite string amounts during long tagless regions.

Modified:
    manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/XMLFuzzyHierarchicalParseState.java

Modified: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/XMLFuzzyHierarchicalParseState.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/XMLFuzzyHierarchicalParseState.java?rev=1444616&r1=1444615&r2=1444616&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/XMLFuzzyHierarchicalParseState.java (original)
+++ manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/XMLFuzzyHierarchicalParseState.java Sun Feb 10 21:05:41 2013
@@ -48,6 +48,10 @@ public class XMLFuzzyHierarchicalParseSt
   /** Whether we're capturing escaped characters */
   protected boolean captureEscaped = false;
   
+  /** This is the maximum size of a chunk of characters getting sent to the characters() method.
+  */
+  protected final static int MAX_CHUNK_SIZE = 4096;
+  
   /** Constructor with default properties.
   */
   public XMLFuzzyHierarchicalParseState()
@@ -89,12 +93,7 @@ public class XMLFuzzyHierarchicalParseSt
   protected boolean noteTagEx(String tagName, String nameSpace, String localName, Map<String,String> attributes)
     throws ManifoldCFException
   {
-    if (characterBuffer.length() > 0)
-    {
-      if (currentContext != null)
-        currentContext.characters(characterBuffer.toString());
-      characterBuffer.setLength(0);
-    }
+    flushCharacterBuffer();
     if (currentContext != null)
       currentContext.startElement(nameSpace,localName,tagName,attributes);
     return false;
@@ -106,12 +105,7 @@ public class XMLFuzzyHierarchicalParseSt
   protected boolean noteEndTagEx(String tagName, String nameSpace, String localName)
     throws ManifoldCFException
   {
-    if (characterBuffer.length() > 0)
-    {
-      if (currentContext != null)
-        currentContext.characters(characterBuffer.toString());
-      characterBuffer.setLength(0);
-    }
+    flushCharacterBuffer();
     if (currentContext != null)
       currentContext.endElement(nameSpace,localName,tagName);
     return false;
@@ -125,10 +119,29 @@ public class XMLFuzzyHierarchicalParseSt
   protected boolean noteNormalCharacter(char thisChar)
     throws ManifoldCFException
   {
-    characterBuffer.append(thisChar);
+    appendToCharacterBuffer(thisChar);
     return false;
   }
+  
+  protected void appendToCharacterBuffer(char thisChar)
+    throws ManifoldCFException
+  {
+    characterBuffer.append(thisChar);
+    if (characterBuffer.length() >= MAX_CHUNK_SIZE)
+      flushCharacterBuffer();
+  }
 
+  protected void flushCharacterBuffer()
+    throws ManifoldCFException
+  {
+    if (characterBuffer.length() > 0)
+    {
+      if (currentContext != null)
+        currentContext.characters(characterBuffer.toString());
+      characterBuffer.setLength(0);
+    }
+  }
+  
   /** New version of the noteEscapedTag method.
   *@return true to halt further processing.
   */
@@ -151,7 +164,7 @@ public class XMLFuzzyHierarchicalParseSt
     throws ManifoldCFException
   {
     if (captureEscaped)
-      characterBuffer.append(thisChar);
+      appendToCharacterBuffer(thisChar);
     return false;
   }
 
@@ -172,12 +185,7 @@ public class XMLFuzzyHierarchicalParseSt
   public void finishUp()
     throws ManifoldCFException
   {
-    if (characterBuffer.length() > 0)
-    {
-      if (currentContext != null)
-        currentContext.characters(characterBuffer.toString());
-      characterBuffer.setLength(0);
-    }
+    flushCharacterBuffer();
     super.finishUp();
   }