Search in sources :

Example 1 with SAXListener

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

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

use of org.jkiss.utils.xml.SAXListener in project dbeaver by dbeaver.

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)

Example 4 with SAXListener

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

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