use of org.apache.poi.POIXMLException in project poi by apache.
the class GeometrySection method getPath.
public Path2D.Double getPath(XDGFShape parent) {
Iterator<GeometryRow> rows = getCombinedRows().iterator();
// special cases
GeometryRow first = rows.next();
if (first instanceof Ellipse) {
return ((Ellipse) first).getPath();
} else if (first instanceof InfiniteLine) {
return ((InfiniteLine) first).getPath();
} else if (first instanceof SplineStart) {
throw new POIXMLException("SplineStart must be preceded by another type");
} else {
// everything else is a path
Path2D.Double path = new Path2D.Double();
// dealing with splines makes this more complex
SplineCollector renderer = null;
GeometryRow row;
while (true) {
if (first != null) {
row = first;
first = null;
} else {
if (!rows.hasNext())
break;
row = rows.next();
}
if (row instanceof SplineStart) {
if (renderer != null)
throw new POIXMLException("SplineStart found multiple times!");
renderer = new SplineCollector((SplineStart) row);
} else if (row instanceof SplineKnot) {
if (renderer == null)
throw new POIXMLException("SplineKnot found without SplineStart!");
renderer.addKnot((SplineKnot) row);
} else {
if (renderer != null) {
renderer.addToPath(path, parent);
renderer = null;
}
row.addToPath(path, parent);
}
}
// just in case we end iteration
if (renderer != null)
renderer.addToPath(path, parent);
return path;
}
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XDGFMasters method onDocumentRead.
@Override
protected void onDocumentRead() {
try {
try {
_mastersObject = MastersDocument.Factory.parse(getPackagePart().getInputStream()).getMasters();
} catch (XmlException e) {
throw new POIXMLException(e);
} catch (IOException e) {
throw new POIXMLException(e);
}
Map<String, MasterType> masterSettings = new HashMap<String, MasterType>();
for (MasterType master : _mastersObject.getMasterArray()) {
masterSettings.put(master.getRel().getId(), master);
}
// create the masters
for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart part = rp.getDocumentPart();
String relId = rp.getRelationship().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);
}
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XDGFPage method getPageSize.
/**
* @return width/height 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()));
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XWPFPictureData method getChecksum.
public Long getChecksum() {
if (this.checksum == null) {
InputStream is = null;
byte[] data;
try {
is = getPackagePart().getInputStream();
data = IOUtils.toByteArray(is);
} catch (IOException e) {
throw new POIXMLException(e);
} finally {
IOUtils.closeQuietly(is);
}
this.checksum = IOUtils.calculateChecksum(data);
}
return this.checksum;
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XWPFHeader method onDocumentRead.
/**
* reads the document
*
* @throws IOException
*/
@Override
protected void onDocumentRead() throws IOException {
super.onDocumentRead();
HdrDocument hdrDocument = null;
InputStream is = null;
try {
is = getPackagePart().getInputStream();
hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
headerFooter = hdrDocument.getHdr();
// parse the document with cursor and add
// the XmlObject to its lists
XmlCursor cursor = headerFooter.newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
paragraphs.add(p);
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
tables.add(t);
bodyElements.add(t);
}
if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}
}
cursor.dispose();
} catch (XmlException e) {
throw new POIXMLException(e);
} finally {
if (is != null) {
is.close();
}
}
}
Aggregations