You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2008/03/26 19:41:44 UTC
svn commit: r641469 - in
/incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft:
ExcelExtractor.java NumberCell.java
Author: jukka
Date: Wed Mar 26 11:41:34 2008
New Revision: 641469
URL: http://svn.apache.org/viewvc?rev=641469&view=rev
Log:
TIKA-132: Refactor Excel extractor to parse per sheet and add hyperlink support
- Added NumberCell for formatted numbers
Added:
incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/NumberCell.java
Modified:
incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java
Modified: incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java?rev=641469&r1=641468&r2=641469&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java (original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java Wed Mar 26 11:41:34 2008
@@ -295,10 +295,7 @@
switch (sid) {
/* FormulaRecord: Cell value from a formula */
case FormulaRecord.sid:
- FormulaRecord formulaRecord = (FormulaRecord)record;
- double fmlValue = formulaRecord.getValue();
- text = Double.toString(fmlValue);
- break;
+ return new NumberCell(((FormulaRecord) record).getValue());
/* LabelRecord: strings stored directly in the cell */
case LabelRecord.sid:
@@ -314,15 +311,11 @@
/* NumberRecord: Contains a numeric cell value */
case NumberRecord.sid:
- double numValue = ((NumberRecord)record).getValue();
- text = Double.toString(numValue);
- break;
+ return new NumberCell(((NumberRecord) record).getValue());
/* RKRecord: Excel internal number record */
case RKRecord.sid:
- double rkValue = ((RKRecord)record).getRKNumber();
- text = Double.toString(rkValue);
- break;
+ return new NumberCell(((RKRecord)record).getRKNumber());
}
if (text != null) {
text = text.trim();
Added: incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/NumberCell.java
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/NumberCell.java?rev=641469&view=auto
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/NumberCell.java (added)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/parser/microsoft/NumberCell.java Wed Mar 26 11:41:34 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.microsoft;
+
+import java.text.NumberFormat;
+
+import org.apache.tika.sax.XHTMLContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * Number cell.
+ */
+public class NumberCell implements Cell {
+
+ private final double number;
+
+ private final NumberFormat format;
+
+ public NumberCell(double number, NumberFormat format) {
+ this.number = number;
+ this.format = format;
+ }
+
+ public NumberCell(double number) {
+ this(number, NumberFormat.getInstance());
+ }
+
+ public void render(XHTMLContentHandler handler) throws SAXException {
+ handler.characters(format.format(number));
+ }
+
+}