incluyo 4 métodos

This commit is contained in:
Isidoro Nevares Martín
2026-10-21 20:28:54 +02:00
parent 89c48987c6
commit 72059e0df4
3 changed files with 160 additions and 0 deletions
+108
View File
@@ -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;
}
}
@@ -0,0 +1,47 @@
package org.palomafp.aadd.inm.gestores;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
*
* GestorConfiguracion: Clase que carga la configuración de la aplicación desde
* un fichero de propiedades
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 8 oct 2026
*
*
*/
public class GestorConfiguracion {
private static final String RUTA_FICHERO_CONFIGURACION = "application.properties";
private static final Properties PROPIEDADES_CONFIGURACION = new Properties();
// Constructor privado: de esta manera conseguimos que esta clase no se puede
// instanciar.
private GestorConfiguracion() {
}
// Este bloque se ejecuta una sola vez, cuando se carga la clase
// GestorConfiguracion
static {
try (InputStream inputStream = GestorConfiguracion.class.getClassLoader().getResourceAsStream(RUTA_FICHERO_CONFIGURACION);)
{
if (inputStream == null) {
throw new IOException(
"No se encuentra "+ RUTA_FICHERO_CONFIGURACION + " en el classpath");
}
PROPIEDADES_CONFIGURACION.load(inputStream);
// System.out.println(PROPIEDADES_CONFIGURACION);
} catch (IOException e) {
throw new RuntimeException("No se ha podido cargar el fichero de configuración", e);
}
}
public static String getRutaFicheroIES() {
return PROPIEDADES_CONFIGURACION.getProperty("ies.ruta.fichero");
}
}