requires java.xml;
-
-
exports com.microsoft.schemas.compatibility;
+ exports com.microsoft.schemas.office.drawing.x2008.diagram;
exports com.microsoft.schemas.office.excel;
exports com.microsoft.schemas.office.office;
+ exports com.microsoft.schemas.office.powerpoint;
+ exports com.microsoft.schemas.office.spreadsheetml.x2018.threadedcomments;
+ exports com.microsoft.schemas.office.spreadsheetml.x2020.threadedcomments2;
exports com.microsoft.schemas.office.visio.x2012.main;
exports com.microsoft.schemas.office.word;
+ exports com.microsoft.schemas.office.word.x2021.wordml;
exports com.microsoft.schemas.office.x2006.digsig;
exports com.microsoft.schemas.vml;
exports org.apache.poi.schemas.ooxml.system.ooxml;
exports org.apache.poi.schemas.vmldrawing;
exports org.etsi.uri.x01903.v13;
+ exports org.etsi.uri.x01903.v14;
exports org.openxmlformats.schemas.drawingml.x2006.chart;
+ exports org.openxmlformats.schemas.drawingml.x2006.chartDrawing;
+ exports org.openxmlformats.schemas.drawingml.x2006.diagram;
+ exports org.openxmlformats.schemas.drawingml.x2006.lockedCanvas;
exports org.openxmlformats.schemas.drawingml.x2006.main;
exports org.openxmlformats.schemas.drawingml.x2006.picture;
exports org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing;
exports org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing;
+ exports org.openxmlformats.schemas.officeDocument.x2006.bibliography;
+ exports org.openxmlformats.schemas.officeDocument.x2006.characteristics;
exports org.openxmlformats.schemas.officeDocument.x2006.customProperties;
+ exports org.openxmlformats.schemas.officeDocument.x2006.customXml;
exports org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes;
exports org.openxmlformats.schemas.officeDocument.x2006.extendedProperties;
exports org.openxmlformats.schemas.officeDocument.x2006.math;
exports org.openxmlformats.schemas.officeDocument.x2006.relationships;
exports org.openxmlformats.schemas.officeDocument.x2006.sharedTypes;
exports org.openxmlformats.schemas.presentationml.x2006.main;
+ exports org.openxmlformats.schemas.schemaLibrary.x2006.main;
exports org.openxmlformats.schemas.spreadsheetml.x2006.main;
exports org.openxmlformats.schemas.wordprocessingml.x2006.main;
exports org.openxmlformats.schemas.xpackage.x2006.digitalSignature;
+ exports org.openxmlformats.schemas.xpackage.x2006.relationships;
exports org.w3.x2000.x09.xmldsig;
-}
\ No newline at end of file
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.xslf.usermodel;
import com.microsoft.schemas.office.drawing.x2008.diagram.CTGroupShape;
import javax.xml.namespace.QName;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
/**
public static final String DRAWINGML_DIAGRAM_URI = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
private final XSLFDiagramDrawing _drawing;
- private final XSLFGroupShape _groupShape;
- private final HashMap<String, POIXMLDocumentPart> blipDocumentParts = new HashMap<>();
+ private final XSLFDiagramGroupShape _groupShape;
/* package protected */ XSLFDiagram(CTGraphicalObjectFrame shape, XSLFSheet sheet) {
super(shape, sheet);
_drawing = readDiagramDrawing(shape, sheet);
- _groupShape = initGroupShape(sheet);
+ _groupShape = initGroupShape();
}
private static boolean hasTextContent(CTShape msShapeCt) {
.anyMatch(run -> run.getT() != null && !run.getT().trim().isEmpty());
}
- private static boolean hasBlipEmbed(CTShape msShapeCt) {
- return msShapeCt != null
- && msShapeCt.getSpPr() != null
- && msShapeCt.getSpPr().getBlipFill() != null
- && msShapeCt.getSpPr().getBlipFill().getBlip() != null
- && msShapeCt.getSpPr().getBlipFill().getBlip().getEmbed() != null;
- }
-
private static XSLFDiagramDrawing readDiagramDrawing(CTGraphicalObjectFrame shape, XSLFSheet sheet) {
CTGraphicalObjectData graphicData = shape.getGraphic().getGraphicData();
XmlObject[] children = graphicData.selectChildren(new QName(DRAWINGML_DIAGRAM_URI, "relIds"));
return null;
}
+ /**
+ * Returns the underlying {@link XSLFDiagramDrawing} used to create this diagram.
+ * <p>
+ * NOTE: Modifying this drawing will not update the groupShape returned from {@link #getGroupShape()}.
+ */
+ public XSLFDiagramDrawing getDiagramDrawing() {
+ return _drawing;
+ }
+
+ /**
+ * Returns the diagram represented as a grouped shape.
+ */
+ public XSLFDiagramGroupShape getGroupShape() {
+ return _groupShape;
+ }
+
// If the shape has text, two XSLFShapes are created. One shape element and one textbox element.
- public List<org.openxmlformats.schemas.presentationml.x2006.main.CTShape> convertShape(CTShape msShapeCt) {
+ private List<org.openxmlformats.schemas.presentationml.x2006.main.CTShape> convertShape(CTShape msShapeCt) {
org.openxmlformats.schemas.presentationml.x2006.main.CTShape shapeCt
= org.openxmlformats.schemas.presentationml.x2006.main.CTShape.Factory.newInstance();
return shapes;
}
- private void mapDocumentParts(CTShape msShapeCt) {
- if (hasBlipEmbed(msShapeCt)) {
- String embedId = msShapeCt.getSpPr().getBlipFill().getBlip().getEmbed();
- POIXMLDocumentPart part = _drawing.getRelationById(embedId);
- if (part != null) {
- blipDocumentParts.put(embedId, part);
- }
- }
- }
-
private org.openxmlformats.schemas.presentationml.x2006.main.CTShape convertText(CTShape msShapeCt, CTShapeNonVisual nonVisualCt) {
org.openxmlformats.schemas.presentationml.x2006.main.CTShape textShapeCT
= org.openxmlformats.schemas.presentationml.x2006.main.CTShape.Factory.newInstance();
return textShapeCT;
}
- /**
- * Returns the underlying {@link XSLFDiagramDrawing} used to create this diagram.
- * <p>
- * NOTE: Modifying this drawing will not update the groupShape returned from {@link #getGroupShape()}.
- */
- public XSLFDiagramDrawing getDiagramDrawing() {
- return _drawing;
- }
-
- private XSLFGroupShape initGroupShape(XSLFSheet sheet) {
+ private XSLFDiagramGroupShape initGroupShape() {
XSLFDiagramDrawing drawing = getDiagramDrawing();
if (drawing == null || drawing.getDrawingDocument() == null) {
return null;
if (msGroupShapeCt == null || msGroupShapeCt.getSpList().isEmpty()) {
return null;
}
- return convertMsGroupToGroupShape(msGroupShapeCt, sheet);
- }
-
- /**
- * Returns the diagram represented as a grouped shape.
- */
- public XSLFGroupShape getGroupShape() {
- return _groupShape;
- }
-
- POIXMLDocumentPart getDocumentPart(String blipId) {
- return blipDocumentParts.get(blipId);
+ return convertMsGroupToGroupShape(msGroupShapeCt, drawing);
}
- private XSLFGroupShape convertMsGroupToGroupShape(CTGroupShape msGroupShapeCt, XSLFSheet sheet) {
+ private XSLFDiagramGroupShape convertMsGroupToGroupShape(CTGroupShape msGroupShapeCt, XSLFDiagramDrawing drawing) {
org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape groupShapeCt
= org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape.Factory.newInstance();
for (CTShape msShapeCt : msGroupShapeCt.getSpList()) {
List<org.openxmlformats.schemas.presentationml.x2006.main.CTShape> shapes = convertShape(msShapeCt);
- mapDocumentParts(msShapeCt);
groupShapeCt.getSpList().addAll(shapes);
}
Rectangle2D anchor = super.getAnchor();
Rectangle2D interiorAnchor = new Rectangle2D.Double(0, 0, anchor.getWidth(), anchor.getHeight());
- XSLFGroupShape groupShape = new XSLFGroupShape(groupShapeCt, getSheet());
+ XSLFDiagramGroupShape groupShape = new XSLFDiagramGroupShape(groupShapeCt, getSheet(), drawing);
groupShape.setAnchor(anchor);
groupShape.setInteriorAnchor(interiorAnchor);
groupShape.setRotation(super.getRotation());
return groupShape;
}
+
+ /**
+ * Simple wrapper around XSLFGroupShape to enable accessing underlying diagram relations correctly.
+ * <p>
+ * Diagrams store relationships to media in `drawing#.xml.rels`. These relationships are accessible using
+ * {@link #getRelationById(String)}.
+ */
+ static class XSLFDiagramGroupShape extends XSLFGroupShape {
+
+ private XSLFDiagramDrawing diagramDrawing;
+
+ protected XSLFDiagramGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape shape,
+ XSLFSheet sheet) {
+ super(shape, sheet);
+ }
+
+ private XSLFDiagramGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape shape,
+ XSLFSheet sheet,
+ XSLFDiagramDrawing diagramDrawing) {
+ super(shape, sheet);
+ this.diagramDrawing = diagramDrawing;
+ }
+
+ POIXMLDocumentPart getRelationById(String id) {
+ return diagramDrawing.getRelationById(id);
+ }
+ }
}
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
-import java.util.stream.Collectors;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.util.POIXMLUnits;
private PackagePart getPart() throws InvalidFormatException {
String blipId = blip.getEmbed();
- for (XSLFDiagram diagram : extractDiagrams(sheet.getSlideShow())) {
- POIXMLDocumentPart documentPart = diagram.getDocumentPart(blipId);
+ if (shape.getParent() != null && shape.getParent() instanceof XSLFDiagram.XSLFDiagramGroupShape) {
+ XSLFDiagram.XSLFDiagramGroupShape diagramGroupShape = (XSLFDiagram.XSLFDiagramGroupShape) shape.getParent();
+ POIXMLDocumentPart documentPart = diagramGroupShape.getRelationById(blipId);
if (documentPart != null) {
return documentPart.getPackagePart();
}
private static int getRectVal(Supplier<Boolean> isSet, Supplier<STPercentage> val) {
return isSet.get() ? POIXMLUnits.parsePercent(val.get()) : 0;
}
-
- private static List<XSLFDiagram> extractDiagrams(XMLSlideShow slideShow) {
- return slideShow.getSlides()
- .stream()
- .flatMap(s -> s.getShapes().stream())
- .filter(s -> s instanceof XSLFDiagram)
- .map(s -> (XSLFDiagram) s)
- .collect(Collectors.toList());
- }
}