Java Code Examples for org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText#setStringValue()
The following examples show how to use
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText#setStringValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BookmarkManager.java From M2Doc with Eclipse Public License 1.0 | 6 votes |
/** * 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); ref.setStringValue(String.format(REF_TAG, name)); messagePositions.put(ref, messageRun); Set<CTText> pendingRefs = pendingReferences.get(name); if (pendingRefs == null) { pendingRefs = new LinkedHashSet<>(); pendingReferences.put(name, pendingRefs); } pendingRefs.add(ref); xmlObjectToName.put(ref, name); } }
Example 2
Source File: BookmarkManager.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * 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); xmlObjectToName.put(bookmark, name); startedBookmarks.put(name, bookmark); Set<CTText> pendingRefs = pendingReferences.remove(name); if (pendingRefs != null) { for (CTText pendingRef : pendingRefs) { xmlObjectToName.remove(pendingRef); // we remove the run 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())); } } } }
Example 3
Source File: BookmarkManager.java From M2Doc with Eclipse Public License 1.0 | 2 votes |
/** * Inserts a reference to the given {@link CTBookmark} with the given text in the given {@link XWPFParagraph}. * * @param paragraph * the {@link XWPFParagraph} * @param bookmark * the {@link CTBookmark} * @param text * the text */ private void insertReference(XWPFParagraph paragraph, CTBookmark bookmark, String text) { final String name = bookmark.getName(); final CTText pendingCTText = insertPendingReference(paragraph, name, text); pendingCTText.setStringValue(String.format(REF_TAG, name)); }