use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class ConfigImportWizardPageDbvis method loadConnections.
@Override
protected void loadConnections(ImportData importData) throws DBException {
File homeFolder = RuntimeUtils.getUserHomeDir();
File dbvisConfigHome = new File(homeFolder, DBVIS_HOME_FOLDER);
if (!dbvisConfigHome.exists()) {
throw new DBException("DBVisualizer installation not found");
}
File configFolder = new File(dbvisConfigHome, DBVIS_CONFIG70_FOLDER);
if (!configFolder.exists()) {
throw new DBException("Only DBVisualizer 7.x version is supported");
}
File configFile = new File(configFolder, DBVIS_CONFIG_FILE);
if (!configFile.exists()) {
throw new DBException("DBVisualizer configuration file not found");
}
try {
Document configDocument = XMLUtils.parseDocument(configFile);
Element driversElement = XMLUtils.getChildElement(configDocument.getDocumentElement(), "Drivers");
if (driversElement != null) {
for (Element driverElement : XMLUtils.getChildElementList(driversElement, "Driver")) {
String name = XMLUtils.getChildElementBody(driverElement, "Name");
String sampleURL = XMLUtils.getChildElementBody(driverElement, "URLFormat");
String driverClass = XMLUtils.getChildElementBody(driverElement, "DefaultClass");
String lastName = XMLUtils.getChildElementBody(driverElement, "LastName");
//String lastVersion = XMLUtils.getChildElementBody(driverElement, "LastVersion");
if (!CommonUtils.isEmpty(name) && !CommonUtils.isEmpty(sampleURL) && !CommonUtils.isEmpty(driverClass)) {
ImportDriverInfo driver = new ImportDriverInfo(null, name, sampleURL, driverClass);
if (!CommonUtils.isEmpty(lastName)) {
driver.setDescription(lastName);
}
adaptSampleUrl(driver);
// Parse libraries
Element locationsElement = XMLUtils.getChildElement(driverElement, "Locations");
if (locationsElement != null) {
for (Element locationElement : XMLUtils.getChildElementList(locationsElement, "Location")) {
String path = XMLUtils.getChildElementBody(locationElement, "Path");
if (!CommonUtils.isEmpty(path)) {
driver.addLibrary(path);
}
}
}
importData.addDriver(driver);
}
}
}
Element databasesElement = XMLUtils.getChildElement(configDocument.getDocumentElement(), "Databases");
if (databasesElement != null) {
for (Element dbElement : XMLUtils.getChildElementList(databasesElement, "Database")) {
String alias = XMLUtils.getChildElementBody(dbElement, "Alias");
String url = XMLUtils.getChildElementBody(dbElement, "Url");
String driverName = XMLUtils.getChildElementBody(dbElement, "Driver");
String user = XMLUtils.getChildElementBody(dbElement, "Userid");
String password = null;
String passwordEncoded = XMLUtils.getChildElementBody(dbElement, "Password");
/*
if (!CommonUtils.isEmpty(passwordEncoded)) {
try {
password = new String(Base64.decode(passwordEncoded), ContentUtils.DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
// Ignore
}
}
*/
String hostName = null, port = null, database = null;
Element urlVarsElement = XMLUtils.getChildElement(dbElement, "UrlVariables");
if (urlVarsElement != null) {
Element driverElement = XMLUtils.getChildElement(urlVarsElement, "Driver");
if (driverElement != null) {
for (Element urlVarElement : XMLUtils.getChildElementList(driverElement, "UrlVariable")) {
final String varName = urlVarElement.getAttribute("UrlVariableName");
final String varValue = XMLUtils.getElementBody(urlVarElement);
if ("Server".equals(varName)) {
hostName = varValue;
} else if ("Port".equals(varName)) {
port = varValue;
} else if ("Database".equals(varName)) {
database = varValue;
}
}
}
}
if (!CommonUtils.isEmpty(alias) && !CommonUtils.isEmpty(driverName) && (!CommonUtils.isEmpty(url) || !CommonUtils.isEmpty(hostName))) {
ImportDriverInfo driver = importData.getDriver(driverName);
if (driver != null) {
ImportConnectionInfo connectionInfo = new ImportConnectionInfo(driver, dbElement.getAttribute("id"), alias, url, hostName, port, database, user, password);
importData.addConnection(connectionInfo);
}
}
}
}
} catch (XMLException e) {
throw new DBException("Configuration parse error: " + e.getMessage());
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class ConfigImportWizardPageSqlDeveloper method parseConnections.
private void parseConnections(File connectionsFile, ImportData importData) throws DBException {
try {
Document configDocument = XMLUtils.parseDocument(connectionsFile);
for (Element refElement : XMLUtils.getChildElementList(configDocument.getDocumentElement(), "Reference")) {
final String conName = refElement.getAttribute("name");
if (CommonUtils.isEmpty(conName)) {
continue;
}
final Map<String, String> propsMap = new LinkedHashMap<>();
final Element refAddressesElement = XMLUtils.getChildElement(refElement, "RefAddresses");
if (refAddressesElement != null) {
for (Element refAddr : XMLUtils.getChildElementList(refAddressesElement, "StringRefAddr")) {
String addrType = refAddr.getAttribute("addrType");
String addrContent = XMLUtils.getChildElementBody(refAddr, "Contents");
if (!CommonUtils.isEmpty(addrType) && !CommonUtils.isEmpty(addrContent)) {
propsMap.put(addrType, addrContent);
}
}
}
String host = propsMap.get("hostname");
String port = propsMap.get("port");
String sid = propsMap.get("sid");
String serviceName = propsMap.get("serviceName");
String user = propsMap.get("user");
String role = propsMap.get("role");
String osAuth = propsMap.get("OS_AUTHENTICATION");
String url = propsMap.get("customUrl");
if (CommonUtils.isEmpty(host) && CommonUtils.isEmpty(url)) {
continue;
}
String dbName = CommonUtils.isEmpty(sid) ? serviceName : sid;
ImportConnectionInfo connectionInfo = new ImportConnectionInfo(oraDriver, null, conName, url, host, port, dbName, user, null);
if (!CommonUtils.isEmpty(sid)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_SID_SERVICE, OracleConnectionType.SID.name());
} else if (!CommonUtils.isEmpty(serviceName)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_SID_SERVICE, OracleConnectionType.SERVICE.name());
}
if (CommonUtils.toBoolean(osAuth)) {
connectionInfo.setUser(OracleConstants.OS_AUTH_USER_NAME);
}
if (!CommonUtils.isEmpty(role)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_INTERNAL_LOGON, role);
}
importData.addConnection(connectionInfo);
}
} catch (XMLException e) {
throw new DBException("Configuration parse error: " + e.getMessage());
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class PostgrePlanAnalyser method explain.
public void explain(DBCSession session) throws DBCException {
JDBCSession connection = (JDBCSession) session;
boolean oldAutoCommit = false;
try {
oldAutoCommit = connection.getAutoCommit();
if (oldAutoCommit) {
connection.setAutoCommit(false);
}
try (JDBCPreparedStatement dbStat = connection.prepareStatement("EXPLAIN (FORMAT XML, ANALYSE) " + query)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
SQLXML planXML = dbResult.getSQLXML(1);
parsePlan(planXML);
}
} catch (XMLException e) {
throw new DBCException("Can't parse plan XML", e);
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
} finally {
// Rollback changes because EXPLAIN actually executes query and it could be INSERT/UPDATE
try {
connection.rollback();
if (oldAutoCommit) {
connection.setAutoCommit(true);
}
} catch (SQLException e) {
log.error("Error closing plan analyser", e);
}
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class ConfigImportWizardPageSquirrel method loadConnections.
@Override
protected void loadConnections(ImportData importData) throws DBException {
File homeFolder = RuntimeUtils.getUserHomeDir();
File sqlConfigHome = new File(homeFolder, SQL_HOME_FOLDER);
if (!sqlConfigHome.exists()) {
throw new DBException("SQL Squirrel installation not found");
}
File driversFile = new File(sqlConfigHome, SQL_DRIVERS_FILE);
if (!driversFile.exists()) {
throw new DBException("SQL Squirrel drivers configuration file not found. Possibly corrupted installation.");
}
File aliasesFile = new File(sqlConfigHome, SQL_ALIASES_FILE);
if (!aliasesFile.exists()) {
throw new DBException("SQL Squirrel configuration file not found. Possibly version older than 2.3 is installed.");
}
try {
// Parse drivers
Document driversDocument = XMLUtils.parseDocument(driversFile);
for (Element driverElement : XMLUtils.getChildElementList(driversDocument.getDocumentElement(), "Bean")) {
if (!"net.sourceforge.squirrel_sql.fw.sql.SQLDriver".equals(driverElement.getAttribute("Class"))) {
continue;
}
final Element driverIdentifier = XMLUtils.getChildElement(driverElement, "identifier");
String driverId = driverIdentifier == null ? null : XMLUtils.getChildElementBody(driverIdentifier, "string");
if (CommonUtils.isEmpty(driverId)) {
continue;
}
String name = XMLUtils.getChildElementBody(driverElement, "name");
String driverClass = XMLUtils.getChildElementBody(driverElement, "driverClassName");
String sampleURL = XMLUtils.getChildElementBody(driverElement, "url");
if (!CommonUtils.isEmpty(name) && !CommonUtils.isEmpty(sampleURL) && !CommonUtils.isEmpty(driverClass)) {
ImportDriverInfo driver = new ImportDriverInfo(driverId, name, sampleURL, driverClass);
adaptSampleUrl(driver);
// Parse libraries
final Element jarFileNames = XMLUtils.getChildElement(driverElement, "jarFileNames");
if (jarFileNames != null) {
for (Element locationElement : XMLUtils.getChildElementList(jarFileNames, "Bean")) {
String path = XMLUtils.getChildElementBody(locationElement, "string");
if (!CommonUtils.isEmpty(path)) {
driver.addLibrary(path);
}
}
}
importData.addDriver(driver);
}
}
// Parse aliases
Document aliasesDocument = XMLUtils.parseDocument(aliasesFile);
for (Element aliasElement : XMLUtils.getChildElementList(aliasesDocument.getDocumentElement(), "Bean")) {
if (!"net.sourceforge.squirrel_sql.client.gui.db.SQLAlias".equals(aliasElement.getAttribute("Class"))) {
continue;
}
final Element driverIdentifier = XMLUtils.getChildElement(aliasElement, "driverIdentifier");
String driverId = driverIdentifier == null ? null : XMLUtils.getChildElementBody(driverIdentifier, "string");
if (CommonUtils.isEmpty(driverId)) {
continue;
}
final ImportDriverInfo driverInfo = importData.getDriverByID(driverId);
if (driverInfo == null) {
continue;
}
String name = XMLUtils.getChildElementBody(aliasElement, "name");
String url = XMLUtils.getChildElementBody(aliasElement, "url");
String userName = XMLUtils.getChildElementBody(aliasElement, "userName");
String password = XMLUtils.getChildElementBody(aliasElement, "password");
ImportConnectionInfo connectionInfo = new ImportConnectionInfo(driverInfo, null, name, url, null, null, null, userName, password);
importData.addConnection(connectionInfo);
}
} catch (XMLException e) {
throw new DBException("Configuration parse error: " + e.getMessage());
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class MavenArtifactVersion method loadPOM.
private void loadPOM(DBRProgressMonitor monitor) throws IOException {
monitor.subTask("Load POM " + this);
File localPOM = getLocalPOM();
if (!localPOM.exists()) {
cachePOM(localPOM);
}
Document pomDocument;
try (InputStream mdStream = new FileInputStream(localPOM)) {
pomDocument = XMLUtils.parseDocument(mdStream);
} catch (XMLException e) {
throw new IOException("Error parsing POM", e);
}
Element root = pomDocument.getDocumentElement();
name = XMLUtils.getChildElementBody(root, "name");
url = XMLUtils.getChildElementBody(root, "url");
version = XMLUtils.getChildElementBody(root, "version");
packaging = XMLUtils.getChildElementBody(root, "packaging");
description = XMLUtils.getChildElementBody(root, "description");
if (description != null) {
description = TextUtils.compactWhiteSpaces(description.trim());
}
{
// Parent
Element parentElement = XMLUtils.getChildElement(root, "parent");
if (parentElement != null) {
String parentGroupId = XMLUtils.getChildElementBody(parentElement, "groupId");
String parentArtifactId = XMLUtils.getChildElementBody(parentElement, "artifactId");
String parentVersion = XMLUtils.getChildElementBody(parentElement, "version");
if (parentGroupId == null || parentArtifactId == null || parentVersion == null) {
log.error("Broken parent reference: " + parentGroupId + ":" + parentArtifactId + ":" + parentVersion);
} else {
MavenArtifactReference parentReference = new MavenArtifactReference(parentGroupId, parentArtifactId, null, parentVersion);
if (this.version == null) {
this.version = parentReference.getVersion();
}
parent = MavenRegistry.getInstance().findArtifact(monitor, this, parentReference);
if (parent == null) {
log.error("Artifact [" + this + "] parent [" + parentReference + "] not found");
}
}
}
}
{
// Licenses
Element licensesElement = XMLUtils.getChildElement(root, "licenses");
if (licensesElement != null) {
for (Element prop : XMLUtils.getChildElementList(licensesElement, "license")) {
licenses.add(new MavenArtifactLicense(XMLUtils.getChildElementBody(prop, "name"), XMLUtils.getChildElementBody(prop, "url")));
}
}
}
// Default profile
MavenProfile defaultProfile = new MavenProfile(DEFAULT_PROFILE_ID);
defaultProfile.active = true;
profiles.add(defaultProfile);
parseProfile(monitor, defaultProfile, root);
{
// Profiles
Element licensesElement = XMLUtils.getChildElement(root, "profiles");
if (licensesElement != null) {
for (Element profElement : XMLUtils.getChildElementList(licensesElement, "profile")) {
MavenProfile profile = new MavenProfile(XMLUtils.getChildElementBody(profElement, "id"));
profiles.add(profile);
parseProfile(monitor, profile, profElement);
}
}
}
monitor.worked(1);
}
Aggregations