MediaSetPipelineProcessor.java 10.9 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.catalog.util.localization.LocaleMap
 *  com.scene7.is.catalog.util.localization.LocalizedText
 *  com.scene7.is.provider.ImageSet
 *  com.scene7.is.provider.ImageSetColorLabel
 *  com.scene7.is.provider.ImageSetItem
 *  com.scene7.is.sleng.Color
 *  com.scene7.is.util.SizeInt
 *  com.scene7.is.util.UrlRequest
 *  com.scene7.is.util.error.ApplicationException
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 */
package com.scene7.is.ps.provider.fvctx;

import com.scene7.is.catalog.util.localization.LocaleMap;
import com.scene7.is.catalog.util.localization.LocalizedText;
import com.scene7.is.provider.ImageSet;
import com.scene7.is.provider.ImageSetColorLabel;
import com.scene7.is.provider.ImageSetItem;
import com.scene7.is.ps.provider.IZoomException;
import com.scene7.is.ps.provider.ModifierSet;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.defs.ModifierEnum;
import com.scene7.is.ps.provider.fvctx.FvctxImageProps;
import com.scene7.is.ps.provider.fvctx.FvctxNode;
import com.scene7.is.ps.provider.fvctx.FvctxUtil;
import com.scene7.is.ps.provider.fvctx.MediaSetItemType;
import com.scene7.is.ps.provider.fvctx.MediaSetMetaData;
import com.scene7.is.ps.provider.fvctx.MediaSetSetType;
import com.scene7.is.ps.provider.fvctx.MediaSetVideoEntry;
import com.scene7.is.ps.provider.fvctx.MediaSetVideoProps;
import com.scene7.is.sleng.Color;
import com.scene7.is.util.SizeInt;
import com.scene7.is.util.UrlRequest;
import com.scene7.is.util.error.ApplicationException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

