Search in sources :

Example 1 with XMLException

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

Example 2 with XMLException

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

Example 3 with XMLException

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

Example 4 with XMLException

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;
        }
    });
}
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 5 with XMLException

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());
    }
}
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) ImportDriverInfo(org.jkiss.dbeaver.ext.import_config.wizards.ImportDriverInfo) Document(org.w3c.dom.Document) File(java.io.File)

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