diff --git a/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/MainDocumentPart.java b/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/MainDocumentPart.java index 388cd7e53..a86486e59 100644 --- a/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/MainDocumentPart.java +++ b/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/MainDocumentPart.java @@ -156,14 +156,31 @@ public List getContent() { return this.getJaxbElement().getContent(); } - private PropertyResolver propertyResolver; + private PropertyResolver propertyResolver; + + /** + * get the PropertyResolver, creating if necessary + */ public PropertyResolver getPropertyResolver() { - if (propertyResolver==null) { + return getPropertyResolver(true); + } + + /** + * get the PropertyResolver + * + * @param create whether to create if null + * @return + * @since 11.5.2 + */ + public PropertyResolver getPropertyResolver(boolean create) { + // create=false is only really necessary where a StackOverflow is a possibility; + // eg getPropertyResolver() being invoked from PropertyResolver's constructor. + if (create && propertyResolver == null) { try { - propertyResolver = new PropertyResolver( (WordprocessingMLPackage)this.pack); + propertyResolver = new PropertyResolver((WordprocessingMLPackage) this.pack); } catch (Docx4JException e) { e.printStackTrace(); - } + } } return propertyResolver; } diff --git a/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/NumberingDefinitionsPart.java b/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/NumberingDefinitionsPart.java index 56b05a939..0d96ef404 100644 --- a/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/NumberingDefinitionsPart.java +++ b/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/NumberingDefinitionsPart.java @@ -410,19 +410,40 @@ private Ind getIndFromLvl(Lvl lvl) { // use any w:ind in it (or TODO styles it is based on) if (lvl.getPStyle()!=null) { + log.debug("override level has linked style: " + lvl.getPStyle().getVal() ); + // Get the style -// StyleDefinitionsPart stylesPart = ((WordprocessingMLPackage)this.getPackage()). -// getMainDocumentPart().getStyleDefinitionsPart(); + org.docx4j.wml.Style style = null; PropertyResolver propertyResolver - = ((WordprocessingMLPackage)this.getPackage()).getMainDocumentPart().getPropertyResolver(); - - log.debug("override level has linked style: " + lvl.getPStyle().getVal() ); - - org.docx4j.wml.Style style = propertyResolver.getStyle( lvl.getPStyle().getVal() ); + = ((WordprocessingMLPackage)this.getPackage()).getMainDocumentPart().getPropertyResolver(false); + /* avoids invoking it during init: + at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getPropertyResolver(MainDocumentPart.java:163) + at org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart.getIndFromLvl(NumberingDefinitionsPart.java:417) + at org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart.getInd(NumberingDefinitionsPart.java:401) + at org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart.getInd(NumberingDefinitionsPart.java:365) + at org.docx4j.model.styles.StyleUtil.apply(StyleUtil.java:1941) + at org.docx4j.model.styles.StyleUtil.apply(StyleUtil.java:1896) + at org.docx4j.model.PropertyResolver.applyPPr(PropertyResolver.java:842) + at org.docx4j.model.PropertyResolver.addNormalToResolvedStylePPrComponent(PropertyResolver.java:234) + at org.docx4j.model.PropertyResolver.init(PropertyResolver.java:212) + at org.docx4j.model.PropertyResolver.(PropertyResolver.java:145) + at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getPropertyResolver(MainDocumentPart.java:163) + */ + if (propertyResolver==null) { + // less efficient + StyleDefinitionsPart stylesPart = ((WordprocessingMLPackage)this.getPackage()).getMainDocumentPart().getStyleDefinitionsPart(); + style = stylesPart.getStyleById(lvl.getPStyle().getVal()); + + } else { + // use propertyResolver + style = propertyResolver.getStyle( lvl.getPStyle().getVal() ); + } if (style==null) { - log.error("Couldn't find style " + lvl.getPStyle().getVal()); + log.warn("Couldn't find style " + lvl.getPStyle().getVal()); return null; + } else { + log.debug(".. found it"); } // If the style has a w:ind, return it.