Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   *  Copyright 2009, Plutext Pty Ltd.
   *  This file is part of docx4j.
      docx4j is licensed 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 
     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.docx4j.model.structure;
 import java.util.List;
Forgetting about sub documents, a docx is made up of a number of sections, each with their own section properties (which define page dimensions, margins etc). So it is natural to think of a document in terms of sections. But since in Open XML, all sectPr elements - except the document level one - are hidden in paragraphs, our JAXB object model doesn't expose this structure. This class does that.

 public class DocumentModel {
 	protected static Logger log = LoggerFactory.getLogger(DocumentModel.class);		
 	private List<SectionWrappersections
 	// At present, objects (eg w:p, w:tbl) don't know which
 	// section they are in, and nor does a SectionWrapper
 	// know which objects are in it.  
 	// Should we add objects to a SectionWrapper? 
 	// PDF via XSL FO pre-processes the document to wrap
 	// section containers, but that is only done in the PDF stuff.
 	public DocumentModel(WordprocessingMLPackage wordMLPackage) {
 		this. = wordMLPackage;

If you have added/deleted sections from your WordprocessingMLPackage, you'll need to call this method in order for the changes to be reflected in the DocumentModel.
 	public void refresh() {
 		HeaderFooterPolicy previousHF = null;
 		BooleanDefaultTrue evenAndOddHeaders = null;
 		for (Object o : doc.getBody().getContent() ) {
 			if (o instanceof org.docx4j.wml.P) {
 				if (((org.docx4j.wml.P)o).getPPr() != null ) {
 					org.docx4j.wml.PPr ppr = ((org.docx4j.wml.P)o).getPPr();
 					if (ppr.getSectPr()!=null) {
 								ppr.getSectPr(), previousHFrelsevenAndOddHeaders); 
						previousHF = sw.getHeaderFooterPolicy();
						.debug"registered sectpr");						
		SectPr sectPr = doc.getBody().getSectPr();	
		// There might not be a sectPr, but we still add a SectionWrapper to
		// represent the body.
		SectionWrapper sw = new SectionWrapper(sectPrpreviousHFrelsevenAndOddHeaders);

the sections
		return ;
New to GrepCode? Check out our FAQ X