FvctxPipelineProcessor.java 7.09 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.MediaSetMetaData;
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 FvctxPipelineProcessor {
    public static void processSingleImageRequest(@NotNull Request request, @NotNull FvctxNode pipeline) throws IZoomException {
        try {
            ModifierSet attr = request.getGlobalAttributes();
            String netPath = attr.getOrDie(ModifierEnum.I_NET_PATH);
            pipeline.startFrameset();
            pipeline.startFrame(netPath, "", request, null, false, false);
            pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
            pipeline.endFrameset(null, null, null, false);
        }
        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) throws IZoomException {
        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());
        }
        pipeline.startFrameset();
        boolean lastSwatchEmpty = false;
        int i = 0;
        for (ImageSetItem item : imageSet.items) {
            switch (item.separator) {
                case ',': {
                    FvctxPipelineProcessor.processFrame(i, item, pipeline);
                    lastSwatchEmpty = false;
                    break;
                }
                case ':': {
                    FvctxPipelineProcessor.processImage(item, pipeline);
                    lastSwatchEmpty = false;
                    break;
                }
                case ';': {
                    lastSwatchEmpty = FvctxPipelineProcessor.processSwatch(lastSwatchEmpty, item, pipeline);
                    break;
                }
                default: {
                    throw new IZoomException(IZoomException.FVCTX_INVALID_SEPARATOR, FvctxPipelineProcessor.errorMessage(item));
                }
            }
            ++i;
        }
        pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
        pipeline.endFrameset(null, null, null, false);
    }

    private FvctxPipelineProcessor() {
    }

    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, FvctxPipelineProcessor.errorMessage(item), (Throwable)e);
        }
    }

    private static void processImage(@NotNull ImageSetItem item, @NotNull FvctxNode pipeline) throws IZoomException {
        try {
            UrlRequest request = FvctxPipelineProcessor.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, FvctxPipelineProcessor.errorMessage(item), (Throwable)e);
        }
    }

    private static boolean processSwatch(boolean lastSwatchEmpty, @NotNull ImageSetItem item, @NotNull FvctxNode pipeline) throws IZoomException {
        try {
            if (lastSwatchEmpty) {
                pipeline.defaultSwatch();
            }
            if (item.colorLabel != null) {
                pipeline.swatch(new ImageSetColorLabel(item.colorLabel.color, item.colorLabel.label.urlDecode()), LocaleMap.EMPTY_LOCALE_MAP, "", false);
                return false;
            }
            UrlRequest request = FvctxPipelineProcessor.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, FvctxPipelineProcessor.errorMessage(item), (Throwable)e);
        }
        catch (IllegalArgumentException e) {
            throw new IZoomException(IZoomException.FVCTX_INVALID_COLOR_LABEL, FvctxPipelineProcessor.errorMessage(item), e);
        }
    }

    @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();
    }
}