Search in sources :

Example 76 with XmlException

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());
}
Also used : XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 77 with XmlException

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();
}
Also used : POIXMLProperties(org.apache.poi.POIXMLProperties) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) POIXMLException(org.apache.poi.POIXMLException) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) InvalidOperationException(org.apache.poi.openxml4j.exceptions.InvalidOperationException) POIXMLException(org.apache.poi.POIXMLException) XLSBUnsupportedException(org.apache.poi.xssf.XLSBUnsupportedException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) EncryptedDocumentException(org.apache.poi.EncryptedDocumentException) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Example 78 with XmlException

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());
}
Also used : InputStream(java.io.InputStream) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException)

Example 79 with XmlException

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();
    }
}
Also used : Context(org.mozilla.javascript.Context) ScriptException(javax.script.ScriptException) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) XMLObject(org.mozilla.javascript.xml.XMLObject) XmlObject(org.apache.xmlbeans.XmlObject)

Example 80 with XmlException

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 };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) XmlException(org.apache.xmlbeans.XmlException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

XmlException (org.apache.xmlbeans.XmlException)112 XmlObject (org.apache.xmlbeans.XmlObject)45 IOException (java.io.IOException)35 DecodingException (org.n52.svalbard.decode.exception.DecodingException)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 POIXMLException (org.apache.poi.POIXMLException)15 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)10 XmlCursor (org.apache.xmlbeans.XmlCursor)10 XmlOptions (org.apache.xmlbeans.XmlOptions)10 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)8 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)7 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)7 Geometry (org.locationtech.jts.geom.Geometry)6 Document (org.w3c.dom.Document)6 Node (org.w3c.dom.Node)6 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 File (java.io.File)5