use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class DataSourceRegistry method loadDataSources.
private void loadDataSources(InputStream is, DataSourceOrigin origin, boolean refresh, ParseResults parseResults) throws DBException, IOException {
SAXReader parser = new SAXReader(is);
try {
final DataSourcesParser dsp = new DataSourcesParser(origin, refresh, parseResults);
parser.parse(dsp);
} catch (XMLException ex) {
throw new DBException("Datasource config parse error", ex);
}
updateProjectNature();
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by dbeaver.
the class DataSourceRegistry method loadDataSources.
private void loadDataSources(InputStream is, DataSourceOrigin origin, boolean refresh, ParseResults parseResults) throws DBException, IOException {
SAXReader parser = new SAXReader(is);
try {
final DataSourcesParser dsp = new DataSourcesParser(origin, refresh, parseResults);
parser.parse(dsp);
} catch (XMLException ex) {
throw new DBException("Datasource config parse error", ex);
}
updateProjectNature();
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class MavenArtifact method loadMetadata.
public void loadMetadata(DBRProgressMonitor monitor) throws IOException {
latestVersion = null;
releaseVersion = null;
versions.clear();
lastUpdate = null;
String metadataPath = getBaseArtifactURL() + MAVEN_METADATA_XML;
monitor.subTask("Load metadata " + this + "");
try (InputStream mdStream = WebUtils.openConnection(metadataPath, getRepository().getAuthInfo(), null).getInputStream()) {
parseMetadata(mdStream);
} catch (XMLException e) {
log.warn("Error parsing artifact metadata", e);
} catch (IOException e) {
// Metadata xml not found. It happens in rare cases. Let's try to get directory listing
try (InputStream dirStream = WebUtils.openConnection(getBaseArtifactURL(), getRepository().getAuthInfo(), null).getInputStream()) {
parseDirectory(dirStream);
} catch (XMLException e1) {
log.warn("Error parsing artifact directory", e);
}
} finally {
removeIgnoredVersions();
monitor.worked(1);
}
metadataLoaded = true;
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class MavenArtifact method parseMetadata.
private void parseMetadata(InputStream mdStream) throws IOException, XMLException {
SAXReader reader = new SAXReader(mdStream);
reader.parse(new SAXListener() {
public String lastTag;
@Override
public void saxStartElement(SAXReader reader, String namespaceURI, String localName, Attributes atts) throws XMLException {
lastTag = localName;
}
@Override
public void saxText(SAXReader reader, String data) throws XMLException {
if ("version".equals(lastTag)) {
versions.add(data);
} else if ("latest".equals(lastTag)) {
latestVersion = data;
} else if ("release".equals(lastTag)) {
releaseVersion = data;
} else if ("lastUpdate".equals(lastTag)) {
try {
lastUpdate = new Date(Long.parseLong(data));
} catch (NumberFormatException e) {
log.warn(e);
}
}
}
@Override
public void saxEndElement(SAXReader reader, String namespaceURI, String localName) throws XMLException {
lastTag = null;
}
});
}
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(ImportConfigMessages.config_import_wizard_page_dbvis_label_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());
}
}
Aggregations