Skip to content

Commit

Permalink
improve quality of MenuController and Corrector
Browse files Browse the repository at this point in the history
  • Loading branch information
firm1 committed Dec 26, 2016
1 parent 87237d3 commit 8029a71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
19 changes: 13 additions & 6 deletions src/main/java/com/zestedesavoir/zestwriter/utils/Corrector.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.languagetool.language.French;
import org.languagetool.markup.AnnotatedText;
import org.languagetool.markup.AnnotatedTextBuilder;
import org.languagetool.rules.Rule;
import org.languagetool.rules.RuleMatch;
import org.languagetool.rules.spelling.SpellingCheckRule;

Expand All @@ -36,7 +35,8 @@ public static String HtmlToTextWithoutCode(String htmlText) {
AnnotatedTextBuilder builder = new AnnotatedTextBuilder();
StringTokenizer tokenizer = new StringTokenizer(htmlText, "<>", true);
boolean inMarkup = false;
int CountCode = 0, CountPre = 0;
int CountCode = 0;
int CountPre = 0;
while (tokenizer.hasMoreTokens()) {
String part = tokenizer.nextToken();
if (inMarkup) {
Expand All @@ -53,6 +53,8 @@ public static String HtmlToTextWithoutCode(String htmlText) {
case "/pre":
CountPre--;
break;
default:
break;
}
}
if (part.startsWith("<")) {
Expand Down Expand Up @@ -86,7 +88,10 @@ public AnnotatedText makeAnnotatedText(String pseudoXml) {
AnnotatedTextBuilder builder = new AnnotatedTextBuilder();
StringTokenizer tokenizer = new StringTokenizer(pseudoXml, "<>", true);
boolean inMarkup = false;
int CountCode = 0, CountPre = 0, CountEm = 0, CountSup = 0;
int CountCode = 0;
int CountPre = 0;
int CountEm = 0;
int CountSup = 0;
while (tokenizer.hasMoreTokens()) {
String part = tokenizer.nextToken();
if (inMarkup) {
Expand Down Expand Up @@ -115,6 +120,8 @@ public AnnotatedText makeAnnotatedText(String pseudoXml) {
case "/sup":
CountSup--;
break;
default:
break;
}
}
if (part.startsWith("<")) {
Expand Down Expand Up @@ -159,7 +166,7 @@ public String checkHtmlContent(String htmlContent) {
String desc = match.getMessage();
desc = new HtmlToPlainText().getPlainText(Jsoup.parse(desc));

if (match.getSuggestedReplacements().size() > 0) {
if (!match.getSuggestedReplacements().isEmpty()) {
desc += Configuration.bundle.getString("ui.alert.correction.tooltip.suggestion")
+ match.getSuggestedReplacements();
}
Expand Down Expand Up @@ -210,10 +217,10 @@ public int countMistakes(MdTextController mdTextController, String markdown) {
langTool.getAllActiveRules().stream()
.filter(rule -> rule instanceof SpellingCheckRule).forEach(rule -> ((SpellingCheckRule) rule).acceptPhrases(wordsToIgnore));
try {
List<RuleMatch> matches = matches = langTool.check(markup);
List<RuleMatch> matches = langTool.check(markup);
return matches.size();
}
catch (Exception e) {
catch (IOException e) {
MainApp.getLogger().error(e.getMessage(), e);
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zestedesavoir.zestwriter.MainApp;
import com.zestedesavoir.zestwriter.model.Content;
import com.zestedesavoir.zestwriter.model.MetaAttribute;
import com.zestedesavoir.zestwriter.model.MetadataContent;
import com.zestedesavoir.zestwriter.model.Textual;
import com.zestedesavoir.zestwriter.model.*;
import com.zestedesavoir.zestwriter.utils.Configuration;
import com.zestedesavoir.zestwriter.utils.Corrector;
import com.zestedesavoir.zestwriter.utils.ZdsHttp;
Expand Down Expand Up @@ -250,25 +247,17 @@ private void handleIndex(Function<Textual, Double> calFlesh, String title, Strin
paramContent.put("slug", ZdsHttp.toSlug((String)paramContent.get("title")));
paramContent.put("version", 2);
paramContent.put("object", "container");
paramContent.put("introduction", "introduction.md");
paramContent.put("conclusion", "conclusion.md");
paramContent.put("introduction", Constant.DEFAULT_INTRODUCTION_FILENAME);
paramContent.put("conclusion", Constant.DEFAULT_CONCLUSION_FILENAME);
paramContent.put("children", new ArrayList<>());

try{
mapper.writeValue(manifest, paramContent);
// create introduction and conclusion
File intro = new File(realLocalPath + File.separator + "introduction.md");
File conclu = new File(realLocalPath + File.separator + "conclusion.md");
if(!intro.createNewFile()) {
logger.error("Problème lors de la création du fichier "+intro.getAbsolutePath());
}
if(!conclu.createNewFile()) {
logger.error("Problème lors de la création du fichier "+intro.getAbsolutePath());
}
FunctionTreeFactory.generateMetadataAttributes(realLocalPath + File.separator);
Content content = mapper.readValue(manifest, Content.class);
content.setRootContent(content, realLocalPath);
FunctionTreeFactory.switchContent(content, mainApp.getContents());

}catch(IOException e){
logger.error(e.getMessage(), e);
}
Expand Down

0 comments on commit 8029a71

Please sign in to comment.