Search in sources :

Example 11 with XMLException

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;
}
Also used : XMLException(org.jkiss.utils.xml.XMLException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 12 with XMLException

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;
        }
    });
}
Also used : XMLException(org.jkiss.utils.xml.XMLException) SAXReader(org.jkiss.utils.xml.SAXReader) SAXListener(org.jkiss.utils.xml.SAXListener) Attributes(org.xml.sax.Attributes)

Example 13 with XMLException

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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) XMLException(org.jkiss.utils.xml.XMLException) SAXReader(org.jkiss.utils.xml.SAXReader)

Example 14 with XMLException

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());
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) XMLException(org.jkiss.utils.xml.XMLException) ImportConnectionInfo(org.jkiss.dbeaver.ext.import_config.wizards.ImportConnectionInfo) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with XMLException

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);
        }
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) SQLXML(java.sql.SQLXML) XMLException(org.jkiss.utils.xml.XMLException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Aggregations

XMLException (org.jkiss.utils.xml.XMLException)24 DBException (org.jkiss.dbeaver.DBException)14 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)12 ImportConnectionInfo (org.jkiss.dbeaver.ext.import_config.wizards.ImportConnectionInfo)8 SAXReader (org.jkiss.utils.xml.SAXReader)6 File (java.io.File)4 SQLException (java.sql.SQLException)4 SQLXML (java.sql.SQLXML)4 LinkedHashMap (java.util.LinkedHashMap)4 ImportDriverInfo (org.jkiss.dbeaver.ext.import_config.wizards.ImportDriverInfo)4 DBCException (org.jkiss.dbeaver.model.exec.DBCException)4 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)4 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 CoreException (org.eclipse.core.runtime.CoreException)2