[SOURCE CODE VAN DE JAVA APPLICATIE]

hundredcarriageSoftware and s/w Development

Nov 3, 2013 (3 years and 7 months ago)

100 views









Windesheim


ISM4I Groep 3


[
SOURCE CODE VAN DE J
AVA
APPLICATIE
]



/* MainForm.java" */


//
-------------------------------------------------------------------------------------------------


package opdracht2;


import XML_DAl.Student;

import XML_DAl.SaxHandler;

import XML_DAl.StudentHandler;

import XML_DAl.XmlPdfCreator;

import XML_DAl.XmlReader;

import java.awt.event.ActionEvent;

import java.io.File;

Import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

import
java.util.Observable;

import java.util.Observer;

import javax.swing.JFileChooser;

import javax.swing.JMenu;

import javax.swing.JMenuItem;

import javax.swing.JOptionPane;

import javax.swing.filechooser.FileFilter;

import javax.swing.table.DefaultTableModel;


/**


*


* @author Laptop
-
Fakkert


*/

public class MainForm extends javax.swing.JFrame implements Observer {



private String selectedXmlBestand = null;



/** Creates new form Main */


public MainForm() {


initComponents();


Initial
ize();


}




private void OnNewStudentClick(java.awt.event.ActionEvent evt)


{


frmStudent NewStudentForm = new frmStudent();


Opdracht2App.getApplication().show(NewStudentForm);


}


private void OnNewRapportageClick(java.awt.event.ActionEvent evt)


{


String bsn = (String)this.jTable1.getModel().getValueAt(this.jTable1.getSelectedRow(),2);


try


{


ConfigurationFile configFile = new ConfigurationFile();


St
ring PDFIMAGELOCATION = configFile.GetProperties().getProperty("PDFIMAGELOCATION");


XmlPdfCreator.Create(this.selectedXmlBestand,PDFIMAGELOCATION,bsn);


}


catch(IOException ex)


{




}




}


private void OnChangeS
tudentClick(java.awt.event.ActionEvent evt)


{


if(this.jTable1.getSelectedRow() !=
-
1)


{


String bsn = (String)this.jTable1.getModel().getValueAt(this.jTable1.getSelectedRow(),2);



frmStudent ChangeStudentForm = ne
w frmStudent(bsn, this.selectedXmlBestand);


Opdracht2App.getApplication().show(ChangeStudentForm);


}


else


{


JOptionPane.showMessageDialog(null, "NoRowSelected");


}




}


private void Initialize()


{


JMenu mnuActies = new JMenu("Acties");


JMenu mnuStudent = new JMenu("Student");


JMenu mnuRapportages = new JMenu("Rapportages");


mnuActies.add(mnuStudent);


mnuActies.add(mnuRapportages);


JMenuItem mnuNewRapportage = new JMenuItem("nieuwe rapportage");


JMenuItem mnuNewStudent = new JMenuItem("nieuwe student");


JMenuItem mnuChangeStudent = new JMenuItem("change student");



mnuNewRapportage.addActionListener(new java.awt.eve
nt.ActionListener() {


public void actionPerformed(ActionEvent evt) {


OnNewRapportageClick(evt);


}


});


mnuChangeStudent.addActionListener(new java.awt.event.ActionListener() {


public void act
ionPerformed(java.awt.event.ActionEvent evt) {


OnChangeStudentClick(evt);


}


});


mnuNewStudent.addActionListener(new java.awt.event.ActionListener() {


public void actionPerformed(java.awt.event.ActionEve
nt evt) {


OnNewStudentClick(evt);


}


});




mnuStudent.add(mnuNewStudent);


mnuStudent.add(mnuChangeStudent);


mnuRapportages.add(mnuNewRapportage);



jMenuBar1.add(mnuActies);



}


private void OpenBestand(){



JFileChooser fileChooser = new JFileChooser();


fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);



//of dit makkelijker kon


fileChooser.setFileFilter(new FileFilter() {



@
Override


public boolean accept(File f) {


return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml");


}



@Override


public String getDescription() {


return "XML files";


}


});



if (fileChooser.showDialog(this, "OK") == JFileChooser.APPROVE_OPTION){




//Determine type bestand.


if(fileChooser.getSelectedFile().getName().toLowerCase().endsWith(".xml")){


this.OpenXmlBestand(fileChooser.getSelectedFile().getPath());


}








}




}



private void OpenXmlBestand(String bestandNaam){



try


{


this.selectedXm
lBestand = bestandNaam;


SaxHandler saxhandler = new SaxHandler();


HashMap< String, String[]> studenten = saxhandler.getStudenten(bestandNaam);




for(Map.Entry<String,String[]> entry: studenten.entrySet()){




((DefaultTableModel)this.jTable1.getModel()).addRow(entry.getValue());



}


}


catch(Exception ex)


{


JOptionPane.showMessageDialog(null, ex.getMessage());


}


}



public void update(Observable o, Object arg) {


((DefaultTableModel)this.jTable1.getModel()).addRow((String[])arg);


}


}



