use of org.apache.poi.POIXMLException in project poi by apache.
the class XDGFBaseContents method onDocumentRead.
@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 + "; Connect; Invalid from id: " + connect.getFromSheet());
if (to == null)
throw new POIXMLException(this + "; Connect; Invalid to id: " + connect.getToSheet());
_connections.add(new XDGFConnection(connect, from, to));
}
}
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class NURBSTo method addToPath.
@Override
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel())
return;
Point2D last = path.getCurrentPoint();
// A NURBS formula: knotLast, degree, xType, yType, x1, y1, knot1,
// weight1, ..
String formula = getE().trim();
if (!formula.startsWith("NURBS(") || !formula.endsWith(")"))
throw new POIXMLException("Invalid NURBS formula: " + formula);
String[] components = formula.substring(6, formula.length() - 1).split(",");
if (components.length < 8)
throw new POIXMLException("Invalid NURBS formula (not enough arguments)");
if ((components.length - 4) % 4 != 0)
throw new POIXMLException("Invalid NURBS formula -- need 4 + n*4 arguments, got " + components.length);
double lastControlX = getX();
double lastControlY = getY();
double secondToLastKnot = getA();
double lastWeight = getB();
double firstKnot = getC();
double firstWeight = getD();
double lastKnot = Double.parseDouble(components[0].trim());
int degree = Integer.parseInt(components[1].trim());
int xType = Integer.parseInt(components[2].trim());
int yType = Integer.parseInt(components[3].trim());
double xScale = 1;
double yScale = 1;
if (xType == 0)
xScale = parent.getWidth();
if (yType == 0)
yScale = parent.getHeight();
// setup first knots/weights/control point
ControlPath controlPath = new ControlPath();
ValueVector knots = new ValueVector();
ValueVector weights = new ValueVector();
knots.add(firstKnot);
weights.add(firstWeight);
controlPath.addPoint(PointFactory.create(last.getX(), last.getY()));
// iterate get knots/weights
int sets = (components.length - 4) / 4;
for (int i = 0; i < sets; i++) {
double x1 = Double.parseDouble(components[4 + i * 4 + 0].trim());
double y1 = Double.parseDouble(components[4 + i * 4 + 1].trim());
double k = Double.parseDouble(components[4 + i * 4 + 2].trim());
double w = Double.parseDouble(components[4 + i * 4 + 3].trim());
controlPath.addPoint(PointFactory.create(x1 * xScale, y1 * yScale));
knots.add(k);
weights.add(w);
}
// last knots/weights/control point
knots.add(secondToLastKnot);
knots.add(lastKnot);
weights.add(lastWeight);
controlPath.addPoint(PointFactory.create(lastControlX, lastControlY));
ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, weights, degree);
path.append(shape, true);
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XSSFSheet method initHyperlinks.
/**
* Read hyperlink relations, link them with CTHyperlink beans in this worksheet
* and initialize the internal array of XSSFHyperlink objects
*/
private void initHyperlinks() {
hyperlinks = new ArrayList<XSSFHyperlink>();
if (!worksheet.isSetHyperlinks()) {
return;
}
try {
PackageRelationshipCollection hyperRels = getPackagePart().getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
// Turn each one into a XSSFHyperlink
for (CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
PackageRelationship hyperRel = null;
if (hyperlink.getId() != null) {
hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
}
hyperlinks.add(new XSSFHyperlink(hyperlink, hyperRel));
}
} catch (InvalidFormatException e) {
throw new POIXMLException(e);
}
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XWPFDocument method onDocumentRead.
@SuppressWarnings("deprecation")
@Override
protected void onDocumentRead() throws IOException {
try {
DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
ctDocument = doc.getDocument();
initFootnotes();
// parse the document with cursor and add
// the XmlObject to its lists
XmlCursor cursor = ctDocument.getBody().newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
bodyElements.add(p);
paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
bodyElements.add(t);
tables.add(t);
} else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
contentControls.add(c);
}
}
cursor.dispose();
// Sort out headers and footers
if (doc.getDocument().getBody().getSectPr() != null)
headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
// Create for each XML-part in the Package a PartClass
for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart p = rp.getDocumentPart();
String relation = rp.getRelationship().getRelationshipType();
if (relation.equals(XWPFRelation.STYLES.getRelation())) {
this.styles = (XWPFStyles) p;
this.styles.onDocumentRead();
} else if (relation.equals(XWPFRelation.NUMBERING.getRelation())) {
this.numbering = (XWPFNumbering) p;
this.numbering.onDocumentRead();
} else if (relation.equals(XWPFRelation.FOOTER.getRelation())) {
XWPFFooter footer = (XWPFFooter) p;
footers.add(footer);
footer.onDocumentRead();
} else if (relation.equals(XWPFRelation.HEADER.getRelation())) {
XWPFHeader header = (XWPFHeader) p;
headers.add(header);
header.onDocumentRead();
} else if (relation.equals(XWPFRelation.COMMENT.getRelation())) {
// TODO Create according XWPFComment class, extending POIXMLDocumentPart
CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
for (CTComment ctcomment : cmntdoc.getComments().getCommentArray()) {
comments.add(new XWPFComment(ctcomment, this));
}
} else if (relation.equals(XWPFRelation.SETTINGS.getRelation())) {
settings = (XWPFSettings) p;
settings.onDocumentRead();
} else if (relation.equals(XWPFRelation.IMAGES.getRelation())) {
XWPFPictureData picData = (XWPFPictureData) p;
picData.onDocumentRead();
registerPackagePictureData(picData);
pictures.add(picData);
} else if (relation.equals(XWPFRelation.GLOSSARY_DOCUMENT.getRelation())) {
// Until we do, we do need to load the glossary child parts of it
for (POIXMLDocumentPart gp : p.getRelations()) {
// Trigger the onDocumentRead for all the child parts
// Otherwise we'll hit issues on Styles, Settings etc on save
// TODO: Refactor this to not need to access protected method
// from other package! Remove the static helper method once fixed!!!
POIXMLDocumentPart._invokeOnDocumentRead(gp);
}
}
}
initHyperlinks();
} catch (XmlException e) {
throw new POIXMLException(e);
}
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XWPFNumbering method onDocumentRead.
/**
* read numbering form an existing package
*/
@Override
protected void onDocumentRead() throws IOException {
NumberingDocument numberingDoc = null;
InputStream is;
is = getPackagePart().getInputStream();
try {
numberingDoc = NumberingDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
ctNumbering = numberingDoc.getNumbering();
//get any Nums
for (CTNum ctNum : ctNumbering.getNumArray()) {
nums.add(new XWPFNum(ctNum, this));
}
for (CTAbstractNum ctAbstractNum : ctNumbering.getAbstractNumArray()) {
abstractNums.add(new XWPFAbstractNum(ctAbstractNum, this));
}
isNew = false;
} catch (XmlException e) {
throw new POIXMLException();
} finally {
is.close();
}
}
Aggregations