Add leerXML clase

Cambiar el nombre de programa y su package
Agregar LICENSE y README.md
Agregar un ejemplo mt.xml
Crear JavaDoc
Este commit está contenido en:
2017-06-23 19:21:56 -04:00
padre c74f849048
commit a6f91086f0
Se han modificado 39 ficheros con 4722 adiciones y 45 borrados

11
src/mt/Controller.java Archivo normal
Ver fichero

@@ -0,0 +1,11 @@
/* Copyright (c) 2017 Christopher Cromer
* Copyright (c) 2017 Carlos Faúndez
*
* This file is part of mt. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution.
* This file may not be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.
*/
package mt;
public class Controller {
}

114
src/mt/LeerXML.java Archivo normal
Ver fichero

@@ -0,0 +1,114 @@
/* Copyright (c) 2017 Christopher Cromer
* Copyright (c) 2017 Carlos Faúndez
*
* This file is part of mt. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution.
* This file may not be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.
*/
package mt;
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import jdk.internal.org.xml.sax.ErrorHandler;
import jdk.internal.org.xml.sax.SAXException;
import jdk.internal.org.xml.sax.SAXParseException;
import org.w3c.dom.Document;
/**
* Esta clase puede abrir y validar un archivo de xml.
*/
class LeerXML {
/**
* El metodo va a verificar que el archivo existe y que contiene xml valido. Si es valido devuelve el documento.
*
* @param archivo Es el archivo a abrir.
* @return Devuelve un document de xml o null si habia algun error.
*/
Document leerArchivo(File archivo) {
try {
if (!archivo.exists()) {
System.out.println("El archivo " + archivo.getName() + " no existe!");
return null;
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new SimpleErrorHandler());
Document document = db.parse(archivo);
document.getDocumentElement().normalize();
return document;
}
catch(Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
return null;
}
}
/**
* Esta clase se usa para validar que el xml es valido.
*/
protected class SimpleErrorHandler implements ErrorHandler, org.xml.sax.ErrorHandler {
/**
* Un warning
* @param e La excepción
* @throws SAXException La excepción thrown
*/
public void warning(SAXParseException e) throws SAXException {
System.out.println(e.getMessage());
}
/**
* Un error
* @param e La excepción
* @throws SAXException La excepción thrown
*/
public void error(SAXParseException e) throws SAXException {
System.out.println(e.getMessage());
}
/**
* Un error fatal
* @param e La excepción
* @throws SAXException La excepción thrown
*/
public void fatalError(SAXParseException e) throws SAXException {
System.out.println(e.getMessage());
}
/**
* Un warning
* @param e La excepción
*/
@Override
public void warning(org.xml.sax.SAXParseException e) {
System.out.println(e.getMessage());
}
/**
* Un error
* @param e La excepción
*/
@Override
public void error(org.xml.sax.SAXParseException e) {
System.out.println(e.getMessage());
}
/**
* Un error fatal
* @param e La excepción
*/
@Override
public void fatalError(org.xml.sax.SAXParseException e) {
System.out.println(e.getMessage());
}
}
}

67
src/mt/MT.java Archivo normal
Ver fichero

@@ -0,0 +1,67 @@
/* Copyright (c) 2017 Christopher Cromer
* Copyright (c) 2017 Carlos Faúndez
*
* This file is part of mt. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution.
* This file may not be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.
*/
package mt;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.scene.input.MouseEvent;
import org.w3c.dom.Document;
import java.io.File;
/**
* Esta clase es la clase princial de la Maquina Turing
*/
public class MT extends Application {
/**
* Metodo de JavaFX llamada para generar el interfaz grafico.
* @param primaryStage La ventana principal
* @throws Exception La excepción
*/
@Override
public void start(final Stage primaryStage) throws Exception{
//Parent root = FXMLLoader.load(getClass().getResource("mt.fxml"));
Group root = new Group();
primaryStage.setTitle("Maquina de Turing");
primaryStage.setScene(new Scene(root, 300, 275));
Button button = new Button("Elegir archivo");
button.setDefaultButton(true);
button.setLayoutX(130);button.setLayoutY(125);
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Abrir archivo XML");
File archivo = fileChooser.showOpenDialog(primaryStage);
LeerXML xml = new LeerXML();
Document document = xml.leerArchivo(archivo);
if (document != null) {
System.out.println(document.getDocumentElement().getNodeName());
}
}
};
button.addEventFilter(MouseEvent.MOUSE_CLICKED,eventHandler);
root.getChildren().add(button);
primaryStage.show();
}
/**
* El metodo principal del programa
* @param args Los argumentos pasado al programa
*/
public static void main(String[] args) {
launch(args);
}
}

Ver fichero

@@ -1,3 +1,3 @@
<GridPane fx:controller="sample.Controller"
<GridPane fx:controller="mt.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>

Ver fichero

@@ -1,4 +0,0 @@
package sample;
public class Controller {
}

Ver fichero

@@ -1,40 +0,0 @@
package sample;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
import javafx.scene.input.MouseEvent;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
//Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
Group root = new Group();
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
Button button = new Button("Exit");
button.setDefaultButton(true);
button.setLayoutX(130);button.setLayoutY(125);
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.exit(0);
}
};
button.addEventFilter(MouseEvent.MOUSE_CLICKED,eventHandler);
root.getChildren().add(button);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}