/* Configurationfile.java */

package opdracht2;

import java.util.Properties;

import java.io.*;

/**


*


* @author Patri
ck


*/

public class ConfigurationFile {




private Properties p_Properties;




public Properties GetProperties()


{


return p_Properties;


}

public ConfigurationFile()

{



try


{


Properties XSDConfig = new Properties();


FileReader fileWriter = new FileReader("configfile.cfg");


BufferedReader out = new BufferedReader (fileWriter);


XSDConfig.load(out);


this.p_Properties = XSDConfig;


out.close();


}

catch(IOException ex)

{


}



}



}




/* frmStudent.ja
va */


package opdracht2;


import Exceptions.XmlNotValidException;

import XML_DAl.Student;

import XML_DAl.Resultaat;

import XML_DAl.StudentHandler;

import XML_DAl.StudentManager;

import XML_DAl.StudentenAdministratie;

import XML_DAl.Vak;

import
java.util.logging.Level;

import java.util.logging.Logger;

import java.io.IOException;

import javax.swing.DefaultListModel;

import javax.swing.JOptionPane;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import java.u
til.regex.*;


/**


*


* @author Patrick


*/

public class frmStudent extends javax.swing.JFrame {



/** Creates new form frmStudent */


private StudentenAdministratie studentenAdministratie;


private Student student;


private Boolean EditMode;



public frmStudent(Student student) {


initComponents();


this.student = student;


this.EditMode = true;


Initialize();


}


private void Initialize()


{


this.txtSofinummer.setText(student.getSofinummer());


this.txtEmailAdres.setText(student.getAdres());


this.txtHuisnummer.setText(student.getHuisNummer());


this.txtMobielNummer.setText(student.getMobielNummer());


this.txtPlaats.setText(student.getPlaats());


this.txtPostcode.setText(student.
getPostcode());


this.txtStraat.setText(student.getStraat());


this.txtVoornaam.setText(student.getVoornaam());


this.txtAchternaam.setText(student.getAchternaam());


this.txtNetNummer.setText(student.getTelefoon());


this.txtSofinummer.setText(student.getSofinummer());


this.txtStudentnummer.setText(student.getStudentnummer());



DefaultListModel model = new DefaultListModel();


model.clear();


lstVakken.setModel(model);




for(Vak vak:student.
getVakken())


{


model.addElement(vak.getAfkorting());


}




}


public frmStudent()


{


this.EditMode = false;


initComponents();


}



public frmStudent(String bsnNummer, String BestandNaam)


{


try {



this.EditMode = false;


this.studentenAdministratie = new StudentHandler().getStudent(bsnNummer, BestandNaam);


this.student = this.studentenAdministratie.getStudenten().get(0);


initComponents();


th
is.Initialize();



//afhandeling nog bekijke.


} catch (IOException ex) {


Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);


} catch (SAXException ex) {


Logger.getLogger(frmStudent.cla
ss.getName()).log(Level.SEVERE, null, ex);


} catch (XmlNotValidException ex) {


Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);


} catch (ParserConfigurationException ex) {


Logger.getLogger(fr
mStudent.class.getName()).log(Level.SEVERE, null, ex);


}


}




private void OnButtonOkClick(java.awt.event.ActionEvent evt) {



/* Constraints check */


boolean formIsValid = true;


boolean emailIsValid = true;


boolean mobielIsValid = true;


if( this.txtEmailAdres.getText().isEmpty() != true )


{


Pattern pattern;


Matcher matcher;


Stri
ng email_pattern = "[a
-
zA
-
Z][
\
\
w
\
\
.
-
]*[a
-
zA
-
Z0
-
9]@[a
-
zA
-
Z0
-
9][
\
\
w
\
\
.
-
]*[a
-
zA
-
Z0
-
9]
\
\
.[a
-
zA
-
Z][a
-
zA
-
Z
\
\
.]*[a
-
zA
-
Z]";



pattern = Pattern.compile(email_pattern);


matcher = pattern.matcher(this.txtEmailAdres.getText());


emai
lIsValid = matcher.matches();


}


if( this.txtMobielNummer.getText().isEmpty() != true )


{


Pattern pattern;


Matcher matcher;


String mobiel_pattern = "06[0
-
9]{8}";



pattern = Pattern.comp
ile(mobiel_pattern);


matcher = pattern.matcher(this.txtMobielNummer.getText());


mobielIsValid = matcher.matches();


}



if( this.txtSofinummer.getText().isEmpty() ||


this.txtVoornaam.getText().isEm
pty() ||


this.txtVoornaam.getText().isEmpty() ||


this.txtStraat.getText().isEmpty() ||


this.txtHuisnummer.getText().isEmpty() ||


this.txtPlaats.getText().isEmpty() ||


this.txtPostcode.getText().isEmpty() ||


!emailIsValid || !mobielIsValid


)


