incluyo 4 métodos
This commit is contained in:
@@ -1,5 +1,113 @@
|
||||
package org.lapaloma.aadd.inm;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.palomafp.aadd.inm.gestores.GestorConfiguracion;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class AppPrincipal {
|
||||
public static void main(String[] args) {
|
||||
AppPrincipal app = new AppPrincipal();
|
||||
|
||||
// Se carga el árbol DOM que más tarde se usará para las consultas.
|
||||
Element elementoRaizArbolDOM = app.cargarArbolDOMFicheroXML();
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int opcion;
|
||||
|
||||
do {
|
||||
System.out.println("Elige una opción:");
|
||||
System.out.println("1. Buscar información instituto");
|
||||
System.out.println("2. Buscar información ciclos");
|
||||
System.out.println("3. Buscar información módulos - filtro 1");
|
||||
System.out.println("4. Buscar información módulos - filtro 2");
|
||||
|
||||
opcion = sc.nextInt();
|
||||
|
||||
if (opcion < 1 || opcion > 4) {
|
||||
System.out.println("Opción no válida. Inténtalo de nuevo.");
|
||||
}
|
||||
switch (opcion) {
|
||||
case 1:
|
||||
app.buscarInformacionInstituto(elementoRaizArbolDOM);
|
||||
break;
|
||||
case 2:
|
||||
app.buscarInformacionCiclos(elementoRaizArbolDOM);
|
||||
break;
|
||||
case 3:
|
||||
app.buscarInformacionModulos(elementoRaizArbolDOM);
|
||||
break;
|
||||
case 4:
|
||||
app.buscarInformacionModulosCiclo(elementoRaizArbolDOM);
|
||||
break;
|
||||
}
|
||||
|
||||
} while (opcion < 1 || opcion > 4);
|
||||
|
||||
System.out.println("Has elegido la opción " + opcion);
|
||||
|
||||
sc.close();
|
||||
}
|
||||
|
||||
private void buscarInformacionInstituto(Element elementoRaizArbolDOM) {
|
||||
Element elementoInstituto = (Element) elementoRaizArbolDOM
|
||||
.getElementsByTagName("instituto")
|
||||
.item(0);
|
||||
|
||||
String nombre = elementoInstituto.getAttribute("nombre");
|
||||
String tipo = elementoInstituto.getAttribute("tipo");
|
||||
|
||||
System.out.println("Nombre: " + nombre + " - " + tipo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void buscarInformacionModulosCiclo(Element elementoRaizArbolDOM) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private void buscarInformacionModulos(Element elementoRaizArbolDOM) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private void buscarInformacionCiclos(Element elementoRaizArbolDOM) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Element cargarArbolDOMFicheroXML() {
|
||||
Element raiz = null;
|
||||
try {
|
||||
// 1. Crear la fábrica
|
||||
DocumentBuilderFactory factory =
|
||||
DocumentBuilderFactory.newInstance();
|
||||
|
||||
// 2. Crear el parser DOM
|
||||
DocumentBuilder builder =
|
||||
factory.newDocumentBuilder();
|
||||
|
||||
// 3. Leer el fichero XML
|
||||
Document document =
|
||||
builder.parse(new File(GestorConfiguracion.getRutaFicheroIES()));
|
||||
|
||||
// 4. Obtener el elemento raíz que voy a devolver
|
||||
document.getDocumentElement().normalize();
|
||||
|
||||
raiz = document.getDocumentElement();
|
||||
System.out.println("Raíz: " + raiz.getTagName());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return raiz;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user