-/* ====================================================================
- 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.
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
==================================================================== */\r
package org.apache.poi.xwpf.usermodel;\r
\r
private final IBody part;\r
\r
public AbstractXWPFSDT(CTSdtPr pr, IBody part) {\r
-\r
- CTString[] aliases = pr.getAliasArray();\r
- if (aliases != null && aliases.length > 0) {\r
- title = aliases[0].getVal();\r
- } else {\r
+ if (pr == null) {\r
title = "";\r
- }\r
- CTString[] tags = pr.getTagArray();\r
- if (tags != null && tags.length > 0) {\r
- tag = tags[0].getVal();\r
- } else {\r
tag = "";\r
+ } else {\r
+ CTString[] aliases = pr.getAliasArray();\r
+ if (aliases != null && aliases.length > 0) {\r
+ title = aliases[0].getVal();\r
+ } else {\r
+ title = "";\r
+ }\r
+ CTString[] tags = pr.getTagArray();\r
+ if (tags != null && tags.length > 0) {\r
+ tag = tags[0].getVal();\r
+ } else {\r
+ tag = "";\r
+ }\r
}\r
this.part = part;\r
\r
package org.apache.poi.xwpf.usermodel;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
}
}
+ 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>();