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
| public void insertionMotivation() {
String expression = "([^\\s]+(\\.(?i)(doc|docx|DOC|DOCX|pdf|PDF))$)";
try{
if((!fileMotivation.getFileName().matches(expression)) ) {
setRendredMotivationRedImage(true);
setRendrerdMotivationValid(false);
}else{
setRendredMotivationRedImage(false);
setRendrerdMotivationValid(true);
String nom = fileMotivation.getFileName();
System.out.println(nom);
candidat.setMotivation(nom);
candidatBuss.modifierCandidat(candidat);
String path = FacesContext.getCurrentInstance().getExternalContext().getResource("/Path.xml").toString();
builder = factory.newDocumentBuilder();
Document xml = builder.parse(path);
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
XPathExpression expr = xPath.compile("//Lettre");
destinationLettreMotivation = (String) expr.evaluate(xml, XPathConstants.STRING);
System.out.println(destinationLettreMotivation);
int ind = nom.indexOf(".");
String mano = nom.substring(ind+1,nom.length());
System.out.println(mano);
if(mano.equals("pdf")){
copyFile(String.valueOf(candidat.getIdcandidat())+".pdf", fileMotivation.getInputstream(),destinationLettreMotivation);
}
if(mano.equals("PDF")){
copyFile(String.valueOf(candidat.getIdcandidat())+".PDF", fileMotivation.getInputstream(),destinationLettreMotivation);
}
if(mano.equals("docx")){
copyFile(String.valueOf(candidat.getIdcandidat())+".docx", fileMotivation.getInputstream(),destinationLettreMotivation);
}
if(mano.equals("DOCX")){
copyFile(String.valueOf(candidat.getIdcandidat())+".DOCX", fileMotivation.getInputstream(),destinationLettreMotivation);
}
if(mano.equals("doc")){
copyFile(String.valueOf(candidat.getIdcandidat())+".doc", fileMotivation.getInputstream(),destinationLettreMotivation);
}
if(mano.equals("DOC")){
copyFile(String.valueOf(candidat.getIdcandidat())+".DOC", fileMotivation.getInputstream(),destinationLettreMotivation);
}
}
}catch(Exception e){
e.printStackTrace();
}
} |
Partager