protected String getMceIgnorable(Body body) { List<Object> content = body.getContent(); // To avoid the traversing a large docx, // we'll try to use a hack here. // The idea is to force JAXB to include // namespace declarations for w14 and w15, by // using them in an innocuous manner. // It works by adding the following to the first // paragraph encountered: // <w:p w14:textId="fdcbd571" w14:paraId="fdcbd571" > // <w:pPr> // <w15:collapsed w:val="false"/> // </w:pPr> // // If this turns out to cause problems, it could be // made configurable in docx4j.properties if (content.size() == 0) { return null; } P p = null; for (Object o : content) { if (o instanceof P) { p = (P) o; break; } } if (p == null) { // No top level paragraph, so // do the work of traversing the document log.debug("traversing for w14, w15"); IgnorablePrefixFinder finder = new IgnorablePrefixFinder(); if (body.getSectPr() != null && body.getSectPr().getFootnoteColumns() != null) { finder.needW15 = true; } new TraversalUtil(content, finder); String mceIgnorableVal = ""; if (finder.needW14) { mceIgnorableVal = "w14"; } if (finder.needW15) { mceIgnorableVal += " w15"; } return mceIgnorableVal; } else { // The quick hack // For W14, we'll check/set paraId, textId if (p.getParaId() == null) { // Values MUST be greater than 0 and less than 0x80000000 // So let's String uuid = java.util.UUID.randomUUID().toString(); // That's 32 digits, but 8'll do nicely /* * 8 can create a number too large - using 7 * Bob Fleischman - July 24, 2014 */ uuid = uuid.replace("-", "").substring(0, 7); p.setParaId(uuid); p.setTextId(uuid); } // For W15, collapse /* * Bob Fleischman - commented this out to generat docs without the namespace issue PPr ppr = p.getPPr(); if (ppr==null) { ppr = Context.getWmlObjectFactory().createPPr(); p.setPPr(ppr); } if (ppr.getCollapsed()==null) { BooleanDefaultTrue notCollapsed = new BooleanDefaultTrue(); notCollapsed.setVal(Boolean.FALSE); ppr.setCollapsed(notCollapsed); } */ } return "w14 w15"; }