use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.
the class GaussianBlur method buildOperation.
@Override
public Operation buildOperation(Map<String, String> parameterMap, InputStream artifactStream, String mimeType) {
String key = FilterTypeEnum.GAUSSIANBLUR.toString().toLowerCase();
if (!containsMyFilterParams(key, parameterMap)) {
return null;
}
Operation operation = new Operation();
operation.setName(key);
String factor = parameterMap.get(key + "-factor");
operation.setFactor(factor == null ? null : Double.valueOf(factor));
UnmarshalledParameter kernelSize = new UnmarshalledParameter();
String kernelSizeApplyFactor = parameterMap.get(key + "-kernel-size-apply-factor");
kernelSize.setApplyFactor(kernelSizeApplyFactor == null ? false : Boolean.valueOf(kernelSizeApplyFactor));
kernelSize.setName("kernel-size");
kernelSize.setType(ParameterTypeEnum.INT.toString());
kernelSize.setValue(parameterMap.get(key + "-kernel-size-amount"));
UnmarshalledParameter numOfPasses = new UnmarshalledParameter();
String numOfPassesApplyFactor = parameterMap.get(key + "-num-passes-apply-factor");
numOfPasses.setApplyFactor(numOfPassesApplyFactor == null ? false : Boolean.valueOf(numOfPassesApplyFactor));
numOfPasses.setName("num-passes");
numOfPasses.setType(ParameterTypeEnum.INT.toString());
numOfPasses.setValue(parameterMap.get(key + "-num-passes-amount"));
operation.setParameters(new UnmarshalledParameter[] { kernelSize, numOfPasses });
return operation;
}
use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.
the class Rotate method buildOperation.
@Override
public Operation buildOperation(Map<String, String> parameterMap, InputStream artifactStream, String mimeType) {
String key = FilterTypeEnum.ROTATE.toString().toLowerCase();
if (!containsMyFilterParams(key, parameterMap)) {
return null;
}
Operation operation = new Operation();
operation.setName(key);
String factor = parameterMap.get(key + "-factor");
operation.setFactor(factor == null ? null : Double.valueOf(factor));
UnmarshalledParameter rotate = new UnmarshalledParameter();
String rotateApplyFactor = parameterMap.get(key + "-rotate-apply-factor");
rotate.setApplyFactor(rotateApplyFactor == null ? false : Boolean.valueOf(rotateApplyFactor));
rotate.setName("rotate");
rotate.setType(ParameterTypeEnum.DOUBLE.toString());
rotate.setValue(parameterMap.get(key + "-rotate-amount"));
operation.setParameters(new UnmarshalledParameter[] { rotate });
return operation;
}
use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.
the class UnsharpMask method buildOperation.
@Override
public Operation buildOperation(Map<String, String> parameterMap, InputStream artifactStream, String mimeType) {
String key = FilterTypeEnum.UNSHARPMASK.toString().toLowerCase();
if (!containsMyFilterParams(key, parameterMap)) {
return null;
}
Operation operation = new Operation();
operation.setName(key);
String factor = parameterMap.get(key + "-factor");
operation.setFactor(factor == null ? null : Double.valueOf(factor));
UnmarshalledParameter amount = new UnmarshalledParameter();
String amountApplyFactor = parameterMap.get(key + "-value-apply-factor");
amount.setApplyFactor(amountApplyFactor == null ? false : Boolean.valueOf(amountApplyFactor));
amount.setName("value");
amount.setType(ParameterTypeEnum.FLOAT.toString());
amount.setValue(parameterMap.get(key + "-value-amount"));
UnmarshalledParameter radius = new UnmarshalledParameter();
String radiusApplyFactor = parameterMap.get(key + "-radius-apply-factor");
radius.setApplyFactor(radiusApplyFactor == null ? false : Boolean.valueOf(radiusApplyFactor));
radius.setName("radius");
radius.setType(ParameterTypeEnum.INT.toString());
radius.setValue(parameterMap.get(key + "-radius-amount"));
operation.setParameters(new UnmarshalledParameter[] { amount, radius });
return operation;
}
use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.
the class StaticAssetStorageServiceImpl method getCacheFileModel.
@Override
public Map<String, String> getCacheFileModel(String fullUrl, Map<String, String> parameterMap) throws Exception {
StaticAsset staticAsset = findStaticAsset(fullUrl);
if (staticAsset == null) {
throw new AssetNotFoundException("Unable to find an asset for the url (" + fullUrl + ")");
}
String mimeType = staticAsset.getMimeType();
// extract the values for any named parameters
Map<String, String> convertedParameters = namedOperationManager.manageNamedParameters(parameterMap);
String cachedFileName = constructCacheFileName(staticAsset, convertedParameters);
// Look for a shared file (this represents a file that was based on a file originally in the classpath.
File cacheFile = getFileFromLocalRepository(cachedFileName);
if (cacheFile.exists()) {
return buildModel(cacheFile.getAbsolutePath(), mimeType);
}
// Obtain the base file (that we may need to convert based on the parameters
String baseCachedFileName = constructCacheFileName(staticAsset, null);
File baseLocalFile = getFileFromLocalRepository(baseCachedFileName);
if (!baseLocalFile.exists()) {
if (broadleafFileService.checkForResourceOnClassPath(staticAsset.getFullUrl())) {
cacheFile = broadleafFileService.getSharedLocalResource(cachedFileName);
baseLocalFile = broadleafFileService.getSharedLocalResource(baseCachedFileName);
createLocalFileFromClassPathResource(staticAsset, baseLocalFile);
} else {
baseLocalFile = lookupAssetAndCreateLocalFile(staticAsset, baseLocalFile);
}
}
if (convertedParameters.isEmpty()) {
return buildModel(baseLocalFile.getAbsolutePath(), mimeType);
} else {
FileInputStream assetStream = new FileInputStream(baseLocalFile);
BufferedInputStream original = new BufferedInputStream(assetStream);
original.mark(0);
Operation[] operations = artifactService.buildOperations(convertedParameters, original, staticAsset.getMimeType());
InputStream converted = artifactService.convert(original, operations, staticAsset.getMimeType());
createLocalFileFromInputStream(converted, cacheFile);
if ("image/gif".equals(mimeType)) {
mimeType = "image/png";
}
return buildModel(cacheFile.getAbsolutePath(), mimeType);
}
}
Aggregations