diff options
author | Nick Burch <nick@apache.org> | 2015-08-11 20:01:26 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-08-11 20:01:26 +0000 |
commit | 3aa84d4555ff73ee44302e9a4c8cd35f7cef2dd8 (patch) | |
tree | 08b5e4acda56c1272b8c4390640d9110736eb918 /src/ooxml/java/org/apache/poi/xwpf | |
parent | 574cd922f446be82d66f364b4ad8229bc4dbb51c (diff) | |
download | poi-3aa84d4555ff73ee44302e9a4c8cd35f7cef2dd8.tar.gz poi-3aa84d4555ff73ee44302e9a4c8cd35f7cef2dd8.zip |
Support XWPF field runs, the same way that we handle hyperlink runs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1695361 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xwpf')
3 files changed, 60 insertions, 9 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFieldRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFieldRun.java new file mode 100644 index 0000000000..997c7d0cb3 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFieldRun.java @@ -0,0 +1,48 @@ +/* ==================================================================== + 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.util.Internal; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSimpleField; + +/** + * A run of text which is part of a field, such as Title + * of Page number or Author.
+ * Any given Field may be made up of multiple of these.
+ */
+public class XWPFFieldRun extends XWPFRun {
+ private CTSimpleField field;
+
+ public XWPFFieldRun(CTSimpleField field, CTR run, IRunBody p) {
+ super(run, p);
+ this.field = field;
+ }
+ + @Internal
+ public CTSimpleField getCTField() { + return field;
+ }
+
+ public String getFieldInstruction() {
+ return field.getInstr();
+ }
+
+ public void setFieldInstruction(String instruction) { + field.setInstr(instruction);
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java index 4c8158a411..9a79b20f0f 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHyperlinkRun.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import org.apache.poi.util.Internal; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; @@ -30,7 +31,8 @@ public class XWPFHyperlinkRun extends XWPFRun { super(run, p);
this.hyperlink = hyperlink;
}
-
+ + @Internal
public CTHyperlink getCTHyperlink() {
return hyperlink;
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index 0eae922479..65c726d102 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -142,13 +142,21 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para iruns.add(r); } if (o instanceof CTHyperlink) { - CTHyperlink link = (CTHyperlink) o; + CTHyperlink link = (CTHyperlink)o; for (CTR r : link.getRArray()) { XWPFHyperlinkRun hr = new XWPFHyperlinkRun(link, r, this); runs.add(hr); iruns.add(hr); } } + if (o instanceof CTSimpleField) { + CTSimpleField field = (CTSimpleField)o; + for (CTR r : field.getRArray()) { + XWPFFieldRun fr = new XWPFFieldRun(field, r, this); + runs.add(fr); + iruns.add(fr); + } + } if (o instanceof CTSdtBlock) { XWPFSDT cc = new XWPFSDT((CTSdtBlock) o, part); iruns.add(cc); @@ -164,13 +172,6 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para iruns.add(cr); } } - if (o instanceof CTSimpleField) { - for (CTR r : ((CTSimpleField) o).getRArray()) { - XWPFRun cr = new XWPFRun(r, this); - runs.add(cr); - iruns.add(cr); - } - } if (o instanceof CTSmartTagRun) { // Smart Tags can be nested many times. // This implementation does not preserve the tagging information |