Search in sources :

Example 41 with KettleXMLException

use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.

the class DTDIgnoringEntityResolver method loadXMLFile.

/**
 * Load a file into an XML document
 *
 * @param resource
 *          The resource to load into a document
 * @return the Document if all went well, null if an error occured!
 */
public static Document loadXMLFile(URL resource) throws KettleXMLException {
    DocumentBuilderFactory dbf;
    DocumentBuilder db;
    Document doc;
    try {
        // Check and open XML document
        dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory();
        db = dbf.newDocumentBuilder();
        InputStream inputStream = resource.openStream();
        try {
            doc = db.parse(inputStream);
        } catch (IOException ef) {
            throw new KettleXMLException(ef);
        } finally {
            inputStream.close();
        }
        return doc;
    } catch (Exception e) {
        throw new KettleXMLException("Error reading information from resource", e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) Document(org.w3c.dom.Document) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 42 with KettleXMLException

use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.

the class DTDIgnoringEntityResolver method loadXMLString.

public static Document loadXMLString(DocumentBuilder db, String string) throws KettleXMLException {
    try {
        StringReader stringReader = new java.io.StringReader(string);
        InputSource inputSource = new InputSource(stringReader);
        Document doc;
        try {
            doc = db.parse(inputSource);
        } catch (IOException ef) {
            throw new KettleXMLException("Error parsing XML", ef);
        } finally {
            stringReader.close();
        }
        return doc;
    } catch (Exception e) {
        throw new KettleXMLException("Error reading information from XML string : " + Const.CR + string, e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) Document(org.w3c.dom.Document) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 43 with KettleXMLException

use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.

the class DTDIgnoringEntityResolver method loadXMLFile.

/**
 * Load a file into an XML document
 *
 * @param inputStream
 *          The stream to load a document from
 * @param systemID
 *          Provide a base for resolving relative URIs.
 * @param ignoreEntities
 *          Ignores external entities and returns an empty dummy.
 * @param namespaceAware
 *          support XML namespaces.
 * @return the Document if all went well, null if an error occured!
 */
public static Document loadXMLFile(InputStream inputStream, String systemID, boolean ignoreEntities, boolean namespaceAware) throws KettleXMLException {
    try {
        // Check and open XML document
        // 
        DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory();
        dbf.setIgnoringComments(true);
        dbf.setNamespaceAware(namespaceAware);
        DocumentBuilder db = dbf.newDocumentBuilder();
        // 
        if (ignoreEntities) {
            db.setEntityResolver(new DTDIgnoringEntityResolver());
        }
        Document doc;
        try {
            if (Utils.isEmpty(systemID)) {
                // Normal parsing
                // 
                doc = db.parse(inputStream);
            } else {
                // Do extra verifications
                // 
                String systemIDwithEndingSlash = systemID.trim();
                // 
                if (!systemIDwithEndingSlash.endsWith("/") && !systemIDwithEndingSlash.endsWith("\\")) {
                    systemIDwithEndingSlash = systemIDwithEndingSlash.concat("/");
                }
                doc = db.parse(inputStream, systemIDwithEndingSlash);
            }
        } catch (FileNotFoundException ef) {
            throw new KettleXMLException(ef);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return doc;
    } catch (Exception e) {
        throw new KettleXMLException("Error reading information from input stream", e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileNotFoundException(java.io.FileNotFoundException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Document(org.w3c.dom.Document) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 44 with KettleXMLException

use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.

the class WebResult method fromXMLString.

public static WebResult fromXMLString(String xml) throws KettleXMLException {
    try {
        Document doc = XMLHandler.loadXMLString(xml);
        Node node = XMLHandler.getSubNode(doc, XML_TAG);
        return new WebResult(node);
    } catch (Exception e) {
        throw new KettleXMLException(BaseMessages.getString(PKG, "WebResult.Error.UnableCreateResult"), e);
    }
}
Also used : Node(org.w3c.dom.Node) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Document(org.w3c.dom.Document) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException)

Example 45 with KettleXMLException

use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.

the class SalesforceDeleteMeta method readData.

private void readData(Node stepnode) throws KettleXMLException {
    try {
        setDeleteField(XMLHandler.getTagValue(stepnode, "DeleteField"));
        setBatchSize(XMLHandler.getTagValue(stepnode, "batchSize"));
        setRollbackAllChangesOnError("Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "rollbackAllChangesOnError")));
    } catch (Exception e) {
        throw new KettleXMLException("Unable to load step info from XML", e);
    }
}
Also used : KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)286 KettleException (org.pentaho.di.core.exception.KettleException)209 Node (org.w3c.dom.Node)164 KettleStepException (org.pentaho.di.core.exception.KettleStepException)150 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)25 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)23 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)20 Document (org.w3c.dom.Document)13 IOException (java.io.IOException)10 KettleValueException (org.pentaho.di.core.exception.KettleValueException)10 StringObjectId (org.pentaho.di.repository.StringObjectId)8 KettleFileException (org.pentaho.di.core.exception.KettleFileException)7 FileNotFoundException (java.io.FileNotFoundException)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)5 InputStream (java.io.InputStream)4 MalformedURLException (java.net.MalformedURLException)4 ParseException (java.text.ParseException)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4