All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.docx4j.finders.SectPrFinder Maven / Gradle / Ivy

Go to download

docx4j is a library which helps you to work with the Office Open XML file format as used in docx documents, pptx presentations, and xlsx spreadsheets.

There is a newer version: 6.1.2
Show newest version
package org.docx4j.finders;

import java.util.ArrayList;
import java.util.List;

import org.docx4j.TraversalUtil.CallbackImpl;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.wml.P;
import org.docx4j.wml.SectPr;

public class SectPrFinder extends CallbackImpl {
	
	private List sectPrList = new ArrayList(); 
	
	public SectPrFinder(MainDocumentPart mdp) {
		// Handle the body level one
		if (mdp.getJaxbElement().getBody().getSectPr()!=null) {
			sectPrList.add(mdp.getJaxbElement().getBody().getSectPr());
		}
	}
	
	private SectPrFinder(){};
	
	/**
	 * @return the sectPrList
	 */
	public List getSectPrList() {
		return sectPrList;
	}

	@Override
	public List apply(Object o) {
		
		if (o instanceof P) {
			P p = (P)o;
			if ( p.getPPr()!=null && p.getPPr().getSectPr()!=null ) {
				sectPrList.add(p.getPPr().getSectPr());
			}
		}
		return null;
	}
	
	public boolean shouldTraverse(Object o) {
		return !(o instanceof P); 
	}
	
}