From 00a2a870974837c9e36a58cd613f46fe422c9844 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 26 Oct 2019 05:26:36 +0000 Subject: [PATCH] XWPF: Insert newlines between multiple paragraphs in comments. Closes PR #161 on GitHub git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1868978 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xwpf/usermodel/XWPFComment.java | 4 ++ .../poi/xwpf/usermodel/TestXWPFComment.java | 37 ++++++++++++++++++ test-data/document/comment.docx | Bin 0 -> 4926 bytes 3 files changed, 41 insertions(+) create mode 100644 src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java create mode 100644 test-data/document/comment.docx diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java index 72de790840..0df8111117 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java @@ -35,6 +35,10 @@ public class XWPFComment { author = comment.getAuthor(); for (CTP ctp : comment.getPArray()) { + if(text.length() > 0) { + text.append("\n"); + } + XWPFParagraph p = new XWPFParagraph(ctp, document); text.append(p.getText()); } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java new file mode 100644 index 0000000000..886d15c0a9 --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java @@ -0,0 +1,37 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + +public class TestXWPFComment { + @Test + public void testText() throws IOException { + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("comment.docx")) { + assertEquals(1, doc.getComments().length); + XWPFComment comment = doc.getComments()[0]; + assertEquals("Unbekannter Autor", comment.getAuthor()); + assertEquals("0", comment.getId()); + assertEquals("This is the first line\n\nThis is the second line", comment.getText()); + } + } +} diff --git a/test-data/document/comment.docx b/test-data/document/comment.docx new file mode 100644 index 0000000000000000000000000000000000000000..dc4bebbf06a1bd6a75257cecb94fddb0dddc64ea GIT binary patch literal 4926 zcma)AWmuGJw535>WN0agfsqaY0R=>Q=$4Z1mTpA4ksL}wx*J3pU}$NCp+S%m6eOhX z;5i=Ad(V09p6C0X`7!JL=3VdFd+q%x$)TbVBVl1-Aw}MnQ$)HJIEe2CPNp`_9PC&3 zvUmkKR59F;-E)A%=Q$ftXwT3gy|_L7H_YJF?a#wQm^_wcm-AxS%}U|fuvU-#J*rXL zp^I#AMnr@dwAfP2k#nS()5;w#!a-v=#?h=P8apnV`h>N3J~-EiNG2w;SNb z$%x@Ak0QqtE8ZkrcRh=9uN(o~p*>YzsrO>#9$&NtwCWp@fcd(Q-7YP8?Y;Y3VKyWB z%MpXQ&}qtpEG0QitWU$pccu~h6+uBlQuc&ccccF@5yxT2-2M#mVLew`pW? z-l3N!FL~kv)WMYS#ML^_G!DE4(kxTDU>7bPV`YyK4>fQFi^@O^rQ{(eDz|CbQ zO1$xn8(G=0+>gtn zasbX!$v29adzhpbE)wzX#w`sm<6Kb-$Ue5ajf{kJfw=yi+MCy@HMVy$z2Y`X=GM8 zW_WvYT=^#~c=^uZIcnpU6h%M`#D(!-gYImfrpEs2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