-/* ====================================================================
- 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 javax.xml.namespace.QName;
+/* ====================================================================\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
+\r
+import javax.xml.namespace.QName;\r
\r
import org.apache.xmlbeans.XmlCursor;\r
import org.apache.xmlbeans.XmlCursor.TokenType;\r
*/\r
public class XWPFSDTContentCell implements ISDTContent {\r
\r
- //A full implementation would grab the icells
- //that a content cell can contain. This would require
- //significant changes, including changing the notion that the
- //parent of a cell can be not just a row, but an sdt.
- //For now we are just grabbing the text out of the text tokentypes.
-
+ //A full implementation would grab the icells\r
+ //that a content cell can contain. This would require\r
+ //significant changes, including changing the notion that the\r
+ //parent of a cell can be not just a row, but an sdt.\r
+ //For now we are just grabbing the text out of the text tokentypes.\r
+\r
//private List<ICell> cells = new ArrayList<ICell>().\r
\r
private String text = "";\r
public XWPFSDTContentCell(CTSdtContentCell sdtContentCell,\r
XWPFTableRow xwpfTableRow, IBody part) {\r
super();\r
+ //sdtContentCell is allowed to be null: minOccurs="0" maxOccurs="1"\r
+ if (sdtContentCell == null) {\r
+ return;\r
+ }\r
StringBuilder sb = new StringBuilder();\r
XmlCursor cursor = sdtContentCell.newCursor();\r
-
+\r
//keep track of the following,\r
//and add "\n" only before the start of a body\r
//element if it is not the first body element.\r
//index of cell in row\r
int tcCnt = 0;\r
//count of body objects\r
- int iBodyCnt = 0;
- int depth = 1;
+ int iBodyCnt = 0;\r
+ int depth = 1;\r
\r
while (cursor.hasNextToken() && depth > 0) {\r
TokenType t = cursor.toNextToken();\r
sb.append(cursor.getTextValue());\r
} else if (isStartToken(cursor, "tr")) {\r
tcCnt = 0;\r
- iBodyCnt = 0;
- } else if (isStartToken(cursor, "tc")) {
- if (tcCnt++ > 0) {
- sb.append("\t");
- }
- iBodyCnt = 0;
- } else if (isStartToken(cursor, "p") ||
- isStartToken(cursor, "tbl") ||
- isStartToken(cursor, "sdt")) {
- if (iBodyCnt > 0) {
- sb.append("\n");
+ iBodyCnt = 0;\r
+ } else if (isStartToken(cursor, "tc")) {\r
+ if (tcCnt++ > 0) {\r
+ sb.append("\t");\r
+ }\r
+ iBodyCnt = 0;\r
+ } else if (isStartToken(cursor, "p") ||\r
+ isStartToken(cursor, "tbl") ||\r
+ isStartToken(cursor, "sdt")) {\r
+ if (iBodyCnt > 0) {\r
+ sb.append("\n");\r
}\r
iBodyCnt++;\r
}\r
depth--;\r
}\r
}\r
- text = sb.toString();
+ text = sb.toString();\r
cursor.dispose();\r
}\r
\r
return false;\r
}\r
QName qName = cursor.getName();\r
- if (qName != null && qName.getLocalPart() != null &&
- qName.getLocalPart().equals(string)) {
- return true;
- }
- return false;
+ if (qName != null && qName.getLocalPart() != null &&\r
+ qName.getLocalPart().equals(string)) {\r
+ return true;\r
+ }\r
+ return false;\r
}\r
\r
\r