From 913d1eecf52382f706d5903b2fbd0ae9c8770494 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 28 Aug 2022 14:16:01 +0000 Subject: [PATCH] [bug-63576] support capitalized text in WordExtractor (HWPF) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903738 13f79535-47bb-0310-9956-ffa450edef68 --- .../hwpf/converter/AbstractWordConverter.java | 5 +++++ .../poi/hwpf/extractor/TestWordExtractor.java | 8 ++++++++ test-data/document/capitalized.doc | Bin 0 -> 26624 bytes 3 files changed, 13 insertions(+) create mode 100644 test-data/document/capitalized.doc diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java index 01c4bed4fe..d6f410d286 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java @@ -52,6 +52,7 @@ import org.apache.poi.hwpf.usermodel.TableRow; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; +import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.StringUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -445,6 +446,10 @@ public abstract class AbstractWordConverter { continue; } + if (characterRun.isCapitalized() || characterRun.isSmallCaps()) { + text = text.toUpperCase(LocaleUtil.getUserLocale()); + } + if (characterRun.isSpecialCharacter()) { if (text.charAt(0) == SPECCHAR_AUTONUMBERED_FOOTNOTE_REFERENCE && (wordDocument instanceof HWPFDocument)) { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java index 2e67e0ff03..4ef67c44c8 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java @@ -402,6 +402,14 @@ public final class TestWordExtractor { } } + @Test + void testCapitalized() throws Exception { + try (WordExtractor wExt = openExtractor("capitalized.doc")) { + String text = wExt.getText().trim(); + assertEquals("The following word is: CAPITALIZED.", text); + } + } + private WordExtractor openExtractor(String fileName) throws IOException { try (InputStream is = docTests.openResourceAsStream(fileName)) { return new WordExtractor(is); diff --git a/test-data/document/capitalized.doc b/test-data/document/capitalized.doc new file mode 100644 index 0000000000000000000000000000000000000000..00f32a2e41e1b6c88832bd5cfb89c41b8541ed69 GIT binary patch literal 26624 zcmeHP3s_BA`(K^T>E=?>J>_&!>0WekNhOgKNpczDRHuth=cJPRlw5NSAbJ{eGhVlQtdFK0ndp*x@ziYi~t@mB)x7XQwueH}crB}P% z-FaA}mb43lh$Q(SlqFJa^b!!apwbG2SV0_hAA~|7s?7lqrNe&_0}XrgNEnf264I!c zgC~&?II|FB2+;?0CH~X=r)^8$mM+r%?jX%nA?95Pd3XN1AcX$!a{rhR3gtg4JBm{U zj*B7_rNwEK8A{^#pUKuDqJnr5Fmk?C`8nAc@=GBfC6zx?m5}`~tZ%i}`;shDMlXc4 zm&GcCFhGA5B!;h%$lz-=LXJVj1Db>kg7izM-|7O*d<+y1l;4jTtr1G!kwm*~17(kr zRKKY*n0^ik8Q=%2K5A`Ldx`$!Aiuqx_G#p&ZJ_M5)qPEz>fe{_eXISB+CbT(c%sHz zMp-YrJ&xsgVH5>QU*5_KRgcO)2|VCX(*|BGLE`wsK$Uw8;{ZcVYkewB<%@Iw??=im zWr;dp=%*Bv6wj2T{8MR4QuRBMRJrz&8jqChs6M5q{8QL1Z91G^#&4fD;iK&EbX4;Rc#_`RDh7Zs9jG0MB@;09}9{0H66@J$iNL zo9)pR|277cltXrFohK?Gje-*-+)b7l1t6-F)^5&9GC*blmGQAO>M13Ydd`3Ux3!vf z^bcVGpHL-CiB)2VM9++Pb9Tl>XPt}$mM%aqF@dF@$Y=J-fU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