Fix some eclipse warnings, add TODOs for fields/hyperlinks XWPF add support, and give a more helpful exception if someone tries to remove a XWPFRun that is not a direct paragraph child
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1695365 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
87a2acf935
commit
ac8ed40f80
@ -131,6 +131,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
* sub-paragraph that correspond to character text
|
* sub-paragraph that correspond to character text
|
||||||
* runs, and builds the appropriate runs for these.
|
* runs, and builds the appropriate runs for these.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void buildRunsInOrderFromXml(XmlObject object) {
|
private void buildRunsInOrderFromXml(XmlObject object) {
|
||||||
XmlCursor c = object.newCursor();
|
XmlCursor c = object.newCursor();
|
||||||
c.selectPath("child::*");
|
c.selectPath("child::*");
|
||||||
@ -1322,7 +1323,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
* @return a new text run
|
* @return a new text run
|
||||||
*/
|
*/
|
||||||
public XWPFRun createRun() {
|
public XWPFRun createRun() {
|
||||||
XWPFRun xwpfRun = new XWPFRun(paragraph.addNewR(), this);
|
XWPFRun xwpfRun = new XWPFRun(paragraph.addNewR(), (IRunBody)this);
|
||||||
runs.add(xwpfRun);
|
runs.add(xwpfRun);
|
||||||
iruns.add(xwpfRun);
|
iruns.add(xwpfRun);
|
||||||
return xwpfRun;
|
return xwpfRun;
|
||||||
@ -1337,7 +1338,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
public XWPFRun insertNewRun(int pos) {
|
public XWPFRun insertNewRun(int pos) {
|
||||||
if (pos >= 0 && pos <= paragraph.sizeOfRArray()) {
|
if (pos >= 0 && pos <= paragraph.sizeOfRArray()) {
|
||||||
CTR ctRun = paragraph.insertNewR(pos);
|
CTR ctRun = paragraph.insertNewR(pos);
|
||||||
XWPFRun newRun = new XWPFRun(ctRun, this);
|
XWPFRun newRun = new XWPFRun(ctRun, (IRunBody)this);
|
||||||
|
|
||||||
// To update the iruns, find where we're going
|
// To update the iruns, find where we're going
|
||||||
// in the normal runs, and go in there
|
// in the normal runs, and go in there
|
||||||
@ -1358,6 +1359,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// TODO Add methods to allow adding a HyperlinkRun or a FieldRun
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this methods parse the paragraph and search for the string searched.
|
* this methods parse the paragraph and search for the string searched.
|
||||||
@ -1369,10 +1371,12 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
*/
|
*/
|
||||||
public TextSegement searchText(String searched, PositionInParagraph startPos) {
|
public TextSegement searchText(String searched, PositionInParagraph startPos) {
|
||||||
int startRun = startPos.getRun(),
|
int startRun = startPos.getRun(),
|
||||||
startText = startPos.getText(),
|
startText = startPos.getText(),
|
||||||
startChar = startPos.getChar();
|
startChar = startPos.getChar();
|
||||||
int beginRunPos = 0, candCharPos = 0;
|
int beginRunPos = 0, candCharPos = 0;
|
||||||
boolean newList = false;
|
boolean newList = false;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
CTR[] rArray = paragraph.getRArray();
|
CTR[] rArray = paragraph.getRArray();
|
||||||
for (int runPos = startRun; runPos < rArray.length; runPos++) {
|
for (int runPos = startRun; runPos < rArray.length; runPos++) {
|
||||||
int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos = 0;
|
int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos = 0;
|
||||||
@ -1433,6 +1437,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
*
|
*
|
||||||
* @param segment
|
* @param segment
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public String getText(TextSegement segment) {
|
public String getText(TextSegement segment) {
|
||||||
int runBegin = segment.getBeginRun();
|
int runBegin = segment.getBeginRun();
|
||||||
int textBegin = segment.getBeginText();
|
int textBegin = segment.getBeginText();
|
||||||
@ -1473,6 +1478,12 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
if (pos >= 0 && pos < paragraph.sizeOfRArray()) {
|
if (pos >= 0 && pos < paragraph.sizeOfRArray()) {
|
||||||
// Remove the run from our high level lists
|
// Remove the run from our high level lists
|
||||||
XWPFRun run = runs.get(pos);
|
XWPFRun run = runs.get(pos);
|
||||||
|
if (run instanceof XWPFHyperlinkRun ||
|
||||||
|
run instanceof XWPFFieldRun) {
|
||||||
|
// TODO Add support for removing these kinds of nested runs,
|
||||||
|
// which aren't on the CTP -> R array, but CTP -> XXX -> R array
|
||||||
|
throw new IllegalArgumentException("Removing Field or Hyperlink runs not yet supported");
|
||||||
|
}
|
||||||
runs.remove(pos);
|
runs.remove(pos);
|
||||||
iruns.remove(run);
|
iruns.remove(run);
|
||||||
// Remove the run from the low-level XML
|
// Remove the run from the low-level XML
|
||||||
|
Loading…
Reference in New Issue
Block a user