{


formIsValid = false;


JOptionPane.showMessageDialog(rootPane, "Niet alle gegevens zijn correct of vol
ledig ingevuld!");


}


/* End of constraints */



if(formIsValid)


{


this.student = new Student();


this.student.setVoornaam(this.txtVoornaam.getText());


this.student.setAchternaam(this.txt
Achternaam.getText());


this.student.setAdres(this.txtEmailAdres.getText());


this.student.setHuisNummer(this.txtHuisnummer.getText());


this.student.setPlaats((this.txtPlaats.getText()));


this.student.setPostcode(this.
txtPostcode.getText());


this.student.setSofinummer(this.txtSofinummer.getText());


this.student.setStraat(this.txtStraat.getText());


this.student.setTelefoon(this.txtHuisnummer.getText());


this.student.setMobielNummer
(this.txtMobielNummer.getText());


this.student.sethuistelefoonnummer(this.txtNetNummer.getText());


this.student.setStudentnummer(this.txtStudentnummer.getText());


try


{



StudentManager.SaveStudentAdministratieToFile(studentenAdministratie);


}


catch(IOException ex)


{


JOptionPane.showMessageDialog(null, "Er is een fout opgetreden bij het wegschrijven van het
bestand");


}


}


else


{



}


}



private void OnSelectionChanged(ja
vax.swing.event.ListSelectionEvent evt) {




Vak selectedVak = this.student.getVakken().get(lstVakken.getSelectedIndex());


DefaultListModel model = new DefaultListModel();


model.clear();



lstResultaten.setModel(model);



if(selectedVak != null)


{


for(Resultaat resultaat:selectedVak.getResultaten())


{


model.addElement(String.format("%s %s","vaktest",resultaat.getCijfer()));



}


}



}



private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:


this.dispose();


}



/**


* @param args the command line arguments


*/


public static void main(String args[]) {


java.awt.EventQueue.invokeLater(new Runnable() {


public void run() {



new frmStudent().setVisible(true);


}


});


}



// Variables declaration
-

do not modify


private javax.swing.JLabel Netnummer;


private javax.swing.JButton jButton1;


private javax.swing.JButton jButt
on2;


private javax.swing.JLabel jLabel10;


private javax.swing.JLabel jLabel11;


private javax.swing.JLabel jLabel12;


private javax.swing.JLabel jLabel13;


private javax.swing.JLabel jLabel2;


private javax.swing.JLabel jLabel3;


private javax.swing.JLabel jLabel4;


private javax.swing.JLabel jLabel5;


private javax.swing.JLabel jLabel6;


private javax.swing.JLabel jLabel7;


private javax.swing.JLabel jLabel8;


private javax.swing.JLabel jLabel9;


private java
x.swing.JScrollPane jScrollPane1;


private javax.swing.JScrollPane jScrollPane2;


private java.awt.Label label1;


private java.awt.Label label7;


private javax.swing.JList lstResultaten;


private javax.swing.JList lstVakken;


private java
x.swing.JTextField txtAchternaam;


private javax.swing.JTextField txtEmailAdres;


private javax.swing.JTextField txtHuisnummer;


private javax.swing.JTextField txtMobielNummer;


private javax.swing.JTextField txtNetNummer;


private javax.swi
ng.JTextField txtPlaats;


private javax.swing.JTextField txtPostcode;


private javax.swing.JTextField txtSofinummer;


private javax.swing.JTextField txtStraat;


private javax.swing.JTextField txtStudentnummer;


private javax.swing.JTextField

txtVoornaam;


// End of variables declaration


}



/* Cursus.java */

/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import org.w3c.dom.Document;

import
org.w3c.dom.Element;


/**


*


* @author Patrick


*/

public class Cursus implements XMLEntity {



private String p_xmlContent;


private Document p_XmlDoc;


private String afkorting;


private String naam;


private String beschrijving;


priv
ate String docentNummer;


public void Create(Document p_xml,Element currentNode)


{


this.p_XmlDoc = p_xml;



Element e_cursus = this.p_XmlDoc.createElement("cursus");



e_cursus.setAttribute("afkorting", getAfkorting());


e_cursus.setAttribute("naam", getNaam());


e_cursus.setAttribute("beschrijving", getBeschrijving());


e_cursus.setAttribute("docentnummer", getDocentNummer());


currentNode.appendChild(e_cursus);




}


public String
getXmlContent()


{


return p_xmlContent;


}


public Document GetXMLDoc()


{


return p_XmlDoc;


}



/**


* @return the afkorting


*/


public String getAfkorting() {


return afkorting;


}



/**


* @
param afkorting the afkorting to set


*/


public void setAfkorting(String afkorting) {


this.afkorting = afkorting;


}



/**


* @return the naam


*/


public String getNaam() {


return naam;


}



/**


* @param naam the naam to set


*/


public void setNaam(String naam) {


this.naam = naam;


}



/**


* @return the beschrijving


*/


public String getBeschrijving() {


return beschrijving;


}



/**


* @par
am beschrijving the beschrijving to set


*/


public void setBeschrijving(String beschrijving) {


this.beschrijving = beschrijving;


}



/**


* @return the docentNummer


*/


public String getDocentNummer() {


return docentNummer;


}



/**


* @param docentNummer the docentNummer to set


*/


public void setDocentNummer(String docentNummer) {


this.docentNummer = docentNummer;


}



}




