mirror of https://github.com/apache/poi.git
POI-60341: handle missing sdtpr in an sdtbody
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1768048 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5f2951ebc6
commit
14645fe5a8
|
@ -1,18 +1,18 @@
|
|||
/* ====================================================================
|
||||
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.
|
||||
/* ====================================================================
|
||||
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;
|
||||
|
||||
|
@ -33,18 +33,22 @@ public abstract class AbstractXWPFSDT implements ISDTContents {
|
|||
private final IBody part;
|
||||
|
||||
public AbstractXWPFSDT(CTSdtPr pr, IBody part) {
|
||||
|
||||
CTString[] aliases = pr.getAliasArray();
|
||||
if (aliases != null && aliases.length > 0) {
|
||||
title = aliases[0].getVal();
|
||||
} else {
|
||||
if (pr == null) {
|
||||
title = "";
|
||||
}
|
||||
CTString[] tags = pr.getTagArray();
|
||||
if (tags != null && tags.length > 0) {
|
||||
tag = tags[0].getVal();
|
||||
} else {
|
||||
tag = "";
|
||||
} else {
|
||||
CTString[] aliases = pr.getAliasArray();
|
||||
if (aliases != null && aliases.length > 0) {
|
||||
title = aliases[0].getVal();
|
||||
} else {
|
||||
title = "";
|
||||
}
|
||||
CTString[] tags = pr.getTagArray();
|
||||
if (tags != null && tags.length > 0) {
|
||||
tag = tags[0].getVal();
|
||||
} else {
|
||||
tag = "";
|
||||
}
|
||||
}
|
||||
this.part = part;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.apache.poi.xwpf.usermodel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -131,6 +132,15 @@ public final class TestXWPFSDT extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void test60341() throws IOException {
|
||||
//handle sdtbody without an sdtpr
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug60341.docx");
|
||||
List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
|
||||
assertEquals(1, sdts.size());
|
||||
assertEquals("", sdts.get(0).getTag());
|
||||
assertEquals("", sdts.get(0).getTitle());
|
||||
}
|
||||
|
||||
private List<AbstractXWPFSDT> extractAllSDTs(XWPFDocument doc) {
|
||||
|
||||
List<AbstractXWPFSDT> sdts = new ArrayList<AbstractXWPFSDT>();
|
||||
|
|
Loading…
Reference in New Issue