use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFSheet method removeShape.
/**
* Removes the specified shape from this sheet, if it is present
* (optional operation). If this sheet does not contain the element,
* it is unchanged.
*
* @param xShape shape to be removed from this sheet, if present
* @return <tt>true</tt> if this sheet contained the specified element
* @throws IllegalArgumentException if the type of the specified shape
* is incompatible with this sheet (optional)
*/
public boolean removeShape(XSLFShape xShape) {
XmlObject obj = xShape.getXmlObject();
CTGroupShape spTree = getSpTree();
if (obj instanceof CTShape) {
spTree.getSpList().remove(obj);
} else if (obj instanceof CTGroupShape) {
spTree.getGrpSpList().remove(obj);
} else if (obj instanceof CTConnector) {
spTree.getCxnSpList().remove(obj);
} else if (obj instanceof CTGraphicalObjectFrame) {
spTree.getGraphicFrameList().remove(obj);
} else if (obj instanceof CTPicture) {
XSLFPictureShape ps = (XSLFPictureShape) xShape;
removePictureRelation(ps);
spTree.getPicList().remove(obj);
} else {
throw new IllegalArgumentException("Unsupported shape: " + xShape);
}
return getShapes().remove(xShape);
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFSheet method buildShapes.
protected static List<XSLFShape> buildShapes(CTGroupShape spTree, XSLFSheet sheet) {
List<XSLFShape> shapes = new ArrayList<XSLFShape>();
for (XmlObject ch : spTree.selectPath("*")) {
if (ch instanceof CTShape) {
// simple shape
XSLFAutoShape shape = XSLFAutoShape.create((CTShape) ch, sheet);
shapes.add(shape);
} else if (ch instanceof CTGroupShape) {
shapes.add(new XSLFGroupShape((CTGroupShape) ch, sheet));
} else if (ch instanceof CTConnector) {
shapes.add(new XSLFConnectorShape((CTConnector) ch, sheet));
} else if (ch instanceof CTPicture) {
shapes.add(new XSLFPictureShape((CTPicture) ch, sheet));
} else if (ch instanceof CTGraphicalObjectFrame) {
XSLFGraphicFrame shape = XSLFGraphicFrame.create((CTGraphicalObjectFrame) ch, sheet);
shapes.add(shape);
}
}
return shapes;
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFSimpleShape method getLn.
private static CTLineProperties getLn(XSLFShape shape, boolean create) {
XmlObject pr = shape.getShapeProperties();
if (!(pr instanceof CTShapeProperties)) {
LOG.log(POILogger.WARN, shape.getClass() + " doesn't have line properties");
return null;
}
CTShapeProperties spr = (CTShapeProperties) pr;
return (spr.isSetLn() || !create) ? spr.getLn() : spr.addNewLn();
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFShape method selectPaint.
protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) {
if (fillRef == null)
return null;
// The idx attribute refers to the index of a fill style or
// background fill style within the presentation's style matrix, defined by the fmtScheme element.
// value of 0 or 1000 indicates no background,
// values 1-999 refer to the index of a fill style within the fillStyleLst element
// values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
int idx = (int) fillRef.getIdx();
CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
final XmlObject styleLst;
int childIdx;
if (idx >= 1 && idx <= 999) {
childIdx = idx - 1;
styleLst = (isLineStyle) ? matrix.getLnStyleLst() : matrix.getFillStyleLst();
} else if (idx >= 1001) {
childIdx = idx - 1001;
styleLst = matrix.getBgFillStyleLst();
} else {
return null;
}
XmlCursor cur = styleLst.newCursor();
XSLFFillProperties fp = null;
if (cur.toChild(childIdx)) {
fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
}
cur.dispose();
CTSchemeColor phClr = fillRef.getSchemeClr();
PaintStyle res = selectPaint(fp, phClr, theme.getPackagePart(), theme, hasPlaceholder);
// see http://officeopenxml.com/prSlide-color.php - "Color Placeholders within Themes"
if (res != null || hasPlaceholder) {
return res;
}
XSLFColor col = new XSLFColor(fillRef, theme, phClr);
return DrawPaint.createSolidPaint(col.getColorStyle());
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSSFDump method dump.
public static void dump(ZipFile zip) throws Exception {
String zipname = zip.getName();
int sep = zipname.lastIndexOf('.');
File root = new File(zipname.substring(0, sep));
createDirIfMissing(root);
System.out.println("Dumping to directory " + root);
Enumeration<? extends ZipEntry> en = zip.entries();
while (en.hasMoreElements()) {
ZipEntry entry = en.nextElement();
String name = entry.getName();
int idx = name.lastIndexOf('/');
if (idx != -1) {
File bs = new File(root, name.substring(0, idx));
recursivelyCreateDirIfMissing(bs);
}
File f = new File(root, entry.getName());
OutputStream out = new FileOutputStream(f);
try {
if (entry.getName().endsWith(".xml") || entry.getName().endsWith(".vml") || entry.getName().endsWith(".rels")) {
try {
Document doc = DocumentHelper.readDocument(zip.getInputStream(entry));
XmlObject xml = XmlObject.Factory.parse(doc, DEFAULT_XML_OPTIONS);
XmlOptions options = new XmlOptions();
options.setSavePrettyPrint();
xml.save(out, options);
} catch (XmlException e) {
System.err.println("Failed to parse " + entry.getName() + ", dumping raw content");
IOUtils.copy(zip.getInputStream(entry), out);
}
} else {
IOUtils.copy(zip.getInputStream(entry), out);
}
} finally {
out.close();
}
}
}
Aggregations