use of org.jkiss.utils.xml.XMLException in project dbeaver by dbeaver.
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 dbeaver.
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 dbeaver.
the class DataFormatterRegistry method loadProfiles.
private void loadProfiles() {
customProfiles = new ArrayList<>();
File storeFile = DBWorkbench.getPlatform().getConfigurationFile(CONFIG_FILE_NAME);
if (!storeFile.exists()) {
return;
}
try {
try (InputStream is = new FileInputStream(storeFile)) {
SAXReader parser = new SAXReader(is);
try {
parser.parse(new FormattersParser());
} catch (XMLException ex) {
throw new DBException("Datasource config parse error", ex);
}
} catch (DBException ex) {
log.warn("Can't load profiles config from " + storeFile.getPath(), ex);
}
} catch (IOException ex) {
log.warn("IO error", ex);
}
}
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);
}
}
}
Aggregations