1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
NodeList fctRecupXML(String nameFile, String path){// Fonction de récupération des noeuds XML
try {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(nameFile);
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile(path);// Requête XPath pour récupérer les valeurs enfants de l'UserType sélectionner depuis l'interface
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList noeud = (NodeList) result;
return noeud;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return null;
}
}
// Fonctions de mapping...
void fctMacMapping(String DriveLetter, String ServerAddress, String Volume) throws InterruptedException{
try {
Process p = r.exec("mkdir "+home+"/xxx/"+DriveLetter+"");
p.waitFor();
System.out.println(p.getInputStream().toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread.sleep(200); // faire attendre le système 2/10 secondes
try {
r.exec("ln -s "+home+"/xxx/MapMyDrive/MapMyDrive.jar "+home+"/xxx/"+DriveLetter+"/connect");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
r.exec("mount_smbfs //"+username+":"+password+"@"+ServerAddress+"/"+Volume +" "+home+"/xxx/"+DriveLetter+"");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread.sleep(200); // faire attendre le système 2/10 secondes
}
void fctLinuxMapping(String DriveLetter, String ServerAddress, String Volume){
try {
r.exec("mkdir "+home+"/xxx/"+DriveLetter+"");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
r.exec("mount //"+username+":"+password+"@"+ServerAddress+"/"+Volume +" "+home+"/xxx/"+DriveLetter+"");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void fctWindowsMapping(String DriveLetter, String ServerAddress, String Volume) throws InterruptedException{
try {
System.out.println("Start");
Process p = r.exec("cmd /c net use "+DriveLetter+": \\\\"+ServerAddress+"\\"+Volume+" "+password+" /USER:"+username+" /PERSISTENT:NO");
String s =null;
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuffer buffer = new StringBuffer();
while ((s = reader.readLine()) != null) {
buffer.append(s);
}
String result = buffer.toString();
System.out.println(result);
if (result.equals("La commande s'est termine correctement.")){
fctWriteLog("User "+ username +" connected to "+sDriveLetter+":"+sVolume+"");
fctChangeEnableToDisable();
mapping = true;
}else{
fctWriteLog("An error occurred while connecting... Yar are not connected to "+sDriveLetter+":"+sVolume+"");
mapping = false;
}
} catch (IOException e) {
e.printStackTrace();}
System.out.println("Fin");
}
File[] fctRecupLetter() {
File[] roots = File.listRoots();
for(int i= 0; i < roots.length; i++){
}
return roots;
}
boolean fctCheckLetter(String DriveLetter){
File[] root = fctRecupLetter();
String DriveLetter2;
DriveLetter2 = DriveLetter+":\\";
for (int i = 0; i < root.length; i++){
String test = root[i].toString();
if (test.equals(DriveLetter2) ){
aLetter = true;
fctWriteLog("Drive "+sDriveLetter+" is already assigned.");
JOptionPane.showMessageDialog(null, "Drive "+sDriveLetter+" is already assigned.", "Erreur", JOptionPane.ERROR_MESSAGE);
}else{
aLetter = false;
}
}
return aLetter;
} |
Partager