本文整理汇总了Java中org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText类的典型用法代码示例。如果您正苦于以下问题:Java CTText类的具体用法?Java CTText怎么用?Java CTText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CTText类属于org.openxmlformats.schemas.wordprocessingml.x2006.main包,在下文中一共展示了CTText类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertReference
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
/**
* Inserts a pending reference to the given name in the given {@link XWPFParagraph}.
*
* @param paragraph
* the {@link XWPFParagraph}
* @param name
* the bookmark name
* @param text
* the text
*/
public void insertReference(XWPFParagraph paragraph, String name, String text) {
final CTBookmark bookmark = bookmarks.get(name);
if (bookmark != null) {
insertReference(paragraph, bookmark, text);
} else {
final XWPFRun messageRun = paragraph.createRun();
final CTText ref = insertPendingReference(paragraph, name, text);
messagePositions.put(ref, messageRun);
Set<CTText> pendingRefs = pendingReferences.get(name);
if (pendingRefs == null) {
pendingRefs = new LinkedHashSet<CTText>();
pendingReferences.put(name, pendingRefs);
}
pendingRefs.add(ref);
}
}
示例2: markDanglingReferences
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
/**
* Marks dangling references.
*
* @param result
* the {@link GenerationResult}
* @return <code>true</code> if any dangling reference was found, <code>false</code> otherwise
*/
public boolean markDanglingReferences(GenerationResult result) {
final boolean res = !pendingReferences.isEmpty();
if (res) {
for (Entry<String, Set<CTText>> entry : pendingReferences.entrySet()) {
for (CTText ref : entry.getValue()) {
final XWPFRun refRun = messagePositions.remove(ref);
result.addMessage(M2DocUtils.insertMessageAfter(refRun, ValidationMessageLevel.ERROR,
"dangling reference for bookmark " + entry.getKey()));
}
}
}
return res;
}
示例3: deleteRuns
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
private void deleteRuns(DocumentPosition position, boolean fromPosition) {
boolean deleteRun = false;
List<CTText> texts = position.run.getCTR().getTList();
for (int textIndex = 0; textIndex < texts.size(); textIndex++) {
CTText text = texts.get(textIndex);
if (!fromPosition && text != position.text) {
position.run.getCTR().removeT(0);
textIndex--;
} else if (!fromPosition) {
return;
}
if (deleteRun) {
position.run.getCTR().removeT(position.positionInRun + 1);
textIndex--;
} else if (fromPosition && text == position.text) {
deleteRun = true;
}
}
if (position.run.getCTR().getTList().isEmpty() && !position.run.getParagraph().getRuns().isEmpty()) {
position.run.getParagraph().removeRun(position.positionInParagraph);
}
}
示例4: searchRun
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
DocumentPosition searchRun(XWPFRun run, int offset) throws BadLocationException {
for (XWPFPicture picture : run.getEmbeddedPictures()) {
// currentOffset++;
}
List<CTText> texts = run.getCTR().getTList();
int textIndex = 0;
for (CTText text : texts) {
String textValue = text.getStringValue();
int textLength = textValue.length();
if (currentOffset + textLength >= offset) {// || (currentOffset + textLength == offset && !textValue.endsWith("\n"))) {
DocumentPosition position = new DocumentPosition();
position.run = run;
position.text = text;
position.offsetInText = offset - currentOffset;
position.positionInRun = textIndex;
return position;
} else {
currentOffset += textLength;
}
textIndex++;
}
return null;
}
示例5: getTextFromChildNodes
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
/**
* Iterates through all and any children of the Node whose reference will be
* passed as an argument to the node parameter, and recover the contents of
* any text nodes. Testing revealed that a node can be called a text node
* and yet report it's type as being something different, an element node
* for example. Calling the getNodeValue() method on a text node will return
* the text the node encapsulates but doing the same on an element node will
* not. In fact, the call will simply return a null value. As a result, this
* method will test the nodes name to catch all text nodes - those whose
* name is to 'w:t' and then it's type. If the type is reported to be a text
* node, it is a trivial task to get at it's contents. However, if the type
* is not reported as a text type, then it is necessary to parse the raw XML
* markup for the node to recover it's value.
*
* @param node An instance of the Node class that encapsulates a reference
* to a node recovered from the document being processed. It should be
* passed a reference to a character run - 'w:r' - node.
* @return An instance of the String class that encapsulates the text
* recovered from the nodes children, if they are text nodes.
* @throws XmlException Thrown if a problem is encountered parsing the XML
* markup recovered from the document in order to construct the CTText
* instance which may be required to obtain the bookmarks text.
*/
private String getTextFromChildNodes(Node node) throws XmlException {
NodeList childNodes = null;
Node childNode = null;
CTText text = null;
StringBuilder builder = new StringBuilder();
int numChildNodes = 0;
// Get a list of chid nodes from the node passed to the method and
// find out how many children there are in the list.
childNodes = node.getChildNodes();
numChildNodes = childNodes.getLength();
// Iterate through the children one at a time - it is possible for a
// run to ciontain zero, one or more text nodes - and recover the text
// from an text type child nodes.
for (int i = 0; i < numChildNodes; i++) {
// Get a node and check it's name. If this is 'w:t' then process as
// text type node.
childNode = childNodes.item(i);
if (childNode.getNodeName().equals(BookMark.TEXT_NODE_NAME)) {
// If the node reports it's type as txet, then simply call the
// getNodeValue() method to get at it's text.
if (childNode.getNodeType() == Node.TEXT_NODE) {
builder.append(childNode.getNodeValue());
} else {
// Correct the type by parsing the node's XML markup and
// creating a CTText object. Call the getStringValue()
// method on that to get the text.
text = CTText.Factory.parse(childNode);
builder.append(text.getStringValue());
}
}
}
return (builder.toString());
}
示例6: insertMHyperLink
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
/**
* Inserts the given {@link MHyperLink}.
*
* @param paragraph
* the {@link XWPFParagraph} to modify
* @param run
* the {@link XWPFRun}
* @param hyperLink
* the {@link MHyperLink}
*/
private void insertMHyperLink(XWPFParagraph paragraph, XWPFRun run, MHyperLink hyperLink) {
final String id = paragraph.getDocument().getPackagePart()
.addExternalRelationship(hyperLink.getUrl(), XWPFRelation.HYPERLINK.getRelation()).getId();
final CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id);
CTText ctText = CTText.Factory.newInstance();
ctText.setStringValue(hyperLink.getText());
CTR ctr = CTR.Factory.newInstance();
ctr.setRPr((CTRPr) run.getCTR().getRPr().copy());
ctr.setTArray(new CTText[] {ctText });
cLink.setRArray(new CTR[] {ctr });
}
示例7: startBookmark
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的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()));
}
}
}
}
示例8: insertPendingReference
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
/**
* Inserts a reference to the given {@link CTBookmark} with the given text in the given {@link XWPFParagraph}.
*
* @param paragraph
* the {@link XWPFParagraph}
* @param name
* the bookmark name
* @param text
* the text
* @return the {@link CTText} corresponding to the reference.
*/
private CTText insertPendingReference(XWPFParagraph paragraph, String name, String text) {
final byte[] id = getReferenceID(name);
final XWPFRun beginRun = paragraph.createRun();
beginRun.getCTR().setRsidR(id);
beginRun.getCTR().addNewFldChar().setFldCharType(STFldCharType.BEGIN);
final XWPFRun preservedRun = paragraph.createRun();
preservedRun.getCTR().setRsidR(id);
final CTText pgcttext = preservedRun.getCTR().addNewInstrText();
pgcttext.setSpace(Space.PRESERVE);
final XWPFRun separateRun = paragraph.createRun();
separateRun.getCTR().setRsidR(id);
separateRun.getCTR().addNewFldChar().setFldCharType(STFldCharType.SEPARATE);
final XWPFRun textRun = paragraph.createRun();
textRun.getCTR().setRsidR(id);
textRun.getCTR().addNewRPr().addNewNoProof();
textRun.setText(text);
textRun.setBold(true);
final XWPFRun endRun = paragraph.createRun();
endRun.getCTR().setRsidR(id);
endRun.getCTR().addNewFldChar().setFldCharType(STFldCharType.END);
return pgcttext;
}
示例9: readUpInstrText
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
/**
* reads up the instruction of a field's run.
*
* @param run
* the run to read.
* @return the aggregated instruction text of the run
*/
public static StringBuilder readUpInstrText(XWPFRun run) {
List<CTText> texts = run.getCTR().getInstrTextList();
StringBuilder runBuilder = new StringBuilder();
for (CTText text : texts) {
runBuilder.append(text.getStringValue());
}
return runBuilder;
}
示例10: buildRun
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
public void buildRun(DefaultMutableTreeNode root, XWPFRun run) {
List<CTText> texts = run.getCTR().getTList();
for (CTText text : texts) {
String nodeText = run.getClass().getSimpleName() + ":" + currentOffset;
DefaultMutableTreeNode node = new DefaultMutableTreeNode(nodeText);
root.add(node);
buildCTText(node, text);
}
}
示例11: processSingleItem
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
void processSingleItem(XWPFDocument document, String citationText, String abstractText, String handleUrl) {
XWPFParagraph para = document.createParagraph();
XWPFRun run = para.createRun();
run.setText(StringUtils.isNotBlank(citationText) ? citationText : "(no citation)");
para.setSpacingAfter(200);
if (StringUtils.isNotBlank(handleUrl)) {
// from http://stackoverflow.com/a/22456273/72625
String linkId = document.getPackagePart().addExternalRelationship(handleUrl, XWPFRelation.HYPERLINK.getRelation()).getId();
para = document.createParagraph();
para.setSpacingAfter(200);
XWPFRun linkPrefix = para.createRun();
CTText linkPrefixText = linkPrefix.getCTR().addNewT();
linkPrefixText.setStringValue("AgScite record: ");
linkPrefixText.setSpace(SpaceAttribute.Space.PRESERVE);
CTHyperlink link = para.getCTP().addNewHyperlink();
link.setId(linkId);
CTText linkText = CTText.Factory.newInstance();
linkText.setStringValue(handleUrl);
CTR ctr = CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{linkText});
ctr.addNewRPr().addNewColor().setVal("0000FF");
ctr.addNewRPr().addNewU().setVal(STUnderline.SINGLE);
link.setRArray(new CTR[]{ctr});
}
if (includeAbstract && StringUtils.isNotBlank(abstractText)) {
// split md string at double newline so we can create actual paragraphs
String[] abstractParas = abstractText.split("\r?\n\r?\n");
for (String abstractPara : abstractParas) {
para = document.createParagraph();
run = para.createRun();
run.setText(abstractPara);
para.setSpacingAfter(200);
para.setIndentationLeft(200);
}
}
para.setSpacingAfter(600); // override spacing for final para
}
示例12: buildCTText
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; //导入依赖的package包/类
public void buildCTText(DefaultMutableTreeNode root, CTText text) {
String textValue = text.getStringValue();
DefaultMutableTreeNode node = new DefaultMutableTreeNode(textValue);
root.add(node);
currentOffset += textValue.length();
}