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(ImportConfigMessages.config_import_wizard_page_squirrel_label_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 dbeaver.
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(ImportConfigMessages.config_import_wizard_page_squirrel_label_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 dbeaver.
the class PostgreExecutionPlan 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 (JDBCStatement dbStat = connection.createStatement()) {
try (JDBCResultSet dbResult = dbStat.executeQuery(getPlanQueryString())) {
if (oldQuery) {
List<String> planLines = new ArrayList<>();
while (dbResult.next()) {
String planLine = dbResult.getString(1);
if (!CommonUtils.isEmpty(planLine)) {
planLines.add(planLine);
}
}
parsePlanText(session, planLines);
} else {
if (dbResult.next()) {
SQLXML planXML = dbResult.getSQLXML(1);
parsePlanXML(session, planXML);
}
}
} catch (XMLException e) {
throw new DBCException("Can't parse plan XML", e);
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getExecutionContext());
} 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 dbeaver.
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 = CommonUtils.trim(XMLUtils.getChildElementBody(root, "name"));
url = CommonUtils.trim(XMLUtils.getChildElementBody(root, "url"));
version = CommonUtils.trim(XMLUtils.getChildElementBody(root, "version"));
packaging = CommonUtils.trim(XMLUtils.getChildElementBody(root, "packaging"));
description = CommonUtils.trim(XMLUtils.getChildElementBody(root, "description"));
if (description != null) {
description = CommonUtils.compactWhiteSpaces(description.trim());
}
repositories.addAll(parseRepositories(root));
{
// Parent
Element parentElement = XMLUtils.getChildElement(root, "parent");
if (parentElement != null) {
String parentGroupId = CommonUtils.trim(XMLUtils.getChildElementBody(parentElement, "groupId"));
String parentArtifactId = CommonUtils.trim(XMLUtils.getChildElementBody(parentElement, "artifactId"));
String parentVersion = CommonUtils.trim(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, true);
{
// 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, false);
}
}
}
monitor.worked(1);
}
Aggregations