Search in sources :

Example 1 with SAXReader

use of org.jkiss.utils.xml.SAXReader 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 SAXReader

use of org.jkiss.utils.xml.SAXReader 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 3 with SAXReader

use of org.jkiss.utils.xml.SAXReader in project dbeaver by serge-rider.

the class DataFormatterRegistry method loadProfiles.

private void loadProfiles() {
    customProfiles = new ArrayList<>();
    File storeFile = DBeaverActivator.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 4 with SAXReader

use of org.jkiss.utils.xml.SAXReader in project dbeaver by serge-rider.

the class ViewerColumnRegistry method loadConfiguration.

private void loadConfiguration(File configFile) {
    columnsConfig.clear();
    try (InputStream in = new FileInputStream(configFile)) {
        SAXReader parser = new SAXReader(in);
        final ColumnsParser dsp = new ColumnsParser();
        parser.parse(dsp);
    } catch (Exception e) {
        log.error("Error loading columns configuration", e);
    }
}
Also used : SAXReader(org.jkiss.utils.xml.SAXReader) XMLException(org.jkiss.utils.xml.XMLException)

Example 5 with SAXReader

use of org.jkiss.utils.xml.SAXReader in project dbeaver by serge-rider.

the class VersionDescriptor method parseVersionInfo.

private void parseVersionInfo(InputStream inputStream) throws IOException, XMLException {
    SAXReader parser = new SAXReader(inputStream);
    SAXListener dsp = new SAXListener() {

        private String lastTag;

        private StringBuilder textBuffer = new StringBuilder();

        @Override
        public void saxStartElement(SAXReader reader, String namespaceURI, String localName, Attributes atts) throws XMLException {
            lastTag = localName;
            textBuffer.setLength(0);
        }

        @Override
        public void saxText(SAXReader reader, String data) throws XMLException {
            textBuffer.append(data);
        }

        @Override
        public void saxEndElement(SAXReader reader, String namespaceURI, String localName) throws XMLException {
            final String text = textBuffer.toString();
            switch(lastTag) {
                case "name":
                    programName = text;
                    break;
                case "number":
                    programVersion = Version.parseVersion(text);
                    break;
                case "date":
                    updateTime = text;
                    break;
                case "base-url":
                    baseURL = text;
                    break;
                case "release-notes":
                    releaseNotes = text;
                    break;
            }
            textBuffer.setLength(0);
        }
    };
    parser.parse(dsp);
}
Also used : SAXReader(org.jkiss.utils.xml.SAXReader) SAXListener(org.jkiss.utils.xml.SAXListener) Attributes(org.xml.sax.Attributes)

Aggregations

SAXReader (org.jkiss.utils.xml.SAXReader)5 XMLException (org.jkiss.utils.xml.XMLException)4 DBException (org.jkiss.dbeaver.DBException)2 SAXListener (org.jkiss.utils.xml.SAXListener)2 Attributes (org.xml.sax.Attributes)2