// Path: src/main/java/org/apache/poi/xdgf/exceptions/XDGFException.java
// public class XDGFException {
// 
// 	/**
// 	 * Creates an error message to be thrown
// 	 */
// 	public static POIXMLException error(String message, Object o) {
// 		return new POIXMLException(o.toString() + ": " + message);
// 	}
// 	
// 	public static POIXMLException error(String message, Object o, Throwable t) {
// 		return new POIXMLException(o.toString() + ": " + message, t);
// 	}
// 	
// 	//
// 	// Use these to wrap error messages coming up so that we have at least
// 	// some idea where the error was located
// 	//
// 
// 	public static POIXMLException wrap(POIXMLDocumentPart part, POIXMLException e) {
// 		return new POIXMLException(part.getPackagePart().getPartName().toString() + ": " + e.getMessage(),
// 								  e.getCause() == null ? e : e.getCause());
// 	}
// 	
// 	public static POIXMLException wrap(String where, POIXMLException e) {
// 		return new POIXMLException(where + ": " + e.getMessage(),
// 								  e.getCause() == null ? e : e.getCause());
// 	}
// }
// 
// Path: src/main/java/org/apache/poi/xdgf/xml/XDGFXMLDocumentPart.java
// public class XDGFXMLDocumentPart extends POIXMLDocumentPart {
// 
// 	protected XDGFDocument _document;
// 	
// 	public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel, XDGFDocument document) {
// 		super(part, rel);
// 		_document = document;
// 	}
// 	
// }


import com.microsoft.schemas.office.visio.x2012.main.PageType;
import com.microsoft.schemas.office.visio.x2012.main.PagesDocument;
import com.microsoft.schemas.office.visio.x2012.main.PagesType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.util.Internal;
import org.apache.poi.xdgf.exceptions.XDGFException;
import org.apache.poi.xdgf.xml.XDGFXMLDocumentPart;
import org.apache.xmlbeans.XmlException;
	@Override
	protected void onDocumentRead() {
		try {
			try {
				_pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
			} catch (XmlException | IOException e) {
				throw new POIXMLException(e);
			}
			
			// this iteration is ordered by page number
			for (PageType pageSettings: _pagesObject.getPageArray()) {
				
				String relId = pageSettings.getRel().getId();
				
				POIXMLDocumentPart pageContentsPart = getRelationById(relId);
				if (pageContentsPart == null)
					throw new POIXMLException("PageSettings relationship for " + relId + " not found");
				
				if (!(pageContentsPart instanceof XDGFPageContents))
					throw new POIXMLException("Unexpected pages relationship for " + relId + ": " + pageContentsPart);
				
				XDGFPageContents contents = (XDGFPageContents)pageContentsPart;
				XDGFPage page = new XDGFPage(pageSettings, contents, _document, this);
				
				contents.onDocumentRead();
				
				_pages.add(page);
			}
			
		} catch (POIXMLException e) {
// Path: src/main/java/org/apache/poi/xdgf/exceptions/XDGFException.java
// public class XDGFException {
// 
// 	/**
// 	 * Creates an error message to be thrown
// 	 */
// 	public static POIXMLException error(String message, Object o) {
// 		return new POIXMLException(o.toString() + ": " + message);
// 	}
// 	
// 	public static POIXMLException error(String message, Object o, Throwable t) {
// 		return new POIXMLException(o.toString() + ": " + message, t);
// 	}
// 	
// 	//
// 	// Use these to wrap error messages coming up so that we have at least
// 	// some idea where the error was located
// 	//
// 
// 	public static POIXMLException wrap(POIXMLDocumentPart part, POIXMLException e) {
// 		return new POIXMLException(part.getPackagePart().getPartName().toString() + ": " + e.getMessage(),
// 								  e.getCause() == null ? e : e.getCause());
// 	}
// 	
// 	public static POIXMLException wrap(String where, POIXMLException e) {
// 		return new POIXMLException(where + ": " + e.getMessage(),
// 								  e.getCause() == null ? e : e.getCause());
// 	}
// }
// 
// Path: src/main/java/org/apache/poi/xdgf/xml/XDGFXMLDocumentPart.java
// public class XDGFXMLDocumentPart extends POIXMLDocumentPart {
// 
// 	protected XDGFDocument _document;
// 	
// 	public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel, XDGFDocument document) {
// 		super(part, rel);
// 		_document = document;
// 	}
// 	
// }


// Path: src/main/java/org/apache/poi/xdgf/usermodel/XDGFPages.java
import com.microsoft.schemas.office.visio.x2012.main.PageType;
import com.microsoft.schemas.office.visio.x2012.main.PagesDocument;
import com.microsoft.schemas.office.visio.x2012.main.PagesType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.util.Internal;
import org.apache.poi.xdgf.exceptions.XDGFException;
import org.apache.poi.xdgf.xml.XDGFXMLDocumentPart;
import org.apache.xmlbeans.XmlException;

	@Override
	protected void onDocumentRead() {
		try {
			try {
				_pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
			} catch (XmlException | IOException e) {
				throw new POIXMLException(e);
			}
			
			// this iteration is ordered by page number
			for (PageType pageSettings: _pagesObject.getPageArray()) {
				
				String relId = pageSettings.getRel().getId();
				
				POIXMLDocumentPart pageContentsPart = getRelationById(relId);
				if (pageContentsPart == null)
					throw new POIXMLException("PageSettings relationship for " + relId + " not found");
				
				if (!(pageContentsPart instanceof XDGFPageContents))
					throw new POIXMLException("Unexpected pages relationship for " + relId + ": " + pageContentsPart);
				
				XDGFPageContents contents = (XDGFPageContents)pageContentsPart;
				XDGFPage page = new XDGFPage(pageSettings, contents, _document, this);
				
				contents.onDocumentRead();
				
				_pages.add(page);
			}
			
		} catch (POIXMLException e) {
			throw XDGFException.wrap(this, e);