private void parseXml() { DOMParser parser = new DOMParser(); try { parser.parse(new InputSource(new URL(Constants.NAVALBATTLE_UPDATE_URL).openStream())); Document doc = parser.getDocument(); NodeList nodeList = doc.getElementsByTagName("string"); for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); NamedNodeMap m = n.getAttributes(); Node actualNode = n.getFirstChild(); if (actualNode != null) { if (m.getNamedItem("name").getTextContent().equals("version_code")) { versionCode = actualNode.getNodeValue(); } if (m.getNamedItem("name").getTextContent().equals("version_readable")) { versionReadable = actualNode.getNodeValue(); } if (m.getNamedItem("name").getTextContent().equals("update_text")) { updateText = actualNode.getNodeValue(); } if (m.getNamedItem("name").getTextContent().equals("update_url")) { updateUrl = actualNode.getNodeValue(); } if (m.getNamedItem("name").getTextContent().equals("announcement_code")) { announcementCode = actualNode.getNodeValue(); } if (m.getNamedItem("name").getTextContent().equals("announcement_title")) { announcementTitle = actualNode.getNodeValue(); } if (m.getNamedItem("name").getTextContent().equals("announcement_text")) { announcementText = actualNode.getNodeValue(); } if (m.getNamedItem("name").getTextContent().equals("announcement_url")) { announcementUrl = actualNode.getNodeValue(); } } } } catch (Exception ex) { NavalBattle.getDebugWindow() .printError("BroadcastService encountered an error while downloading data"); } }
private void checkForUpdates() { try { int clientVersion = Integer.parseInt(Constants.VERSION_CODE); int latestVersion = Integer.parseInt(versionCode); if (clientVersion < latestVersion) { needsUpdate = true; } else { NavalBattle.getDebugWindow().printInfo("You are running the latest version!"); } } catch (Exception e) { } }
private void checkForAnnouncement() { try { int clientAnnouncement = Integer.parseInt(announcementId); int latestAnnouncement = Integer.parseInt(announcementCode); if (clientAnnouncement < latestAnnouncement || latestAnnouncement == -1) { hasAnnouncement = true; if (latestAnnouncement != -1) { NavalBattleIO.saveAttribute("announcementId", announcementCode); } } else { NavalBattle.getDebugWindow().printInfo("No new announcements!"); } } catch (Exception e) { } }