Package org.openstreetmap.josm.tools

Examples of org.openstreetmap.josm.tools.XmlParsingException


            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            UserInfo userInfo = new UserInfo();
            Node xmlNode = (Node)xpath.compile("/osm/user[1]").evaluate(document, XPathConstants.NODE);
            if ( xmlNode== null)
                throw new XmlParsingException(tr("XML tag <user> is missing."));

            // -- id
            String v = getAttribute(xmlNode, "id");
            if (v == null)
                throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "id", "user"));
            try {
                userInfo.setId(Integer.parseInt(v));
            } catch(NumberFormatException e) {
                throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "id", "user", v));
            }
            // -- display name
            v = getAttribute(xmlNode, "display_name");
            userInfo.setDisplayName(v);
            // -- account_created
            v = getAttribute(xmlNode, "account_created");
            if (v!=null) {
                userInfo.setAccountCreated(DateUtils.fromString(v));
            }
            // -- description
            xmlNode = (Node)xpath.compile("/osm/user[1]/description[1]/text()").evaluate(document, XPathConstants.NODE);
            if (xmlNode != null) {
                userInfo.setDescription(xmlNode.getNodeValue());
            }
            // -- home
            xmlNode = (Node)xpath.compile("/osm/user[1]/home").evaluate(document, XPathConstants.NODE);
            if (xmlNode != null) {
                v = getAttribute(xmlNode, "lat");
                if (v == null)
                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lat", "home"));
                double lat;
                try {
                    lat = Double.parseDouble(v);
                } catch(NumberFormatException e) {
                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lat", "home", v));
                }

                v = getAttribute(xmlNode, "lon");
                if (v == null)
                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lon", "home"));
                double lon;
                try {
                    lon = Double.parseDouble(v);
                } catch(NumberFormatException e) {
                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lon", "home", v));
                }

                v = getAttribute(xmlNode, "zoom");
                if (v == null)
                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "zoom", "home"));
                int zoom;
                try {
                    zoom = Integer.parseInt(v);
                } catch(NumberFormatException e) {
                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "zoom", "home", v));
                }
                userInfo.setHome(new LatLon(lat,lon));
                userInfo.setHomeZoom(zoom);
            }

            // -- language list
            NodeList xmlNodeList = (NodeList)xpath.compile("/osm/user[1]/languages[1]/lang/text()").evaluate(document, XPathConstants.NODESET);
            if (xmlNodeList != null) {
                List<String> languages = new LinkedList<>();
                for (int i=0; i < xmlNodeList.getLength(); i++) {
                    languages.add(xmlNodeList.item(i).getNodeValue());
                }
                userInfo.setLanguages(languages);
            }
           
            // -- messages
            xmlNode = (Node)xpath.compile("/osm/user[1]/messages/received").evaluate(document, XPathConstants.NODE);
            if (xmlNode != null) {
                v = getAttribute(xmlNode, "unread");
                if (v == null)
                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "unread", "received"));
                try {
                    userInfo.setUnreadMessages(Integer.parseInt(v));
                } catch(NumberFormatException e) {
                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v), e);
                }
            }
           
            return userInfo;
        } catch(XPathException e) {
            throw new XmlParsingException(e);
        }
    }
View Full Code Here


            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
                throw new OsmApiException(connection.getResponseCode(),connection.getHeaderField("Error"), null);
            Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(connection.getInputStream());
            return OsmServerUserInfoReader.buildFromXML(d);
        } catch(SAXException | ParserConfigurationException e) {
            throw new XmlParsingException(e);
        } catch(IOException e) {
            throw new OsmTransferException(e);
        } catch(OAuthException e) {
            throw new OsmOAuthAuthorizationException(e);
        } finally {
View Full Code Here

            progressMonitor.indeterminateSubTask(tr("Parsing changeset content ..."));
            SAXParserFactory.newInstance().newSAXParser().parse(source, new Parser());
        } catch(XmlParsingException e) {
            throw e;
        } catch (ParserConfigurationException | SAXException | IOException e) {
            throw new XmlParsingException(e);
        } finally {
            progressMonitor.finishTask();
        }
        return data;
    }
View Full Code Here

        /** the current change modification type */
        private ChangesetDataSet.ChangesetModificationType currentModificationType;

        @Override
        protected void throwException(String message) throws XmlParsingException {
            throw new XmlParsingException(message).rememberLocation(locator);
        }
View Full Code Here

        protected void throwException(String message) throws XmlParsingException {
            throw new XmlParsingException(message).rememberLocation(locator);
        }

        protected void throwException(Exception e) throws XmlParsingException {
            throw new XmlParsingException(e).rememberLocation(locator);
        }
View Full Code Here

            InputSource inputSource = new InputSource(new StringReader(diffUploadResponse));
            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser());
        } catch(XmlParsingException e) {
            throw e;
        } catch(IOException | ParserConfigurationException | SAXException e) {
            throw new XmlParsingException(e);
        } finally {
            progressMonitor.finishTask();
        }
    }
View Full Code Here

        public void setDocumentLocator(Locator locator) {
            this.locator = locator;
        }

        protected void throwException(String msg) throws XmlParsingException {
            throw new XmlParsingException(msg).rememberLocation(locator);
        }
View Full Code Here

                    break;
                default:
                    throwException(tr("Unexpected XML element with name ''{0}''", qName));
                }
            } catch (NumberFormatException e) {
                throw new XmlParsingException(e).rememberLocation(locator);
            }
        }
View Full Code Here

        public void setDocumentLocator(Locator locator) {
            this.locator = locator;
        }

        protected void throwException(String msg) throws XmlParsingException {
            throw new XmlParsingException(msg).rememberLocation(locator);
        }
View Full Code Here

TOP

Related Classes of org.openstreetmap.josm.tools.XmlParsingException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.