| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.internal.query; |
| 21 |
|
|
| 22 |
|
import java.util.List; |
| 23 |
|
import java.util.Locale; |
| 24 |
|
|
| 25 |
|
import javax.inject.Inject; |
| 26 |
|
import javax.inject.Named; |
| 27 |
|
import javax.inject.Singleton; |
| 28 |
|
|
| 29 |
|
import org.xwiki.component.annotation.Component; |
| 30 |
|
import org.xwiki.context.Execution; |
| 31 |
|
import org.xwiki.query.internal.AbstractWhereQueryFilter; |
| 32 |
|
|
| 33 |
|
import com.xpn.xwiki.XWikiContext; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@version |
| 39 |
|
@since |
| 40 |
|
|
| 41 |
|
@Component |
| 42 |
|
@Named("currentlanguage") |
| 43 |
|
@Singleton |
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 44 |
|
public class CurrentLanguageQueryFilter extends AbstractWhereQueryFilter |
| 45 |
|
{ |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
@Inject |
| 50 |
|
private Execution execution; |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
97 |
@Override... |
| 53 |
|
public String filterStatement(String statement, String language) |
| 54 |
|
{ |
| 55 |
|
|
| 56 |
97 |
return insertWhereClause(String.format("(doc.language is null or doc.language = '' or doc.language = '%s')", |
| 57 |
|
getCurrentLanguage().toString()), statement, language); |
| 58 |
|
} |
| 59 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 60 |
96 |
@Override... |
| 61 |
|
public List filterResults(List results) |
| 62 |
|
{ |
| 63 |
96 |
return results; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
@return |
| 68 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 69 |
97 |
private Locale getCurrentLanguage()... |
| 70 |
|
{ |
| 71 |
97 |
XWikiContext context = getXWikiContext(); |
| 72 |
97 |
return context.getWiki().getDefaultLocale(context); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
@return |
| 77 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 78 |
97 |
private XWikiContext getXWikiContext()... |
| 79 |
|
{ |
| 80 |
97 |
return (XWikiContext) this.execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY); |
| 81 |
|
} |
| 82 |
|
} |