本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFRun.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFRun.getParent方法的具体用法?Java XWPFRun.getParent怎么用?Java XWPFRun.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFRun
的用法示例。
在下文中一共展示了XWPFRun.getParent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertRun
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Inserts a run in the generated document. The new run is a copy from the specified run.
*
* @param paragraph
* the {@link XWPFParagraph} to modify
* @param srcRun
* the run to copy
* @return the inserted {@link XWPFRun}
*/
private XWPFRun insertRun(XWPFParagraph paragraph, XWPFRun srcRun) {
final XWPFParagraph newParagraph;
if (srcRun.getParent() != currentTemplateParagraph || forceNewParagraph) {
newParagraph = createNewParagraph(generatedDocument, (XWPFParagraph) srcRun.getParent());
forceNewParagraph = false;
} else {
newParagraph = paragraph;
}
XWPFRun newRun = null;
if (srcRun instanceof XWPFHyperlinkRun) {
// Hyperlinks meta information is saved in the paragraph and not in the run. So we have to update the paragrapah with a copy of
// the hyperlink to insert.
CTHyperlink newHyperlink = newParagraph.getCTP().addNewHyperlink();
newHyperlink.set(((XWPFHyperlinkRun) srcRun).getCTHyperlink());
newRun = new XWPFHyperlinkRun(newHyperlink, srcRun.getCTR(), srcRun.getParent());
newParagraph.addRun(newRun);
} else {
newRun = newParagraph.createRun();
newRun.getCTR().set(srcRun.getCTR());
}
return newRun;
}
示例2: endBookmark
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Ends the bookmark with the given name.
*
* @param result
* the {@link GenerationResult}
* @param paragraph
* the current {@link XWPFParagraph}
* @param name
* the bookmark name
*/
public void endBookmark(GenerationResult result, XWPFParagraph paragraph, String name) {
final CTBookmark bookmark = startedBookmarks.remove(name);
if (bookmark != null) {
final CTMarkupRange range = paragraph.getCTP().addNewBookmarkEnd();
range.setId(bookmarks.get(name).getId());
// we remove the created for error messages.
final XWPFRun run = messagePositions.get(bookmark);
final IRunBody parent = run.getParent();
if (parent instanceof XWPFParagraph) {
((XWPFParagraph) parent).removeRun(((XWPFParagraph) parent).getRuns().indexOf(run));
} else {
throw new IllegalStateException("this should not happend");
}
} else if (bookmarks.containsKey(name)) {
result.addMessage(M2DocUtils.appendMessageRun(paragraph, ValidationMessageLevel.ERROR,
"Can't end already closed bookmark " + name));
} else {
result.addMessage(M2DocUtils.appendMessageRun(paragraph, ValidationMessageLevel.ERROR,
"Can't end not existing bookmark " + name));
}
}
示例3: insertFieldRunReplacement
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Inserts a run in the generated document and set it's text to the specified replacement. The new run is a copy from the specified run.
*
* @param paragraph
* the {@link XWPFParagraph} to modify
* @param srcRun
* the run to copy
* @param replacement
* the text to set
* @return the inserted run
*/
private XWPFRun insertFieldRunReplacement(XWPFParagraph paragraph, XWPFRun srcRun, String replacement) {
final XWPFParagraph newParagraph;
if (srcRun.getParent() != currentTemplateParagraph || forceNewParagraph) {
newParagraph = createNewParagraph(generatedDocument, (XWPFParagraph) srcRun.getParent());
forceNewParagraph = false;
} else {
newParagraph = paragraph;
}
return insertString(newParagraph, srcRun, replacement);
}
示例4: closingRepretition
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Closes the generation of the given {@link Repetition}.
* if the end of {@link Repetition} lies on a distinct paragraph, insert a new
* paragraph there to take this into account.
*
* @param repetition
* {@link Repetition} to close
*/
private void closingRepretition(Repetition repetition) {
int bodySize = repetition.getBody().getStatements().size();
if (bodySize > 0 && repetition.getBody().getStatements().get(bodySize - 1).getRuns().size() > 0) {
IConstruct lastBodyPart = repetition.getBody().getStatements().get(bodySize - 1);
int runNumber = lastBodyPart.getRuns().size();
XWPFRun lastRun = lastBodyPart.getRuns().get(runNumber - 1);
int closingRunNumber = repetition.getClosingRuns().size();
if (closingRunNumber > 0 && repetition.getClosingRuns().get(0).getParent() != lastRun.getParent()) {
forceNewParagraph = true;
}
}
}
示例5: startBookmark
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Starts a bookmark in the given {@link XWPFParagraph} with the given name.
*
* @param result
* the {@link GenerationResult}
* @param paragraph
* the current {@link XWPFParagraph}
* @param name
* the bookmark name
*/
public void startBookmark(GenerationResult result, XWPFParagraph paragraph, String name) {
if (bookmarks.containsKey(name)) {
result.addMessage(M2DocUtils.appendMessageRun(paragraph, ValidationMessageLevel.ERROR,
"Can't start duplicated bookmark " + name));
} else {
final CTBookmark bookmark = paragraph.getCTP().addNewBookmarkStart();
// we create a new run for future error messages.
messagePositions.put(bookmark, paragraph.createRun());
bookmark.setName(name);
final BigInteger id = getRandomID();
bookmark.setId(id);
bookmarks.put(name, bookmark);
startedBookmarks.put(name, bookmark);
Set<CTText> pendingRefs = pendingReferences.remove(name);
if (pendingRefs != null) {
for (CTText pendingRef : pendingRefs) {
// we remove the created for error messages.
final XWPFRun run = messagePositions.get(pendingRef);
final IRunBody parent = run.getParent();
if (parent instanceof XWPFParagraph) {
((XWPFParagraph) parent).removeRun(((XWPFParagraph) parent).getRuns().indexOf(run));
} else {
throw new IllegalStateException("this should not happend");
}
pendingRef.setStringValue(String.format(REF_TAG, bookmark.getName()));
}
}
}
}
示例6: copyStatements
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Copies the given {@link List} of {@link Statement} from the given {@link XWPFParagraph} to the given output {@link XWPFParagraph}.
*
* @param outputParagraph
* the output {@link XWPFParagraph}
* @param currentInputParagraph
* the current input {@link XWPFParagraph}
* @param previousInputParagraph
* the previous input {@link XWPFParagraph} if any, <code>null</code> otherwise
* @param statements
* the {@link List} of {@link Statement} to copy
* @return last paragraph created by copy
* @throws InvalidFormatException
* InvalidFormatException
* @throws XmlException
* XmlException
* @throws IOException
* if the copy fails
*/
@SuppressWarnings("resource")
private XWPFParagraph copyStatements(XWPFParagraph outputParagraph, XWPFParagraph currentInputParagraph,
XWPFParagraph previousInputParagraph, final List<Statement> statements)
throws InvalidFormatException, IOException, XmlException {
XWPFParagraph localCurrentInputParagraph = currentInputParagraph;
final XWPFDocument containerOutputDocument = outputParagraph.getDocument();
final IBody outputBody = outputParagraph.getBody();
final List<XWPFParagraph> listOutputParagraphs = new ArrayList<>();
final List<XWPFTable> listOutputTables = new ArrayList<>();
final List<XWPFRun> listOutputRuns = new ArrayList<>();
final Map<String, String> inputPicuteIdToOutputmap = new HashMap<>();
XWPFParagraph currentOutputParagraph = outputParagraph;
for (Statement statement : statements) {
for (XWPFRun inputRun : statement.getRuns()) {
final XWPFParagraph currentRunParagraph = (XWPFParagraph) inputRun.getParent();
if (currentRunParagraph != localCurrentInputParagraph) {
localCurrentInputParagraph = currentRunParagraph;
// currentOutputParagraph = outputDocument.createParagraph();
currentOutputParagraph = createNewParagraph(outputBody);
// Copy new paragraph
currentOutputParagraph.getCTP().set(localCurrentInputParagraph.getCTP());
listOutputParagraphs.add(currentOutputParagraph);
}
// Test if some run exist between userContent tag and first paragraph in this tag
if (currentRunParagraph == previousInputParagraph) {
// Clone run directly, paragraph is already generate by normal processing
final XWPFRun outputRun = currentOutputParagraph.createRun();
outputRun.getCTR().set(inputRun.getCTR());
// Keep run to change relation id later
listOutputRuns.add(outputRun);
}
// Create picture embedded in run and keep relation id in map (input to output)
createPictures(inputPicuteIdToOutputmap, inputRun, containerOutputDocument);
}
// In case of table (no run in abstractConstruct)
if (statement instanceof Table) {
Table table = (Table) statement;
XWPFTable inputTable = table.getTable();
// XWPFTable outputTable = contenerOutputDocument.createTable();
XWPFTable outputTable = createNewTable(outputBody, inputTable);
outputTable.getCTTbl().set(inputTable.getCTTbl());
copyTableStyle(inputTable, containerOutputDocument);
listOutputTables.add(outputTable);
// Inspect table to extract all picture ID in run
collectRelationId(inputPicuteIdToOutputmap, inputTable, containerOutputDocument);
} else if (statement instanceof ContentControl) {
final ContentControl contentControl = (ContentControl) statement;
final XWPFSDT control = contentControl.getControl();
copyControl(outputBody, control);
}
}
// Change Picture Id by xml replacement
changePictureId(inputPicuteIdToOutputmap, listOutputRuns, listOutputParagraphs, listOutputTables);
return currentOutputParagraph;
}
示例7: insertMessageAfter
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Inserts a new message {@link XWPFRun} after the given {@link XWPFRun}.
*
* @param run
* the {@link XWPFRun} used as reference.
* @param level
* the {@link ValidationMessageLevel}
* @param message
* the message
* @return the created {@link XWPFRun}
*/
public static TemplateValidationMessage insertMessageAfter(XWPFRun run, ValidationMessageLevel level,
String message) {
final IRunBody parent = run.getParent();
if (parent instanceof XWPFParagraph) {
final XWPFParagraph paragraph = (XWPFParagraph) parent;
final XWPFRun newRun = paragraph.insertNewRun(paragraph.getRuns().indexOf(run));
setRunMessage(newRun, level, message);
return new TemplateValidationMessage(level, message, newRun);
} else {
throw new IllegalStateException("this should not happend");
}
}
示例8: KrXWPFRun
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
public KrXWPFRun(XWPFRun run) {
this(run.getCTR(), run.getParent());
}