From 72059e0df4409ff0b7bf82fc4b9e794a4ca60853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isidoro=20Nevares=20Mart=C3=ADn?= Date: Wed, 21 Oct 2026 20:28:54 +0200 Subject: [PATCH] =?UTF-8?q?incluyo=204=20m=C3=A9todos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application.properties | 5 + src/org/lapaloma/aadd/inm/AppPrincipal.java | 108 ++++++++++++++++++ .../inm/gestores/GestorConfiguracion.java | 47 ++++++++ 3 files changed, 160 insertions(+) create mode 100644 config/application.properties create mode 100644 src/org/palomafp/aadd/inm/gestores/GestorConfiguracion.java diff --git a/config/application.properties b/config/application.properties new file mode 100644 index 0000000..701424a --- /dev/null +++ b/config/application.properties @@ -0,0 +1,5 @@ +# Elegir nombres de entradas que sean SIGNIFICATIVOS +# y que no se repitan con otras entradas de la misma aplicaci髇 + +# Informaci髇 relativa al IES +ies.ruta.fichero=C:\\Users\\Isidoro NM\\03-AADD-2AMT\\ficheros\\act1_11\\informacion-IES.xml diff --git a/src/org/lapaloma/aadd/inm/AppPrincipal.java b/src/org/lapaloma/aadd/inm/AppPrincipal.java index 026c419..febe275 100644 --- a/src/org/lapaloma/aadd/inm/AppPrincipal.java +++ b/src/org/lapaloma/aadd/inm/AppPrincipal.java @@ -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; + } } diff --git a/src/org/palomafp/aadd/inm/gestores/GestorConfiguracion.java b/src/org/palomafp/aadd/inm/gestores/GestorConfiguracion.java new file mode 100644 index 0000000..224535f --- /dev/null +++ b/src/org/palomafp/aadd/inm/gestores/GestorConfiguracion.java @@ -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"); + } +}