org.docx4j.utils.CompoundTraversalUtilVisitorCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docx4j Show documentation
Show all versions of docx4j Show documentation
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.
The newest version!
package org.docx4j.utils;
import java.util.HashMap;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
/**
* Use this if there is more than one object type (eg Tables and Paragraphs)
* you are interested in doing something with during the traversal.
*
* @author alberto
*/
public class CompoundTraversalUtilVisitorCallback extends
AbstractTraversalUtilVisitorCallback {
Map> visitorMap = null;
public CompoundTraversalUtilVisitorCallback(
List visitorList) {
visitorMap = setupTraversalVistorMap(visitorList);
}
protected Map> setupTraversalVistorMap(
List visitorList) {
Map> ret = new HashMap>();
Class visitorClass = null;
List classVisitorList = null;
for (TraversalUtilVisitor visitor : visitorList) {
visitorClass = findClassParameter(visitor.getClass());
if (visitorClass == null) {
throw new IllegalArgumentException(
"Can't identify the parameter class of the visitor "
+ visitor.getClass().getName());
}
classVisitorList = ret.get(visitorClass);
if (classVisitorList == null) {
classVisitorList = new LinkedList();
ret.put(visitorClass, classVisitorList);
}
classVisitorList.add(visitor);
}
return ret;
}
@Override
protected List