Gestion des attributs, on regarde le type de fichier envoyé..

This commit is contained in:
Frederic Debuire
2008-02-23 18:56:37 +00:00
parent 9c20249ba9
commit 6e06067215
6 changed files with 132 additions and 34 deletions

View File

@@ -49,7 +49,7 @@
<div>
<form:label path="abstractText"><fmt:message key="form.submission.article.abstractText" /></form:label>
<form:textarea path="abstractText" cols="60" rows="10" />*<br />
<span class="abstractText"><form:errors path="theme" /></span>
<span class="formError"><form:errors path="abstractText" /></span>
</div>
</fieldset>
@@ -85,7 +85,7 @@
<div>
<form:label path="file"><fmt:message key="form.article.file" /></form:label>
<input type="file" name="file" />*
<span class="abstractText"><form:errors path="file" /></span>
<span class="formError"><form:errors path="file" /></span>
</div>
</fieldset>

View File

@@ -41,7 +41,7 @@
<prop key="/login.htm">LogonController</prop>
<prop key="/listEvaluation.htm">ListEvaluationController</prop>
<prop key="/download.htm">ArticleDownloadController</prop>
<prop key="/delete.htm">ArticleDeleteController</prop>
<prop key="/deleteArticle.htm">ArticleDeleteController</prop>
<prop key="/listReport.htm">ListReportController</prop>
<prop key="/forgotPassword.htm">ForgotPasswordController</prop>
<prop key="/detailArticle.htm">DetailArticleController</prop>

View File

