aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-03-16 16:51:58 +0000
committerNick Burch <nick@apache.org>2008-03-16 16:51:58 +0000
commit23ec83189931e8e2c7b6b1e6c663c98d2393b6dc (patch)
tree8033e60382a05c26526b89c0010fb0af6b3af6a1 /src
parentf4f71fc9bce4dcdbb015034b50a638f25fe0e398 (diff)
downloadpoi-23ec83189931e8e2c7b6b1e6c663c98d2393b6dc.tar.gz
poi-23ec83189931e8e2c7b6b1e6c663c98d2393b6dc.zip
Further workarounds for java being rubbish, by having a dedicated class to create concrete instances of interfaces for you
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@637610 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CreationHelper.java19
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java11
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java42
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/DataFormat.java4
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java9
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java43
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java32
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java4
8 files changed, 149 insertions, 15 deletions
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CreationHelper.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CreationHelper.java
new file mode 100644
index 0000000000..d9e545ca13
--- /dev/null
+++ b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CreationHelper.java
@@ -0,0 +1,19 @@
+/* ====================================================================
+ 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.poi.ss.usermodel;
+
+public interface CreationHelper {}
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
index 1a8fc2b9bc..39113f59c7 100644
--- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
@@ -154,17 +154,6 @@ public interface Cell {
String getCellFormula();
/**
- * Creates a RichTextString, which you can then pass to
- * {@link #setCellValue(RichTextString)}. This is required
- * because Java is broken, and won't allow you to define
- * static methods or constructors on interfaces, and without
- * that there's no way to get a RichTextString without
- * creating the appropriate concrete class.
- * @param text The text to initialise the RichTextString with
- */
- RichTextString createRichTextString(String text);
-
- /**
* get the value of the cell as a number. For strings we throw an exception.
* For blank cells we return a 0.
*/
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java
new file mode 100644
index 0000000000..78fe632527
--- /dev/null
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java
@@ -0,0 +1,42 @@
+/* ====================================================================
+ 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.poi.ss.usermodel;
+
+/**
+ * An object that handles instantiating concrete
+ * classes of the various instances one needs for
+ * HSSF and XSSF.
+ * Works around a major shortcoming in Java, where we
+ * can't have static methods on interfaces or abstract
+ * classes.
+ * This allows you to get the appropriate class for
+ * a given interface, without you having to worry
+ * about if you're dealing with HSSF or XSSF, despite
+ * Java being quite rubbish.
+ */
+public interface CreationHelper {
+ /**
+ * Creates a new RichTextString instance
+ * @param text The text to initialise the RichTextString with
+ */
+ RichTextString createRichTextString(String text);
+
+ /**
+ * Creates a new DataFormat instance
+ */
+ DataFormat createDataFormat();
+} \ No newline at end of file
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/DataFormat.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/DataFormat.java
index ad60810519..3728541ef6 100644
--- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/DataFormat.java
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/DataFormat.java
@@ -18,14 +18,12 @@
package org.apache.poi.ss.usermodel;
public interface DataFormat {
-
/**
* get the format index that matches the given format string.
* Creates a new format if one is not found. Aliases text to the proper format.
* @param format string matching a built in format
* @return index of format.
*/
-
short getFormat(String format);
/**
@@ -33,7 +31,5 @@ public interface DataFormat {
* @param index of a format
* @return string represented at index of format or null if there is not a format at that index
*/
-
String getFormat(short index);
-
} \ No newline at end of file
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
index bafa6b792c..e66cf0e1d7 100644
--- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
@@ -455,4 +455,13 @@ public interface Workbook {
*/
List getAllEmbeddedObjects();
+ /**
+ * Returns an object that handles instantiating concrete
+ * classes of the various instances one needs for
+ * HSSF and XSSF.
+ * Works around a major shortcoming in Java, where we
+ * can't have static methods on interfaces or abstract
+ * classes.
+ */
+ CreationHelper getCreationHelper();
} \ No newline at end of file
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java
new file mode 100644
index 0000000000..7941a86610
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java
@@ -0,0 +1,43 @@
+/* ====================================================================
+ 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.poi.xssf.usermodel;
+
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.DataFormat;
+import org.apache.poi.ss.usermodel.RichTextString;
+
+public class XSSFCreationHelper implements CreationHelper {
+ private XSSFWorkbook workbook;
+ private XSSFDataFormat dataFormat;
+ XSSFCreationHelper(XSSFWorkbook wb) {
+ workbook = wb;
+
+ // Create the things we only ever need one of
+ dataFormat = new XSSFDataFormat();
+ }
+
+ /**
+ * Creates a new XSSFRichTextString for you.
+ */
+ public RichTextString createRichTextString(String text) {
+ return new XSSFRichTextString(text);
+ }
+
+ public DataFormat createDataFormat() {
+ return dataFormat;
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java
new file mode 100644
index 0000000000..837b7ca5ef
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java
@@ -0,0 +1,32 @@
+/* ====================================================================
+ 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.poi.xssf.usermodel;
+
+import org.apache.poi.ss.usermodel.DataFormat;
+
+/**
+ * TODO - figure out how this should really work for XSSF
+ */
+public class XSSFDataFormat implements DataFormat {
+ public short getFormat(String format) {
+ return -1;
+ }
+
+ public String getFormat(short index) {
+ return null;
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 2f7442dac2..e3dd080620 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -27,6 +27,7 @@ import javax.xml.namespace.QName;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Name;
@@ -533,4 +534,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
this.sharedStringSource = sharedStringSource;
}
+ public CreationHelper getCreationHelper() {
+ return new XSSFCreationHelper(this);
+ }
}