poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1575684 - /poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
Date Sun, 09 Mar 2014 09:53:26 GMT
Author: nick
Date: Sun Mar  9 09:53:25 2014
New Revision: 1575684

URL: http://svn.apache.org/r1575684
Log:
Fix inconsistent whitespace, and add a close call in the main method to avoid a resource-leak
warning

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java?rev=1575684&r1=1575683&r2=1575684&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
Sun Mar  9 09:53:25 2014
@@ -82,6 +82,7 @@ public class XSSFEventBasedExcelExtracto
         POIXMLTextExtractor extractor =
             new XSSFEventBasedExcelExtractor(args[0]);
         System.out.println(extractor.getText());
+        extractor.close();
     }
 
     /**
@@ -252,113 +253,113 @@ public class XSSFEventBasedExcelExtracto
 		super.close();
 	}
 
-   protected class SheetTextExtractor implements SheetContentsHandler {
-      private final StringBuffer output;
-      private boolean firstCellOfRow;
-      private final Map<String, String> headerFooterMap;
-      
-      protected SheetTextExtractor() {
-         this.output = new StringBuffer();
-         this.firstCellOfRow = true;
-         this.headerFooterMap = includeHeadersFooters ? new HashMap<String, String>()
: null;
-      }
-      
-      public void startRow(int rowNum) {
-         firstCellOfRow = true;
-      }
-      
-      public void endRow() {
-         output.append('\n');
-      }
-
-      public void cell(String cellRef, String formattedValue) {
-         if(firstCellOfRow) {
-            firstCellOfRow = false;
-         } else {
-            output.append('\t');
-         }
-         output.append(formattedValue);
-      }
-      
-      public void headerFooter(String text, boolean isHeader, String tagName) {
-          if (headerFooterMap != null) {
-              headerFooterMap.put(tagName, text);
-          }
-      }
-      
-      
-      /**
-       * Append the text for the named header or footer if found.
-       */
-      private void appendHeaderFooterText(StringBuffer buffer, String name) {
-          String text = headerFooterMap.get(name);
-          if (text != null && text.length() > 0) {
-              // this is a naive way of handling the left, center, and right
-              // header and footer delimiters, but it seems to be as good as
-              // the method used by XSSFExcelExtractor
-              text = handleHeaderFooterDelimiter(text, "&L");
-              text = handleHeaderFooterDelimiter(text, "&C");
-              text = handleHeaderFooterDelimiter(text, "&R");
-              buffer.append(text).append('\n');
-          }
-      }
-      /**
-       * Remove the delimiter if its found at the beginning of the text,
-       * or replace it with a tab if its in the middle.
-       */
-      private String handleHeaderFooterDelimiter(String text, String delimiter) {
-          int index = text.indexOf(delimiter);
-          if (index == 0) {
-              text = text.substring(2);
-          } else if (index > 0) {
-              text = text.substring(0, index) + "\t" + text.substring(index + 2);
-          }
-          return text;
-      }
+    protected class SheetTextExtractor implements SheetContentsHandler {
+        private final StringBuffer output;
+        private boolean firstCellOfRow;
+        private final Map<String, String> headerFooterMap;
+
+        protected SheetTextExtractor() {
+            this.output = new StringBuffer();
+            this.firstCellOfRow = true;
+            this.headerFooterMap = includeHeadersFooters ? new HashMap<String, String>()
: null;
+        }
 
-      
-      /**
-       * Append the text for each header type in the same order
-       * they are appended in XSSFExcelExtractor.
-       * @see XSSFExcelExtractor#getText()
-       * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(org.apache.poi.ss.usermodel.HeaderFooter)
-       */
-      private void appendHeaderText(StringBuffer buffer) {
-          appendHeaderFooterText(buffer, "firstHeader");
-          appendHeaderFooterText(buffer, "oddHeader");
-          appendHeaderFooterText(buffer, "evenHeader");
-      }
-      
-      /**
-       * Append the text for each footer type in the same order
-       * they are appended in XSSFExcelExtractor.
-       * @see XSSFExcelExtractor#getText()
-       * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(org.apache.poi.ss.usermodel.HeaderFooter)
-       */
-      private void appendFooterText(StringBuffer buffer) {
-          // append the text for each footer type in the same order
-          // they are appended in XSSFExcelExtractor
-          appendHeaderFooterText(buffer, "firstFooter");
-          appendHeaderFooterText(buffer, "oddFooter");
-          appendHeaderFooterText(buffer, "evenFooter");
-      }
-
-      /**
-       * Append the cell contents we have collected.
-       */
-      private void appendCellText(StringBuffer buffer) {
-          buffer.append(output);
-      }
-      
-      /**
-       * Reset this <code>SheetTextExtractor</code> for the next sheet.
-       */
-      private void reset() {
-          output.setLength(0);
-          firstCellOfRow = true;
-          if (headerFooterMap != null) {
-              headerFooterMap.clear();
-          }
-      }
-   }
+        public void startRow(int rowNum) {
+            firstCellOfRow = true;
+        }
+
+        public void endRow() {
+            output.append('\n');
+        }
+
+        public void cell(String cellRef, String formattedValue) {
+            if(firstCellOfRow) {
+                firstCellOfRow = false;
+            } else {
+                output.append('\t');
+            }
+            output.append(formattedValue);
+        }
+
+        public void headerFooter(String text, boolean isHeader, String tagName) {
+            if (headerFooterMap != null) {
+                headerFooterMap.put(tagName, text);
+            }
+        }
+
+
+        /**
+         * Append the text for the named header or footer if found.
+         */
+        private void appendHeaderFooterText(StringBuffer buffer, String name) {
+            String text = headerFooterMap.get(name);
+            if (text != null && text.length() > 0) {
+                // this is a naive way of handling the left, center, and right
+                // header and footer delimiters, but it seems to be as good as
+                // the method used by XSSFExcelExtractor
+                text = handleHeaderFooterDelimiter(text, "&L");
+                text = handleHeaderFooterDelimiter(text, "&C");
+                text = handleHeaderFooterDelimiter(text, "&R");
+                buffer.append(text).append('\n');
+            }
+        }
+        /**
+         * Remove the delimiter if its found at the beginning of the text,
+         * or replace it with a tab if its in the middle.
+         */
+        private String handleHeaderFooterDelimiter(String text, String delimiter) {
+            int index = text.indexOf(delimiter);
+            if (index == 0) {
+                text = text.substring(2);
+            } else if (index > 0) {
+                text = text.substring(0, index) + "\t" + text.substring(index + 2);
+            }
+            return text;
+        }
+
+
+        /**
+         * Append the text for each header type in the same order
+         * they are appended in XSSFExcelExtractor.
+         * @see XSSFExcelExtractor#getText()
+         * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(org.apache.poi.ss.usermodel.HeaderFooter)
+         */
+        private void appendHeaderText(StringBuffer buffer) {
+            appendHeaderFooterText(buffer, "firstHeader");
+            appendHeaderFooterText(buffer, "oddHeader");
+            appendHeaderFooterText(buffer, "evenHeader");
+        }
+
+        /**
+         * Append the text for each footer type in the same order
+         * they are appended in XSSFExcelExtractor.
+         * @see XSSFExcelExtractor#getText()
+         * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(org.apache.poi.ss.usermodel.HeaderFooter)
+         */
+        private void appendFooterText(StringBuffer buffer) {
+            // append the text for each footer type in the same order
+            // they are appended in XSSFExcelExtractor
+            appendHeaderFooterText(buffer, "firstFooter");
+            appendHeaderFooterText(buffer, "oddFooter");
+            appendHeaderFooterText(buffer, "evenFooter");
+        }
+
+        /**
+         * Append the cell contents we have collected.
+         */
+        private void appendCellText(StringBuffer buffer) {
+            buffer.append(output);
+        }
+
+        /**
+         * Reset this <code>SheetTextExtractor</code> for the next sheet.
+         */
+        private void reset() {
+            output.setLength(0);
+            firstCellOfRow = true;
+            if (headerFooterMap != null) {
+                headerFooterMap.clear();
+            }
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message