private List<AssetProcessor> getCompatibleProcessorFor(Asset asset) { List<AssetProcessor> compatibleProcessors = new ArrayList<AssetProcessor>(); for (AssetProcessor assetProcessor : context.getActiveProcessors()) { Annotation annotation = assetProcessor.getClass().getAnnotation(CompatibleAssetType.class); CompatibleAssetType compatibleAssetType = (CompatibleAssetType) annotation; List<AssetType> compatibleAssetTypes = Arrays.asList(compatibleAssetType.types()); if (compatibleAssetTypes.contains(asset.getType())) { compatibleProcessors.add(assetProcessor); } } return compatibleProcessors; } }
private List<AssetProcessor> getCompatibleProcessorFor(Asset asset) { List<AssetProcessor> compatibleProcessors = new ArrayList<AssetProcessor>(); for (AssetProcessor assetProcessor : context.getActiveProcessors()) { Annotation annotation = assetProcessor.getClass().getAnnotation(CompatibleAssetType.class); CompatibleAssetType compatibleAssetType = (CompatibleAssetType) annotation; List<AssetType> compatibleAssetTypes = Arrays.asList(compatibleAssetType.types()); if (compatibleAssetTypes.contains(asset.getType())) { compatibleProcessors.add(assetProcessor); } } return compatibleProcessors; } }
public Asset process(Asset asset, HttpServletRequest request) { if (context.getActiveProcessors().isEmpty()) { return asset; } List<AssetProcessor> compatibleAssetProcessors = getCompatibleProcessorFor(asset); if (!compatibleAssetProcessors.isEmpty()) { // Context to be passed in asset processors ProcessingContext processingContext = new ProcessingContext(context, asset, request); AssetLocator locator = AssetUtils.getAssetLocator(asset, context); String contents = locator.getContent(asset, request); Reader assetReader = new StringReader(contents); Writer assetWriter = new StringWriter(); for (AssetProcessor assetProcessor : compatibleAssetProcessors) { LOG.trace("Applying processor {} on {}", assetProcessor.getProcessorKey(), asset.toLog()); assetWriter = new StringWriter(); assetProcessor.process(assetReader, assetWriter, processingContext); assetReader = new StringReader(assetWriter.toString()); } if (asset.isNotVendor()) { asset.setFinalLocation(AssetUtils.getAssetFinalLocation(request, asset, "min")); } // The cache system is updated with the new key/content pair context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, assetWriter.toString())); } else { LOG.trace("No compatible processor was found for the asset {}", asset.toLog()); } return asset; }
public Asset process(Asset asset, HttpServletRequest request) { if (context.getActiveProcessors().isEmpty()) { return asset; } List<AssetProcessor> compatibleAssetProcessors = getCompatibleProcessorFor(asset); if (!compatibleAssetProcessors.isEmpty()) { // Context to be passed in asset processors ProcessingContext processingContext = new ProcessingContext(context, asset, request); AssetLocator locator = AssetUtils.getAssetLocator(asset, context); String contents = locator.getContent(asset, request); Reader assetReader = new StringReader(contents); Writer assetWriter = new StringWriter(); for (AssetProcessor assetProcessor : compatibleAssetProcessors) { LOG.trace("Applying processor {} on {}", assetProcessor.getProcessorKey(), asset.toLog()); assetWriter = new StringWriter(); assetProcessor.process(assetReader, assetWriter, processingContext); assetReader = new StringReader(assetWriter.toString()); } if (asset.isNotVendor()) { asset.setFinalLocation(AssetUtils.getAssetFinalLocation(request, asset, "min")); } // The cache system is updated with the new key/content pair context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, assetWriter.toString())); } else { LOG.trace("No compatible processor was found for the asset {}", asset.toLog()); } return asset; }