use of org.apache.xmlbeans.XmlException in project poi by apache.
the class XSLFGraphicFrame method getFallbackPicture.
@Override
public XSLFPictureShape getFallbackPicture() {
String xquery = "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main'; " + "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' " + ".//mc:Fallback/*/p:pic";
XmlObject xo = selectProperty(XmlObject.class, xquery);
if (xo == null) {
return null;
}
CTGroupShape gs;
try {
gs = CTGroupShape.Factory.parse(xo.newDomNode());
} catch (XmlException e) {
LOG.log(POILogger.WARN, "Can't parse fallback picture stream of graphical frame", e);
return null;
}
if (gs.sizeOfPicArray() == 0) {
return null;
}
return new XSLFPictureShape(gs.getPicArray(0), getSheet());
}
use of org.apache.xmlbeans.XmlException in project poi by apache.
the class TestXSSFBugs method bug54764.
@Test
public void bug54764() throws IOException, OpenXML4JException, XmlException {
OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("54764.xlsx");
// Check the core properties - will be found but empty, due
// to the expansion being too much to be considered valid
POIXMLProperties props = new POIXMLProperties(pkg);
assertEquals(null, props.getCoreProperties().getTitle());
assertEquals(null, props.getCoreProperties().getSubject());
assertEquals(null, props.getCoreProperties().getDescription());
// Now check the spreadsheet itself
try {
new XSSFWorkbook(pkg).close();
fail("Should fail as too much expansion occurs");
} catch (POIXMLException e) {
// Expected
}
pkg.close();
// Try with one with the entities in the Content Types
try {
XSSFTestDataSamples.openSamplePackage("54764-2.xlsx").close();
fail("Should fail as too much expansion occurs");
} catch (Exception e) {
// Expected
}
// Check we can still parse valid files after all that
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
assertEquals(3, wb.getNumberOfSheets());
wb.close();
}
use of org.apache.xmlbeans.XmlException in project knime-core by knime.
the class MissingCellHandlerDescriptionFactory method getDescription.
/**
* Creates the default {@link MissingCellHandlerDescription}
* for the given missing cell handler factory. The description xml file.
* which is named as the simple class name of the missing cell handler factory + .xml
* is expected to be located at the same factory.
*
* @param fac the missing cell handler factory to create the description for
* @return creates parses the configuration file expected in the same package as the given distance factory class
*/
public static final MissingCellHandlerDescription getDescription(final MissingCellHandlerFactory fac) {
Class<?> factoryClass = CheckUtils.checkNotNull(fac).getClass();
// do some stuff to determine the version
LOGGER.debugWithFormat("Loading description for factory: %s", factoryClass);
String descriptionFile = factoryClass.getSimpleName() + ".xml";
InputStream resourceAsStream = factoryClass.getResourceAsStream(descriptionFile);
if (resourceAsStream != null) {
try {
return new MissingCellHandlerDescriptionV1(resourceAsStream);
} catch (XmlException | IOException e) {
LOGGER.error("Error during loading description for factory: " + factoryClass, e);
return errorDescription(fac.getDisplayName());
} finally {
IOUtils.closeQuietly(resourceAsStream);
}
}
return emptyDescription(fac.getDisplayName());
}
use of org.apache.xmlbeans.XmlException in project wso2-synapse by wso2.
the class JavaScriptXmlHelper method toScriptXML.
/**
* This method will convert the message payload in to ScriptXML Object
*
* @param omElement
* @return Scriptable object by adding the xml content
* @throws ScriptException when error
*/
public Object toScriptXML(OMElement omElement) throws ScriptException {
if (omElement == null) {
return null;
}
Context cx = Context.enter();
try {
XmlObject xml;
try {
xml = XmlObject.Factory.parse(omElement.getXMLStreamReader());
} catch (XmlException e) {
throw new ScriptException(e);
}
Object wrappedXML = cx.getWrapFactory().wrap(cx, this.scope, xml, XmlObject.class);
Object obj = cx.newObject(this.scope, "XML", new Object[] { wrappedXML });
return obj;
} finally {
Context.exit();
}
}
use of org.apache.xmlbeans.XmlException in project knime-core by knime.
the class PMMLReaderNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// read the data dictionary and the mining schema and create a
// PMMLPortObjectSpec
String fileS = m_file.getStringValue();
String warning = CheckUtils.checkSourceFile(fileS);
if (warning != null) {
setWarningMessage(warning);
}
URL url = getURLFromSettings(fileS);
try {
PMMLImport pmmlImport = new PMMLImport(url, false);
m_pmmlPort = pmmlImport.getPortObject();
} catch (IllegalArgumentException e) {
String msg = "File \"" + url + "\" is not a valid PMML file:\n" + e.getMessage();
setWarningMessage(msg);
throw new InvalidSettingsException(msg);
} catch (XmlException e) {
throw new InvalidSettingsException(e);
} catch (IOException e) {
throw new InvalidSettingsException(e);
}
PMMLPortObjectSpec parsedSpec = m_pmmlPort.getSpec();
PMMLPortObjectSpec outSpec = createPMMLOutSpec(m_hasPMMLIn ? (PMMLPortObjectSpec) inSpecs[0] : null, parsedSpec);
return new PortObjectSpec[] { outSpec };
}
Aggregations