]> source.dussan.org Git - poi.git/commitdiff
1. removed interfaces-jdk14, they are now obsolete2. started paving the way for XWPF
authorYegor Kozlov <yegor@apache.org>
Sun, 9 Nov 2008 16:18:46 +0000 (16:18 +0000)
committerYegor Kozlov <yegor@apache.org>
Sun, 9 Nov 2008 16:18:46 +0000 (16:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@712508 13f79535-47bb-0310-9956-ffa450edef68

47 files changed:
src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java [new file with mode: 0755]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/extractor/ExcelExtractor.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Cell.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CellStyle.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Color.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CreationHelper.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/DataFormat.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Font.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Footer.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Header.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Hyperlink.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Iterable.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Name.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Palette.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Patriarch.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PrintSetup.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/RichTextString.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Row.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Sheet.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Textbox.java [deleted file]
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java [deleted file]
src/ooxml/java/org/apache/poi/POIXMLDocument.java
src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java [deleted file]
src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
src/ooxml/java/org/apache/poi/xwpf/model/XWPFCommentsDecorator.java
src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
src/ooxml/java/org/apache/poi/xwpf/model/XWPFHyperlinkDecorator.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java [deleted file]
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraphText.java [deleted file]
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
src/ooxml/testcases/org/apache/poi/TestEmbeded.java
src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java

diff --git a/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java b/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java
new file mode 100755 (executable)
index 0000000..29d502f
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xwpf.usermodel;\r
+\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ * A simple WOrdprocessingML document created by POI XWPF API\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class SimpleDocument {\r
+\r
+    public static void main(String[] args) throws Exception {\r
+        XWPFDocument doc = new XWPFDocument();\r
+\r
+        XWPFParagraph p1 = doc.createParagraph();\r
+        p1.setAlignment(ParagraphAlignment.CENTER);\r
+\r
+        XWPFRun r1 = p1.createRun();\r
+        r1.setBold(true);\r
+        r1.setText("The quick brown fox");\r
+\r
+        XWPFParagraph p2 = doc.createParagraph();\r
+        p2.setAlignment(ParagraphAlignment.RIGHT);\r
+\r
+        XWPFRun r2 = p2.createRun();\r
+        r2.setBold(false);\r
+        r2.setText("jumped over the lazy dog");\r
+\r
+        FileOutputStream out = new FileOutputStream("simple.docx");\r
+        doc.write(out);\r
+        out.close();\r
+\r
+    }\r
+}\r
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/extractor/ExcelExtractor.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/extractor/ExcelExtractor.java
deleted file mode 100644 (file)
index 8817bc7..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/* ====================================================================
-   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.extractor;
-
-/**
- * Common interface for Excel text extractors, covering
- *  HSSF and XSSF
- */
-public interface ExcelExtractor {
-       /**
-        * Should sheet names be included? Default is true
-        */
-       public void setIncludeSheetNames(boolean includeSheetNames);
-
-       /**
-        * Should we return the formula itself, and not
-        *  the result it produces? Default is false
-        */
-       public void setFormulasNotResults(boolean formulasNotResults);
-
-       /**
-     * Should cell comments be included? Default is false
-     */
-    public void setIncludeCellComments(boolean includeCellComments);
-
-       /**
-        * Retreives the text contents of the file
-        */
-       public String getText();
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Cell.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Cell.java
deleted file mode 100644 (file)
index 2dbb571..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/* ====================================================================
-   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;
-
-import java.util.Date;
-
-import org.apache.poi.hssf.usermodel.HSSFCellStyle;
-import org.apache.poi.hssf.usermodel.HSSFRichTextString;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-
-/**
- * This is a JDK 1.4 compatible interface for HSSFCell.
- * If you are using JDK 1.5 or later, use the other set of interfaces,
- *  which work properly for both HSSFCell and XSSFCell
- */
-public interface Cell {
-    /**
-     * Numeric Cell type (0)
-     * @see #setCellType(int)
-     * @see #getCellType()
-     */
-
-    public final static int CELL_TYPE_NUMERIC = 0;
-
-    /**
-     * String Cell type (1)
-     * @see #setCellType(int)
-     * @see #getCellType()
-     */
-
-    public final static int CELL_TYPE_STRING = 1;
-
-    /**
-     * Formula Cell type (2)
-     * @see #setCellType(int)
-     * @see #getCellType()
-     */
-
-    public final static int CELL_TYPE_FORMULA = 2;
-
-    /**
-     * Blank Cell type (3)
-     * @see #setCellType(int)
-     * @see #getCellType()
-     */
-
-    public final static int CELL_TYPE_BLANK = 3;
-
-    /**
-     * Boolean Cell type (4)
-     * @see #setCellType(int)
-     * @see #getCellType()
-     */
-
-    public final static int CELL_TYPE_BOOLEAN = 4;
-
-    /**
-     * Error Cell type (5)
-     * @see #setCellType(int)
-     * @see #getCellType()
-     */
-
-    public final static int CELL_TYPE_ERROR = 5;
-
-
-    int getCellType();
-    /**
-     * @deprecated (Oct 2008) use {@link #getColumnIndex()}
-     */
-    short getCellNum();
-    
-    /**
-     * @return the cell's column index (zero based)
-     */
-    int getColumnIndex();
-    int getRowIndex();
-
-    String getCellFormula();
-
-    byte getErrorCellValue();
-    void setCellErrorValue(byte value);
-
-    HSSFCellStyle getCellStyle();
-    HSSFSheet getSheet();
-
-    boolean getBooleanCellValue();
-    double getNumericCellValue();
-    /**
-     * get the value of the cell as a date.  For strings we throw an exception.
-     * For blank cells we return a null.
-     */
-    Date getDateCellValue();
-    HSSFRichTextString getRichStringCellValue();
-
-    void setCellType(int cellType);
-    void setCellValue(boolean value);
-    void setCellValue(double value);
-    void setCellValue(RichTextString value);
-    void setCellFormula(String formula);
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CellStyle.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/CellStyle.java
deleted file mode 100644 (file)
index 2105937..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ====================================================================
-   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 CellStyle {
-    short getDataFormat();
-    String getDataFormatString();
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Color.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Color.java
deleted file mode 100644 (file)
index 7a9633a..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 Color {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java
deleted file mode 100644 (file)
index c85f79b..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ====================================================================
-   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 Comment {
-       public void setRow(int row);
-       public void setColumn(short row);
-}
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
deleted file mode 100644 (file)
index fb56019..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* ====================================================================
-   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;
-
-import org.apache.poi.hssf.usermodel.HSSFRichTextString;
-
-/**
- * This is a JDK 1.4 compatible interface for HSSFCreationHelper.
- * If you are using JDK 1.5 or later, use the other set of interfaces,
- *  which work properly for both HSSFCreationHelper and XSSFCreationHelper
- */
-public interface CreationHelper {
-    HSSFRichTextString createRichTextString(String text);
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/DataFormat.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/DataFormat.java
deleted file mode 100644 (file)
index 525c79c..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 DataFormat {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Font.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Font.java
deleted file mode 100644 (file)
index f19bac4..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/* ====================================================================
-   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 Font {
-
-    /**
-     * Arial font
-     */
-
-    public final static String FONT_ARIAL          = "Arial";
-
-    /**
-     * Normal boldness (not bold)
-     */
-
-    public final static short  BOLDWEIGHT_NORMAL   = 0x190;
-
-    /**
-     * Bold boldness (bold)
-     */
-
-    public final static short  BOLDWEIGHT_BOLD     = 0x2bc;
-
-    /**
-     * normal type of black color.
-     */
-
-    public final static short  COLOR_NORMAL        = 0x7fff;
-
-    /**
-     * Dark Red color
-     */
-
-    public final static short  COLOR_RED           = 0xa;
-
-    /**
-     * no type offsetting (not super or subscript)
-     */
-
-    public final static short  SS_NONE             = 0;
-
-    /**
-     * superscript
-     */
-
-    public final static short  SS_SUPER            = 1;
-
-    /**
-     * subscript
-     */
-
-    public final static short  SS_SUB              = 2;
-
-    /**
-     * not underlined
-     */
-
-    public final static byte   U_NONE              = 0;
-
-    /**
-     * single (normal) underline
-     */
-
-    public final static byte   U_SINGLE            = 1;
-
-    /**
-     * double underlined
-     */
-
-    public final static byte   U_DOUBLE            = 2;
-
-    /**
-     * accounting style single underline
-     */
-
-    public final static byte   U_SINGLE_ACCOUNTING = 0x21;
-
-    /**
-     * accounting style double underline
-     */
-
-    public final static byte   U_DOUBLE_ACCOUNTING = 0x22;
-
-    /**
-     * ANSI character set
-     */
-    public final static byte ANSI_CHARSET = 0;
-
-    /**
-     * Default character set.
-     */
-    public final static byte DEFAULT_CHARSET = 1;
-
-    /**
-     * Symbol character set
-     */
-    public final static byte SYMBOL_CHARSET = 2;
-
-
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Footer.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Footer.java
deleted file mode 100644 (file)
index c278c5d..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 Footer {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Header.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Header.java
deleted file mode 100644 (file)
index 0c7ba2c..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 Header {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Hyperlink.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Hyperlink.java
deleted file mode 100644 (file)
index 04d7dc4..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/* ====================================================================
-   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 Hyperlink {
-    /**
-     * Link to a existing file or web page
-     */
-    public static final int LINK_URL = 1;
-
-    /**
-     * Link to a place in this document
-     */
-    public static final int LINK_DOCUMENT = 2;
-
-    /**
-     * Link to an E-mail address
-     */
-    public static final int LINK_EMAIL = 3;
-
-    /**
-     * Link to a file
-     */
-    public static final int LINK_FILE = 4;
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Iterable.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Iterable.java
deleted file mode 100644 (file)
index 17a2820..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* ====================================================================
-   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;
-
-import java.util.Iterator;
-
-/**
- * Workaround for java.lang.Iterable not existing on java 1.4, but
- *  people wanting to use it all the same.
- * Must only be present for java 1.4 interfaces! Do not add for 
- *  java 1.5, as that has its own real one from java.lang
- */
-public interface Iterable {
-       public Iterator iterator();
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Name.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Name.java
deleted file mode 100644 (file)
index bf48239..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ====================================================================
-   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 Name {
-    void setNameName(String nameName);
-       boolean isFunctionName();
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Palette.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Palette.java
deleted file mode 100644 (file)
index 9048fb5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 Palette {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Patriarch.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Patriarch.java
deleted file mode 100644 (file)
index 92db057..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 Patriarch {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
deleted file mode 100644 (file)
index a38a70a..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 PictureData {}
\ No newline at end of file
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PrintSetup.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PrintSetup.java
deleted file mode 100644 (file)
index 20b5b08..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 PrintSetup {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/RichTextString.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/RichTextString.java
deleted file mode 100644 (file)
index d026f05..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/* ====================================================================
-   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;
-
-/**
- * This is a JDK 1.4 compatible interface for HSSFRichTextString.
- * If you are using JDK 1.5 or later, use the other set of interfaces,
- *  which work properly for both HSSFRichTextString and XSSFRichTextString
- */
-public interface RichTextString {
-    String getString();
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Row.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Row.java
deleted file mode 100644 (file)
index 8a0810d..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ====================================================================
-   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;
-
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import java.util.Iterator;
-
-/**
- * This is a JDK 1.4 compatible interface for HSSFRow.
- * If you are using JDK 1.5 or later, use the other set of interfaces,
- *  which work properly for both HSSFRow and XSSFRow
- */
-public interface Row {
-    int getRowNum();
-    short getFirstCellNum();
-    short getLastCellNum();
-    int getPhysicalNumberOfCells();
-    HSSFCell getCell(int cellnum);
-
-    Iterator cellIterator();
-
-    /**
-     * Used to specify the different possible policies
-     *  if for the case of null and blank cells
-     */
-    public static class MissingCellPolicy {
-       private static int NEXT_ID = 1;
-       public final int id;
-       private MissingCellPolicy() {
-               this.id = NEXT_ID++;
-       }
-    }
-    /** Missing cells are returned as null, Blank cells are returned as normal */
-    public static final MissingCellPolicy RETURN_NULL_AND_BLANK = new MissingCellPolicy();
-    /** Missing cells are returned as null, as are blank cells */
-    public static final MissingCellPolicy RETURN_BLANK_AS_NULL = new MissingCellPolicy();
-    /** A new, blank cell is created for missing cells. Blank cells are returned as normal */
-    public static final MissingCellPolicy CREATE_NULL_AS_BLANK = new MissingCellPolicy();
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Sheet.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Sheet.java
deleted file mode 100644 (file)
index ef5aac4..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/* ====================================================================
-   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;
-
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import java.util.Iterator;
-
-/**
- * This is a JDK 1.4 compatible interface for HSSFSheet.
- * If you are using JDK 1.5 or later, use the other set of interfaces,
- *  which work properly for both HSSFSheet and XSSFSheet
- */
-public interface Sheet {
-    int getPhysicalNumberOfRows();
-    int getFirstRowNum();
-    int getLastRowNum();
-
-    HSSFRow getRow(int rownum);
-    Iterator rowIterator();
-}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Textbox.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Textbox.java
deleted file mode 100644 (file)
index 212c400..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ====================================================================
-   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 Textbox {}
diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java
deleted file mode 100644 (file)
index c4cdd21..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* ====================================================================
-   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;
-
-import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
-import org.apache.poi.hssf.usermodel.*;
-
-/**
- * This is a JDK 1.4 compatible interface for HSSFWorkbook.
- * If you are using JDK 1.5 or later, use the other set of interfaces,
- *  which work properly for both HSSFWorkbook and XSSFWorkbook
- */
-public interface Workbook {
-
-    int getActiveSheetIndex();
-    void setActiveSheet(int sheetIndex);
-
-    int getFirstVisibleTab();
-    void setFirstVisibleTab(int sheetIndex);
-
-    int getNumberOfSheets();
-    short getNumberOfFonts();
-    int getNumberOfNames();
-
-    HSSFName createName();
-    HSSFName getNameAt(int index);
-    int getNameIndex(String name);
-    String getNameName(int index);
-
-    String getSheetName(int sheet);
-    HSSFSheet getSheetAt(int index);
-    int getSheetIndex(String name);
-    int getSheetIndex(Sheet sheet);
-
-    CreationHelper getCreationHelper();
-
-       /**
-        * Retrieves the current policy on what to do when
-        *  getting missing or blank cells from a row.
-        * The default is to return blank and null cells.
-        *  {@link MissingCellPolicy}
-        */
-       MissingCellPolicy getMissingCellPolicy();
-       /**
-        * Sets the policy on what to do when
-        *  getting missing or blank cells from a row.
-        * This will then apply to all calls to 
-        *  {@link Row.getCell()}. See
-        *  {@link MissingCellPolicy}
-        */
-       void setMissingCellPolicy(MissingCellPolicy missingCellPolicy);
-}
index 2287ef4f18fa3ec8a0b474292ddaaf7e274a39ab..ab2d04c72e7dfb760a7b88ab54d24e547169feaf 100644 (file)
@@ -21,6 +21,7 @@ import java.util.List;
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.PackageHelper;
 import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.InvalidFormatException;
 import org.openxml4j.exceptions.OpenXML4JException;
@@ -169,4 +170,35 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
      */
     public abstract List<PackagePart> getAllEmbedds() throws OpenXML4JException;
 
+    /**
+     * YK: current implementation of OpenXML4J is funny.
+     * Packages opened by Package.open(InputStream is) are read-only,
+     * there is no way to change or even save such an instance in a OutputStream.
+     * The workaround is to create a copy via a temp file
+     */
+    protected static Package ensureWriteAccess(Package pkg) throws IOException {
+        if(pkg.getPackageAccess() == PackageAccess.READ){
+            try {
+                return PackageHelper.clone(pkg);
+            } catch (OpenXML4JException e){
+                throw new POIXMLException(e);
+            }
+        }
+        return pkg;
+    }
+
+    /**
+     * Write out this document to an Outputstream.
+     *
+     * @param stream - the java OutputStream you wish to write the XLS to
+     *
+     * @exception IOException if anything can't be written.
+     */
+    public final void write(OutputStream stream) throws IOException {
+        //force all children to commit their changes into the underlying OOXML Package
+        onSave();
+
+        getPackage().save(stream);
+    }
+
 }
index 8e07afd1fdc6dd291ea72db14845a2561d1e87dc..3eed794c0bdc989611c7219ed091fabc066f8246 100644 (file)
@@ -41,7 +41,8 @@ import org.apache.poi.xslf.XSLFSlideShow;
 import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
 import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
 import org.apache.poi.xssf.usermodel.XSSFRelation;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFRelation;
 import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
 import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.InvalidFormatException;
@@ -99,7 +100,7 @@ public class ExtractorFactory {
                if(corePart.getContentType().equals(XSSFRelation.WORKBOOK.getContentType())) {
                        return new XSSFExcelExtractor(pkg);
                }
-               if(corePart.getContentType().equals(XWPFDocument.MAIN_CONTENT_TYPE)) {
+               if(corePart.getContentType().equals(XWPFRelation.MAIN_CONTENT_TYPE)) {
                        return new XWPFWordExtractor(pkg);
                }
                if(corePart.getContentType().equals(XSLFSlideShow.MAIN_CONTENT_TYPE)) {
index 5a42033634c43da6b2e050654ca1d2744325c6e3..efa2d1289d669195e20b96fbc0a26f3cca9dfcd8 100644 (file)
@@ -137,23 +137,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         this(openPackage(path));
     }
 
-    /**
-     * YK: current implementation of OpenXML4J is funny.
-     * Packages opened by Package.open(InputStream is) are read-only,
-     * there is no way to change or even save such an instance in a OutputStream.
-     * The workaround is to create a copy via a temp file
-     */
-    private static Package ensureWriteAccess(Package pkg) throws IOException {
-        if(pkg.getPackageAccess() == PackageAccess.READ){
-            try {
-                return PackageHelper.clone(pkg);
-            } catch (OpenXML4JException e){
-                throw new POIXMLException(e);
-            }
-        }
-        return pkg;
-    }
-
     @Override
     protected void onDocumentRead() throws IOException {
         try {
@@ -1057,20 +1040,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         out.close();
     }
 
-    /**
-     * Write out this workbook to an Outputstream.
-     *
-     * @param stream - the java OutputStream you wish to write the XLS to
-     *
-     * @exception IOException if anything can't be written.
-     */
-    public void write(OutputStream stream) throws IOException {
-        //force all children to commit their changes into the underlying OOXML Package
-        onSave();
-
-        getPackage().save(stream);
-    }
-
     /**
      * Returns SharedStringsTable - tha cache of string for this workbook
      *
diff --git a/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java
deleted file mode 100644 (file)
index 8ef9ad8..0000000
+++ /dev/null
@@ -1,255 +0,0 @@
-/* ====================================================================
-   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.xwpf;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
-import org.apache.poi.xwpf.usermodel.XWPFComment;
-import org.apache.poi.xwpf.usermodel.XWPFHyperlink;
-import org.apache.poi.xwpf.usermodel.XWPFParagraph;
-import org.apache.poi.xwpf.usermodel.XWPFTable;
-import org.apache.xmlbeans.XmlException;
-import org.openxml4j.exceptions.InvalidFormatException;
-import org.openxml4j.exceptions.OpenXML4JException;
-import org.openxml4j.opc.Package;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackageRelationship;
-import org.openxml4j.opc.PackageRelationshipCollection;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
-
-/**
- * Experimental class to do low level processing
- *  of docx files.
- * 
- * If you are using these low level classes, then you
- *  will almost certainly need to refer to the OOXML
- *  specifications from
- *  http://www.ecma-international.org/publications/standards/Ecma-376.htm
- *  
- * WARNING - APIs expected to change rapidly
- */
-public class XWPFDocument extends POIXMLDocument {
-       public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
-       public static final String HEADER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml";
-       public static final String HEADER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
-       public static final String FOOTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";
-       public static final String FOOTER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
-       public static final String STYLES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";
-       public static final String STYLES_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
-       public static final String HYPERLINK_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
-       public static final String COMMENT_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
-       
-       private DocumentDocument wordDoc;
-       protected List<XWPFComment> comments;
-       protected List<XWPFHyperlink> hyperlinks;
-       protected List<XWPFParagraph> paragraphs;
-       protected List<XWPFTable> tables;
-    /**
-     * The embedded OLE2 files in the OPC package
-     */
-    private List<PackagePart> embedds;
-
-       /** Handles the joy of different headers/footers for different pages */
-       private XWPFHeaderFooterPolicy headerFooterPolicy;
-       
-       public XWPFDocument(Package container) throws OpenXML4JException, IOException, XmlException {
-               super(container);
-
-               hyperlinks = new LinkedList<XWPFHyperlink>();
-               comments = new LinkedList<XWPFComment>();
-               paragraphs = new LinkedList<XWPFParagraph>();
-               tables= new LinkedList<XWPFTable>();
-               
-               wordDoc =
-                       DocumentDocument.Factory.parse(getCorePart().getInputStream());
-               
-               // filling paragraph list
-               for (CTP p : getDocumentBody().getPArray())     {
-                       paragraphs.add(new XWPFParagraph(p, this));
-               }
-
-               // Get the hyperlinks 
-               // TODO: make me optional/separated in private function
-               try     {
-                       Iterator <PackageRelationship> relIter = 
-                               getCorePart().getRelationshipsByType(HYPERLINK_RELATION_TYPE).iterator();
-                       while(relIter.hasNext()) {
-                               PackageRelationship rel = relIter.next();
-                               hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
-                       }
-               } catch(Exception e) {
-                       throw new OpenXML4JException(e.getLocalizedMessage());
-               }
-
-               // Get the comments, if there are any
-               PackageRelationshipCollection commentsRel = getCmntRelations();
-               if(commentsRel != null && commentsRel.size() > 0) {
-                       PackagePart commentsPart = getTargetPart(commentsRel.getRelationship(0));
-                       CommentsDocument cmntdoc = CommentsDocument.Factory.parse(commentsPart.getInputStream());
-                       for(CTComment ctcomment : cmntdoc.getComments().getCommentArray()) {
-                               comments.add(new XWPFComment(ctcomment));
-                       }
-               }
-               
-               // Get any tables
-               for(CTTbl table : getDocumentBody().getTblArray()) {
-                       tables.add(new XWPFTable(table));
-               }
-               
-               /// Process embedded document parts
-        this.embedds = new LinkedList<PackagePart>();
-        for(PackageRelationship rel : getCorePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE)) {
-            embedds.add(getTargetPart(rel));
-        }
-        for(PackageRelationship rel : getCorePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
-            embedds.add(getTargetPart(rel));
-        }
-        
-        // Sort out headers and footers
-        headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
-       }
-       
-       /**
-        * Returns the low level document base object
-        */
-       public CTDocument1 getDocument() {
-               return wordDoc.getDocument();
-       }
-       
-       public Iterator<XWPFParagraph> getParagraphsIterator() {
-               return paragraphs.iterator();
-       }
-       public XWPFParagraph[] getParagraphs() {
-               return paragraphs.toArray(
-                       new XWPFParagraph[paragraphs.size()]
-               );
-       }
-       
-       public Iterator<XWPFTable> getTablesIterator()
-       {
-               return tables.iterator();
-       }
-       
-       public XWPFHyperlink getHyperlinkByID(String id) {
-               Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
-               while(iter.hasNext())
-               {
-                       XWPFHyperlink link = iter.next();
-                       if(link.getId().equals(id))
-                               return link; 
-               }
-               
-               return null;
-       }
-       public XWPFHyperlink[] getHyperlinks() {
-               return hyperlinks.toArray(
-                               new XWPFHyperlink[hyperlinks.size()]
-               );
-       }
-       
-       public XWPFComment getCommentByID(String id) {
-               Iterator<XWPFComment> iter = comments.iterator();
-               while(iter.hasNext())
-               {
-                       XWPFComment comment = iter.next();
-                       if(comment.getId().equals(id))
-                               return comment; 
-               }
-               
-               return null;
-       }
-       public XWPFComment[] getComments() {
-               return comments.toArray(
-                               new XWPFComment[comments.size()]
-               );
-       }
-       
-       /**
-        * Get the document part that's defined as the
-        *  given relationship of the core document.
-        */
-       public PackagePart getPartById(String id) {
-               try {
-                       return getTargetPart(
-                                       getCorePart().getRelationship(id)
-                       );
-               } catch(InvalidFormatException e) {
-                       throw new IllegalArgumentException(e);
-               }
-       }
-
-       /**
-        * Returns the policy on headers and footers, which
-        *  also provides a way to get at them.
-        */
-       public XWPFHeaderFooterPolicy getHeaderFooterPolicy() {
-               return headerFooterPolicy;
-       }
-       
-       /**
-        * Returns the low level body of the document
-        */
-       public CTBody getDocumentBody() {
-               return getDocument().getBody();
-       }
-       
-       /**
-        * Returns the styles object used
-        */
-       public CTStyles getStyle() throws XmlException, IOException {
-               PackagePart[] parts;
-               try {
-                       parts = getRelatedByType(STYLES_RELATION_TYPE);
-               } catch(InvalidFormatException e) {
-                       throw new IllegalStateException(e);
-               }
-               if(parts.length != 1) {
-                       throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length);
-               }
-               
-               StylesDocument sd =
-                       StylesDocument.Factory.parse(parts[0].getInputStream());
-               return sd.getStyles();
-       }
-
-       protected PackageRelationshipCollection getCmntRelations() throws InvalidFormatException
-       {
-               return getCorePart().getRelationshipsByType(COMMENT_RELATION_TYPE);
-       }
-
-    /**
-     * Get the document's embedded files.
-     */
-    public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
-        return embedds;
-    }
-
-}
-
index 14031ebc81f4b4d2b07dc884ce939073b4d448c2..91d52a72ca7cc05bfe3bc3038f368eba364e5e96 100644 (file)
@@ -21,7 +21,7 @@ import java.util.Iterator;
 
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.POIXMLTextExtractor;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.model.XWPFCommentsDecorator;
 import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
 import org.apache.poi.xwpf.model.XWPFHyperlinkDecorator;
index 1abc262607117276e000e1fbc71285d4f99e4b1f..0ceb8accb17e55fb0af42e5a07775714df1470e1 100644 (file)
@@ -41,7 +41,7 @@ public class XWPFCommentsDecorator extends XWPFParagraphDecorator {
 
                for(CTMarkupRange anchor : paragraph.getCTP().getCommentRangeStartArray())
                {
-                       if((comment = paragraph.getDocRef().getCommentByID(anchor.getId().toString())) != null)
+                       if((comment = paragraph.getDocument().getCommentByID(anchor.getId().toString())) != null)
                                commentText.append("\tComment by " + comment.getAuthor()+": "+comment.getText());
                }
        }
index 83a67ade994bea0a7bf13717998039d0fc99edd5..a92972acf8717e1ac174fa6161447d8ca8d55a7e 100644 (file)
@@ -18,7 +18,7 @@ package org.apache.poi.xwpf.model;
 
 import java.io.IOException;
 
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFFooter;
 import org.apache.poi.xwpf.usermodel.XWPFHeader;
 import org.apache.xmlbeans.XmlException;
@@ -57,7 +57,7 @@ public class XWPFHeaderFooterPolicy {
                // For now, we don't care about different ranges, as it
                //  doesn't seem that .docx properly supports that
                //  feature of the file format yet
-               CTSectPr sectPr = doc.getDocumentBody().getSectPr();
+               CTSectPr sectPr = doc.getDocument().getBody().getSectPr();
                for(int i=0; i<sectPr.sizeOfHeaderReferenceArray(); i++) {
                        // Get the header
                        CTHdrFtrRef ref = sectPr.getHeaderReferenceArray(i);
index ab5784bf7d1879176d72371c5d80a6384602c031..4a246063c973ff6dda0a97c3fc90eff569e3e05b 100644 (file)
@@ -56,8 +56,8 @@ public class XWPFHyperlinkDecorator extends XWPFParagraphDecorator {
                                        hyperlinkText.append(text.getStringValue());
                                }
                        }
-                       if(outputHyperlinkUrls && paragraph.getDocRef().getHyperlinkByID(link.getId()) != null) {
-                               hyperlinkText.append(" <"+paragraph.getDocRef().getHyperlinkByID(link.getId()).getURL()+">");
+                       if(outputHyperlinkUrls && paragraph.getDocument().getHyperlinkByID(link.getId()) != null) {
+                               hyperlinkText.append(" <"+paragraph.getDocument().getHyperlinkByID(link.getId()).getURL()+">");
                        }
                }
        }
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
new file mode 100755 (executable)
index 0000000..6c8aad1
--- /dev/null
@@ -0,0 +1,65 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xwpf.usermodel;\r
+\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+\r
+/**\r
+ * Specifies all types of alignment which are available to be applied to objects in a\r
+ * WordprocessingML document\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public enum ParagraphAlignment {\r
+    //YK: TODO document each alignment option\r
+\r
+    LEFT(1),\r
+    CENTER(2),\r
+    RIGHT(3),\r
+    BOTH(4),\r
+    MEDIUM_KASHIDA(5),\r
+    DISTRIBUTE(6),\r
+    NUM_TAB(7),\r
+    HIGH_KASHIDA(8),\r
+    LOW_KASHIDA(9),\r
+    THAI_DISTRIBUTE(10);\r
+\r
+    private final int value;\r
+\r
+    private ParagraphAlignment(int val){\r
+        value = val;\r
+    }\r
+\r
+    public int getValue(){\r
+        return value;\r
+    }\r
+\r
+    private static Map<Integer, ParagraphAlignment> imap = new HashMap<Integer, ParagraphAlignment>();\r
+    static{\r
+        for (ParagraphAlignment p : values()) {\r
+            imap.put(p.getValue(), p);\r
+        }\r
+    }\r
+\r
+    public static ParagraphAlignment valueOf(int type){\r
+        ParagraphAlignment err = imap.get(type);\r
+        if(err == null) throw new IllegalArgumentException("Unknown paragraph alignment: " + type);\r
+        return err;\r
+    }\r
+\r
+}\r
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java
deleted file mode 100644 (file)
index 3a79da9..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/* ====================================================================
-   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.xwpf.usermodel;
-
-import org.apache.poi.xwpf.XWPFDocument;
-import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
-
-/**
- * High level representation of a ooxml text document.
- */
-public class XMLWordDocument {
-       private XWPFDocument xwpfXML;
-       
-       public XMLWordDocument(XWPFDocument xml) {
-               this.xwpfXML = xml;
-       }
-       
-       public XWPFDocument _getXWPFXML() {
-               return xwpfXML;
-       }
-       
-       public XWPFHyperlink getHyperlinkByID(String id) {
-               return xwpfXML.getHyperlinkByID(id);
-       }
-       public XWPFHyperlink[] getHyperlinks() {
-               return xwpfXML.getHyperlinks();
-       }
-       
-       public XWPFComment getCommentByID(String id) {
-               return xwpfXML.getCommentByID(id);
-       }
-       public XWPFComment[] getComments() {
-               return xwpfXML.getComments();
-       }
-       
-       public XWPFHeaderFooterPolicy getHeaderFooterPolicy() {
-               return xwpfXML.getHeaderFooterPolicy();
-       }
-}
index 7de86d400ef2593de6680036ce9f83cec68266f3..72596085d3c59ed9869843e2c1fc3318dffa5412 100644 (file)
@@ -39,7 +39,7 @@ public class XWPFComment
         
         for(CTP ctp : comment.getPArray())
         {
-            XWPFParagraph p = new XWPFParagraph(ctp);
+            XWPFParagraph p = new XWPFParagraph(ctp, null);
             text.append(p.getText());
         }
     }
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
new file mode 100644 (file)
index 0000000..f8ff5c8
--- /dev/null
@@ -0,0 +1,322 @@
+/* ====================================================================
+   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.xwpf.usermodel;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.*;
+
+import org.apache.poi.POIXMLDocument;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.util.PackageHelper;
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxml4j.exceptions.InvalidFormatException;
+import org.openxml4j.exceptions.OpenXML4JException;
+import org.openxml4j.opc.*;
+import org.openxml4j.opc.Package;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Experimental class to do low level processing
+ *  of docx files.
+ *
+ * If you are using these low level classes, then you
+ *  will almost certainly need to refer to the OOXML
+ *  specifications from
+ *  http://www.ecma-international.org/publications/standards/Ecma-376.htm
+ *
+ * WARNING - APIs expected to change rapidly
+ */
+public class XWPFDocument extends POIXMLDocument {
+
+    private CTDocument1 ctDocument;
+    protected List<XWPFComment> comments;
+    protected List<XWPFHyperlink> hyperlinks;
+    protected List<XWPFParagraph> paragraphs;
+    protected List<XWPFTable> tables;
+
+    /** Handles the joy of different headers/footers for different pages */
+    private XWPFHeaderFooterPolicy headerFooterPolicy;
+
+    public XWPFDocument(Package pkg) throws IOException {
+        super(ensureWriteAccess(pkg));
+
+        //build a tree of POIXMLDocumentParts, this document being the root
+        try {
+            read(XWPFFactory.getInstance());
+        } catch (OpenXML4JException e){
+            throw new POIXMLException(e);
+        }
+        onDocumentRead();
+    }
+
+    public XWPFDocument(){
+        super(newPackage());
+        onDocumentCreate();
+    }
+
+    @Override
+    protected void onDocumentRead() throws IOException {
+        hyperlinks = new ArrayList<XWPFHyperlink>();
+        comments = new ArrayList<XWPFComment>();
+        paragraphs = new ArrayList<XWPFParagraph>();
+        tables= new ArrayList<XWPFTable>();
+
+        try {
+            DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
+            ctDocument = doc.getDocument();
+
+            CTBody body = ctDocument.getBody();
+
+            // filling paragraph list
+            for (CTP p : body.getPArray())     {
+                paragraphs.add(new XWPFParagraph(p, this));
+            }
+
+            // Get any tables
+            for(CTTbl table : body.getTblArray()) {
+                tables.add(new XWPFTable(table));
+            }
+
+            // Sort out headers and footers
+            headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
+
+            for(POIXMLDocumentPart p : getRelations()){
+                String relation = p.getPackageRelationship().getRelationshipType();
+                if(relation.equals(XWPFRelation.COMMENT_RELATION_TYPE)){
+                    CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream());
+                    for(CTComment ctcomment : cmntdoc.getComments().getCommentArray()) {
+                        comments.add(new XWPFComment(ctcomment));
+                    }
+                }
+            }
+
+            initHyperlinks();
+
+        } catch (XmlException e) {
+            throw new POIXMLException(e);
+        }
+    }
+
+    private void initHyperlinks(){
+        // Get the hyperlinks
+        // TODO: make me optional/separated in private function
+        try    {
+            Iterator <PackageRelationship> relIter =
+                getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK_RELATION_TYPE).iterator();
+            while(relIter.hasNext()) {
+                PackageRelationship rel = relIter.next();
+                hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
+            }
+        } catch (InvalidFormatException e){
+            throw new POIXMLException(e);
+        }
+    }
+
+    /**
+     * Create a new SpreadsheetML package and setup the default minimal content
+     */
+    protected static Package newPackage() {
+        try {
+            Package pkg = Package.create(PackageHelper.createTempFile());
+            // Main part
+            PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
+            // Create main part relationship
+            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
+            // Create main document part
+            pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());
+
+            pkg.getPackageProperties().setCreatorProperty("Apache POI");
+
+            return pkg;
+        } catch (Exception e){
+            throw new POIXMLException(e);
+        }
+    }
+
+    /**
+     * Create a new CTWorkbook with all values set to default
+     */
+    protected void onDocumentCreate() {
+        hyperlinks = new ArrayList<XWPFHyperlink>();
+        comments = new ArrayList<XWPFComment>();
+        paragraphs = new ArrayList<XWPFParagraph>();
+        tables= new ArrayList<XWPFTable>();
+
+        ctDocument = CTDocument1.Factory.newInstance();
+        ctDocument.addNewBody();
+    }
+
+    /**
+     * Returns the low level document base object
+     */
+    public CTDocument1 getDocument() {
+        return ctDocument;
+    }
+
+    public Iterator<XWPFParagraph> getParagraphsIterator() {
+        return paragraphs.iterator();
+    }
+    public XWPFParagraph[] getParagraphs() {
+        return paragraphs.toArray(
+            new XWPFParagraph[paragraphs.size()]
+        );
+    }
+
+    public Iterator<XWPFTable> getTablesIterator()
+    {
+        return tables.iterator();
+    }
+
+    public XWPFHyperlink getHyperlinkByID(String id) {
+        Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
+        while(iter.hasNext())
+        {
+            XWPFHyperlink link = iter.next();
+            if(link.getId().equals(id))
+                return link;
+        }
+
+        return null;
+    }
+    public XWPFHyperlink[] getHyperlinks() {
+        return hyperlinks.toArray(
+                new XWPFHyperlink[hyperlinks.size()]
+        );
+    }
+
+    public XWPFComment getCommentByID(String id) {
+        Iterator<XWPFComment> iter = comments.iterator();
+        while(iter.hasNext())
+        {
+            XWPFComment comment = iter.next();
+            if(comment.getId().equals(id))
+                return comment;
+        }
+
+        return null;
+    }
+    public XWPFComment[] getComments() {
+        return comments.toArray(
+                new XWPFComment[comments.size()]
+        );
+    }
+
+    /**
+     * Get the document part that's defined as the
+     *  given relationship of the core document.
+     */
+    public PackagePart getPartById(String id) {
+        try {
+            return getTargetPart(
+                    getCorePart().getRelationship(id)
+            );
+        } catch(InvalidFormatException e) {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    /**
+     * Returns the policy on headers and footers, which
+     *  also provides a way to get at them.
+     */
+    public XWPFHeaderFooterPolicy getHeaderFooterPolicy() {
+        return headerFooterPolicy;
+    }
+
+    /**
+     * Returns the styles object used
+     */
+    public CTStyles getStyle() throws XmlException, IOException {
+        PackagePart[] parts;
+        try {
+            parts = getRelatedByType(XWPFRelation.STYLES_RELATION_TYPE);
+        } catch(InvalidFormatException e) {
+            throw new IllegalStateException(e);
+        }
+        if(parts.length != 1) {
+            throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length);
+        }
+
+        StylesDocument sd =
+            StylesDocument.Factory.parse(parts[0].getInputStream());
+        return sd.getStyles();
+    }
+
+    /**
+     * Get the document's embedded files.
+     */
+    public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
+        List<PackagePart> embedds = new LinkedList<PackagePart>();
+
+        // Get the embeddings for the workbook
+        for(PackageRelationship rel : getPackagePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE))
+            embedds.add(getTargetPart(rel));
+
+        for(PackageRelationship rel : getPackagePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE))
+            embedds.add(getTargetPart(rel));
+
+        return embedds;
+    }
+
+    @Override
+    protected void commit() throws IOException {
+
+        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
+        Map map = new HashMap();
+        map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
+        map.put("urn:schemas-microsoft-com:office:office", "o");
+        map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
+        map.put("urn:schemas-microsoft-com:vml", "v");
+        map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
+        map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
+        map.put("urn:schemas-microsoft-com:office:word", "w10");
+        map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
+        map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
+        xmlOptions.setSaveSuggestedPrefixes(map);
+
+        PackagePart part = getPackagePart();
+        OutputStream out = part.getOutputStream();
+        ctDocument.save(out, xmlOptions);
+        out.close();
+    }
+
+    /**
+     * Appends a new paragraph to this document
+     *
+     * @return a new paragraph
+     */
+    public XWPFParagraph createParagraph(){
+        return new XWPFParagraph(ctDocument.getBody().addNewP(), this);
+    }
+
+}
+
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java
new file mode 100755 (executable)
index 0000000..3761241
--- /dev/null
@@ -0,0 +1,73 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xwpf.usermodel;\r
+\r
+import org.apache.poi.POIXMLFactory;\r
+import org.apache.poi.POIXMLDocumentPart;\r
+import org.apache.poi.POIXMLException;\r
+import org.apache.poi.POIXMLRelation;\r
+import org.apache.poi.util.POILogger;\r
+import org.apache.poi.util.POILogFactory;\r
+import org.openxml4j.opc.PackageRelationship;\r
+import org.openxml4j.opc.PackagePart;\r
+\r
+import java.lang.reflect.Constructor;\r
+\r
+/**\r
+ * @author Yegor Kozlov\r
+ */\r
+public class XWPFFactory extends POIXMLFactory  {\r
+\r
+    private static POILogger logger = POILogFactory.getLogger(XWPFFactory.class);\r
+\r
+    private XWPFFactory(){\r
+\r
+    }\r
+\r
+    private static final XWPFFactory inst = new XWPFFactory();\r
+\r
+    public static XWPFFactory getInstance(){\r
+        return inst;\r
+    }\r
+\r
+    public POIXMLDocumentPart createDocumentPart(PackageRelationship rel, PackagePart part){\r
+        POIXMLRelation descriptor = XWPFRelation.getInstance(rel.getRelationshipType());\r
+        if(descriptor == null || descriptor.getRelationClass() == null){\r
+            logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());\r
+            return new POIXMLDocumentPart(part, rel);\r
+        }\r
+\r
+        try {\r
+            Class cls = descriptor.getRelationClass();\r
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);\r
+            return constructor.newInstance(part, rel);\r
+        } catch (Exception e){\r
+            throw new POIXMLException(e);\r
+        }\r
+    }\r
+\r
+    public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){\r
+        try {\r
+            Class cls = descriptor.getRelationClass();\r
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();\r
+            return constructor.newInstance();\r
+        } catch (Exception e){\r
+            throw new POIXMLException(e);\r
+        }\r
+    }\r
+\r
+}\r
index 708944cf7ea9d488c3ecb56be300bfb58804ec71..22ca339ab8a6de8ce47d696bc33849215e12574e 100644 (file)
@@ -47,7 +47,7 @@ public abstract class XWPFHeaderFooter {
                        new XWPFParagraph[headerFooter.getPArray().length];
                for(int i=0; i<paras.length; i++) {
                        paras[i] = new XWPFParagraph(
-                                       headerFooter.getPArray(i)
+                                       headerFooter.getPArray(i), null
                        );
                }
                return paras;
index c56aef00d4fe2ff084fbfb9aed4122c5c07700ab..f0dc207081e364f1f75a45c66dbfa9645e7d7275 100644 (file)
@@ -18,89 +18,83 @@ package org.apache.poi.xwpf.usermodel;
 
 import java.util.ArrayList;
 
-import org.apache.poi.xwpf.XWPFDocument;
-import org.apache.poi.xwpf.model.XMLParagraph;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtContentRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 
 /**
  * Sketch of XWPF paragraph class
  */
-public class XWPFParagraph extends XMLParagraph
+public class XWPFParagraph
 {
-    protected XWPFDocument docRef; // XXX: we'd like to have access to document's hyperlink, comments and other tables
+    private CTP paragraph;
+    protected XWPFDocument document; // XXX: we'd like to have access to document's hyperlink, comments and other tables
     /**
      * TODO - replace with RichText String
      */
     private StringBuffer text = new StringBuffer();
     private StringBuffer pictureText = new StringBuffer();
     
-    public XWPFParagraph(CTP prgrph, XWPFDocument docRef)
+    protected XWPFParagraph(CTP prgrph, XWPFDocument docRef)
     {
-        super(prgrph);
-        this.docRef = docRef;
-        
-        // All the runs to loop over
-        // TODO - replace this with some sort of XPath expression
-        //  to directly find all the CTRs, in the right order
-        ArrayList<CTR> rs = new ArrayList<CTR>();
-        CTR[] tmp;
-        
-        // Get the main text runs
-        tmp = paragraph.getRArray();
-        for(int i=0; i<tmp.length; i++) {
-               rs.add(tmp[i]);
-        }
-        
-        // Not sure quite what these are, but they hold 
-        //  more text runs
-        CTSdtRun[] sdts = paragraph.getSdtArray();
-        for(int i=0; i<sdts.length; i++) {
-               CTSdtContentRun run = sdts[i].getSdtContent();
-               tmp = run.getRArray();
-            for(int j=0; j<tmp.length; j++) {
-               rs.add(tmp[j]);
+        this.paragraph = prgrph;
+        this.document = docRef;
+
+        if(!isEmpty()) {
+            // All the runs to loop over
+            // TODO - replace this with some sort of XPath expression
+            //  to directly find all the CTRs, in the right order
+            ArrayList<CTR> rs = new ArrayList<CTR>();
+            CTR[] tmp;
+
+            // Get the main text runs
+            tmp = paragraph.getRArray();
+            for(int i=0; i<tmp.length; i++) {
+                rs.add(tmp[i]);
             }
-        }
-    
-        
-        // Get text of the paragraph
-        for (int j = 0; j < rs.size(); j++) {
-            // Grab the text and tabs of the paragraph
-               // Do so in a way that preserves the ordering
-               XmlCursor c = rs.get(j).newCursor();
-               c.selectPath( "./*" );
-               while(c.toNextSelection()) {
-                       XmlObject o = c.getObject();
-                       if(o instanceof CTText) {
-                               text.append( ((CTText)o).getStringValue() );
-                       }
-                       if(o instanceof CTPTab) {
-                               text.append("\t");
-                       }
-               }
-               
-            // Loop over pictures inside our
-            //  paragraph, looking for text in them
-            CTPicture[] picts = rs.get(j).getPictArray();
-            for (int k = 0; k < picts.length; k++) {
-                XmlObject[] t = picts[k].selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
-                for (int m = 0; m < t.length; m++) {
-                    NodeList kids = t[m].getDomNode().getChildNodes();
-                    for (int n = 0; n < kids.getLength(); n++) {
-                        if (kids.item(n) instanceof Text) {
-                            pictureText.append("\n" + kids.item(n).getNodeValue());
+
+            // Not sure quite what these are, but they hold
+            //  more text runs
+            CTSdtRun[] sdts = paragraph.getSdtArray();
+            for(int i=0; i<sdts.length; i++) {
+                CTSdtContentRun run = sdts[i].getSdtContent();
+                tmp = run.getRArray();
+                for(int j=0; j<tmp.length; j++) {
+                    rs.add(tmp[j]);
+                }
+            }
+
+
+            // Get text of the paragraph
+            for (int j = 0; j < rs.size(); j++) {
+                // Grab the text and tabs of the paragraph
+                // Do so in a way that preserves the ordering
+                XmlCursor c = rs.get(j).newCursor();
+                c.selectPath( "./*" );
+                while(c.toNextSelection()) {
+                    XmlObject o = c.getObject();
+                    if(o instanceof CTText) {
+                        text.append( ((CTText)o).getStringValue() );
+                    }
+                    if(o instanceof CTPTab) {
+                        text.append("\t");
+                    }
+                }
+
+                // Loop over pictures inside our
+                //  paragraph, looking for text in them
+                CTPicture[] picts = rs.get(j).getPictArray();
+                for (int k = 0; k < picts.length; k++) {
+                    XmlObject[] t = picts[k].selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
+                    for (int m = 0; m < t.length; m++) {
+                        NodeList kids = t[m].getDomNode().getChildNodes();
+                        for (int n = 0; n < kids.getLength(); n++) {
+                            if (kids.item(n) instanceof Text) {
+                                pictureText.append("\n");
+                                pictureText.append(kids.item(n).getNodeValue());
+                            }
                         }
                     }
                 }
@@ -108,22 +102,16 @@ public class XWPFParagraph extends XMLParagraph
         }
     }
     
-    public XWPFParagraph(CTP prgrph) {
-        this(prgrph, null);
+    public CTP getCTP() {
+        return paragraph;
     }
-    
-    public XWPFParagraph(XMLParagraph paragraph) {
-        this(paragraph.getCTP());
-    }
-    
-    
+
     public boolean isEmpty() {
        return !paragraph.getDomNode().hasChildNodes();
     }
-    
-    
-    public XWPFDocument getDocRef() {
-        return docRef;
+
+    public XWPFDocument getDocument() {
+        return document;
     }
     
     /**
@@ -147,4 +135,49 @@ public class XWPFParagraph extends XMLParagraph
     public String getPictureText() {
        return pictureText.toString();
     }
+
+    /**
+     * Appends a new run to this paragraph
+     *
+     * @return a new text run
+     */
+    public XWPFRun createRun(){
+        return new XWPFRun(paragraph.addNewR(), this);
+    }
+
+    /**
+     * Returns the paragraph alignment which shall be applied to text in this paragraph.
+     *
+     * <p>
+     * If this element is not set on a given paragraph, its value is determined by the setting previously
+     * set at any level of the style hierarchy (i.e. that previous setting remains unchanged).
+     * If this setting is never specified in the style hierarchy, then no alignment is applied to the paragraph.
+     * </p>
+     *
+     * @return the paragraph alignment of this paragraph.
+     */
+    public ParagraphAlignment getAlignment(){
+        CTPPr pr = paragraph.getPPr();
+        return pr == null || !pr.isSetJc() ? ParagraphAlignment.LEFT :
+                ParagraphAlignment.valueOf(pr.getJc().getVal().intValue());
+    }
+
+    /**
+     * Specifies the paragraph alignment which shall be applied to text in this paragraph.
+     *
+     * <p>
+     * If this element is not set on a given paragraph, its value is determined by the setting previously
+     * set at any level of the style hierarchy (i.e. that previous setting remains unchanged).
+     * If this setting is never specified in the style hierarchy, then no alignment is applied to the paragraph.
+     * </p>
+     *
+     * @param align the paragraph alignment to apply to this paragraph.
+     */
+    public void setAlignment(ParagraphAlignment align){
+        CTPPr pr = paragraph.isSetPPr() ? paragraph.getPPr() : paragraph.addNewPPr();
+        CTJc jc = pr.isSetJc() ? pr.getJc() : pr.addNewJc();
+        STJc.Enum en = STJc.Enum.forInt(align.getValue());
+        jc.setVal(en);
+    }
+
 }
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraphText.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraphText.java
deleted file mode 100644 (file)
index a25b164..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.apache.poi.xwpf.usermodel;
-
-public class XWPFParagraphText
-{
-
-}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
new file mode 100755 (executable)
index 0000000..7b44e84
--- /dev/null
@@ -0,0 +1,94 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xwpf.usermodel;\r
+\r
+import org.apache.poi.POIXMLRelation;\r
+import org.apache.poi.POIXMLDocumentPart;\r
+\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+\r
+/**\r
+ * @author Yegor Kozlov\r
+ */\r
+public class XWPFRelation extends POIXMLRelation {\r
+    public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";\r
+    public static final String HEADER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml";\r
+    public static final String HEADER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";\r
+    public static final String FOOTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";\r
+    public static final String FOOTER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";\r
+    public static final String STYLES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";\r
+    public static final String STYLES_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";\r
+    public static final String HYPERLINK_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";\r
+    public static final String COMMENT_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";\r
+\r
+    /**\r
+     * A map to lookup POIXMLRelation by its relation type\r
+     */\r
+    protected static Map<String, XWPFRelation> _table = new HashMap<String, XWPFRelation>();\r
+\r
+\r
+    public static final XWPFRelation DOCUMENT = new XWPFRelation(\r
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",\r
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",\r
+            "/word/document.xml",\r
+            null\r
+    );\r
+    public static final XWPFRelation FONT_TABLE = new XWPFRelation(\r
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml",\r
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",\r
+            "/word/fontTable.xml",\r
+            null\r
+    );\r
+    public static final XWPFRelation SETTINGS = new XWPFRelation(\r
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",\r
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",\r
+            "/word/settings.xml",\r
+            null\r
+    );\r
+    public static final XWPFRelation STYLES = new XWPFRelation(\r
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",\r
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",\r
+            "/word/styles.xml",\r
+            null\r
+    );\r
+    public static final XWPFRelation WEB_SETTINGS = new XWPFRelation(\r
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml",\r
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings",\r
+            "/word/webSettings.xml",\r
+            null\r
+    );\r
+\r
+\r
+    private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {\r
+        super(type, rel, defaultName, cls);\r
+\r
+        if (cls != null && !_table.containsKey(rel)) _table.put(rel, this);\r
+    }\r
+\r
+    /**\r
+     * Get POIXMLRelation by relation type\r
+     *\r
+     * @param rel relation type, for example,\r
+     *            <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>\r
+     * @return registered POIXMLRelation or null if not found\r
+     */\r
+    public static XWPFRelation getInstance(String rel) {\r
+        return _table.get(rel);\r
+    }\r
+\r
+}\r
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
new file mode 100755 (executable)
index 0000000..0db7a8a
--- /dev/null
@@ -0,0 +1,105 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xwpf.usermodel;\r
+\r
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;\r
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;\r
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;\r
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;\r
+\r
+/**\r
+ * XWPFRun object  defines a region of text with a common set of properties\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class XWPFRun {\r
+    private CTR run;\r
+    private XWPFParagraph paragraph;\r
+\r
+    /**\r
+     *\r
+     * @param r the CTR bean which holds the run attributes\r
+     * @param p the parent paragraph\r
+     */\r
+    protected XWPFRun(CTR r, XWPFParagraph p){\r
+        this.run = r;\r
+        this.paragraph = p;\r
+    }\r
+\r
+    public CTR getCTR(){\r
+        return run;\r
+    }\r
+\r
+    public XWPFParagraph getParagraph(){\r
+        return paragraph;\r
+    }\r
+\r
+    /**\r
+     * Whether the bold property shall be applied to all non-complex script characters in the\r
+     * contents of this run when displayed in a document\r
+     *\r
+     * @return <code>true</code> if the bold property is applied\r
+     */\r
+    public boolean isBold(){\r
+        CTRPr pr = run.getRPr();\r
+        return pr != null && pr.isSetB();\r
+    }\r
+\r
+    /**\r
+     * Whether the bold property shall be applied to all non-complex script characters in the\r
+     * contents of this run when displayed in a document\r
+     *\r
+     * <p>\r
+     * This formatting property is a toggle property, which specifies that its behavior differs between its use within a\r
+     * style definition and its use as direct formatting. When used as part of a style definition, setting this property\r
+     * shall toggle the current state of that property as specified up to this point in the hierarchy (i.e. applied to not\r
+     * applied, and vice versa). Setting it to <code>false</code> (or an equivalent) shall result in the current\r
+     * setting remaining unchanged. However, when used as direct formatting, setting this property to true or false\r
+     * shall set the absolute state of the resulting property.\r
+     * </p>\r
+     * <p>\r
+     * If this element is not present, the default value is to leave the formatting applied at previous level in the style\r
+     * hierarchy. If this element is never applied in the style hierarchy, then bold shall not be applied to non-complex\r
+     * script characters.\r
+     * </p>\r
+     *\r
+     * @param value <code>true</code> if the bold property is applied to this run\r
+     */\r
+    public void setBold(boolean value){\r
+        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();\r
+        pr.addNewB().setVal(value ? STOnOff.TRUE : STOnOff.FALSE);\r
+    }\r
+\r
+    /**\r
+     * Return the string content of this text run\r
+     *\r
+     * @return the text of this text run or <code>null</code> if not set\r
+     */\r
+    public String getText(){\r
+        return run.sizeOfTArray() == 0 ? null : run.getTArray(0).getStringValue();\r
+    }\r
+\r
+    /**\r
+     * Sets the text of this text run\r
+     *\r
+     * @param value the literal text which shall be displayed in the document\r
+     */\r
+    public void setText(String value){\r
+        CTText t = run.sizeOfTArray() == 0 ? run.addNewT() : run.getTArray(0);\r
+        t.setStringValue(value);\r
+    }\r
+}\r
index aa647503b9a5c2893cd5ad0b2a3346e6e5a5e6f9..35218121940fd54357b269da83c32d7f9e24b481 100644 (file)
@@ -37,7 +37,7 @@ public class XWPFTable
                StringBuffer rowText = new StringBuffer();
             for(CTTc cell : row.getTcArray()) {
                 for(CTP ctp : cell.getPArray()) {
-                    XWPFParagraph p = new XWPFParagraph(ctp);
+                    XWPFParagraph p = new XWPFParagraph(ctp, null);
                     if(rowText.length() > 0) {
                        rowText.append('\t');
                     }
index 95bbe51f29dbf79061c6e2f53437d9868c6c94ba..f6049c396d9c76b3a38811e2b4bba0d15b96492d 100644 (file)
 package org.apache.poi;
 
 import java.io.File;
-import java.util.Iterator;
 
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.xslf.XSLFSlideShow;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 
index 0bd24a20721ca029d2bc1fb3b8bf3d894642e1d3..c76df4691067ef796d01ca7b767e45e3fdc0179d 100644 (file)
@@ -19,6 +19,8 @@ package org.apache.poi.xwpf;
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFRelation;
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 
@@ -49,7 +51,7 @@ public class TestXWPFDocument extends TestCase {
                
                boolean found = false;
                for(PackagePart part : pack.getParts()) {
-                       if(part.getContentType().equals(XWPFDocument.MAIN_CONTENT_TYPE)) {
+                       if(part.getContentType().equals(XWPFRelation.MAIN_CONTENT_TYPE)) {
                                found = true;
                        }
                        System.out.println(part);
@@ -76,7 +78,7 @@ public class TestXWPFDocument extends TestCase {
                );
                // Check it has key parts
                assertNotNull(xml.getDocument());
-               assertNotNull(xml.getDocumentBody());
+               assertNotNull(xml.getDocument().getBody());
                assertNotNull(xml.getStyle());
                
                // Complex file
@@ -84,7 +86,7 @@ public class TestXWPFDocument extends TestCase {
                                POIXMLDocument.openPackage(complexFile.toString())
                );
                assertNotNull(xml.getDocument());
-               assertNotNull(xml.getDocumentBody());
+               assertNotNull(xml.getDocument().getBody());
                assertNotNull(xml.getStyle());
        }
        
index 8fc83bc91e1bf4f8eb4fcb512503bb64b9c7e1e5..2704e0371e3dba9f910aeef81f7dc38d03a0833d 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.poi.xwpf.extractor;
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 
 import junit.framework.TestCase;
 
index 9d0e96a175a7488320b2e5e0ec5bda36cebaee73..b55b01951bcf74da3cd2c153de0b2666de77f47b 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.poi.xwpf.model;
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 
 import junit.framework.TestCase;
 
index 5a775c361dad2aac53de280bbb287cace6f5507c..65fb7f3312be2ebc10a9f5060569082844869fca 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.poi.xwpf.usermodel;
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 
 import junit.framework.TestCase;