| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.transform; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.Asset; |
| 18 | |
import org.apache.tapestry5.ComponentResources; |
| 19 | |
import org.apache.tapestry5.annotations.SetupRender; |
| 20 | |
import org.apache.tapestry5.internal.services.ComponentResourcesOperation; |
| 21 | |
import org.apache.tapestry5.ioc.Resource; |
| 22 | |
import org.apache.tapestry5.ioc.internal.util.CollectionFactory; |
| 23 | |
import org.apache.tapestry5.ioc.services.SymbolSource; |
| 24 | |
import org.apache.tapestry5.model.MutableComponentModel; |
| 25 | |
import org.apache.tapestry5.services.AssetSource; |
| 26 | |
import org.apache.tapestry5.services.ClassTransformation; |
| 27 | |
import org.apache.tapestry5.services.ComponentClassTransformWorker; |
| 28 | |
import org.apache.tapestry5.services.TransformConstants; |
| 29 | |
|
| 30 | |
import java.util.List; |
| 31 | |
import java.util.Locale; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 2074 | public abstract class AbstractIncludeAssetWorker implements ComponentClassTransformWorker |
| 38 | |
{ |
| 39 | |
private final AssetSource assetSource; |
| 40 | |
|
| 41 | |
private final SymbolSource symbolSource; |
| 42 | |
|
| 43 | |
public AbstractIncludeAssetWorker(AssetSource assetSource, SymbolSource symbolSource) |
| 44 | 116 | { |
| 45 | 116 | this.assetSource = assetSource; |
| 46 | 116 | this.symbolSource = symbolSource; |
| 47 | 116 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
protected final void addOperationForAssetPaths(ClassTransformation transformation, |
| 58 | |
MutableComponentModel model, String[] assetPaths) |
| 59 | |
{ |
| 60 | 20 | final Resource baseResource = model.getBaseResource(); |
| 61 | 20 | final List<String> paths = CollectionFactory.newList(); |
| 62 | |
|
| 63 | 48 | for (String value : assetPaths) |
| 64 | |
{ |
| 65 | 28 | String expanded = symbolSource.expandSymbols(value); |
| 66 | |
|
| 67 | 28 | paths.add(expanded); |
| 68 | |
} |
| 69 | |
|
| 70 | 20 | ComponentResourcesOperation op = new ComponentResourcesOperation() |
| 71 | |
{ |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | 20 | public void perform(ComponentResources resources) |
| 77 | |
{ |
| 78 | 1110 | Locale locale = resources.getLocale(); |
| 79 | |
|
| 80 | 1110 | for (String assetPath : paths) |
| 81 | |
{ |
| 82 | 2074 | Asset asset = assetSource.getAsset(baseResource, assetPath, locale); |
| 83 | |
|
| 84 | 2074 | handleAsset(asset); |
| 85 | 2074 | } |
| 86 | 1110 | } |
| 87 | |
}; |
| 88 | |
|
| 89 | 20 | String opFieldName = transformation.addInjectedField(ComponentResourcesOperation.class, "operation", op); |
| 90 | |
|
| 91 | 20 | String resourcesName = transformation.getResourcesFieldName(); |
| 92 | |
|
| 93 | 20 | String body = String.format("%s.perform(%s);", opFieldName, resourcesName); |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | 20 | transformation.extendMethod(TransformConstants.SETUP_RENDER_SIGNATURE, body); |
| 100 | |
|
| 101 | 20 | model.addRenderPhase(SetupRender.class); |
| 102 | 20 | } |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
protected abstract void handleAsset(Asset asset); |
| 111 | |
} |