gt:                     NodeList fileData = currentChild.getChildNodes();
context: /*
   *  This file is part of SWADroid.
   *
   *  Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
   *
   *  SWADroid is free software: you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation, either version 3 of the License, or
   *  (at your option) any later version.
   *
   *  SWADroid is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with SWADroid.  If not, see <http://www.gnu.org/licenses/>.
   */
  package es.ugr.swad.swadroid.modules.downloads;
  
  import android.content.Context;
  import android.util.Log;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  import java.io.StringReader;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.List;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;
  
  import es.ugr.swad.swadroid.Constants;
  
  
  /**
   * Class used to navigate around the XML file. That XML file contains the
   * information of all the directory.
   *
   * @author Sergio Ropero Oliver. <sro0000@gmail.com>
   * @author Helena Rodriguez Gijon <hrgijon@gmail.com>
   * @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
   * @version 1.0
   */
  
  //TODO look for a more efficient navigation
  public class DirectoryNavigator {
  
      private String XMLinfo;
  
      private final ArrayList<String> path;
  
      private ArrayList<DirectoryItem> currentItems;
      /**
       * Application context
       */
      private Context mContext;
  
      /**
       * Downloads tag name for Logcat
       */
      private static final String TAG = Constants.APP_TAG + " DirectoryNavigator";
  
      /**
       * Constructor.
       *
       * @param fileXML File where we obtain all the information.
       */
      public DirectoryNavigator(Context ctx, String fileXML) {
          this.XMLinfo = fileXML;
          this.path = new ArrayList<>();
          this.mContext = ctx;
      }
  
      /**
       * Travel inside a subdirectory.
       *
       * @param subDirectory The subdirectory where we will travel.
       * @return Return a list of items that are inside the subdirectory.
       * @throws InvalidPathException When the directory don't exist.
       */
      public ArrayList<DirectoryItem> goToSubDirectory(String subDirectory) throws InvalidPathException {
          //We increase the path.
          path.add(subDirectory);
  
          Node node = goToDirectory();
  
          currentItems = new ArrayList<>(getItems(node));
  
          return currentItems;
      }
  
  
      public ArrayList<DirectoryItem> goToCurrentDirectory() {
          return currentItems;
      }
  
      /**
       * Travel inside a subdirectory.
       *
       * @param directoryPosition The position of the subdirectory where we will travel.
       * @return Return a list of items that are inside the subdirectory.
       * @throws InvalidPathException When the directory don't exist.
       */
      public ArrayList<DirectoryItem> goToSubDirectory(int directoryPosition) throws InvalidPathException {
          String subDirectory = currentItems.get(directoryPosition).getName();
  
          //We increase the path.
          path.add(subDirectory);
  
          Node node = goToDirectory();
  
          currentItems = new ArrayList<>(getItems(node));
  
          return currentItems;
      }
  
      /**
       * Travel to the parent directory.
       *
       * @return Return a list of items that are inside the parent directory.
       * @throws InvalidPathException When the directory does not exist.
       */
      public ArrayList<DirectoryItem> goToParentDirectory() throws InvalidPathException {
  
          if (path.size() != 0) {
              //We decrease the path.
              path.remove(path.size() - 1);
              Node node = goToDirectory();
  
              currentItems = new ArrayList<>(getItems(node));
          }
  
          return currentItems;
      }
  
      /**
       * Refresh the XML file and refresh the directory data. We throw an exception if the directory was erased.
       *
       * @return Return a list of items in the current directory.
       * @throws InvalidPathException When the directory don't exist.
       */
      public ArrayList<DirectoryItem> refresh(String fileXML) throws InvalidPathException {
          this.XMLinfo = fileXML;
  
          Node node = goToDirectory();
  
          currentItems = new ArrayList<>(getItems(node));
          return currentItems;
      }
  
      /**
       * Go to the root directory.
       *
       * @return The items of the root directory.
       * @throws InvalidPathException When the directory don't exist.
       */
      public ArrayList<DirectoryItem> goToRoot() throws InvalidPathException {
          path.clear();
  
          Node node = goToDirectory();
  
          currentItems = new ArrayList<>(getItems(node));
          return currentItems;
      }
  
      /**
       * Obtain all the items of the specific directory.
       *
       * @param node Node that represents the current directory.
       * @return Return a list of items of the directory passed as parameter.
       */
      private List<DirectoryItem> getItems(Node node) {
          List<DirectoryItem> items = new ArrayList<>();
          NodeList childs = node.getChildNodes();
          DirectoryItem item;
  
          for (int i = 0; i < childs.getLength(); i++) {
              Node currentChild = childs.item(i);
              NamedNodeMap attributes = currentChild.getAttributes();
              String name;
  
              switch(currentChild.getNodeName()) {
                  case "dir":
                      name = attributes.getNamedItem("name").getNodeValue();
                      item = new DirectoryItem(name);
                      items.add(item);
                      break;
                  case "file":
                      String type = "";
                      long fileCode = -1;
                      long size = -1; //In bytes
                      long time = -1;
                      String license = "";
                      String publisher = "";
                      String photo = "";
  
                      name = attributes.getNamedItem("name").getNodeValue();
  
                      //WE GET THE REST OF THE INFO
  