/* docent.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import org.w3c.dom.Document;

import org.w3c.dom.Element;


/**


*


* @author Patrick


*/

public class Docent extends Persoon implements
XMLEntity {



private Document p_xmlDoc;


private String xmlContent;


private String docentNummer;


private String kamerNummer;



public void Create(Document p_xml,Element currentNode)


{


this.setP_xmlDoc(p_xml);



Element Doc
ent = p_xml.createElement("Docent");


Docent.setAttribute("sofinummer", super.getSofinummer());


Docent.setAttribute("docentnummer", this.getDocentNummer());


Docent.setAttribute("kamernummer", this.getKamerNummer());


currentNode.appendChi
ld(Docent);



}


public String getXmlContent()


{


return this.xmlContent;


}


public Document GetXMLDoc()


{


return this.getP_xmlDoc();


}



/**


* @return the p_xmlDoc


*/


public Document getP_xmlDoc() {


return p_xmlDoc;


}



/**


* @param p_xmlDoc the p_xmlDoc to set


*/


public void setP_xmlDoc(Document p_xmlDoc) {


this.p_xmlDoc = p_xmlDoc;


}



/**


* @param xmlContent the xmlContent to set


*/


public v
oid setXmlContent(String xmlContent) {


this.xmlContent = xmlContent;


}



/**


* @return the docentNummer


*/


public String getDocentNummer() {


return docentNummer;


}



/**


* @param docentNummer the docentNummer to set


*/


public void setDocentNummer(String docentNummer) {


this.docentNummer = docentNummer;


}



/**


* @return the kamerNummer


*/


public String getKamerNummer() {


r
eturn kamerNummer;


}



/**


* @param kamerNummer the kamerNummer to set


*/


public void setKamerNummer(String kamerNummer) {


this.kamerNummer = kamerNummer;


}


}




/* Persoon.java */


package XML_DAl;

import
XML_DAl.XMLEntity;

import XML_DAl.XMLTransformer;

import com.sun.org.apache.xerces.internal.dom.DocumentImpl;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;

import java.io.StringWriter;

import java.io.Writer;

import org.w3c.dom.Document;

im
port org.w3c.dom.Element;

import org.w3c.dom.Node;

/**


*


* @author Patrick


*/

public class Persoon implements XMLEntity

