Created
November 23, 2010 08:17
-
-
Save bussiere/711449 to your computer and use it in GitHub Desktop.
Algorithm de merde >.>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Test; | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Enumeration; | |
import java.util.HashMap; | |
import java.util.Dictionary; | |
import java.util.Hashtable; | |
public class Generation | |
{ | |
private static final String String = null; | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) | |
{ | |
String Code = "1"; | |
String Nom = "2"; | |
String URL_appli ="3"; | |
String Commentaire = "4"; | |
String URL_logo = "5"; | |
Dictionary<String, String> Type_de_stockage_des_habilitations = new Hashtable<String, String>(); | |
Type_de_stockage_des_habilitations.put("Stockage de type DGCP long", "id4_1"); | |
Type_de_stockage_des_habilitations.put("Stockage de type DGCP court", "id4_2"); | |
Type_de_stockage_des_habilitations.put("Stockage de type DGI court", "id4_3"); | |
Dictionary<String, String> Delegation_de_profils = new Hashtable<String, String>(); | |
Delegation_de_profils.put("Oui", "id5_1"); | |
Delegation_de_profils.put("Non", "id5_2"); | |
Dictionary<String, String> Exclusion_Administrateur_Utilisateur = new Hashtable<String, String>(); | |
Exclusion_Administrateur_Utilisateur.put("Oui", "id6_1"); | |
Exclusion_Administrateur_Utilisateur.put("Non", "id6_2"); | |
Dictionary<String, String> Multi_Habilitations = new Hashtable<String, String>(); | |
Multi_Habilitations.put("Oui", "id7_1"); | |
Multi_Habilitations.put("Non", "id7_2"); | |
Dictionary<String, String> Type_de_gestion_du_code_structure = new Hashtable<String, String>(); | |
Type_de_gestion_du_code_structure.put("Code structure d'affectation seul", "id8_1"); | |
Type_de_gestion_du_code_structure.put("Filtre seul", "id8_2"); | |
Type_de_gestion_du_code_structure.put("Code structure d'affectation et filtre", "id8_3"); | |
Type_de_gestion_du_code_structure.put("Code structure d'affectation ou filtre", "id8_4"); | |
Dictionary<String, String> Periode_de_validite = new Hashtable<String, String>(); | |
Periode_de_validite.put("Oui", "id9_1"); | |
Periode_de_validite.put("Non", "id9_2"); | |
String codeprofil = "6"; | |
String libelleprofil = "7"; | |
String Commentaireprofil = "8"; | |
String Codefiltre = "9"; | |
Dictionary<String, String[]> Type_de_filtre = new Hashtable<String, String[]>(); | |
String[] id3 = {"label=Valeur plafond","label=Valeur plancher","label=Enumeration de valeurs"}; | |
Type_de_filtre.put("id3", id3); | |
Dictionary<String, String> Filtre_delegue = new Hashtable<String, String>(); | |
Periode_de_validite.put("Oui", "id4_1"); | |
Periode_de_validite.put("Non", "id4_2"); | |
Object[] ListeVariable = { | |
Code, | |
Nom, | |
URL_appli, | |
Commentaire, | |
URL_logo, | |
Type_de_stockage_des_habilitations, | |
Delegation_de_profils, | |
Exclusion_Administrateur_Utilisateur, | |
Multi_Habilitations, | |
Type_de_gestion_du_code_structure, | |
Periode_de_validite, | |
codeprofil, | |
libelleprofil, | |
Commentaireprofil, | |
Codefiltre, | |
Type_de_filtre, | |
Filtre_delegue | |
}; | |
ArrayList<ArrayList<String>> rendu = new ArrayList<ArrayList<String>>(); | |
System.out.println(Nom.getClass().toString()); | |
System.out.println(Nom.getClass().toString().equals("class java.lang.String")); | |
rendu = parcours(ListeVariable,rendu); | |
System.out.println("final"+rendu.toString()); | |
File f; | |
f=new File("d:/generation.xml"); | |
if(!f.exists()){ | |
try | |
{ | |
f.createNewFile(); | |
} | |
catch (IOException e) | |
{ | |
System.out.println(e); | |
} | |
FileWriter fstream; | |
try | |
{ | |
fstream = new FileWriter("d:/generation.xml"); | |
BufferedWriter out = new BufferedWriter(fstream); | |
out.write("<?xml version='1.0' encoding='UTF-8'?>"); | |
out.write("<dataset>"); | |
out.write("<SIZE size="+rendu.size()+">"); | |
for (int i=0;i < rendu.size();i++) | |
{ | |
out.write("<APP"+i+""); | |
out.write("size="+rendu.get(i).size()+""); | |
for (int j=0;j<rendu.get(i).size();j++) | |
{ | |
out.write("attrib"+j+"="+rendu.get(i).get(j)+""); | |
} | |
out.write(">"); | |
} | |
out.write("</dataset>"); | |
out.close(); | |
} | |
catch (IOException e1) | |
{ | |
System.out.println(e1); | |
} | |
} | |
} | |
public static ArrayList<ArrayList<String>> parcours(Object[] ListeVariable,ArrayList<ArrayList<String>> pRendu) | |
{ | |
int i = 0; | |
for (i=0;i < ListeVariable.length;i++) | |
{ | |
System.out.println("parcours"+pRendu.toString()); | |
pRendu = add(ListeVariable[i],pRendu); | |
} | |
System.out.println("Avant final"+pRendu.toString()); | |
return pRendu; | |
} | |
public static ArrayList<ArrayList<String>> add(Object objet,ArrayList<ArrayList<String>> pRendu) | |
{ | |
System.out.println(objet.getClass().toString()); | |
if (objet.getClass().toString().equals("class java.lang.String")) | |
{ | |
System.out.println("objet1 :"+objet); | |
int i = 0; | |
for (i=0;i<pRendu.size();i++) | |
{ | |
System.out.println("objet2 :"+objet); | |
System.out.println("prendu"+pRendu.toString()); | |
pRendu.get(i).add((String)objet); | |
System.out.println("listeglobaleadd"+pRendu.toString()); | |
} | |
if (pRendu.size() == 0) | |
{ | |
pRendu.add(i,new ArrayList<String>()); | |
pRendu.get(i).add((String)objet); | |
} | |
} | |
else | |
{ | |
if (objet.getClass().toString().equals("class java.util.Hashtable")) | |
{ | |
System.out.println("tititititititit"); | |
System.out.println(objet.toString()); | |
System.out.println(((Dictionary) objet).keys()); | |
int k = 0; | |
int l = pRendu.size(); | |
ArrayList<ArrayList<String>> listeTemp = new ArrayList<ArrayList<String>>(); | |
for (int j=0;j< l ; j++) | |
{ | |
ArrayList<String> temp; | |
for (Enumeration e = ((Dictionary) objet).keys() ; e.hasMoreElements() ;) | |
{ | |
Object obj = ((Dictionary)objet).get(e.nextElement()); | |
System.out.println("test4:"+obj.getClass()); | |
System.out.println("j:"+j); | |
if (obj.getClass().toString().equals("class java.lang.String")) | |
{ | |
temp = (ArrayList<java.lang.String>) pRendu.get(j).clone(); | |
System.out.println("test5."+obj); | |
System.out.println("liste:"+pRendu.get(j).clone()); | |
System.out.println("ListeTemp:"+listeTemp.toString()); | |
temp.add((java.lang.String)obj); | |
listeTemp.add( | |
(ArrayList<java.lang.String>) | |
temp.clone()); | |
System.out.println("liste:"+pRendu.get(j).clone()); | |
System.out.println("ListeTemp:"+listeTemp.toString()); | |
} | |
else | |
{ | |
if (obj.getClass().toString().equals("class [Ljava.lang.String;")) | |
{ | |
String titi = ""; | |
String[] toti = (String[]) obj; | |
for (int i=0 ; i < toti.length ; i++) | |
{ | |
System.out.println("test5.5"+toti[i]); | |
temp = (ArrayList<java.lang.String>) pRendu.get(j).clone(); | |
temp.add(toti[i]); | |
listeTemp.add((ArrayList<java.lang.String>) temp.clone()); | |
System.out.println("liste:"+pRendu.get(j).clone()); | |
System.out.println("ListeTemp:"+listeTemp.toString()); | |
} | |
} | |
} | |
System.out.println("Zarb"+objet.getClass().toString()); | |
System.out.println("Zarbobjet"+objet.toString()); | |
} | |
} | |
pRendu = (ArrayList<ArrayList<java.lang.String>>) listeTemp.clone(); | |
} | |
} | |
return pRendu; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment