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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations