Android Open Source - Airplanes Java Xml Parser






From Project

Back to project page Airplanes.

License

The source code is released under:

GNU General Public License

If you think the Android project Airplanes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.axnsan.airplanes.util;
//from ww  w  .  j  a  va2s  .c o m
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;

public class JavaXmlParser implements StringXmlParser {
  
  @Override
  public Map<String, String> loadStringsForLocale(String locale, String STRING_FILE) {
    HashMap<String, String> ret = new HashMap<String, String>();
    
    try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            FileHandle fileHandle = Gdx.files.internal(STRING_FILE);
            Document doc = db.parse(fileHandle.read());
           
            Element root = doc.getDocumentElement();
            NodeList languages = root.getElementsByTagName("language");
            if (languages.getLength() <= 0)
              throw new RuntimeException("The " + STRING_FILE + " file must contain one or more " +
                  "language elements");
            
            for (int i = 0; i < languages.getLength(); ++i) {                
                Node lang = languages.item(i);
                
                if (lang.getAttributes().getNamedItem("name").getTextContent().equals(locale)) 
                {
                  
                    Element langRoot = (Element) lang;
                    NodeList strings = langRoot.getElementsByTagName("string");
                    
                    for (int j = 0;j < strings.getLength();++j) {
                      Node string = strings.item(j);
                      
                      String name = string.getAttributes().getNamedItem("name").getTextContent();
                      String value = string.getTextContent();
                      
                      ret.put(name, value);
                    }
                }
            }
    } catch (Exception e) {
      throw new RuntimeException("Error parsing strings XML from file " + STRING_FILE + " for locale " + locale);
    }
    
    return ret;
  }

  @Override
  public Map<String, String> loadStringsForCurrentLocale(String STRING_FILE) {
    return loadStringsForLocale(getCurrentLocale(), STRING_FILE);
  }

  @Override
  public String getCurrentLocale() {
    return java.util.Locale.getDefault().toString().substring(0, 5);
  }
}




Java Source Code List

com.axnsan.airplanes.Airplanes.java
com.axnsan.airplanes.BaseGrid.java
com.axnsan.airplanes.GameConfiguration.java
com.axnsan.airplanes.GameState.java
com.axnsan.airplanes.GridRandomizer.java
com.axnsan.airplanes.Grid.java
com.axnsan.airplanes.GuardedScreen.java
com.axnsan.airplanes.HotseatMatchHandler.java
com.axnsan.airplanes.MainActivity.java
com.axnsan.airplanes.Main.java
com.axnsan.airplanes.MatchHandler.java
com.axnsan.airplanes.PlacementGrid.java
com.axnsan.airplanes.Plane.java
com.axnsan.airplanes.Player.java
com.axnsan.airplanes.PlayingGrid.java
com.axnsan.airplanes.online.ClientSocket.java
com.axnsan.airplanes.online.EventHandler.java
com.axnsan.airplanes.online.Game.java
com.axnsan.airplanes.online.LobbyScreen.java
com.axnsan.airplanes.online.LoginScreen.java
com.axnsan.airplanes.online.Message.java
com.axnsan.airplanes.online.Messages.java
com.axnsan.airplanes.online.OnlineGameScreen.java
com.axnsan.airplanes.online.OnlineMatchHandler.java
com.axnsan.airplanes.online.OnlineMenuScreen.java
com.axnsan.airplanes.online.OnlineSettingsScreen.java
com.axnsan.airplanes.online.SessionData.java
com.axnsan.airplanes.screens.BeginTurnScreen.java
com.axnsan.airplanes.screens.HotseatPlayersScreen.java
com.axnsan.airplanes.screens.HotseatScreen.java
com.axnsan.airplanes.screens.HotseatSettingsScreen.java
com.axnsan.airplanes.screens.HotseatStartScreen.java
com.axnsan.airplanes.screens.MainMenuScreen.java
com.axnsan.airplanes.screens.PlacementScreen.java
com.axnsan.airplanes.screens.PlayMenuScreen.java
com.axnsan.airplanes.screens.PracticeScreen.java
com.axnsan.airplanes.screens.PracticeSettingsScreen.java
com.axnsan.airplanes.screens.PracticeStartScreen.java
com.axnsan.airplanes.util.ActionManager.java
com.axnsan.airplanes.util.ActionResolver.java
com.axnsan.airplanes.util.BasicFontManager.java
com.axnsan.airplanes.util.Detector.java
com.axnsan.airplanes.util.DoubleTapDetector.java
com.axnsan.airplanes.util.DoubleTapListener.java
com.axnsan.airplanes.util.FontManagerInterface.java
com.axnsan.airplanes.util.FontManager.java
com.axnsan.airplanes.util.JavaXmlParser.java
com.axnsan.airplanes.util.Point2D.java
com.axnsan.airplanes.util.RandomizedQueue.java
com.axnsan.airplanes.util.StringManager.java
com.axnsan.airplanes.util.StringXmlParser.java
com.axnsan.airplanes.util.TTFFontManager.java
com.axnsan.airplanes.util.TapDetector.java
com.axnsan.airplanes.util.TapListener.java