use of org.apache.poi.POIXMLException in project poi by apache.
the class XWPFRun method getCTPictures.
private List<CTPicture> getCTPictures(XmlObject o) {
List<CTPicture> pics = new ArrayList<CTPicture>();
XmlObject[] picts = o.selectPath("declare namespace pic='" + CTPicture.type.getName().getNamespaceURI() + "' .//pic:pic");
for (XmlObject pict : picts) {
if (pict instanceof XmlAnyTypeImpl) {
// Pesky XmlBeans bug - see Bugzilla #49934
try {
pict = CTPicture.Factory.parse(pict.toString(), DEFAULT_XML_OPTIONS);
} catch (XmlException e) {
throw new POIXMLException(e);
}
}
if (pict instanceof CTPicture) {
pics.add((CTPicture) pict);
}
}
return pics;
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XWPFStyles method onDocumentRead.
/**
* Read document
*/
@Override
protected void onDocumentRead() throws IOException {
StylesDocument stylesDoc;
InputStream is = getPackagePart().getInputStream();
try {
stylesDoc = StylesDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
setStyles(stylesDoc.getStyles());
latentStyles = new XWPFLatentStyles(ctStyles.getLatentStyles(), this);
} catch (XmlException e) {
throw new POIXMLException("Unable to read styles", e);
} finally {
is.close();
}
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class TestXSSFFont method testCharSet.
@Test
public void testCharSet() throws IOException {
CTFont ctFont = CTFont.Factory.newInstance();
CTIntProperty prop = ctFont.addNewCharset();
prop.setVal(FontCharset.ANSI.getValue());
ctFont.setCharsetArray(0, prop);
XSSFFont xssfFont = new XSSFFont(ctFont);
assertEquals(Font.ANSI_CHARSET, xssfFont.getCharSet());
xssfFont.setCharSet(FontCharset.DEFAULT);
assertEquals(FontCharset.DEFAULT.getValue(), ctFont.getCharsetArray(0).getVal());
// Try with a few less usual ones:
// Set with the Charset itself
xssfFont.setCharSet(FontCharset.RUSSIAN);
assertEquals(FontCharset.RUSSIAN.getValue(), xssfFont.getCharSet());
// And set with the Charset index
xssfFont.setCharSet(FontCharset.ARABIC.getValue());
assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
xssfFont.setCharSet((byte) (FontCharset.ARABIC.getValue()));
assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
// This one isn't allowed
assertEquals(null, FontCharset.valueOf(9999));
try {
xssfFont.setCharSet(9999);
fail("Shouldn't be able to set an invalid charset");
} catch (POIXMLException e) {
}
// Now try with a few sample files
// Normal charset
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
assertEquals(0, wb1.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet());
wb1.close();
// GB2312 charact set
XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx");
assertEquals(134, wb2.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet());
wb2.close();
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XSSFFileHandler method handleAdditional.
@SuppressWarnings("resource")
@Override
public void handleAdditional(File file) throws Exception {
// redirect stdout as the examples often write lots of text
PrintStream oldOut = System.out;
try {
System.setOut(new NullPrintStream());
FromHowTo.main(new String[] { file.getAbsolutePath() });
XLSX2CSV.main(new String[] { file.getAbsolutePath() });
assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!", EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
} catch (OLE2NotOfficeXmlFileException e) {
// we have some files that are not actually OOXML and thus cannot be tested here
} catch (IllegalArgumentException e) {
if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
throw e;
}
} catch (InvalidFormatException e) {
if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
throw e;
}
} catch (IOException e) {
if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
throw e;
}
} catch (POIXMLException e) {
if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
throw e;
}
} finally {
System.setOut(oldOut);
}
}
use of org.apache.poi.POIXMLException in project poi by apache.
the class XMLSlideShow method onDocumentRead.
@Override
protected void onDocumentRead() throws IOException {
try {
PresentationDocument doc = PresentationDocument.Factory.parse(getCorePart().getInputStream(), DEFAULT_XML_OPTIONS);
_presentation = doc.getPresentation();
Map<String, XSLFSlideMaster> masterMap = new HashMap<String, XSLFSlideMaster>();
Map<String, XSLFSlide> shIdMap = new HashMap<String, XSLFSlide>();
for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart p = rp.getDocumentPart();
if (p instanceof XSLFSlide) {
shIdMap.put(rp.getRelationship().getId(), (XSLFSlide) p);
} else if (p instanceof XSLFSlideMaster) {
masterMap.put(getRelationId(p), (XSLFSlideMaster) p);
} else if (p instanceof XSLFTableStyles) {
_tableStyles = (XSLFTableStyles) p;
} else if (p instanceof XSLFNotesMaster) {
_notesMaster = (XSLFNotesMaster) p;
} else if (p instanceof XSLFCommentAuthors) {
_commentAuthors = (XSLFCommentAuthors) p;
}
}
_masters = new ArrayList<XSLFSlideMaster>(masterMap.size());
for (CTSlideMasterIdListEntry masterId : _presentation.getSldMasterIdLst().getSldMasterIdList()) {
XSLFSlideMaster master = masterMap.get(masterId.getId2());
_masters.add(master);
}
_slides = new ArrayList<XSLFSlide>(shIdMap.size());
if (_presentation.isSetSldIdLst()) {
for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdList()) {
XSLFSlide sh = shIdMap.get(slId.getId2());
if (sh == null) {
LOG.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
continue;
}
_slides.add(sh);
}
}
} catch (XmlException e) {
throw new POIXMLException(e);
}
}
Aggregations