You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by vi...@apache.org on 2015/10/19 07:52:37 UTC

svn commit: r1709354 [1/3] - in /poi/trunk/src: ooxml/java/org/apache/poi/xdgf/ ooxml/java/org/apache/poi/xdgf/exceptions/ ooxml/java/org/apache/poi/xdgf/geom/ ooxml/java/org/apache/poi/xdgf/usermodel/ ooxml/java/org/apache/poi/xdgf/usermodel/section/ ...

Author: virtuald
Date: Mon Oct 19 05:52:35 2015
New Revision: 1709354

URL: http://svn.apache.org/viewvc?rev=1709354&view=rev
Log:
Import poi-visio codebase

Added:
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/exceptions/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/exceptions/XDGFException.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/Dimension2dDouble.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineCollector.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFBaseContents.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFConnection.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMaster.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasterContents.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPage.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageContents.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPages.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFStyleSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFText.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XmlVisioDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CharacterSection.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GenericSection.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/XDGFSection.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/ArcTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/Ellipse.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/GeometryRow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/GeometryRowFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/InfiniteLine.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/LineTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/MoveTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/NURBSTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelCubBezTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelEllipticalArcTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelLineTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelMoveTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDataAcceptor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDebuggerRenderer.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeRenderer.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitorAcceptor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisiting.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisitingThisBranch.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/HierarchyPrinter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/ObjectFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/Util.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/VsdxToPng.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/xml/
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/xml/XDGFXMLDocumentPart.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/
    poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/usermodel/
    poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/usermodel/section/
    poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/usermodel/section/CombinedIteratorTest.java
    poi/trunk/src/resources/devtools/unpack_ooxml.sh   (with props)

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/exceptions/XDGFException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/exceptions/XDGFException.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/exceptions/XDGFException.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/exceptions/XDGFException.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.exceptions;
+
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
+
+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());
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/Dimension2dDouble.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/Dimension2dDouble.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/Dimension2dDouble.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/Dimension2dDouble.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,73 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.geom;
+
+import java.awt.geom.Dimension2D;
+
+public class Dimension2dDouble extends Dimension2D {
+
+	double width;
+	double height;
+	
+	public Dimension2dDouble() {
+		width = 0d;
+		height = 0d;
+	}
+	
+	public Dimension2dDouble(double width, double height) {
+		this.width = width;
+		this.height = height;
+	}
+	
+	@Override
+	public double getWidth() {
+		return width;
+	}
+
+	@Override
+	public double getHeight() {
+		return height;
+	}
+
+	@Override
+	public void setSize(double width, double height) {
+		this.width = width;
+		this.height = height;
+	}
+	
+	@Override
+	public boolean equals(Object obj) {
+		if (obj instanceof Dimension2dDouble) {
+			Dimension2dDouble other = (Dimension2dDouble)obj;
+			return width == other.width && height == other.height;
+		}
+		
+		return false;
+	}
+	
+	@Override
+	public int hashCode() {
+		double sum = width + height;
+        return (int)Math.ceil(sum * (sum + 1)/2 + width);
+	}
+	
+	@Override
+	public String toString() {
+		return "Dimension2dDouble[" + width + ", " + height + "]";
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineCollector.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineCollector.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineCollector.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineCollector.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,79 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.geom;
+
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+
+import org.apache.poi.xdgf.usermodel.XDGFShape;
+import org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot;
+import org.apache.poi.xdgf.usermodel.section.geometry.SplineStart;
+
+import com.graphbuilder.curve.ControlPath;
+import com.graphbuilder.curve.ShapeMultiPath;
+import com.graphbuilder.curve.ValueVector;
+import com.graphbuilder.geom.PointFactory;
+
+public class SplineCollector {
+
+	SplineStart _start;
+	ArrayList<SplineKnot> _knots = new ArrayList<>();
+
+	public SplineCollector(SplineStart start) {
+		_start = start;
+	}
+	
+	public void addKnot(SplineKnot knot) {
+		if (!knot.getDel())
+			_knots.add(knot);
+	}
+	
+	public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
+		// ok, we have the start, and all knots... do something with this
+		
+		Point2D last = path.getCurrentPoint();
+		
+		// create a control path and knots
+		ControlPath controlPath = new ControlPath();
+		ValueVector knots = new ValueVector(_knots.size() + 3);
+		
+		double firstKnot = _start.getB();
+		double lastKnot = _start.getC();
+		int degree = _start.getD();
+		
+		// first/second knot
+		knots.add(firstKnot);
+		knots.add(_start.getA());
+		
+		// first/second control point
+		controlPath.addPoint(PointFactory.create(last.getX(), last.getY()));
+		controlPath.addPoint(PointFactory.create(_start.getX(), _start.getY()));
+		
+		// middle knots/control points
+		for (SplineKnot knot: _knots) {
+			knots.add(knot.getA());
+			controlPath.addPoint(PointFactory.create(knot.getX(), knot.getY()));
+		}
+		
+		// last knot
+		knots.add(lastKnot);
+		
+		ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, null, degree);
+		path.append(shape, true);
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,68 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.geom;
+
+import com.graphbuilder.curve.ControlPath;
+import com.graphbuilder.curve.GroupIterator;
+import com.graphbuilder.curve.NURBSpline;
+import com.graphbuilder.curve.ShapeMultiPath;
+import com.graphbuilder.curve.ValueVector;
+
+public class SplineRenderer {
+
+	public static ShapeMultiPath createNurbsSpline(ControlPath controlPoints,
+			 									   ValueVector knots,
+			 									   ValueVector weights,
+			 									   int degree) {
+		
+		double firstKnot = knots.get(0);
+		double lastKnot = knots.get(knots.size()-1);
+		
+		// scale knots to [0, 1] based on first/last knots
+		for (int i = 0; i < knots.size(); i++) {
+			knots.set((knots.get(i) - firstKnot)/lastKnot, i);
+		}
+		
+		// if we don't have enough knots, duplicate the last knot until we do
+		for (int i = knots.size(); i < controlPoints.numPoints() + degree + 1; i++) {
+			knots.add(1);
+		}
+		
+		GroupIterator gi = new GroupIterator("0:n-1", controlPoints.numPoints());
+		
+		NURBSpline spline = new NURBSpline(controlPoints, gi);
+		
+		spline.setDegree(degree);
+		spline.setKnotVectorType(NURBSpline.NON_UNIFORM);
+		spline.setKnotVector(knots);
+		
+		if (weights == null) {
+			spline.setUseWeightVector(false);
+		} else {
+			spline.setWeightVector(weights);
+		}
+		
+		// now that this is done, add it to the path
+		ShapeMultiPath shape = new ShapeMultiPath();
+		shape.setFlatness(0.01);
+		
+		spline.appendTo(shape);
+		return shape;
+	}
+	
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFBaseContents.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFBaseContents.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFBaseContents.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFBaseContents.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,159 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.usermodel.shape.ShapeRenderer;
+import org.apache.poi.xdgf.usermodel.shape.ShapeVisitor;
+import org.apache.poi.xdgf.usermodel.shape.exceptions.StopVisiting;
+import org.apache.poi.xdgf.xml.XDGFXMLDocumentPart;
+
+import com.microsoft.schemas.office.visio.x2012.main.ConnectType;
+import com.microsoft.schemas.office.visio.x2012.main.PageContentsType;
+import com.microsoft.schemas.office.visio.x2012.main.ShapeSheetType;
+
+/**
+ * Container of shapes for a page in a visio document
+ */
+public class XDGFBaseContents extends XDGFXMLDocumentPart {
+
+	protected PageContentsType _pageContents;
+	
+	// shapes without parents
+	protected List<XDGFShape> _toplevelShapes = new ArrayList<>();
+	protected Map<Long, XDGFShape> _shapes = new HashMap<>();
+	protected List<XDGFConnection> _connections = new ArrayList<>();
+	
+	public XDGFBaseContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
+		super(part, rel, document);
+	}
+	
+	@Internal
+	public PageContentsType getXmlObject() {
+		return _pageContents;
+	}
+	
+	
+	@Override
+	protected void onDocumentRead() {
+		
+		if (_pageContents.isSetShapes()) {
+			for (ShapeSheetType shapeSheet: _pageContents.getShapes().getShapeArray()) {
+				XDGFShape shape = new XDGFShape(shapeSheet, this, _document);
+				_toplevelShapes.add(shape);
+				addToShapeIndex(shape);
+			}
+		}
+		
+		if (_pageContents.isSetConnects()) {
+			for (ConnectType connect: _pageContents.getConnects().getConnectArray()) {
+				
+				XDGFShape from = _shapes.get(connect.getFromSheet());
+				XDGFShape to = _shapes.get(connect.getToSheet());
+				
+				if (from == null)
+					throw new POIXMLException(this.toString() + "; Connect; Invalid from id: " + connect.getFromSheet());
+				
+				if (to == null)
+					throw new POIXMLException(this.toString() + "; Connect; Invalid to id: " + connect.getToSheet());
+				
+				_connections.add(new XDGFConnection(connect, from, to));
+			}
+		}
+	}
+	
+	protected void addToShapeIndex(XDGFShape shape) {
+		_shapes.put(shape.getID(), shape);
+		
+		List<XDGFShape> shapes = shape.getShapes();
+		if (shapes == null)
+			return;
+		
+		for (XDGFShape subshape: shapes)
+			addToShapeIndex(subshape);
+	}
+	
+	//
+	// API
+	//
+	
+	/**
+	 * 
+	 * @param graphics
+	 */
+	public void draw(Graphics2D graphics) {
+		visitShapes(new ShapeRenderer(graphics));
+	}
+	
+	
+	public XDGFShape getShapeById(long id) {
+		return _shapes.get(id);
+	}
+	
+	public Map<Long, XDGFShape> getShapesMap() {
+		return Collections.unmodifiableMap(_shapes);
+	}
+	
+	public Collection<XDGFShape> getShapes() {
+		return _shapes.values();
+	}
+	
+	public List<XDGFShape> getTopLevelShapes() {
+		return Collections.unmodifiableList(_toplevelShapes);
+	}
+	
+	// get connections
+	public List<XDGFConnection> getConnections() {
+		return Collections.unmodifiableList(_connections);
+	}
+	
+	@Override
+	public String toString() {
+		return getPackagePart().getPartName().toString();
+	}
+	
+
+	/**
+	 * Provides iteration over the shapes using the visitor pattern, and provides
+	 * an easy way to convert shape coordinates into global coordinates
+	 */
+	public void visitShapes(ShapeVisitor visitor) {
+		try {
+			for (XDGFShape shape: _toplevelShapes) {
+				shape.visitShapes(visitor, new AffineTransform(), 0);
+			}
+		} catch (StopVisiting e) {
+			// intentionally empty
+		} catch (POIXMLException e) {
+			throw XDGFException.wrap(this, e);
+		}
+	}
+	
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFCell.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFCell.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFCell.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,150 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.util.Map;
+
+import org.apache.poi.POIXMLException;
+import org.apache.poi.util.Internal;
+
+import com.microsoft.schemas.office.visio.x2012.main.CellType;
+
+/**
+ * There are a lot of different cell types. Cell is really just an attribute
+ * of the thing that it's attached to. Will probably refactor this once I
+ * figure out a better way to use them
+ * 
+ * The various attributes of a Cell are constrained, and are better defined
+ * in the XSD 1.1 visio schema 
+ */
+public class XDGFCell {
+
+	public static Boolean maybeGetBoolean(Map<String, XDGFCell> cells, String name) {
+		XDGFCell cell = cells.get(name);
+		if (cell == null)
+			return null;
+			
+		if (cell.getValue().equals("0"))
+			return false;
+		if (cell.getValue().equals("1"))
+			return true;
+		
+		throw new POIXMLException("Invalid boolean value for '" + cell.getName() + "'");
+	}
+	
+	public static Double maybeGetDouble(Map<String, XDGFCell> cells, String name) {
+		XDGFCell cell = cells.get(name);
+		if (cell != null)
+			return parseDoubleValue(cell._cell);
+		return null;
+	}
+	
+	public static Integer maybeGetInteger(Map<String, XDGFCell> cells, String name) {
+		XDGFCell cell = cells.get(name);
+		if (cell != null)
+			return parseIntegerValue(cell._cell);
+		return null;
+	}
+	
+	public static String maybeGetString(Map<String, XDGFCell> cells, String name) {
+		XDGFCell cell = cells.get(name);
+		if (cell != null) {
+			String v = cell._cell.getV();
+			if (v.equals("Themed"))
+				return null;
+			return v;
+		}
+		return null;
+	}
+	
+	public static Double parseDoubleValue(CellType cell) {
+		try {
+			return Double.parseDouble(cell.getV());
+		} catch (NumberFormatException e) {
+			if (cell.getV().equals("Themed"))
+				return null;
+			throw new POIXMLException("Invalid float value for '" + cell.getN() + "': " + e);
+		}
+	}
+	
+	public static Integer parseIntegerValue(CellType cell) {
+		try {
+			return Integer.parseInt(cell.getV());
+		} catch (NumberFormatException e) {
+			if (cell.getV().equals("Themed"))
+				return null;
+			throw new POIXMLException("Invalid integer value for '" + cell.getN() + "': " + e);
+		}
+	}
+	
+	// returns a length, converts it to inches?
+	public static Double parseVLength(CellType cell) {
+		try {
+			return Double.parseDouble(cell.getV());
+		} catch (NumberFormatException e) {
+			if (cell.getV().equals("Themed"))
+				return null;
+			throw new POIXMLException("Invalid float value for '" + cell.getN() + "': " + e);
+		}
+	}
+	
+	
+	CellType _cell;
+	
+	public XDGFCell(CellType cell) {
+		_cell = cell;
+	}
+	
+	@Internal
+	CellType getXmlObject() {
+		return _cell;
+	}
+	
+	/**
+	 * Represents the name of the ShapeSheet cell.
+	 */
+	public String getName() {
+		return _cell.getN();
+	}
+	
+	/**
+	 * Represents the value of the cell.
+	 */
+	public String getValue() {
+		return _cell.getV();
+	}
+	
+	/**
+	 * Represents the element’s formula. This attribute can contain one of the following strings:
+	 * - ‘(some formula)’ if the formula exists locally
+	 * - No Formula if the formula is locally deleted or blocked
+	 * - Inh if the formula is inherited.
+	 */
+	public String getFormula() {
+		return _cell.getF();
+	}
+	
+	/*
+	 * Indicates that the formula evaluates to an error. The value of E is the
+	 * current value (an error message string); the value of the V attribute is
+	 * the last valid value.
+	 */
+	public String getError() {
+		return _cell.getE();
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFConnection.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFConnection.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFConnection.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFConnection.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,134 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import com.microsoft.schemas.office.visio.x2012.main.ConnectType;
+
+public class XDGFConnection {
+
+	// comments on frompart/topart taken from pkgVisio 
+	
+	// https://msdn.microsoft.com/en-us/library/ms367611(v=office.12).aspx
+	
+    //    The following constants declared by the Microsoft Office Visio type 
+    //       library show return values for the FromPart property.
+    // Constant                  Value  
+    // visConnectFromError         -1
+    // visFromNone                 0
+    // visLeftEdge                 1
+    // visCenterEdge               2
+    // visRightEdge                3
+    // visBottomEdge               4
+    // visMiddleEdge               5
+    // visTopEdge                  6
+    // visBeginX                   7
+    // visBeginY                   8
+    // visBegin                    9
+    // visEndX                     10
+    // visEndY                     11
+    // visEnd                      12
+    // visFromAngle                13
+    // visFromPin                  14
+    // visControlPoint             100 + zero-based row index (for example, visControlPoint = 100 if the control point is in row 0; visControlPoint = 101 if the control point is in row 1)
+	
+	public static final int visConnectFromError        = -1;
+	public static final int visFromNone                = 0;
+	public static final int visLeftEdge                = 1;
+	public static final int visCenterEdge              = 2;
+	public static final int visRightEdge               = 3;
+	public static final int visBottomEdge              = 4;
+	public static final int visMiddleEdge              = 5;
+	public static final int visTopEdge                 = 6;
+	public static final int visBeginX                  = 7;
+	public static final int visBeginY                  = 8;
+	public static final int visBegin                   = 9;
+	public static final int visEndX                    = 10;
+	public static final int visEndY                    = 11;
+	public static final int visEnd                     = 12;
+	public static final int visFromAngle               = 13;
+	public static final int visFromPin                 = 14;
+	
+	
+	//  The ToPart property identifies the part of a shape to which another 
+	//    shape is glued, such as its begin point or endpoint, one of its edges, 
+	//    or a connection point. The following constants declared by the Visio type library in member VisToParts show possible return values for the ToPart property.
+	// Constant               Value  
+	// visConnectToError       -1
+	// visToNone               0
+	// visGuideX               1
+	// visGuideY               2
+	// visWholeShape           3
+	// visGuideIntersect       4
+	// visToAngle              7
+	// visConnectionPoint      100 + row index of connection point
+	
+	public static final int visConnectToError          = -1;
+	public static final int visToNone                  = 0;
+	public static final int visGuideX                  = 1;
+	public static final int visGuideY                  = 2;
+	public static final int visWholeShape              = 3;
+	public static final int visGuideIntersect          = 4;
+	public static final int visToAngle                 = 7;
+	
+	private ConnectType _connect;
+	private XDGFShape _from;
+	private XDGFShape _to;
+	
+	
+	public XDGFConnection(ConnectType connect, XDGFShape from, XDGFShape to) {
+		_connect = connect;
+		_from = from;
+		_to = to;
+	}
+	
+	public XDGFShape getFromShape() {
+		return _from;
+	}
+	
+	public XDGFCell getFromCell() {
+		return _from.getCell(_connect.getFromCell());
+	}
+	
+	public String getFromCellName() {
+		return _connect.getFromCell();
+	}
+	
+	public XDGFShape getToShape() {
+		return _to;
+	}
+	
+	public String getToCellName() {
+		return _connect.getToCell();
+	}
+	
+	// see constants above
+	public Integer getFromPart() {
+		if (_connect.isSetFromPart())
+			return _connect.getFromPart();
+		else
+			return null;
+	}
+	
+	// see constants above
+	public Integer getToPart() {
+		if (_connect.isSetToPart())
+			return _connect.getToPart();
+		else
+			return null;
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFDocument.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFDocument.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFDocument.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,116 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.poi.POIXMLException;
+import org.apache.poi.util.Internal;
+
+import com.microsoft.schemas.office.visio.x2012.main.DocumentSettingsType;
+import com.microsoft.schemas.office.visio.x2012.main.StyleSheetType;
+import com.microsoft.schemas.office.visio.x2012.main.VisioDocumentType;
+
+/**
+ * Represents the root document: /visio/document.xml
+ */
+public class XDGFDocument {
+
+	protected VisioDocumentType _document;
+
+	Map<Long, XDGFStyleSheet> _styleSheets = new HashMap<>();
+	
+	// defaults
+	long _defaultFillStyle = 0;
+	long _defaultGuideStyle = 0;
+	long _defaultLineStyle = 0;
+	long _defaultTextStyle = 0;
+	
+	
+	public XDGFDocument(VisioDocumentType document) {
+		
+		_document = document;
+		
+		if (!_document.isSetDocumentSettings())
+			throw new POIXMLException("Document settings not found");
+		
+		DocumentSettingsType docSettings = _document.getDocumentSettings();
+		
+		if (docSettings.isSetDefaultFillStyle())
+			_defaultFillStyle = docSettings.getDefaultFillStyle();
+		
+		if (docSettings.isSetDefaultGuideStyle())
+			_defaultGuideStyle = docSettings.getDefaultGuideStyle();
+		
+		if (docSettings.isSetDefaultLineStyle())
+			_defaultLineStyle = docSettings.getDefaultLineStyle();
+		
+		if (docSettings.isSetDefaultTextStyle())
+			_defaultTextStyle = docSettings.getDefaultTextStyle();
+		
+		if (_document.isSetStyleSheets()) {
+			
+			for (StyleSheetType styleSheet: _document.getStyleSheets().getStyleSheetArray()) { 
+				_styleSheets.put(styleSheet.getID(), new XDGFStyleSheet(styleSheet, this));
+			}
+		}
+	}
+	
+
+	@Internal
+	public VisioDocumentType getXmlObject() {
+		return _document;
+	}
+	
+
+	public XDGFStyleSheet getStyleById(long id) {
+		return _styleSheets.get(id);
+	}
+
+
+	public XDGFStyleSheet getDefaultFillStyle() {
+		XDGFStyleSheet style = getStyleById(_defaultFillStyle);
+		if (style == null)
+			throw new POIXMLException("No default fill style found!");
+		return style;
+	}
+	
+	public XDGFStyleSheet getDefaultGuideStyle() {
+		XDGFStyleSheet style = getStyleById(_defaultGuideStyle);
+		if (style == null)
+			throw new POIXMLException("No default guide style found!");
+		return style;
+	}
+	
+	public XDGFStyleSheet getDefaultLineStyle() {
+		XDGFStyleSheet style = getStyleById(_defaultLineStyle);
+		if (style == null)
+			throw new POIXMLException("No default line style found!");
+		return style;
+	}
+	
+	public XDGFStyleSheet getDefaultTextStyle() {
+		XDGFStyleSheet style = getStyleById(_defaultTextStyle);
+		if (style == null)
+			throw new POIXMLException("No default text style found!");
+		return style;
+	}
+
+	
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFFactory.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFFactory.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFFactory.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,75 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.POIXMLFactory;
+import org.apache.poi.POIXMLRelation;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
+public class XDGFFactory extends POIXMLFactory {
+
+    private static final POILogger logger = POILogFactory.getLogger(XDGFFactory.class);
+    
+	private XDGFDocument _document;
+	
+	public XDGFFactory(XDGFDocument document){
+		_document = document;
+    }
+	
+	@Override
+	public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent,
+			PackageRelationship rel, PackagePart part) {
+		POIXMLRelation descriptor = XDGFRelation.getInstance(rel.getRelationshipType());
+        if(descriptor == null || descriptor.getRelationClass() == null){
+            logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
+            return new POIXMLDocumentPart(part, rel);
+        }
+
+        try {
+            Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
+            try {
+                Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(POIXMLDocumentPart.class, PackagePart.class, PackageRelationship.class, XDGFDocument.class);
+                return constructor.newInstance(parent, part, rel, _document);
+            } catch (NoSuchMethodException e) {
+                Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class, XDGFDocument.class);
+                return constructor.newInstance(part, rel, _document);
+            }
+        } catch (Exception e){
+            throw new POIXMLException(e);
+        }
+	}
+
+	@Override
+	public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor) {
+        try {
+            Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
+            return constructor.newInstance();
+        } catch (Exception e){
+            throw new POIXMLException(e);
+        }
+	}
+
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMaster.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMaster.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMaster.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMaster.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,68 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import org.apache.poi.util.Internal;
+
+import com.microsoft.schemas.office.visio.x2012.main.MasterType;
+
+/**
+ * Provides the API to work with an underlying master
+ */
+public class XDGFMaster {
+
+	private MasterType _master;
+	private XDGFMasterContents _content;
+	XDGFSheet _pageSheet = null;
+	
+	public XDGFMaster(MasterType master, XDGFMasterContents content, XDGFDocument document) {
+		_master = master;
+		_content = content;
+		content.setMaster(this);
+		
+		if (master.isSetPageSheet())
+			_pageSheet = new XDGFPageSheet(master.getPageSheet(), document);
+	}
+	
+	@Internal
+	MasterType getXmlObject() {
+		return _master;
+	}
+	
+	@Override
+	public String toString() {
+		return "<Master ID=\"" + getID() + "\" " + _content + ">";
+	}
+	
+	public long getID() {
+		return _master.getID();
+	}
+	
+	public String getName() {
+		return _master.getName();
+	}
+	
+	public XDGFMasterContents getContent() {
+		return _content;
+	}
+	
+	public XDGFSheet getPageSheet() {
+		return _pageSheet;
+	}
+	
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasterContents.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasterContents.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasterContents.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasterContents.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,64 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.io.IOException;
+
+import org.apache.poi.POIXMLException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.xdgf.exceptions.XDGFException;
+import org.apache.xmlbeans.XmlException;
+
+import com.microsoft.schemas.office.visio.x2012.main.MasterContentsDocument;
+
+public class XDGFMasterContents extends XDGFBaseContents {
+
+	private XDGFMaster _master;
+	
+	public XDGFMasterContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
+		super(part, rel, document);
+	}
+	
+	@Override
+	protected void onDocumentRead() {
+
+		try {
+		
+			try {
+				_pageContents = MasterContentsDocument.Factory.parse(getPackagePart().getInputStream()).getMasterContents();
+			} catch (XmlException | IOException e) {
+				throw new POIXMLException(e);
+			}
+			
+			super.onDocumentRead();
+			
+		} catch (POIXMLException e) {
+			throw XDGFException.wrap(this, e);
+		}
+	}
+
+	public XDGFMaster getMaster() {
+		return _master;
+	}
+
+	protected void setMaster(XDGFMaster master) {
+		_master = master;
+	}
+
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,99 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+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;
+
+import com.microsoft.schemas.office.visio.x2012.main.MasterType;
+import com.microsoft.schemas.office.visio.x2012.main.MastersDocument;
+import com.microsoft.schemas.office.visio.x2012.main.MastersType;
+
+public class XDGFMasters extends XDGFXMLDocumentPart {
+
+	MastersType _mastersObject;
+	
+	// key: id of master
+	Map<Long, XDGFMaster> _masters = new HashMap<>();
+	
+	public XDGFMasters(PackagePart part, PackageRelationship rel, XDGFDocument document) {
+		super(part, rel, document);
+	}
+	
+	@Internal
+	MastersType getXmlObject() {
+		return _mastersObject;
+	}
+	
+	@Override
+	protected void onDocumentRead() {
+		try {
+			try {
+				_mastersObject = MastersDocument.Factory.parse(getPackagePart().getInputStream()).getMasters();
+			} catch (XmlException | IOException e) {
+				throw new POIXMLException(e);
+			}
+			
+			Map<String, MasterType> masterSettings = new HashMap<>();
+			for (MasterType master: _mastersObject.getMasterArray()) {
+				masterSettings.put(master.getRel().getId(), master);
+			}
+			
+			// create the masters
+			for (POIXMLDocumentPart part: getRelations()) {
+				
+				String relId = part.getPackageRelationship().getId();
+				MasterType settings = masterSettings.get(relId);
+				
+				if (settings == null)
+					throw new POIXMLException("Master relationship for " + relId + " not found");
+				
+				if (!(part instanceof XDGFMasterContents))
+					throw new POIXMLException("Unexpected masters relationship for " + relId + ": " + part);
+				
+				XDGFMasterContents contents = (XDGFMasterContents)part;
+				contents.onDocumentRead();
+				
+				XDGFMaster master = new XDGFMaster(settings, contents, _document);
+				_masters.put(master.getID(), master);
+			}
+		} catch (POIXMLException e) {
+			throw XDGFException.wrap(this, e);
+		}
+	}
+	
+	public Collection<XDGFMaster> getMastersList() {
+		return Collections.unmodifiableCollection(_masters.values());
+	}
+	
+	public XDGFMaster getMasterById(long masterId) {
+		return _masters.get(masterId);
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPage.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPage.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPage.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,113 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import org.apache.poi.POIXMLException;
+import org.apache.poi.util.Internal;
+import org.apache.poi.xdgf.geom.Dimension2dDouble;
+
+import com.microsoft.schemas.office.visio.x2012.main.PageType;
+
+/**
+ * Provides the API to work with an underlying page
+ */
+public class XDGFPage {
+
+	PageType _page;
+	XDGFPageContents _content;
+	XDGFPages _pages;
+	XDGFSheet _pageSheet = null;
+	
+	public XDGFPage(PageType page, XDGFPageContents content, XDGFDocument document, XDGFPages pages) {
+		_page = page;
+		_content = content;
+		_pages = pages;
+		content.setPage(this);
+		
+		if (page.isSetPageSheet())
+			_pageSheet = new XDGFPageSheet(page.getPageSheet(), document);
+	}
+	
+	@Internal
+	PageType getXmlObject() {
+		return _page;
+	}
+	
+	public long getID() {
+		return _page.getID();
+	}
+	
+	public String getName() {
+		return _page.getName();
+	}
+	
+	public XDGFPageContents getContent() {
+		return _content;
+	}
+	
+	public XDGFSheet getPageSheet() {
+		return _pageSheet;
+	}
+	
+	public long getPageNumber() {
+		return _pages.getPageList().indexOf(this) + 1;
+	}
+	
+	// height/width of page
+	public Dimension2dDouble getPageSize() {
+		XDGFCell w = _pageSheet.getCell("PageWidth");
+		XDGFCell h = _pageSheet.getCell("PageHeight");
+		
+		if (w == null || h == null)
+			throw new POIXMLException("Cannot determine page size");
+		
+		return new Dimension2dDouble(Double.parseDouble(w.getValue()),
+									 Double.parseDouble(h.getValue()));
+	}
+	
+	// origin of coordinate system
+	public Point2D.Double getPageOffset() {
+		XDGFCell xoffcell = _pageSheet.getCell("XRulerOrigin");
+		XDGFCell yoffcell = _pageSheet.getCell("YRulerOrigin");
+		
+		double xoffset = 0;
+		double yoffset = 0;
+		
+		if (xoffcell != null)
+			xoffset = Double.parseDouble(xoffcell.getValue());
+		
+		if (xoffcell != null)
+			yoffset = Double.parseDouble(yoffcell.getValue());
+		
+		return new Point2D.Double(xoffset, yoffset);
+	}
+	
+	// bounding box of page
+	public Rectangle2D getBoundingBox() {
+		Dimension2dDouble sz = getPageSize();
+		Point2D.Double offset = getPageOffset();
+		
+		return new Rectangle2D.Double(-offset.getX(),
+									  -offset.getY(),
+									  sz.getWidth(),
+									  sz.getHeight());
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageContents.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageContents.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageContents.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageContents.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,83 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+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.xdgf.exceptions.XDGFException;
+import org.apache.xmlbeans.XmlException;
+
+import com.microsoft.schemas.office.visio.x2012.main.PageContentsDocument;
+
+public class XDGFPageContents extends XDGFBaseContents {
+
+	Map<Long, XDGFMaster> _masters = new HashMap<>();
+	XDGFPage _page;
+	
+	public XDGFPageContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
+		super(part, rel, document);
+	}
+
+	@Override
+	protected void onDocumentRead() {
+		try {
+			try {
+				_pageContents = PageContentsDocument.Factory.parse(getPackagePart().getInputStream()).getPageContents();
+			} catch (XmlException | IOException e) {
+				throw new POIXMLException(e);
+			}
+			
+			for (POIXMLDocumentPart part: getRelations()) {
+				if (!(part instanceof XDGFMasterContents))
+					continue;
+					//throw new POIXMLException("Unexpected page relation: " + part);
+				
+				XDGFMaster master = ((XDGFMasterContents)part).getMaster();
+				_masters.put(master.getID(), master);
+			}
+			
+			super.onDocumentRead();
+			
+			for (XDGFShape shape: _shapes.values()) {
+				if (shape.isTopmost())
+					shape.setupMaster(this, null);
+			}
+		
+		} catch (POIXMLException e) {
+			throw XDGFException.wrap(this, e);
+		}
+	}
+
+	public XDGFPage getPage() {
+		return _page;
+	}
+	
+	protected void setPage(XDGFPage page) {
+		_page = page;
+	}
+	
+	public XDGFMaster getMasterById(long id) {
+		return _masters.get(id);
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageSheet.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageSheet.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPageSheet.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,36 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import com.microsoft.schemas.office.visio.x2012.main.PageSheetType;
+
+public class XDGFPageSheet extends XDGFSheet {
+
+	PageSheetType _pageSheet;
+	
+	public XDGFPageSheet(PageSheetType sheet, XDGFDocument document) {
+		super(sheet, document);
+		_pageSheet = sheet;
+	}
+
+	@Override
+	PageSheetType getXmlObject() {
+		return _pageSheet;
+	}
+
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPages.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPages.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPages.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFPages.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,95 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+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;
+
+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;
+
+
+/**
+ * Contains a list of Page objects (not page content!)
+ */
+public class XDGFPages extends XDGFXMLDocumentPart {
+
+	PagesType _pagesObject;
+	
+	// ordered by page number
+	List<XDGFPage> _pages = new ArrayList<>();
+	
+	public XDGFPages(PackagePart part, PackageRelationship rel, XDGFDocument document) {
+		super(part, rel, document);
+	}
+	
+	@Internal
+	PagesType getXmlObject() {
+		return _pagesObject;
+	}
+	
+	@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);
+		}
+	}
+	
+	// ordered by page number
+	public List<XDGFPage> getPageList() {
+		return Collections.unmodifiableList(_pages);
+	}
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java?rev=1709354&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java Mon Oct 19 05:52:35 2015
@@ -0,0 +1,99 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.apache.poi.xdgf.usermodel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.poi.POIXMLRelation;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.poi.xdgf.xml.XDGFXMLDocumentPart;
+
+public class XDGFRelation extends POIXMLRelation {
+	
+	/**
+     * A map to lookup POIXMLRelation by its relation type
+     */
+    protected static final Map<String, XDGFRelation> _table = new HashMap<String, XDGFRelation>();
+
+    public static final XDGFRelation DOCUMENT = new XDGFRelation(
+            "application/vnd.ms-visio.drawing.main+xml",
+            "http://schemas.microsoft.com/visio/2010/relationships/document",
+            "/visio/document.xml",
+            null
+    );
+    
+    public static final XDGFRelation MASTERS = new XDGFRelation(
+            "application/vnd.ms-visio.masters+xml",
+            "http://schemas.microsoft.com/visio/2010/relationships/masters",
+            "/visio/masters/masters.xml",
+            XDGFMasters.class
+    );
+    
+    public static final XDGFRelation MASTER = new XDGFRelation(
+            "application/vnd.ms-visio.master+xml",
+            "http://schemas.microsoft.com/visio/2010/relationships/master",
+            "/visio/masters/master#.xml",
+            XDGFMasterContents.class
+    );
+    
+    public static final XDGFRelation IMAGES = new XDGFRelation(
+            null,
+            PackageRelationshipTypes.IMAGE_PART,
+            null,
+            null // XSSFPictureData.class
+        );
+    
+    public static final XDGFRelation PAGES = new XDGFRelation(
+            "application/vnd.ms-visio.pages+xml",
+            "http://schemas.microsoft.com/visio/2010/relationships/pages",
+            "/visio/pages/pages.xml",
+            XDGFPages.class
+    );
+    
+    public static final XDGFRelation PAGE = new XDGFRelation(
+            "application/vnd.ms-visio.page+xml",
+            "http://schemas.microsoft.com/visio/2010/relationships/page",
+            "/visio/pages/page#.xml",
+            XDGFPageContents.class
+    );
+    
+    public static final XDGFRelation WINDOW = new XDGFRelation(
+            "application/vnd.ms-visio.windows+xml",
+            "http://schemas.microsoft.com/visio/2010/relationships/windows",
+            "/visio/windows.xml",
+            null
+    );
+    
+    private XDGFRelation(String type, String rel, String defaultName, Class<? extends XDGFXMLDocumentPart> cls) {
+        super(type, rel, defaultName, cls);
+
+        if (cls != null && !_table.containsKey(rel)) _table.put(rel, this);
+    }
+
+    /**
+     * Get POIXMLRelation by relation type
+     *
+     * @param rel relation type, for example,
+     *            <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
+     * @return registered POIXMLRelation or null if not found
+     */
+    public static XDGFRelation getInstance(String rel) {
+        return _table.get(rel);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org