{



protected Element e_persoon;


private String sofinummer;


private String voornaam;


private String achternaam;


pr
ivate String straat;


private String huistelefoonnummer;


private String mobielNummer;


private String huisNummer;


private String postcode;


private String plaats;


private String adres;


private String telefoon;


protected String XmlContent;


protected Document p_xmldoc;



public Persoon(Document xmldoc)


{


this.p_xmldoc = xmldoc;


}


public Persoon()


{




}


public Persoon(Persoon persoon)


{


this.sofinummer = persoon.getSofinummer();


this.achternaam = persoon.getAchternaam();


this.voornaam = persoon.getVoornaam();


this.adres = persoon.getAdres();


this.huistelefoonnummer = persoon.gethuistelefoonnummer();



this.plaats = persoon.getPlaats();


this.telefoon = persoon.getTelefoon();


this.mobielNummer = persoon.getMobielNummer();


this.huisNummer = persoon.getHuisNummer();


this.straat = persoon.getStraat();



}


public String getXmlContent()


{


return this.XmlContent;


}


public Document GetXMLDoc()


{


return this.p_xmldoc;


}


public void Create(Document p_xml,Element currentnode)


{


this.p_xmldoc = p_xml;


e_persoo
n = p_xmldoc.createElement("Persoon");




Element e_naam = p_xmldoc.createElement("naam");


Element e_adres = p_xmldoc.createElement("adres");


Element e_contact = p_xmldoc.createElement("Contact");


Element e_email = p_xm
ldoc.createElement("Email");


Element e_mobiel = p_xmldoc.createElement("mobiel");


Element e_telefoon = p_xmldoc.createElement("telefoon");


e_persoon.setAttribute("sofinummer", getSofinummer());


e_naam.setAttribute("voornaam"
, getVoornaam());


e_naam.setAttribute("achternaam", getAchternaam());



e_adres.setAttribute("straat", getStraat());


e_adres.setAttribute("huisnummer",this.getHuisNummer());


e_adres.setAttribute("postcode",this.getPostcode())
;


e_adres.setAttribute("plaats", getPlaats());




e_email.setAttribute("adres", getAdres());


e_mobiel.setAttribute("nummer", this.getMobielNummer());


e_telefoon.setAttribute("nummer", this.gethuistelefoonnummer());


e_persoon.appendChild(e_naam);


e_persoon.appendChild(e_adres);


e_contact.appendChild(e_email);


e_contact.appendChild(e_mobiel);


e_contact.appendChild(e_telefoon);


e_persoon.appendChild(e_contact);


// e
_persoon.appendChild(e_contact);


// e_persoon.appendChild(e_email);


// e_persoon.appendChild(e_mobiel);


// e_persoon.appendChild(e_telefoon);


currentnode.appendChild(e_persoon);



this.XmlContent = XMLTransformer.TransFormDOM(p_xmldoc);




}



/**


* @return the sofinummer


*/


public String getSofinummer() {


return sofinummer;


}



/**


* @param sofinummer the sofinummer to set



*/


public void setSofinummer(String sofinummer) {


this.sofinummer = sofinummer;


}



/**


* @return the voornaam


*/


public String getVoornaam() {


return voornaam;


}



/**


* @param voornaam the voornaam to set


*/


public void setVoornaam(String voornaam) {


this.voornaam = voornaam;


}



/**


* @return the achternaam


*/


public String getAchternaam() {


return achternaam;


}




/**


* @param achternaam the achternaam to set


*/


public void setAchternaam(String achternaam) {


this.achternaam = achternaam;


}



/**


* @return the straat


*/


public String getStraat() {


return straat;


}



/**


* @param straat the straat to set


*/


public void setStraat(String straat) {


this.straat = straat;


}



/**


* @return the huis


*/


public String gethuistelefoonnummer() {


return huistelefoonnummer;


}



/**


* @param huis the huis to set


*/


public void sethuistelefoonnummer(String huis) {


this.huistelefoonnummer = huis;


}



/**


* @return the postcode


*/


public String getPostcode() {


return postcode;


}



/**


* @param postcode the postcode to set


*/


public void setPostcode(String postcode) {


this.postcode = postcode;


}



/**


* @return the plaats


*/



public String getPlaats() {


return plaats;


}



/**


* @param plaats the plaats to set


*/


public void setPlaats(String plaats) {


this.plaats = plaats;


}



/**


* @return the adres


*/


public String getAdres() {


return adres;


}



/**


* @param adres the adres to set


*/


public void setAdres(String adres) {


this.adres = adres;


}



/**


* @return the telefoon


*/


public String getTe
lefoon() {


return telefoon;


}



/**


* @param telefoon the telefoon to set


*/


public void setTelefoon(String telefoon) {


this.telefoon = telefoon;


}



/**


* @return the mobielNummer


*/


public String getMobielNummer() {


return mobielNummer;


}



/**


* @param mobielNummer the mobielNummer to set


*/


public void setMobielNummer(String mobielNummer) {


this.mobielNummer = mobielNummer;


}



/**



* @return the huisNummer


*/


public String getHuisNummer() {


return huisNummer;


}



/**


* @param huisNummer the huisNummer to set


*/


public void setHuisNummer(String huisNummer) {


this.huisNummer = huisNummer;


}





}





/* resultaat.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;


/**


*


* @author Patrick


*/

