Extensions mapping
Mapping by Extension
Since WebExplorer4.0.0 you can choose witch strategy to use to preview a file, based on it’s extension.
Standard strategies
- Office documents : converts office documents to pdf
- Image : displays images directly in the browser without conversion
- 3D documents : optional configuration, converts 3D files using TFT
- “.url” files : shows a button to follow the link
Standard error/info messages
- Unknown file (no extension) : info message and download button
- Not handled extension : info message and download button
- TFT optional configuration missing for 3D files : info message and download button
- Every other unexpected exception : error message and download button
Add your own mapping
You can add you own mapping to handle more extensions. You’ll need to create a XML mapping file and a java class ( ConverterStrategy). The further examples will show how the standard image conversion strategy works.
XML configuration
Do not override the standard Webexplorer mapping file, you can specify a custom mapping for an existing extension in your custom mapping file, it will override the standard mapping.
Add a XML file in this folder (you can name it as you wish):
Since WebExplorer4.0.0 (Deprecated in 2024.1)
[custom/webexplorer/my-custom-mapping-file.xml]
Since WebExplorer2024.1
[custom/viewer/my-custom-mapping-file.xml]
Map each file extension with a java class extending AbstractConverterStrategy
<mappings>
<!-- Images -->
<mapping extension="png" strategy="com.vdoc.vdocwebexplorer.viewer.navigation.strategies.ImageConverterStrategy"/>
<mapping extension="jpg" strategy="com.vdoc.vdocwebexplorer.viewer.navigation.strategies.ImageConverterStrategy"/>
<mapping extension="jpeg" strategy="com.vdoc.vdocwebexplorer.viewer.navigation.strategies.ImageConverterStrategy"/>
<mapping extension="bmp" strategy="com.vdoc.vdocwebexplorer.viewer.navigation.strategies.ImageConverterStrategy"/>
<mapping extension="gif" strategy="com.vdoc.vdocwebexplorer.viewer.navigation.strategies.ImageConverterStrategy"/>
</mappings>
Converter strategy (java class)
This class is the standard class used to show images in viewer.
In the following example, no conversion is needed so <T>
is Void
, the only treatment needed is to build a widget to
show the image.
If you need to convert document, you have to create a Future
Object. A loader will be displayed untill your conversion
ends.
Since WebExplorer4.0.0 (Deprecated in 2024.1)
import com.vdoc.vdocwebexplorer.viewer.navigation.convertable.Convertable;
import com.vdoc.vdocwebexplorer.viewer.navigation.strategies.AbstractConverterStrategy;
import com.vdoc.vdocwebexplorer.viewer.navigation.strategies.ReadyFuture;
Since WebExplorer2024.1
import com.axemble.vdoc.sdk.interfaces.IViewerConvertable;
import com.axemble.vdoc.sdk.viewer.AbstractConverterStrategy;
import com.axemble.vdoc.sdk.viewer.ReadyFuture;
public class ImageConverterStrategy extends AbstractConverterStrategy<Void> {
/**
* Stores the Convertable item
*/
public ImageConverterStrategy(Convertable convertable) {
super(convertable);
}
/**
* Called when opening document, must return a Future<T>, T representing the result type (String, File, Void ...)
*/
@Override
public Future<Void> start() {
// ReadyFuture is used to inform that the render can directly be done
return new ReadyFuture<>(null);
}
/**
* Final render used inside lightbox.
*/
@Override
public IWidget toWidget() {
CtlImage image = new CtlImage(null);
image.setUrl(this.convertable.getUrl());
CtlDiv imageContainer = new CtlDiv();
imageContainer.addAttribute("id", "image-viewer");
imageContainer.addContent(image);
return imageContainer;
}
/**
* Called when the conversion succeed
*/
@Override
public void onSuccess(Void result) {
// nothing to do
}
/**
* Called when the conversion fails
*/
@Override
public void onException(Exception e) {
// nothing to do
}
}
Display error/info messages using default render
If you want to show an error or info message with the download button underneath as the standard does, you can throw
a GenericConversionException
with a translation key :
Since WebExplorer4.0.0 (Deprecated in 2024.1)
import com.vdoc.vdocwebexplorer.viewer.navigation.exception.GenericConversionException;
throw new GenericConversionException("LG_VIEWER_NO_PREVIEW", e);
Since WebExplorer2024.1
import com.axemble.vdoc.sdk.exceptions.ViewerGenericConversionException;
throw new ViewerGenericConversionException("LG_VIEWER_NO_PREVIEW", e);
If you want to customize the error message, you can return you own widget in the toWidget
method.