Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
30   95   19   10
26   54   0.63   3
3     6.33  
1    
 
  LatexList2Text       Line # 23 30 19 98.3% 0.9830508
 
  (104)
 
1    package org.qedeq.kernel.se.visitor;
2   
3    import org.qedeq.base.utility.StringUtility;
4    import org.qedeq.kernel.se.base.module.Latex;
5    import org.qedeq.kernel.se.base.module.LatexList;
6   
7    /**
8    * Transform latex list into text. We make here only a basic conversion to have a plain text
9    * description of such things as chapter titles. So we have to remove something like
10    * "\index".
11    * <br/>
12    * TODO 20130126 m31: this transformation is mainly used to get a good location description
13    * when a plugin is running. So it must work with chapter, section and subsection titles.
14    * We just have to check what LaTeX stuff is used there.
15    * <br/>
16    * Another problem: currently only the method {@link #transform(LatexList)} is called.
17    * <br/>
18    * It might be a good idea to idea to externalize the usage. So one could use a better transformer
19    * transformer (like Latex2UnicodeParser) if we have it in our class path...
20    *
21    * @author Michael Meyling
22    */
 
23    public class LatexList2Text {
24   
25    /**
26    * Filters English entry out of LaTeX list.
27    *
28    * @param list List of LaTeX entries.
29    * @return Selected entry transformed into text.
30    */
 
31  559032 toggle public String transform(final LatexList list) {
32  559032 return transform(list, "en");
33    }
34   
35    /**
36    * Filters given language entry out of LaTeX list.
37    * Fallback is the default language.
38    *
39    * @param list List of LaTeX entries.
40    * @param language Filter for this language.
41    * @return Selected entry transformed into text.
42    */
 
43  559042 toggle public String transform(final LatexList list, final String language) {
44  559042 if (list == null) {
45  125 return "";
46    }
47    // if we got no language we take "en"
48  558917 String lan = (language != null ? language : "en");
49  559097 for (int i = 0; i < list.size(); i++) {
50  558931 if (list.get(i) != null && lan.equals(list.get(i).getLanguage())) {
51  558751 return getLatex(list.get(i));
52    }
53    }
54    // assume entry with missing language as default
55  178 for (int i = 0; i < list.size(); i++) {
56  168 if (list.get(i) != null && list.get(i).getLanguage() == null) {
57  156 return getLatex(list.get(i));
58    }
59    }
60    // if we haven't tried "en" yet we give it a try
61  10 if (!"en".equals(lan)) {
62  3 lan = "en";
63  9 for (int i = 0; i < list.size(); i++) {
64  8 if (list.get(i) != null && lan.equals(list.get(i).getLanguage())) {
65  2 return getLatex(list.get(i));
66    }
67    }
68    }
69    // fallback: now we take the first entry
70  8 for (int i = 0; i < list.size(); i++) {
71  3 if (list.get(i) != null) {
72  3 return getLatex(list.get(i));
73    }
74    }
75    // nothing found, so we return just an empty string
76  5 return "";
77    }
78   
 
79  558923 toggle protected String getLatex(final Latex latex) {
80  558923 if (latex == null) {
81  1 return "";
82    }
83  558922 String result = latex.getLatex();
84  558922 if (result == null) {
85  6 result = "";
86    }
87  558922 result = result.trim();
88  558922 result = result.replaceAll("\\\\index\\{.*\\}", "");
89  558922 result = result.replaceAll("\\\\(\\w*)\\{(.*)\\}", "$2");
90  558922 result = StringUtility.replace(result, "{", "");
91  558922 result = StringUtility.replace(result, "}", "");
92  558922 return result.trim();
93    }
94   
95    }