class MediaSetPipelineProcessor {
    public static void processImage(@NotNull Request request, @NotNull FvctxNode pipeline, @Nullable ImageSetItem swatch, boolean isMediaSet) throws IZoomException {
        try {
            ModifierSet attr = request.getGlobalAttributes();
            String netPath = "/" + attr.getOrDie(ModifierEnum.I_NET_PATH);
            String netQuery = "";
            if (isMediaSet) {
                netQuery = attr.getOrDie(ModifierEnum.I_NET_QUERY);
            }
            pipeline.startFrame(netPath, netQuery, request, null, false, isMediaSet);
            MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
            pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
        }
        catch (IZoomException e) {
            throw e;
        }
        catch (ApplicationException e) {
            throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, e.getMessage(), (Throwable)e);
        }
    }

    public static void processSingleVideo(@NotNull MediaSetVideoEntry videoEntry, @NotNull FvctxNode pipeline, @Nullable ImageSetItem swatch) throws IZoomException {
        try {
            MediaSetVideoProps videoProps = new MediaSetVideoProps(videoEntry);
            pipeline.startVideoFrame(videoEntry.getNetPath(), "", videoProps);
            String posterImageId = videoEntry.getPosterImage();
            if (posterImageId != null) {
                pipeline.image(posterImageId, "", null, null);
            }
            MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
            pipeline.endVideoFrame(MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, "", videoEntry.getFileSuffix());
        }
        catch (IZoomException e) {
            throw e;
        }
        catch (ApplicationException e) {
            throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, e.getMessage(), (Throwable)e);
        }
    }

    public static void processOuterVideoSet(@NotNull List<MediaSetVideoEntry> videoEntries, @NotNull FvctxNode pipeline) throws IZoomException {
        for (MediaSetVideoEntry videoEntry : videoEntries) {
            MediaSetPipelineProcessor.processSingleVideo(videoEntry, pipeline, null);
        }
    }

    public static void processVideoSetAsMediaSetItem(@NotNull MediaSetItemType videoSetType, @NotNull List<MediaSetVideoEntry> videoEntries, @NotNull FvctxNode pipeline, @NotNull String recordName, @Nullable ImageSetItem swatch, @NotNull MediaSetMetaData mediaSetItemMetaData) throws IZoomException {
        try {
            pipeline.startItem(videoSetType);
            pipeline.startSet(recordName, MediaSetItemType.convertItemToSetType(videoSetType));
            MediaSetPipelineProcessor.processOuterVideoSet(videoEntries, pipeline);
            pipeline.endSet(mediaSetItemMetaData);
            MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
            pipeline.endItem("");
        }
        catch (IZoomException e) {
            throw e;
        }
        catch (ApplicationException e) {
            throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, e.getMessage(), (Throwable)e);
        }
    }

    public static void processImageSet(@NotNull ImageSet imageSet, @NotNull FvctxNode pipeline, @NotNull MediaSetSetType setType, @NotNull MediaSetItemType itemType, @Nullable ImageSetItem swatch, boolean isMediaSet, boolean isNestedSet, @NotNull String recordName, @NotNull MediaSetMetaData mediaSetItemMetaData) throws IZoomException {
        try {
            if (imageSet.items.isEmpty()) {
                return;
            }
            if (((ImageSetItem)imageSet.items.get((int)0)).separator != ',') {
                throw new IZoomException(IZoomException.FVCTX_NO_FRAME_AT_START_IMAGESET, imageSet.generateString(), null);
            }
            if (isMediaSet) {
                pipeline.startItem(itemType);
                pipeline.startSet(recordName, setType);
            } else if (isNestedSet) {
                pipeline.startSet(recordName, setType);
            }
            int i = 0;
            for (ImageSetItem item : imageSet.items) {
                switch (item.separator) {
                    case ',': {
                        MediaSetPipelineProcessor.processFrame(i, item, pipeline);
                        break;
                    }
                    case ':': {
                        MediaSetPipelineProcessor.processImage(item, pipeline);
                        break;
                    }
                    case ';': {
                        MediaSetPipelineProcessor.processSwatch(item, pipeline, mediaSetItemMetaData.getLocaleMap(), mediaSetItemMetaData.getLocale());
                        break;
                    }
                    default: {
                        throw new IZoomException(IZoomException.FVCTX_INVALID_SEPARATOR, MediaSetPipelineProcessor.errorMessage(item), null);
                    }
                }
                ++i;
            }
            pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
            if (isMediaSet) {
                pipeline.endSet(mediaSetItemMetaData);
                MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
                pipeline.endItem("");
            } else if (isNestedSet) {
                pipeline.endSet(mediaSetItemMetaData);
            }
        }
        catch (IZoomException e) {
            throw e;
        }
        catch (ApplicationException e) {
            throw new IZoomException(IZoomException.FVCTX_SWATCH_ERROR, e.getMessage(), (Throwable)e);
        }
    }

    private MediaSetPipelineProcessor() {
    }

    private static void processFrame(int i, @NotNull ImageSetItem item, @NotNull FvctxNode pipeline) throws IZoomException {
        try {
            if (i > 0) {
                pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
            }
            if (item.asset == null || item.asset.isEmpty()) {
                throw new IZoomException(IZoomException.FVCTX_IMAGE_EXPECTED, item.generateString(), null);
            }
            if (FvctxUtil.hasBraces(item.asset)) {
                pipeline.startFrame(item.asset, "", null, null, false, false);
            } else {
                UrlRequest request = UrlRequest.splitUrlRequest((String)item.asset);
                pipeline.startFrame(request.path, request.query, null, null, false, false);
            }
        }
        catch (IZoomException e) {
            throw e;
        }
        catch (ApplicationException e) {
            throw new IZoomException(IZoomException.FVCTX_FRAME_ERROR, MediaSetPipelineProcessor.errorMessage(item), (Throwable)e);
        }
    }

    private static void processImage(@NotNull ImageSetItem item, @NotNull FvctxNode pipeline) throws IZoomException {
        try {
            UrlRequest request = MediaSetPipelineProcessor.processImageAsset(item);
            if (request != null) {
                pipeline.image(request.path, request.query, null, null);
            }
        }
        catch (IZoomException e) {
            throw e;
        }
        catch (ApplicationException e) {
            throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, MediaSetPipelineProcessor.errorMessage(item), (Throwable)e);
        }
    }

    private static boolean processSwatch(@NotNull ImageSetItem item, @NotNull FvctxNode pipeline, @NotNull LocaleMap localeMap, @NotNull String locale) throws IZoomException {
        try {
            if (item.colorLabel != null) {
                pipeline.swatch(new ImageSetColorLabel(item.colorLabel.color, item.colorLabel.label.urlDecode()), localeMap, locale, false);
                return false;
            }
            UrlRequest request = MediaSetPipelineProcessor.processImageAsset(item);
            if (request != null) {
                pipeline.swatch(request.path, request.query, null, null, false, false);
                return false;
            }
            return true;
        }
        catch (IZoomException e) {
            throw e;
        }
        catch (ApplicationException e) {
            throw new IZoomException(IZoomException.FVCTX_SWATCH_ERROR, MediaSetPipelineProcessor.errorMessage(item), (Throwable)e);
        }
        catch (IllegalArgumentException e) {
            throw new IZoomException(IZoomException.FVCTX_INVALID_COLOR_LABEL, MediaSetPipelineProcessor.errorMessage(item), e);
        }
    }

    private static void handleSwatch(@Nullable ImageSetItem swatch, @NotNull FvctxNode pipeline) throws ApplicationException {
        UrlRequest swatchRequest;
        if (swatch != null && (swatchRequest = MediaSetPipelineProcessor.processImageAsset(swatch)) != null) {
            pipeline.swatch(swatchRequest.path, swatchRequest.query, null, null, false, true);
        }
    }

    @Nullable
    private static UrlRequest processImageAsset(@NotNull ImageSetItem item) throws IZoomException {
        if (item.asset == null) {
            throw new IZoomException(IZoomException.FVCTX_IMAGE_EXPECTED, item.generateString(), null);
        }
        if (item.asset.isEmpty()) {
            return null;
        }
        return UrlRequest.splitUrlRequest((String)item.asset);
    }

    @NotNull
    private static String errorMessage(@NotNull ImageSetItem item) {
        return item.generateString();
    }
}