forked from apache/poi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from airslate-oss/MSP-610-add-graphic-usermodels
[MSP-610] added graphic usermodels
- Loading branch information
Showing
36 changed files
with
2,108 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-778 Bytes
(99%)
...l-full/src/main/xmlschema/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip
Binary file not shown.
43 changes: 43 additions & 0 deletions
43
poi-ooxml-full/src/main/xmlschema/org/apache/poi/schemas/office-word-2010-wps.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<xsd:schema elementFormDefault="qualified" | ||
targetNamespace="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" | ||
xmlns="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" | ||
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" | ||
xmlns:w12="http://schemas.openxmlformats.org/wordprocessingml/2006/main" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
<xsd:import schemaLocation="dml-main.xsd" namespace="http://schemas.openxmlformats.org/drawingml/2006/main"/> | ||
<xsd:import schemaLocation="shared-relationshipReference.xsd" | ||
namespace="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/> | ||
<xsd:complexType name="CT_TextboxInfo"> | ||
<xsd:sequence> | ||
<xsd:element ref="w12:txbxContent" minOccurs="0" maxOccurs="1"/> | ||
<xsd:element name="extLst" type="a:CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/> | ||
</xsd:sequence> | ||
<xsd:attribute name="id" type="xsd:unsignedShort" use="optional" default="0"/> | ||
</xsd:complexType> | ||
<xsd:complexType name="CT_LinkedTextboxInformation"> | ||
<xsd:sequence> | ||
<xsd:element name="extLst" type="a:CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/> | ||
</xsd:sequence> | ||
<xsd:attribute name="id" type="xsd:unsignedShort" use="required"/> | ||
<xsd:attribute name="seq" type="xsd:unsignedShort" use="required"/> | ||
</xsd:complexType> | ||
<xsd:complexType name="CT_WordprocessingShape"> | ||
<xsd:sequence minOccurs="1" maxOccurs="1"> | ||
<xsd:element name="cNvPr" type="a:CT_NonVisualDrawingProps" minOccurs="0" maxOccurs="1"/> | ||
<xsd:choice minOccurs="1" maxOccurs="1"> | ||
<xsd:element name="cNvSpPr" type="a:CT_NonVisualDrawingShapeProps" minOccurs="1" maxOccurs="1"/> | ||
<xsd:element name="cNvCnPr" type="a:CT_NonVisualConnectorProperties" minOccurs="1" maxOccurs="1"/> | ||
</xsd:choice> | ||
<xsd:element name="spPr" type="a:CT_ShapeProperties" minOccurs="1" maxOccurs="1"/> | ||
<xsd:element name="style" type="a:CT_ShapeStyle" minOccurs="0" maxOccurs="1"/> | ||
<xsd:element name="extLst" type="a:CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/> | ||
<xsd:choice minOccurs="0" maxOccurs="1"> | ||
<xsd:element name="txbx" type="CT_TextboxInfo" minOccurs="1" maxOccurs="1"/> | ||
<xsd:element name="linkedTxbx" type="CT_LinkedTextboxInformation" minOccurs="1" maxOccurs="1"/> | ||
</xsd:choice> | ||
<xsd:element name="bodyPr" type="a:CT_TextBodyProperties" minOccurs="1" maxOccurs="1"/> | ||
</xsd:sequence> | ||
<xsd:attribute name="normalEastAsianFlow" type="xsd:boolean" use="optional" default="false"/> | ||
</xsd:complexType> | ||
<xsd:element name="wsp" type="CT_WordprocessingShape"/> | ||
</xsd:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ public enum BodyType { | |
FOOTER, | ||
FOOTNOTE, | ||
TABLECELL, | ||
COMMENT | ||
COMMENT, | ||
TEXTBOXCONTENT, | ||
} |
8 changes: 8 additions & 0 deletions
8
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/IDrawing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.apache.poi.xwpf.usermodel; | ||
|
||
import java.util.List; | ||
|
||
public interface IDrawing { | ||
XWPFRun getParent(); | ||
List<XWPFTextBoxContent> getTextBoxContents(); | ||
} |
6 changes: 6 additions & 0 deletions
6
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/IDrawingContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.apache.poi.xwpf.usermodel; | ||
|
||
public interface IDrawingContent { | ||
XWPFDrawing getParent(); | ||
XWPFGraphicalObject getGraphicalObject(); | ||
} |
53 changes: 53 additions & 0 deletions
53
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAnchor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* ==================================================================== | ||
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.xwpf.usermodel; | ||
|
||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject; | ||
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor; | ||
|
||
public class XWPFAnchor implements IDrawingContent { | ||
private final CTAnchor ctAnchor; | ||
private final XWPFDrawing parent; | ||
private XWPFGraphicalObject graphic; | ||
|
||
public XWPFAnchor(CTAnchor ctAnchor, XWPFDrawing parent) { | ||
this.ctAnchor = ctAnchor; | ||
this.parent = parent; | ||
if (ctAnchor.getGraphic() != null) { | ||
this.graphic = new XWPFGraphicalObject(ctAnchor.getGraphic(), this); | ||
} | ||
} | ||
|
||
public XWPFGraphicalObject createGraphicalObject() { | ||
CTGraphicalObject ctGraphicalObject = ctAnchor.addNewGraphic(); | ||
XWPFGraphicalObject graphicalObject = new XWPFGraphicalObject(ctGraphicalObject, this); | ||
graphic = graphicalObject; | ||
return graphicalObject; | ||
} | ||
|
||
public CTAnchor getCTAnchor() { | ||
return ctAnchor; | ||
} | ||
|
||
public XWPFDrawing getParent() { | ||
return parent; | ||
} | ||
|
||
public XWPFGraphicalObject getGraphicalObject() { | ||
return graphic; | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDrawing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* ==================================================================== | ||
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.xwpf.usermodel; | ||
|
||
import org.apache.xmlbeans.XmlCursor; | ||
import org.apache.xmlbeans.XmlObject; | ||
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor; | ||
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing; | ||
import org.w3c.dom.NodeList; | ||
import org.w3c.dom.Text; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class XWPFDrawing implements IDrawing { | ||
private final CTDrawing ctDrawing; | ||
private final XWPFRun parent; | ||
private final List<IDrawingContent> drawingContents = new ArrayList<>(); | ||
|
||
public XWPFDrawing(CTDrawing ctDrawing, XWPFRun parent) { | ||
this.ctDrawing = ctDrawing; | ||
this.parent = parent; | ||
|
||
try (XmlCursor cursor = ctDrawing.newCursor()) { | ||
cursor.selectPath("./*"); | ||
while (cursor.toNextSelection()) { | ||
XmlObject child = cursor.getObject(); | ||
if (child instanceof CTAnchor) { | ||
drawingContents.add(new XWPFAnchor((CTAnchor) child, this)); | ||
} else if (child instanceof CTInline) { | ||
drawingContents.add(new XWPFInline((CTInline) child, this)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public XWPFAnchor createAnchor() { | ||
CTAnchor ctAnchor = ctDrawing.addNewAnchor(); | ||
XWPFAnchor anchor = new XWPFAnchor(ctAnchor, this); | ||
drawingContents.add(anchor); | ||
return anchor; | ||
} | ||
|
||
public XWPFInline createInline() { | ||
CTInline ctInline = ctDrawing.addNewInline(); | ||
XWPFInline inline = new XWPFInline(ctInline, this); | ||
drawingContents.add(inline); | ||
return inline; | ||
} | ||
|
||
public CTDrawing getCtDrawing() { | ||
return ctDrawing; | ||
} | ||
|
||
public XWPFRun getParent() { | ||
return parent; | ||
} | ||
|
||
public List<IDrawingContent> getDrawingContents() { | ||
return drawingContents; | ||
} | ||
|
||
public List<XWPFGraphicalObject> getGraphics() { | ||
List<XWPFGraphicalObject> graphics = new ArrayList<>(); | ||
for (IDrawingContent iDrawingContent : drawingContents) { | ||
XWPFGraphicalObject graphic = iDrawingContent.getGraphicalObject(); | ||
if (graphic == null) { | ||
continue; | ||
} | ||
graphics.add(graphic); | ||
} | ||
return graphics; | ||
} | ||
|
||
public List<XWPFGraphicalObjectData> getGraphicData() { | ||
List<XWPFGraphicalObjectData> graphicalObjectData = new ArrayList<>(); | ||
for (XWPFGraphicalObject graphic : getGraphics()) { | ||
XWPFGraphicalObjectData graphicData = graphic.getGraphicalObjectData(); | ||
if (graphicData == null) { | ||
continue; | ||
} | ||
graphicalObjectData.add(graphicData); | ||
} | ||
return graphicalObjectData; | ||
} | ||
|
||
public List<XWPFPicture> getPictures() { | ||
List<XWPFPicture> pictures = new ArrayList<>(); | ||
for (XWPFGraphicalObjectData graphicDatum : getGraphicData()) { | ||
XWPFPicture picture = graphicDatum.getPicture(); | ||
if (picture == null) { | ||
continue; | ||
} | ||
pictures.add(picture); | ||
} | ||
return pictures; | ||
} | ||
|
||
public List<XWPFWordprocessingShape> getWordprocessingShapes() { | ||
List<XWPFWordprocessingShape> wordprocessingShapes = new ArrayList<>(); | ||
for (XWPFGraphicalObjectData graphicDatum : getGraphicData()) { | ||
XWPFWordprocessingShape wordprocessingShape = graphicDatum.getWordprocessingShape(); | ||
if (wordprocessingShape == null) { | ||
continue; | ||
} | ||
wordprocessingShapes.add(wordprocessingShape); | ||
} | ||
return wordprocessingShapes; | ||
} | ||
|
||
public List<XWPFTextBoxContent> getTextBoxContents() { | ||
List<XWPFTextBoxContent> textBoxContents = new ArrayList<>(); | ||
for (XWPFWordprocessingShape wordprocessingShape : getWordprocessingShapes()) { | ||
XWPFTextBoxContent textBoxContent = wordprocessingShape.getTextBoxContent(); | ||
if (textBoxContent == null) { | ||
continue; | ||
} | ||
textBoxContents.add(textBoxContent); | ||
} | ||
return textBoxContents; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder text = new StringBuilder(); | ||
XmlObject[] ts = ctDrawing.selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t"); | ||
for (XmlObject t : ts) { | ||
NodeList kids = t.getDomNode().getChildNodes(); | ||
for (int n = 0; n < kids.getLength(); n++) { | ||
if (kids.item(n) instanceof Text) { | ||
if (text.length() > 0) { | ||
text.append("\n"); | ||
} | ||
text.append(kids.item(n).getNodeValue()); | ||
} | ||
} | ||
} | ||
return text.toString(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFGraphicalObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* ==================================================================== | ||
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.xwpf.usermodel; | ||
|
||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject; | ||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData; | ||
|
||
public class XWPFGraphicalObject { | ||
private final CTGraphicalObject ctGraphicalObject; | ||
private final IDrawingContent parent; | ||
private XWPFGraphicalObjectData graphicalObjectData; | ||
|
||
public XWPFGraphicalObject(CTGraphicalObject ctGraphicalObject, IDrawingContent parent) { | ||
this.ctGraphicalObject = ctGraphicalObject; | ||
this.parent = parent; | ||
if (ctGraphicalObject.getGraphicData() != null) { | ||
this.graphicalObjectData = new XWPFGraphicalObjectData(ctGraphicalObject.getGraphicData(), this); | ||
} | ||
} | ||
|
||
public XWPFGraphicalObjectData createGraphicalObjectData() { | ||
CTGraphicalObjectData ctGraphicalObjectData = ctGraphicalObject.addNewGraphicData(); | ||
XWPFGraphicalObjectData graphicalObjectData = new XWPFGraphicalObjectData(ctGraphicalObjectData, this); | ||
this.graphicalObjectData = graphicalObjectData; | ||
return graphicalObjectData; | ||
} | ||
|
||
public CTGraphicalObject getCTGraphicalObject() { | ||
return ctGraphicalObject; | ||
} | ||
|
||
public IDrawingContent getParent() { | ||
return parent; | ||
} | ||
|
||
public XWPFGraphicalObjectData getGraphicalObjectData() { | ||
return graphicalObjectData; | ||
} | ||
} |
Oops, something went wrong.