| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.platform.svg.script; |
| 21 |
|
|
| 22 |
|
import javax.inject.Inject; |
| 23 |
|
import javax.inject.Named; |
| 24 |
|
import javax.inject.Singleton; |
| 25 |
|
|
| 26 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
| 27 |
|
import org.slf4j.Logger; |
| 28 |
|
import org.xwiki.component.annotation.Component; |
| 29 |
|
import org.xwiki.model.reference.DocumentReference; |
| 30 |
|
import org.xwiki.platform.svg.SVGRasterizer; |
| 31 |
|
import org.xwiki.resource.ResourceReferenceSerializer; |
| 32 |
|
import org.xwiki.resource.temporary.TemporaryResourceReference; |
| 33 |
|
import org.xwiki.script.service.ScriptService; |
| 34 |
|
import org.xwiki.stability.Unstable; |
| 35 |
|
import org.xwiki.url.ExtendedURL; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@version |
| 41 |
|
@since |
| 42 |
|
|
| 43 |
|
@Component |
| 44 |
|
@Named("svg") |
| 45 |
|
@Singleton |
| 46 |
|
@Unstable("New API introduced in 8.0") |
| |
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 9 |
Complexity Density: 0.53 |
|
| 47 |
|
public class SVGScriptService implements ScriptService |
| 48 |
|
{ |
| 49 |
|
@Inject |
| 50 |
|
private Logger logger; |
| 51 |
|
|
| 52 |
|
@Inject |
| 53 |
|
private SVGRasterizer component; |
| 54 |
|
|
| 55 |
|
@Inject |
| 56 |
|
@Named("standard/tmp") |
| 57 |
|
private ResourceReferenceSerializer<TemporaryResourceReference, ExtendedURL> serializer; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
@param |
| 64 |
|
@return |
| 65 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 66 |
2 |
public ExtendedURL rasterizeToTemporaryResource(String content)... |
| 67 |
|
{ |
| 68 |
2 |
return rasterizeToTemporaryResource(content, 0, 0); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
@param |
| 76 |
|
@param |
| 77 |
|
|
| 78 |
|
@param |
| 79 |
|
|
| 80 |
|
@return |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 82 |
4 |
public ExtendedURL rasterizeToTemporaryResource(String content, int width, int height)... |
| 83 |
|
{ |
| 84 |
4 |
try { |
| 85 |
4 |
return this.serializer.serialize(this.component.rasterizeToTemporaryResource(content, width, height)); |
| 86 |
|
} catch (Exception ex) { |
| 87 |
2 |
this.logger.warn("Failed to rasterize SVG image to temporary resource: {}", |
| 88 |
|
ExceptionUtils.getRootCauseMessage(ex)); |
| 89 |
|
} |
| 90 |
2 |
return null; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
@param |
| 98 |
|
@param |
| 99 |
|
@return |
| 100 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 101 |
2 |
public ExtendedURL rasterizeToTemporaryResource(String content, DocumentReference targetContext)... |
| 102 |
|
{ |
| 103 |
2 |
return rasterizeToTemporaryResource(content, 0, 0, targetContext); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
@param |
| 111 |
|
@param |
| 112 |
|
|
| 113 |
|
@param |
| 114 |
|
|
| 115 |
|
@param |
| 116 |
|
@return |
| 117 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 118 |
4 |
public ExtendedURL rasterizeToTemporaryResource(String content, int width, int height,... |
| 119 |
|
DocumentReference targetContext) |
| 120 |
|
{ |
| 121 |
4 |
try { |
| 122 |
4 |
ExtendedURL result = this.serializer |
| 123 |
|
.serialize(this.component.rasterizeToTemporaryResource(content, width, height, targetContext)); |
| 124 |
2 |
return result; |
| 125 |
|
} catch (Exception ex) { |
| 126 |
2 |
this.logger.warn("Failed to rasterize SVG image to temporary resource in context [{}]: {}", targetContext, |
| 127 |
|
ExceptionUtils.getRootCauseMessage(ex)); |
| 128 |
|
} |
| 129 |
2 |
return null; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
@param |
| 136 |
|
@return |
| 137 |
|
|
| 138 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 139 |
2 |
public boolean rasterizeToResponse(String content)... |
| 140 |
|
{ |
| 141 |
2 |
return rasterizeToResponse(content, 0, 0); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
@param |
| 148 |
|
@param |
| 149 |
|
|
| 150 |
|
@param |
| 151 |
|
|
| 152 |
|
@return |
| 153 |
|
|
| 154 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 155 |
4 |
public boolean rasterizeToResponse(String content, int width, int height)... |
| 156 |
|
{ |
| 157 |
4 |
try { |
| 158 |
4 |
this.component.rasterizeToResponse(content, width, height); |
| 159 |
2 |
return true; |
| 160 |
|
} catch (Exception ex) { |
| 161 |
2 |
this.logger.warn("Failed to rasterize SVG image to response: {}", ExceptionUtils.getRootCauseMessage(ex)); |
| 162 |
|
} |
| 163 |
2 |
return false; |
| 164 |
|
} |
| 165 |
|
} |