io.wcm.handler.media.spi.helpers.AbstractMediaHandlerConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of io.wcm.handler.media Show documentation
Show all versions of io.wcm.handler.media Show documentation
Media resolving, processing and markup generation.
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2014 wcm.io
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package io.wcm.handler.media.spi.helpers;
import io.wcm.handler.media.format.MediaFormat;
import io.wcm.handler.media.markup.DummyImageMediaMarkupBuilder;
import io.wcm.handler.media.markup.SimpleImageMediaMarkupBuilder;
import io.wcm.handler.media.spi.MediaHandlerConfig;
import io.wcm.handler.media.spi.MediaMarkupBuilder;
import io.wcm.handler.media.spi.MediaProcessor;
import io.wcm.handler.media.spi.MediaSource;
import io.wcm.handler.mediasource.dam.DamMediaSource;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.osgi.annotation.versioning.ConsumerType;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
/**
* Default implementation of configuration options of {@link MediaHandlerConfig} interface.
* Subclasses may decide to override only some of the methods.
*/
@ConsumerType
public abstract class AbstractMediaHandlerConfig implements MediaHandlerConfig {
private static final Set DOWNLOAD_MEDIA_FORMATS = ImmutableSet.of();
private static final List> MEDIA_SOURCES =
ImmutableList.>of(
DamMediaSource.class
);
private static final List> MEDIA_MARKUP_BUILDERS =
ImmutableList.>of(
SimpleImageMediaMarkupBuilder.class,
DummyImageMediaMarkupBuilder.class
);
@Override
public List> getSources() {
return MEDIA_SOURCES;
}
@Override
public List> getMarkupBuilders() {
return MEDIA_MARKUP_BUILDERS;
}
@Override
public List> getPreProcessors() {
// no processors
return ImmutableList.of();
}
@Override
public List> getPostProcessors() {
// no processors
return ImmutableList.of();
}
@Override
public Set getDownloadMediaFormats() {
return DOWNLOAD_MEDIA_FORMATS;
}
@Override
public double getDefaultImageQuality(String mimeType) {
if (StringUtils.isNotEmpty(mimeType)) {
String format = StringUtils.substringAfter(mimeType.toLowerCase(), "image/");
if (StringUtils.equals(format, "jpg") || StringUtils.equals(format, "jpeg")) {
return DEFAULT_JPEG_QUALITY;
}
else if (StringUtils.equals(format, "gif")) {
return 256d; // 256 colors
}
}
// return quality "1" for all other mime types
return 1d;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy