aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-03-16 23:30:51 +0000
committerNick Burch <nick@apache.org>2008-03-16 23:30:51 +0000
commit9adfbc6eac3def8039472f853bf686ec6b7f97ae (patch)
tree3ee446e0741d2fc45a66bd865e838d86ae243fcb /src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
parentb2af50dc8108864a668e43fdb90428dcf9759402 (diff)
downloadpoi-9adfbc6eac3def8039472f853bf686ec6b7f97ae.tar.gz
poi-9adfbc6eac3def8039472f853bf686ec6b7f97ae.zip
Tidy up the xssf models stuff, by pushing more of the logic onto XSSFWorkbook
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@637688 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
index 122a1b4401..c5227c1c1c 100644
--- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
@@ -25,13 +25,14 @@ import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Map.Entry;
+import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.StylesSource;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
-import org.openxml4j.opc.PackagePart;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFonts;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmts;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;;
@@ -40,10 +41,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;;
/**
* Table of styles shared across all sheets in a workbook.
*
- * FIXME: I don't like having a dependency on PackagePart (from OpenXML4J) in model classes.
- * I'd rather let Workbook keep track of all part-document relationships and keep all other
- * classes clean. -- Ugo
- *
* @version $Id: SharedStringsTable.java 612495 2008-01-16 16:08:22Z ugo $
*/
public class StylesTable implements StylesSource, XSSFModel {
@@ -52,23 +49,28 @@ public class StylesTable implements StylesSource, XSSFModel {
private final LinkedList<CTFill> fills = new LinkedList<CTFill>();
private final LinkedList<CTBorder> borders = new LinkedList<CTBorder>();
- private PackagePart part;
+ /**
+ * The first style id available for use as a custom style
+ */
+ public static final long FIRST_CUSTOM_STYLE_ID = 165;
+
private StyleSheetDocument doc;
/**
- * Create a new StylesTable by reading it from a PackagePart.
+ * Create a new StylesTable, by reading it from
+ * the InputStream of a a PackagePart.
*
- * @param part The PackagePart to read.
+ * @param is The input stream containing the XML document.
* @throws IOException if an error occurs while reading.
*/
- public StylesTable(PackagePart part) throws IOException {
- this.part = part;
- InputStream is = part.getInputStream();
- try {
- readFrom(is);
- } finally {
- if (is != null) is.close();
- }
+ public StylesTable(InputStream is) throws IOException {
+ readFrom(is);
+ }
+ /**
+ * Create a new, empty StylesTable
+ */
+ public StylesTable() {
+ doc = StyleSheetDocument.Factory.newInstance();
}
/**
@@ -106,7 +108,6 @@ public class StylesTable implements StylesSource, XSSFModel {
public String getNumberFormatAt(long idx) {
return numberFormats.get(idx);
}
-
public synchronized long putNumberFormat(String fmt) {
if (numberFormats.containsValue(fmt)) {
// Find the key, and return that
@@ -120,7 +121,7 @@ public class StylesTable implements StylesSource, XSSFModel {
}
// Find a spare key, and add that
- long newKey = 1;
+ long newKey = FIRST_CUSTOM_STYLE_ID;
while(numberFormats.containsKey(newKey)) {
newKey++;
}
@@ -128,6 +129,15 @@ public class StylesTable implements StylesSource, XSSFModel {
return newKey;
}
+ public Font getFontAt(long idx) {
+ // TODO
+ return null;
+ }
+ public synchronized long putFont(Font font) {
+ // TODO
+ return -1;
+ }
+
/**
* For unit testing only
*/
@@ -155,20 +165,6 @@ public class StylesTable implements StylesSource, XSSFModel {
/**
- * Save this table to its own PackagePart.
- *
- * @throws IOException if an error occurs while writing.
- */
- public void save() throws IOException {
- OutputStream out = this.part.getOutputStream();
- try {
- writeTo(out);
- } finally {
- out.close();
- }
- }
-
- /**
* Write this table out as XML.
*
* @param out The stream to write to.
@@ -193,7 +189,12 @@ public class StylesTable implements StylesSource, XSSFModel {
doc.getStyleSheet().setNumFmts(formats);
// Fonts
- // TODO
+ CTFonts fnts = CTFonts.Factory.newInstance();
+ fnts.setCount(fonts.size());
+ fnts.setFontArray(
+ fonts.toArray(new CTFont[fonts.size()])
+ );
+ doc.getStyleSheet().setFonts(fnts);
// Fills
// TODO