implementación de las consultas
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
# y que no se repitan con otras entradas de la misma aplicación
|
||||
|
||||
# Información relativa al IES
|
||||
ies.ruta.fichero=C:\\Users\\Isidoro NM\\03-AADD-2AMT\\ficheros\\act1_11\\informacion-IES.xml
|
||||
ies.ruta.fichero=C:\\Users\\ineva\\INM\\tmp\\aadd\\fic11\\informacion-IES.xml
|
||||
|
||||
@@ -9,105 +9,160 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.palomafp.aadd.inm.gestores.GestorConfiguracion;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
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();
|
||||
Document documentoDOM = app.cargarArbolDOMFicheroXML();
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int opcion;
|
||||
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");
|
||||
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();
|
||||
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;
|
||||
}
|
||||
if (opcion < 1 || opcion > 4) {
|
||||
System.out.println("Opción no válida. Inténtalo de nuevo.");
|
||||
}
|
||||
switch (opcion) {
|
||||
case 1:
|
||||
app.buscarInformacionInstituto(documentoDOM);
|
||||
break;
|
||||
case 2:
|
||||
app.buscarInformacionCiclos(documentoDOM);
|
||||
break;
|
||||
case 3:
|
||||
app.buscarInformacionModulos(documentoDOM);
|
||||
break;
|
||||
case 4:
|
||||
app.buscarInformacionModulosCiclo(documentoDOM);
|
||||
break;
|
||||
}
|
||||
|
||||
} while (opcion < 1 || opcion > 4);
|
||||
} while (opcion < 1 || opcion > 4);
|
||||
|
||||
System.out.println("Has elegido la opción " + opcion);
|
||||
System.out.println("Has elegido la opción " + opcion);
|
||||
|
||||
sc.close();
|
||||
sc.close();
|
||||
}
|
||||
|
||||
private void buscarInformacionInstituto(Element elementoRaizArbolDOM) {
|
||||
Element elementoInstituto = (Element) elementoRaizArbolDOM
|
||||
.getElementsByTagName("instituto")
|
||||
.item(0);
|
||||
private void buscarInformacionInstituto(Document docDOM) {
|
||||
Element elementoInstituto = (Element) docDOM.getElementsByTagName("instituto").item(0);
|
||||
|
||||
String nombre = elementoInstituto.getAttribute("nombre");
|
||||
String tipo = elementoInstituto.getAttribute("tipo");
|
||||
|
||||
System.out.println("Nombre: " + nombre + " - " + tipo);
|
||||
|
||||
System.out.println("Instituto - Nombre: " + nombre + " - Tipo: " + tipo);
|
||||
|
||||
}
|
||||
|
||||
private void buscarInformacionModulosCiclo(Element elementoRaizArbolDOM) {
|
||||
// TODO Auto-generated method stub
|
||||
private void buscarInformacionCiclos(Document docDOM) {
|
||||
NodeList nodosCiclo = docDOM.getElementsByTagName("ciclo");
|
||||
for (int i = 0; i < nodosCiclo.getLength(); i++) {
|
||||
Node nodoCiclo = nodosCiclo.item(i);
|
||||
|
||||
if (nodoCiclo.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element elementoCiclo = (Element) nodoCiclo;
|
||||
|
||||
String codigo = elementoCiclo.getAttribute("codigo");
|
||||
String nombre = elementoCiclo.getElementsByTagName("nombre_corto").item(0).getTextContent();
|
||||
|
||||
System.out.println("Ciclo - Nombre: " + nombre + " - Código: " + codigo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buscarInformacionModulos(Document docDOM) {
|
||||
|
||||
NodeList nodosModulo = docDOM.getElementsByTagName("modulo");
|
||||
for (int i = 0; i < nodosModulo.getLength(); i++) {
|
||||
Node nodoModulo = nodosModulo.item(i);
|
||||
|
||||
if (nodoModulo.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element elementoModulo = (Element) nodoModulo;
|
||||
|
||||
String identificador = elementoModulo.getAttribute("id");
|
||||
String referencia = elementoModulo.getAttribute("ref");
|
||||
String titulo = elementoModulo.getElementsByTagName("titulo").item(0).getTextContent();
|
||||
String numerohoras = elementoModulo.getElementsByTagName("numerohoras").item(0).getTextContent();
|
||||
|
||||
if (titulo != null && titulo.trim().startsWith("Programa")) {
|
||||
|
||||
System.out.println("Módulo - Título: " + titulo + " - Identificador: " + identificador
|
||||
+ " - Referencia: " + referencia + " - Número horas: " + numerohoras);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buscarInformacionModulos(Element elementoRaizArbolDOM) {
|
||||
// TODO Auto-generated method stub
|
||||
private void buscarInformacionModulosCiclo(Document docDOM) {
|
||||
NodeList nodosModulo = docDOM.getElementsByTagName("modulo");
|
||||
for (int i = 0; i < nodosModulo.getLength(); i++) {
|
||||
Node nodoModulo = nodosModulo.item(i);
|
||||
|
||||
// Obtener el nodo padre del módulo --> el nodo curso
|
||||
Node nodoCurso = nodoModulo.getParentNode();
|
||||
String numero = null;
|
||||
if (nodoCurso.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element elementoCurso = (Element) nodoCurso;
|
||||
numero = elementoCurso.getAttribute("numero");
|
||||
}
|
||||
|
||||
// Saltar los módulos que no pertenecen al curso 1
|
||||
if (numero == null || !"1".equals(numero)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mostrar info de los módulos que pertenecen al curso 1
|
||||
if (nodoModulo.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element elementoModulo = (Element) nodoModulo;
|
||||
|
||||
String identificador = elementoModulo.getAttribute("id");
|
||||
String referencia = elementoModulo.getAttribute("ref");
|
||||
String titulo = elementoModulo.getElementsByTagName("titulo").item(0).getTextContent();
|
||||
String numerohoras = elementoModulo.getElementsByTagName("numerohoras").item(0).getTextContent();
|
||||
|
||||
if (titulo != null && titulo.trim().startsWith("Programa")) {
|
||||
|
||||
System.out.println("Módulo - Título: " + titulo + " - Identificador: " + identificador
|
||||
+ " - Referencia: " + referencia + " - Número horas: " + numerohoras);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buscarInformacionCiclos(Element elementoRaizArbolDOM) {
|
||||
// TODO Auto-generated method stub
|
||||
private Document cargarArbolDOMFicheroXML() {
|
||||
Document document = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Element cargarArbolDOMFicheroXML() {
|
||||
Element raiz = null;
|
||||
try {
|
||||
// 1. Crear la fábrica
|
||||
DocumentBuilderFactory factory =
|
||||
DocumentBuilderFactory.newInstance();
|
||||
// 1. Crear la fábrica
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
// 2. Crear el parser DOM
|
||||
DocumentBuilder builder =
|
||||
factory.newDocumentBuilder();
|
||||
// 2. Crear el parser que se usará para obtener el árbol DOM
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
// 3. Leer el fichero XML
|
||||
Document document =
|
||||
builder.parse(new File(GestorConfiguracion.getRutaFicheroIES()));
|
||||
// 3. Leer el fichero XML y lo parseamos para obtener el árbol DOM
|
||||
File fichero = new File(GestorConfiguracion.getRutaFicheroIES());
|
||||
document = builder.parse(fichero);
|
||||
|
||||
// 4. Obtener el elemento raíz que voy a devolver
|
||||
document.getDocumentElement().normalize();
|
||||
|
||||
raiz = document.getDocumentElement();
|
||||
System.out.println("Raíz: " + raiz.getTagName());
|
||||
// 4. Obtener el documento raíz normalizado
|
||||
document.getDocumentElement().normalize();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return raiz;
|
||||
return document;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user