| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.icon.internal; |
| 21 |
|
|
| 22 |
|
import javax.inject.Inject; |
| 23 |
|
import javax.inject.Singleton; |
| 24 |
|
|
| 25 |
|
import org.xwiki.cache.Cache; |
| 26 |
|
import org.xwiki.cache.CacheException; |
| 27 |
|
import org.xwiki.cache.CacheFactory; |
| 28 |
|
import org.xwiki.cache.CacheManager; |
| 29 |
|
import org.xwiki.cache.config.CacheConfiguration; |
| 30 |
|
import org.xwiki.component.annotation.Component; |
| 31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 32 |
|
import org.xwiki.component.phase.Initializable; |
| 33 |
|
import org.xwiki.component.phase.InitializationException; |
| 34 |
|
import org.xwiki.icon.IconSet; |
| 35 |
|
import org.xwiki.icon.IconSetCache; |
| 36 |
|
import org.xwiki.model.reference.DocumentReference; |
| 37 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@link |
| 41 |
|
|
| 42 |
|
@since |
| 43 |
|
@version |
| 44 |
|
|
| 45 |
|
@Component |
| 46 |
|
@Singleton |
| |
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 15 |
Complexity Density: 0.83 |
|
| 47 |
|
public class DefaultIconSetCache implements IconSetCache, Initializable |
| 48 |
|
{ |
| 49 |
|
private static final String ICON_SET_CACHE_ID = "iconset"; |
| 50 |
|
|
| 51 |
|
private static final String NAME_SUFFIX = "NAMED:"; |
| 52 |
|
|
| 53 |
|
private static final String DOCUMENT_SUFFIX = "DOC:"; |
| 54 |
|
|
| 55 |
|
@Inject |
| 56 |
|
private CacheManager cacheManager; |
| 57 |
|
|
| 58 |
|
@Inject |
| 59 |
|
private EntityReferenceSerializer<String> entityReferenceSerializer; |
| 60 |
|
|
| 61 |
|
private Cache<IconSet> cache; |
| 62 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 63 |
72 |
@Override... |
| 64 |
|
public void initialize() throws InitializationException |
| 65 |
|
{ |
| 66 |
72 |
try { |
| 67 |
72 |
CacheConfiguration configuration = new CacheConfiguration(ICON_SET_CACHE_ID); |
| 68 |
72 |
CacheFactory cacheFactory = cacheManager.getCacheFactory(); |
| 69 |
72 |
this.cache = cacheFactory.newCache(configuration); |
| 70 |
|
} catch (ComponentLookupException | CacheException e) { |
| 71 |
1 |
throw new InitializationException("Failed to initialize the IconSet Cache.", e); |
| 72 |
|
} |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
23 |
private String getCacheKey(String name, String wikiId)... |
| 76 |
|
{ |
| 77 |
23 |
return wikiId.length() + wikiId + '_' + name; |
| 78 |
|
} |
| 79 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
2674 |
@Override... |
| 81 |
|
public IconSet get(String name) |
| 82 |
|
{ |
| 83 |
2674 |
return cache.get(getKeyFromName(name)); |
| 84 |
|
} |
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
19 |
@Override... |
| 87 |
|
public IconSet get(String name, String wikiId) |
| 88 |
|
{ |
| 89 |
19 |
return get(getCacheKey(name, wikiId)); |
| 90 |
|
} |
| 91 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 92 |
1 |
@Override... |
| 93 |
|
public IconSet get(DocumentReference documentReference) |
| 94 |
|
{ |
| 95 |
1 |
return cache.get(getKeyFromDocument(documentReference)); |
| 96 |
|
} |
| 97 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 98 |
32 |
@Override... |
| 99 |
|
public void put(String name, IconSet iconSet) |
| 100 |
|
{ |
| 101 |
32 |
cache.set(getKeyFromName(name), iconSet); |
| 102 |
|
} |
| 103 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 104 |
3 |
@Override... |
| 105 |
|
public void put(String name, String wikiId, IconSet iconSet) |
| 106 |
|
{ |
| 107 |
3 |
put(getCacheKey(name, wikiId), iconSet); |
| 108 |
|
} |
| 109 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
3 |
@Override... |
| 111 |
|
public void put(DocumentReference documentReference, IconSet iconSet) |
| 112 |
|
{ |
| 113 |
3 |
cache.set(getKeyFromDocument(documentReference), iconSet); |
| 114 |
|
} |
| 115 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
1 |
@Override... |
| 117 |
|
public void clear() |
| 118 |
|
{ |
| 119 |
1 |
cache.removeAll(); |
| 120 |
|
} |
| 121 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 122 |
1 |
@Override... |
| 123 |
|
public void clear(DocumentReference documentReference) |
| 124 |
|
{ |
| 125 |
1 |
cache.remove(getKeyFromDocument(documentReference)); |
| 126 |
|
} |
| 127 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 128 |
2 |
@Override... |
| 129 |
|
public void clear(String name) |
| 130 |
|
{ |
| 131 |
2 |
cache.remove(getKeyFromName(name)); |
| 132 |
|
} |
| 133 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
1 |
@Override... |
| 135 |
|
public void clear(String name, String wikiId) |
| 136 |
|
{ |
| 137 |
1 |
clear(getCacheKey(name, wikiId)); |
| 138 |
|
} |
| 139 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 140 |
2707 |
private String getKeyFromName(String name)... |
| 141 |
|
{ |
| 142 |
2707 |
return NAME_SUFFIX + name; |
| 143 |
|
} |
| 144 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 145 |
5 |
private String getKeyFromDocument(DocumentReference docRef)... |
| 146 |
|
{ |
| 147 |
5 |
return DOCUMENT_SUFFIX + entityReferenceSerializer.serialize(docRef); |
| 148 |
|
} |
| 149 |
|
} |