use of org.jkiss.dbeaver.ext.import_config.wizards.ImportConnectionInfo in project dbeaver by serge-rider.
the class ConfigImportWizardPageCustomConnections method makeConnectionFromProps.
private void makeConnectionFromProps(ImportData importData, ImportDriverInfo driver, Map<String, String> conProps) {
String name = conProps.get("name");
if (CommonUtils.isEmpty(name)) {
return;
}
importData.addConnection(new ImportConnectionInfo(driver, conProps.get("id"), name, conProps.get("url"), conProps.get("host"), conProps.get("port"), conProps.get("database"), conProps.get("user"), conProps.get("password")));
}
use of org.jkiss.dbeaver.ext.import_config.wizards.ImportConnectionInfo 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.dbeaver.ext.import_config.wizards.ImportConnectionInfo 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.dbeaver.ext.import_config.wizards.ImportConnectionInfo 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());
}
}
Aggregations