Lines 39-46
Link Here
|
39 |
"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the ${organization} and all the POI contributors for their assistance in this matter.\r"; |
39 |
"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the ${organization} and all the POI contributors for their assistance in this matter.\r"; |
40 |
private String searchText = "${organization}"; |
40 |
private String searchText = "${organization}"; |
41 |
private String replacementText = "Apache Software Foundation"; |
41 |
private String replacementText = "Apache Software Foundation"; |
42 |
private String expectedText = |
42 |
private String expectedText2 = |
43 |
"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the Apache Software Foundation and all the POI contributors for their assistance in this matter.\r"; |
43 |
"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the Apache Software Foundation and all the POI contributors for their assistance in this matter.\r"; |
|
|
44 |
private String expectedText3 = "Thank you, Apache Software Foundation!\r"; |
44 |
|
45 |
|
45 |
private String illustrativeDocFile; |
46 |
private String illustrativeDocFile; |
46 |
|
47 |
|
Lines 84-90
Link Here
|
84 |
/** |
85 |
/** |
85 |
* Test that we can replace text in our Range with Unicode text. |
86 |
* Test that we can replace text in our Range with Unicode text. |
86 |
*/ |
87 |
*/ |
87 |
public void testRangeReplacement() throws Exception { |
88 |
public void testRangeReplacementOne() throws Exception { |
88 |
|
89 |
|
89 |
HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile)); |
90 |
HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile)); |
90 |
|
91 |
|
Lines 104-119
Link Here
|
104 |
|
105 |
|
105 |
para.replaceText(searchText, replacementText, offset); |
106 |
para.replaceText(searchText, replacementText, offset); |
106 |
|
107 |
|
107 |
// we need to let the model re-calculate the Range before we evaluate it |
|
|
108 |
range = daDoc.getRange(); |
109 |
|
110 |
assertEquals(1, range.numSections()); |
108 |
assertEquals(1, range.numSections()); |
111 |
section = range.getSection(0); |
109 |
section = range.getSection(0); |
112 |
|
110 |
|
|
|
111 |
assertEquals(4, section.numParagraphs()); |
112 |
para = section.getParagraph(2); |
113 |
|
114 |
text = para.text(); |
115 |
assertEquals(expectedText2, text); |
116 |
} |
117 |
|
118 |
/** |
119 |
* Test that we can replace text in our Range with Unicode text. |
120 |
*/ |
121 |
public void testRangeReplacementAll() throws Exception { |
122 |
|
123 |
HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile)); |
124 |
|
125 |
Range range = daDoc.getRange(); |
126 |
assertEquals(1, range.numSections()); |
127 |
|
128 |
Section section = range.getSection(0); |
113 |
assertEquals(5, section.numParagraphs()); |
129 |
assertEquals(5, section.numParagraphs()); |
|
|
130 |
|
131 |
Paragraph para = section.getParagraph(2); |
132 |
|
133 |
String text = para.text(); |
134 |
assertEquals(originalText, text); |
135 |
|
136 |
range.replaceText(searchText, replacementText); |
137 |
|
138 |
assertEquals(1, range.numSections()); |
139 |
section = range.getSection(0); |
140 |
assertEquals(5, section.numParagraphs()); |
141 |
|
114 |
para = section.getParagraph(2); |
142 |
para = section.getParagraph(2); |
|
|
143 |
text = para.text(); |
144 |
assertEquals(expectedText2, text); |
115 |
|
145 |
|
|
|
146 |
para = section.getParagraph(3); |
116 |
text = para.text(); |
147 |
text = para.text(); |
117 |
assertEquals(expectedText, text); |
148 |
assertEquals(expectedText3, text); |
118 |
} |
149 |
} |
119 |
} |
150 |
} |