@@ -72,6 +72,55 @@ public class SArticleController extends SimpleFormController {
}
else {
String extension = file.getOriginalFilename().substring(file.getOriginalFilename().length() - 4).toLowerCase();
logger.info("The file extension is: " + extension);
boolean typePDF = conf.isTypePDF();
boolean typeLatec = conf.isTypeLatec();
boolean typeWord = conf.isTypeWord();
boolean typeODT = conf.isTypeODT();
boolean isOneSelected = false;
boolean extensionTrue = false;
String acceptedExt = "";
if (typePDF || typeLatec || typeWord || typeODT)
isOneSelected = true;
if (isOneSelected) {
if (typePDF) {
acceptedExt = acceptedExt + ".pdf ";
if (extension.equals(".pdf"))
extensionTrue = true;
}
if (typeLatec) {
acceptedExt = acceptedExt + ".tex ";
if (extension.equals(".tex"))
extensionTrue = true;
}
if (typeWord) {
acceptedExt = acceptedExt + ".doc .docx ";
String extension1 = file.getOriginalFilename().substring(file.getOriginalFilename().length() - 4).toLowerCase();
String extension2 = file.getOriginalFilename().substring(file.getOriginalFilename().length() - 5).toLowerCase();
if (extension1.equals(".doc"))
extensionTrue = true;
if (extension2.equals(".docx"))
extensionTrue = true;
}
if (typeODT) {
acceptedExt = acceptedExt + ".odt";
if (extension.equals(".odt"))
extensionTrue = true;
}
if (! extensionTrue) {
errors.rejectValue("file", null, "The file's extensions allowed are the following: " + acceptedExt);
try {
return showForm(request, response, errors);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Creates the article
Article newArticle = articleManager.addArticle(
title, theme, abstractText, nomFile, user.getLogin(),
@@ -102,6 +151,7 @@ public class SArticleController extends SimpleFormController {
articleManager.updateArticle(newArticle);
}
}
catch (FileNotFoundException e) {
System.out.println(e);
} catch (IOException e) {
@@ -130,6 +180,56 @@ public class SArticleController extends SimpleFormController {
articleManager.updateArticle(old);
}
else {
String extension = file.getOriginalFilename().substring(file.getOriginalFilename().length() - 4).toLowerCase();
logger.info("The file extension is: " + extension);
boolean typePDF = conf.isTypePDF();
boolean typeLatec = conf.isTypeLatec();
boolean typeWord = conf.isTypeWord();
boolean typeODT = conf.isTypeODT();
boolean isOneSelected = false;
boolean extensionTrue = false;
String acceptedExt = "";
if (typePDF || typeLatec || typeWord || typeODT)
isOneSelected = true;
if (isOneSelected) {
if (typePDF) {
acceptedExt = acceptedExt + ".pdf ";
if (extension.equals(".pdf"))
extensionTrue = true;
}
if (typeLatec) {
acceptedExt = acceptedExt + ".tex ";
if (extension.equals(".tex"))
extensionTrue = true;
}
if (typeWord) {
acceptedExt = acceptedExt + ".doc .docx ";
String extension1 = file.getOriginalFilename().substring(file.getOriginalFilename().length() - 4).toLowerCase();
String extension2 = file.getOriginalFilename().substring(file.getOriginalFilename().length() - 5).toLowerCase();
if (extension1.equals(".doc"))
extensionTrue = true;
if (extension2.equals(".docx"))
extensionTrue = true;
}
if (typeODT) {
acceptedExt = acceptedExt + ".odt";
if (extension.equals(".odt"))
extensionTrue = true;
}
if (! extensionTrue) {
errors.rejectValue("file", null, "The file's extensions allowed are the following: " + acceptedExt);
try {
return showForm(request, response, errors);
} catch (Exception e) {
e.printStackTrace();
}
}
}
byte b[] = file.getBytes();
String path = "conference"+conf.getId()+"/";
@@ -144,6 +244,7 @@ public class SArticleController extends SimpleFormController {
old.setURL_article(path);
articleManager.updateArticle(old);
}
} catch (NumberFormatException e) {
throw new ModelAndViewDefiningException(new ModelAndView("404error"));

View File

@@ -4,7 +4,6 @@ import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.yacos.web.author.form.FormSubmission;
public class ValidateSubmission implements Validator {
@SuppressWarnings("unchecked")
@@ -21,23 +20,15 @@ public class ValidateSubmission implements Validator {
String abs = sub.getAbstractText();
if (title == null || title.trim().length() == 0) {
arg1.rejectValue("title",
"submissionArticle.title",
"Le title est n<><6E>cessaire !");
arg1.rejectValue("title", "submissionArticle.title", "The title should not be null");
}
if (theme==null|theme.trim().length()==0)
{
arg1.rejectValue("theme", "submissionArticle.theme");
if (theme == null || theme.trim().length()==0) {
arg1.rejectValue("theme", "submissionArticle.theme", "The theme should not be null");
}
if (abs==null|abs.trim().length()==0)
{ arg1.rejectValue("abstractText", "submissionArticle.abstractText", "text is not nullable");
if (abs == null || abs.trim().length()==0) {
arg1.rejectValue("abstractText", "submissionArticle.abstractText", "The abstract should not be null");
}
}
}

View File

@@ -243,6 +243,7 @@ public class AddConferenceController extends AbstractWizardFormController {
setPages(new String[] {"addConference", "addConference2", "addConference3", "addConference4", "addConference5"});
}
// TODO : comment modifier la conf ?
@Secured({"ROLE_CONFERENCE_CREATOR"})
protected Object formBackingObject(HttpServletRequest request) throws ModelAndViewDefiningException {
logger.info(this.getClass().toString() + " dans le formBackingObject");
@@ -384,14 +385,13 @@ public class AddConferenceController extends AbstractWizardFormController {
conference.setDateStart(format.format(conf.getDateStart()));
conference.setDescription(conf.getDescription());
conference.setOtherInformations(conf.getOtherInformations());
// TODO : ajouter ca ds conf ejb...
/*conference.setPageNumber(pageNumber);
conference.setSendInfo(sendInfo);
conference.setTypeLatec(typeLatec);
conference.setTypeODT(typeODT);
conference.setTypePDF(typePDF);
conference.setTypeWord(typeWord);*/
conference.setPageNumberChecked(conf.getPageNumber());
conference.setPageNumber(conf.getPageNumber().toString());
conference.setTypePDF(conf.isTypePDF());
conference.setTypeLatec(conf.isTypeLatec());
conference.setTypeWord(conf.isTypeWord());
conference.setTypeODT(conf.isTypeODT());
conference.setSendInfo(conf.getSendInfo());
return conference;
@@ -439,7 +439,13 @@ public class AddConferenceController extends AbstractWizardFormController {
conference.getDateArticleParsed(),
conference.getDateEvaluationParsed(),
conference.getDateStartParsed(),
conference.getDateEndParsed());
conference.getDateEndParsed(),
conference.getPageNumberChecked(),
conference.isTypePDF(),
conference.isTypeLatec(),
conference.isTypeWord(),
conference.isTypeODT(),
conference.getSendInfo());
} catch (NoConferenceCreationTokenLeftException e1) {
return new ModelAndView("denied","message",getMessageSourceAccessor().getMessage("conference.error.noTokenLeft"));
}

View File

@@ -40,7 +40,7 @@ public class ConferenceValidator implements Validator {
dateStart = format.parse(conference.getDateStart());
conference.setDateStartParsed(dateStart);
} catch (ParseException e) {
errors.rejectValue("dateStart", "conference.errors.dateStartNonValid");
errors.reject("dateStart", "conference.errors.dateStartNonValid");
}
try {
dateEnd = format.parse(conference.getDateEnd());