From 0f4eaf3b5de797e9f3fd73f57cd1a6ed1c7cc92c Mon Sep 17 00:00:00 2001 From: "juanperoh11-lgtm." Date: Thu, 22 Oct 2026 16:06:21 +0200 Subject: [PATCH] Actividad 11 --- .classpath | 10 ++ .gitignore | 1 + .project | 28 ++++ .settings/org.eclipse.core.resources.prefs | 2 + .settings/org.eclipse.jdt.core.prefs | 11 ++ config/application.properties | 2 + config/informacion-IES.xml | 119 ++++++++++++++ src/org/palomafp/aadd/aez/AppPrincipal.java | 151 ++++++++++++++++++ .../aadd/aez/config/GestorConfiguracion.java | 36 +++++ 9 files changed, 360 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 config/application.properties create mode 100644 config/informacion-IES.xml create mode 100644 src/org/palomafp/aadd/aez/AppPrincipal.java create mode 100644 src/org/palomafp/aadd/aez/config/GestorConfiguracion.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..efedf92 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..1cae59f --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + Ficheros_11 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + 1792677715655 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3124684 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=25 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=25 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=25 diff --git a/config/application.properties b/config/application.properties new file mode 100644 index 0000000..081d6c8 --- /dev/null +++ b/config/application.properties @@ -0,0 +1,2 @@ +# Ruta del fichero XML de información del IES +ies.xml.ruta=C:/Users/aleja/Desktop/2ºDam/Eclipse 2º DAM/Ficheros_11/config/informacion-IES.xml \ No newline at end of file diff --git a/config/informacion-IES.xml b/config/informacion-IES.xml new file mode 100644 index 0000000..9e27bba --- /dev/null +++ b/config/informacion-IES.xml @@ -0,0 +1,119 @@ + + + + DAM + Técnico Superior en Desarrollo de Aplicaciones Multiplataforma + + + Bases de datos + 205 + + + 90 + Entornos de desarrollo + + + 90 + Formación y orientación laboral + + + 140 + Lenguaje de marcas y sistemas de gestión de información + + + 270 + Programación + + + 205 + Sistemas informáticos + + + + + Acceso a Datos + 120 + + + 120 + Diseño de interfaces + + + 65 + Empresa e iniciativa emprendedora + + + 80 + Programación de servicios y procesos + + + 80 + Programación multimedia y dispositivos móviles + + + 40 + Inglés técnico para grado superior + + + + + DAW + Técnico Superior en Desarrollo de Aplicaciones Web + + + Bases de datos + 205 + + + 90 + Entornos de desarrollo + + + 90 + Formación y orientación laboral + + + 140 + Lenguaje de marcas y sistemas de gestión de información + + + 270 + Programación + + + 205 + Sistemas informáticos + + + + + Desarrollo web en entorno cliente + 115 + + + 180 + Desarrollo web en entorno servidor + + + 85 + Despliegue de aplicaciones web + + + 115 + Diseño de interfaces web + + + 30 + Proyecto de desarrollo de aplicaciones web + + + 40 + Inglés técnico para grado superior + + + 65 + Empresa e iniciativa emprendedora + + + + \ No newline at end of file diff --git a/src/org/palomafp/aadd/aez/AppPrincipal.java b/src/org/palomafp/aadd/aez/AppPrincipal.java new file mode 100644 index 0000000..15d4feb --- /dev/null +++ b/src/org/palomafp/aadd/aez/AppPrincipal.java @@ -0,0 +1,151 @@ +package org.palomafp.aadd.aez; + +import java.io.File; +import java.util.Scanner; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.palomafp.aadd.aez.config.GestorConfiguracion; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +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. + Document documentoDOM = 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(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); + + System.out.println("Has elegido la opción " + opcion); + + sc.close(); + } + + 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("Instituto - Nombre: " + nombre + " - Tipo: " + tipo); + + } + + private void buscarInformacionCiclos(Document docDOM) { + NodeList nodosCiclo = docDOM.getElementsByTagName("ciclo"); + for (int i = 0; i < nodosCiclo.getLength(); i++) { + Element elementoCiclo = (Element) nodosCiclo.item(i); + + 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++) { + Element elementoModulo = (Element) nodosModulo.item(i); + + 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 buscarInformacionModulosCiclo(Document docDOM) { + NodeList nodosModulo = docDOM.getElementsByTagName("modulo"); + for (int i = 0; i < nodosModulo.getLength(); i++) { + Element elementoModulo = (Element) nodosModulo.item(i); + + // Obtener el nodo padre del módulo --> el nodo curso + Element elementoCurso = (Element) elementoModulo.getParentNode(); + String numero = elementoCurso.getAttribute("numero"); + + // Saltar los módulos que no pertenecen al curso 1 + if (numero == null || !"1".equals(numero)) { + continue; + } + + String titulo = elementoModulo.getElementsByTagName("titulo").item(0).getTextContent().trim(); + + if (titulo != null && titulo.trim().startsWith("Programa")) { + + String identificador = elementoModulo.getAttribute("id"); + String referencia = elementoModulo.getAttribute("ref"); + String numerohoras = elementoModulo.getElementsByTagName("numerohoras").item(0).getTextContent(); + + System.out.println("Módulo - Título: " + titulo + " - Identificador: " + identificador + + " - Referencia: " + referencia + " - Número horas: " + numerohoras); + } + } + } + + private Document cargarArbolDOMFicheroXML() { + Document document = null; + + try { + // 1. Crear la fábrica + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + // 2. Crear el parser que se usará para obtener el árbol DOM + DocumentBuilder builder = factory.newDocumentBuilder(); + + // 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 documento raíz normalizado + document.getDocumentElement().normalize(); + + } catch (Exception e) { + e.printStackTrace(); + } + return document; + } + +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/aez/config/GestorConfiguracion.java b/src/org/palomafp/aadd/aez/config/GestorConfiguracion.java new file mode 100644 index 0000000..95ec1dd --- /dev/null +++ b/src/org/palomafp/aadd/aez/config/GestorConfiguracion.java @@ -0,0 +1,36 @@ +package org.palomafp.aadd.aez.config; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +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"); + } +} \ No newline at end of file