public class Resultaat implements XMLEntity {



private Document p_xml;



private String beschrijving;


private String cijfer;


private String XMLContent;


public Resultaat(Document p_xml)


{


this.p_xml = p_xml;


}



Resultaat() {


}



public void Create(Document xml,Element currentNode)


{


this.p_xml = xml;


Element resultaat = this.p_xml.createElement("resultaat");


resultaat.setAttribute("beschrijving
", getBeschrijving());


resultaat.setAttribute("cijfer", getCijfer());


currentNode.appendChild(resultaat);


this.XMLContent = XMLTransformer.TransFormDOM(this.p_xml);


// this.setXMLContent(this.p_xml.toString());


}


public St
ring getXmlContent()


{


return getXMLContent();


}


public Document GetXMLDoc()


{


return p_xml;


}



/**


* @return the beschrijving


*/


public String getBeschrijving() {


return beschrijving;


}



/**


* @param beschrijving the beschrijving to set


*/


public void setBeschrijving(String beschrijving) {


this.beschrijving = beschrijving;


}



/**


* @return the cijfer


*/


public String getCijfer() {


ret
urn cijfer;


}



/**


* @param cijfer the cijfer to set


*/


public void setCijfer(String cijfer) {


this.cijfer = cijfer;


}



/**


* @return the XMLContent


*/


public String getXMLContent() {


return XMLContent;


}



/**


* @param XMLContent the XMLContent to set


*/


public void setXMLContent(String XMLContent) {


this.XMLContent = XMLContent;


}




}



/* student.java */


/*


* To change this template, cho
ose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import XML_DAl.Vak;

import XML_DAl.XMLTransformer;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;

import com.sun.org.apache.xml.internal.serialize.XMLSeria
lizer;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.StringWriter;

import java.util.ArrayList;

import java.util.List;

import javax.swing.JOptionPane;

import javax.xml.transform.Transformer;

import
javax.xml.transform.TransformerConfigurationException;

import javax.xml.transform.TransformerException;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import org.w3c.
dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;


/**


*


* @author Patrick


*/

public class Student extends Persoon

{


private String studentnummer;



private List<Vak> Vakken;


public Student(Document p_xmldoc)


{


super(p_xmldoc);


this.Vakken = new ArrayList<Vak>();


}


public Student()


{


this.Vakken = new ArrayList<Vak>();


}



public void AddVak(Vak vak)


{


this.Vakken.add(vak);


}


public void Create(Document p_xml,Element currentNode)


{


this.p_xmldoc = p_xml;


Element student = this.p_xmldoc.createElement("student");


student.setAttribute("sofinummer",super.getSofinummer());


student.setAttribute("st
udentnummer", getStudentnummer());



currentNode.appendChild(student);


if(getVakken() != null)


{


for(Vak vak: this.getVakken())


{


vak.Create(this.p_xmldoc,student);


// this.p_xmldoc.appendChil
d(vak.GetXMLDoc().getDocumentElement());


}


}



this.XmlContent = XMLTransformer.TransFormDOM(p_xmldoc);


}



/**


* @return the studentnummer


*/


public String getStudentnummer() {


return studentnummer;


}



/**


* @param studentnummer the studentnummer to set


*/


public void setStudentnummer(String studentnummer) {


this.studentnummer = studentnummer;


}



/**


* @return the Vakken


*/


public List<Vak> getVakken() {



return Vakken;


}



/**


* @param Vakken the Vakken to set


*/


public void setVakken(List<Vak> Vakken) {


this.Vakken = Vakken;


}

}





/* studentenAdministratie.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import java.util.ArrayList;

import java.util.List;

import opdracht2.ConfigurationFile;

import org.w3c.dom.Document;

import org.w3c.dom.Eleme
nt;


/**


*


* @author Patrick


*/

public class StudentenAdministratie implements XMLEntity {



private Document p_xmldoc;


private Element e_personen;


private Element e_studenten;


private Element e_docenten;


private Element e_cursussen;



private List<Student> studenten;


private List<Docent> docenten;


private List<Cursus> cursussen;




private String xmlContent;


public StudentenAdministratie(Document p_xmldoc)


{


this.p_xmldoc = p_xmldoc;



}


public St
udentenAdministratie()


{


this.studenten = new ArrayList<Student>();


this.docenten = new ArrayList<Docent>();


this.cursussen = new ArrayList<Cursus>();


}


public void AddStudent(Student student )


{


studenten.add(student
);


}


public List<Student> GetStudenten()


{


return this.studenten;


}


public void AddDocent(Docent docent)


{


docenten.add(docent);


}


public void AddCursus(Cursus cursus)


{


cursussen.add(cursus);


}



public List<Student> getStudenten(){


return this.studenten;


}



public List<Docent> getDocenten(){


return this.docenten;


}



public List<Cursus> getCursusen(){



return this.cursussen;


}



public Strin
g getXmlContent()


{


return this.xmlContent;


}


public Document GetXMLDoc()


{


return this.p_xmldoc;


}


public void Create(Document p_xml,Element currrentNode)


{


ConfigurationFile configFile = new ConfigurationFile();


this.p_xmldoc = p_xml;


Element studentenAdministratie = this.p_xmldoc.createElement("studentenadministratie");


studentenAdministratie.setAttributeNS("http://www.w3.org/2000/xm
lns/","xmlns:xsi","http://www.w3.org/2001/X
MLSchema
-
instance");


studentenAdministratie.setAttributeNS("http://www.w3.org/2000/xmlns",
"xsi:noNamespaceSchemaLocation",configFile.GetProperties().getProperty("XSDLOCATION"));


this.e_personen = this.p
_xmldoc.createElement("personen");


this.e_studenten = this.p_xmldoc.createElement("studenten");


this.e_docenten = this.p_xmldoc.createElement("docenten");


this.e_cursussen = this.p_xmldoc.createElement("cursussen");


studentenAdministrat
ie.appendChild(this.e_personen);


studentenAdministratie.appendChild(this.e_docenten);


studentenAdministratie.appendChild(this.e_cursussen);


studentenAdministratie.appendChild(this.e_studenten);




this.p_xmldoc.appendChild(studentenA
dministratie);


for(Student student:this.studenten)


{


student.Create(this.p_xmldoc,this.e_studenten);


// this.e_studenten.appendChild(student.GetXMLDoc().getDocumentElement());


Persoon persoon = new Persoon((Persoon)student
);



persoon.Create(this.p_xmldoc,this.e_personen);


// persoon.Create(this.p_xmldoc);

// this.e_personen.appendChild(persoon.GetXMLDoc());


}



for(Docent docent:this.docenten)


{


docent.Create(p_xml,this.e_docente
n);


}


for(Cursus cursus:this.cursussen)


{


cursus.Create(p_xml, this.e_cursussen);


}


this.xmlContent = XMLTransformer.TransFormDOM(this.p_xmldoc);



}

}





/* vak.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;


/**


*


* @author Patrick


*/

public class Vak implements XMLEntity {



private Document p_xmldoc;


private String XMLContent;


private String afkorting;



private List<Resultaat> Resultaten;


public Vak(Document p_xmldoc)


{


this.p_xml
doc = p_xmldoc;


this.Resultaten = new ArrayList<Resultaat>();


}



Vak() {


//graag een lege constructor als je de deafault overschrijft :D


this.Resultaten = new ArrayList<Resultaat>();


}



public void AddResultaat(Resultaat resultaat)


{


getResultaten().add(resultaat);


}


public void Create(Document p_xml,Element currentNode)


{


this.p_xmldoc = p_xml;


Element vak = this.p_xmldoc.createElement("vak");


Element resultaten = this.p_xmldoc.createElement("resultaten");



vak.setAttribute("afkorting", this.getAfkorting());



for(Resultaat resultaat: this.getResultaten())


{


resultaat.Create(this.p_xmldoc,resultaten);


}



vak.appendChild(resultaten);


currentNode.appendChild(vak);


this.XMLContent = XMLTransformer.TransFormDOM(this.p_xmldoc);


}


public String getXmlContent()


{



return XMLContent;


}


public Document GetXMLDoc()


{



return p_xmldoc;



}



/**


* @return the afkorting


*/


public String getAfkorting() {


return afkorting;


}



/**


* @param afkorting the afkorting to set


*/


public void setAfkorting(String afkorting) {


this.afkorting = afkorting;


}



/**


* @return the Resultaten


*/


public List<Resultaat> getResultaten() {


return Resultaten;


}



/**


* @param Resultaten the Resultaten to set


*/


public void setResult
aten(List<Resultaat> Resultaten) {


this.Resultaten = Resultaten;


}


}





/* XMLEntity.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import
org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;


/**


*


* @author Patrick


*/

public interface XMLEntity {



public void Create(Document p_xml,Element currentNode);


public String getXmlContent();


public Document GetXM
LDoc();


}





/* XMLTransformer.java */

/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import java.io.IOException;

import java.io.StringWriter;

import javax.swing.JOptionPane;

import
javax.xml.transform.OutputKeys;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult
;

import org.w3c.dom.Document;


/**


*


* @author Patrick


*/

public class XMLTransformer {




public static String TransFormDOM(Document p_xmldoc)


{


try


{


StringWriter writer = new StringWriter();


StreamResult result
= new StreamResult(writer);



Transformer transformer = TransformerFactory.newInstance().newTransformer();


transformer.setOutputProperty(OutputKeys.INDENT, "yes");



DOMSource source = new DOMSource(p_xmldoc);


transformer.transform(source, result);


return writer.toString();


}


catch(TransformerException ex)


{


ex.printStackTrace();


return "";


}


}

}




/* XmlPdfCreator.java */


package XML_DAl;


import java.io.Fil
e;

import java.io.IOException;

import java.io.OutputStream;

import java.util.logging.Level;

import java.util.logging.Logger;


import javax.xml.transform.Result;

import javax.xml.transform.Source;

import javax.xml.transform.Transformer;

import
javax.xml.transform.TransformerFactory;

import javax.xml.transform.sax.SAXResult;

import javax.xml.transform.stream.StreamSource;

import opdracht2.ConfigurationFile;

import org.apache.fop.apps.FOUserAgent;


import org.apache.fop.apps.FopFactory;

import org
.apache.fop.apps.Fop;

import org.apache.fop.apps.MimeConstants;


/**


*


* @author JosVinke


*/

public class XmlPdfCreator {



public static void Create(String xmlfile,String logo, String bsn) throws IOException


{


ConfigurationFile file = ne
w ConfigurationFile();



String pdfFile = file.GetProperties().getProperty("PDFSAVELOCATION");


String xsltFile = file.GetProperties().getProperty("XSLTLOCATION");


File xsltfile = new File(xsltFile);


File pdffile = new File(p
dfFile + "
\
\
rapportage.pdf");




FopFactory fopFactory = FopFactory.newInstance();


FOUserAgent foUserAgent = fopFactory.newFOUserAgent();



OutputStream out = new java.io.FileOutputStream(pdffile);


out = new java.io.BufferedOutputStream(out);



try {



Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);



TransformerFactory factory = TransformerFactory.newInstance();


Transformer transforme
r = factory.newTransformer(new StreamSource(xsltfile));




transformer.setParameter("bsn", bsn);


transformer.setParameter("image", logo);




Source src = new StreamSource(new File(xmlfile));



Result res = new
SAXResult(fop.getDefaultHandler());


transformer.transform(src, res);



}


catch (Exception e) {


Logger.getLogger("XmlPdfCreator").log(Level.SEVERE, null, e);


}


finally {


out.close();


}


}

}




/* xmlreader.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import Exceptions.XmlNotValidException;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;

import opdracht2.ConfigurationFile;

import org.xml.sax.SAXException;

import org.xml.sax.helper
s.DefaultHandler;

/**


*


* @author Laptop
-
Fakkert


*/

public class XmlReader{



private DefaultHandler defaultHandler;


private InputStream xmlStream;



public XmlReader(String bestandNaam, DefaultHandler defaultHandler) throws IOException, SAXException,
XmlNotValidException, ParserConfigurationException{



try


{


xmlStream = new FileInputStream(bestandNaam);



XmlValidat
or validator = new XmlValidator(this.xmlStream);


xmlStream = new FileInputStream(bestandNaam);


ConfigurationFile file = new ConfigurationFile();


validator.SetXsd(file.GetProperties().getProperty("XSDLOCATION"));


if(valid
ator.Validate())


{


this.defaultHandler = defaultHandler;


// this.xmlStream.reset();


SAXParserFactory factory = SAXParserFactory.newInstance();


SAXParser saxParser = factory.newSAXParser();


//saxParser.par


saxParser.parse(this.xmlStream, this.defaultHandler);




}


else


{


throw new XmlNotValidException();


}


// validator.SetXsd();


}


catch(IOException ex)


{


throw ex;


}


catch(SAXException ex)


{


throw ex;


}




}



}






/* xmlvalidator.java

*/


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;

import java.io
.IOException;

import java.io.InputStream;

import javax.xml.transform.stream.StreamSource;

import javax.xml.validation.*;

import org.xml.sax.SAXException;

/**


*


* @author Patrick


*/

public class XmlValidator {





private String p_xsd;


private String p_xml;



private InputStream xmlStream;


private String schemaLang = "http://www.w3.org/2001/XMLSchema";



// get validation driver:


SchemaFactory factory;


Schema schema;


Validator validator;


public XmlVa
lidator()


{


factory = SchemaFactory.newInstance(schemaLang);


}



public XmlValidator(InputStream inputStream)


{


this();


this.xmlStream = inputStream;


}



public void SetXsd(String Xsd) throws SAXException


{


try


{


p_xsd = Xsd;


schema = factory.newSchema(new StreamSource(Xsd));


}


catch(SAXException ex)


{


throw ex;


}


}



public void SetXml(String Xml)


{


p_xml

= Xml;


}


public String GetXml()


{


return p_xml;


}


public Boolean Validate()


{


try


{




validator = schema.newValidator();




schema = factory.newSchema(new StreamSource(p_xsd));


if(this.xmlStream == null)


{


validator.validate(new StreamSource(p_xml));


}


else


{


validator.validate(new StreamSource(this.xmlStream));


}


return true;


}


catch(IOException ex)



{


return false;



}


catch(SAXException ex)


{


return false;




}


}

}





/* XmlNotValidException.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package
Exceptions;

import java.lang.*;

/**


*


* @author Patrick


*/

public class XmlNotValidException extends Exception {




public XmlNotValidException()


{




}


}





/* Saxhandler.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import Exceptions.XmlNotValidException;

import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

import java.util.Observer;

import javax.xml.parsers.ParserConfigurationExcept
ion;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;


/**


*


* @author Laptop
-
Fakkert


*/

public class SaxHandler extends DefaultHandler {



private String sofinummer = null;


private Observer Observer;


HashMap< Strin
g, String[]> bla = new HashMap<String, String[]>();



public HashMap< String, String[]> getStudenten(String bestandsNaam) throws IOException, SAXException,
XmlNotValidException, ParserConfigurationException {



XmlReader XmlReader2 = new XmlReade
r(bestandsNaam, this);


return this.bla;



}



@Override


public void startElement(String uri, String localName, String qName, org.xml.sax.Attributes attributes) throws
SAXException {



if (qName.equalsIgnoreCase("persoon")) {


this.sofinummer = attributes.getValue("sofinummer");


}



if (this.sofinummer != null && qName.equalsIgnoreCase("naam")){




String[] Data = new String[3];



Data[0] = attribu
tes.getValue("voornaam");


Data[1] = attributes.getValue("achternaam");


Data[2] = this.sofinummer;


this.bla.put(this.sofinummer, Data);


this.sofinummer = null;


}



if(qName.eq
ualsIgnoreCase("docent")){



bla.remove(attributes.getValue("sofinummer"));



}



}

}




/* studentmanager.java */


/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package XML_DAl;


import com.sun.org.apache.xerces.internal.dom.DocumentImpl;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import opdracht2.ConfigurationFile;


/**


*


* @author Patrick


*/

public class StudentManager

{



public static void

SaveStudentAdministratieToFile(StudentenAdministratie administratie) throws IOException


{


ConfigurationFile configFile = new ConfigurationFile();



administratie.Create(new DocumentImpl(), null);


Integer counter = 0;


File file;


String OutputDirectory = configFile.GetProperties().getProperty("XMLSAVELOCATION");


do


{


counter++;



file = new File(String.format("%s
\
\
student%s.xml",OutputDirectory,counter));



} while(file.exists());



try


{


FileWriter fileWriter = new FileWriter(String.format("%s
\
\
student%s.xml",OutputDirectory,counter));



fileWriter.write(administratie.getXmlContent());



fileWriter.close();



}



catch(IOException ex)


{


throw ex;


}


}


}