FvctxNodeFrameset.java 4.2 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.util.DigestAdler32
 *  com.scene7.is.util.SizeInt
 *  com.scene7.is.util.error.ApplicationException
 *  org.jetbrains.annotations.NotNull
 */
package com.scene7.is.ps.provider.fvctx;

import com.scene7.is.ps.provider.IZoomException;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.fvctx.FvctxImageProps;
import com.scene7.is.ps.provider.fvctx.FvctxNode;
import com.scene7.is.ps.provider.fvctx.FvctxNodeNull;
import com.scene7.is.ps.provider.fvctx.FvctxSizeCounter;
import com.scene7.is.ps.provider.fvctx.MediaSetMetaData;
import com.scene7.is.util.DigestAdler32;
import com.scene7.is.util.SizeInt;
import com.scene7.is.util.error.ApplicationException;
import java.util.zip.Adler32;
import org.jetbrains.annotations.NotNull;

class FvctxNodeFrameset
extends FvctxNodeNull {
    private final int maxFramesPerSet;
    private int numFrames;
    private Adler32 imageDigest;
    private Adler32 metaDigest;
    private FvctxSizeCounter framesetSizeCounter;
    private boolean anonymousFrames;

    FvctxNodeFrameset(int maxFramesPerSet, @NotNull FvctxNode next) {
        super(next);
        this.maxFramesPerSet = maxFramesPerSet;
    }

    @Override
    public void startFrameset() {
        this.numFrames = 0;
        this.imageDigest = DigestAdler32.createMessageDigest();
        this.metaDigest = DigestAdler32.createMessageDigest();
        this.framesetSizeCounter = new FvctxSizeCounter();
        this.anonymousFrames = false;
        this.getNext().startFrameset();
    }

    @Override
    public void endFrameset(SizeInt size, String imageVersion, String metaVersion, boolean anonymousFrames) {
        this.finishFrameset();
    }

    @Override
    public void startFrame(@NotNull String netPath, @NotNull String query, @NotNull Request parsedRequest, @NotNull FvctxImageProps imageProps, boolean hasNestedFrame, boolean isMediaSetItem) throws ApplicationException {
        if (this.numFrames == this.maxFramesPerSet) {
            this.finishFrameset();
            this.startFrameset();
        }
        FvctxImageProps.updateImageDigest(this.imageDigest, imageProps);
        FvctxImageProps.updateMetaDigest(this.metaDigest, imageProps);
        ++this.numFrames;
        this.getNext().startFrame(netPath, query, parsedRequest, imageProps, hasNestedFrame, isMediaSetItem);
    }

    @Override
    public void endFrame(@NotNull SizeInt size, @NotNull String imageVersion, @NotNull MediaSetMetaData metaData, boolean hasNestedFrame) throws IZoomException {
        this.framesetSizeCounter.add(size);
        this.getNext().endFrame(size, imageVersion, metaData, hasNestedFrame);
    }

    @Override
    public void startAnonymousFrame() throws IZoomException {
        if (this.numFrames == this.maxFramesPerSet) {
            this.finishFrameset();
            this.startFrameset();
        }
        this.anonymousFrames = true;
        ++this.numFrames;
        this.getNext().startAnonymousFrame();
    }

    @Override
    public void image(@NotNull String netPath, @NotNull String query, @NotNull Request parsedRequest, @NotNull FvctxImageProps imageProps) throws ApplicationException {
        FvctxImageProps.updateImageDigest(this.imageDigest, imageProps);
        FvctxImageProps.updateMetaDigest(this.metaDigest, imageProps);
        this.getNext().image(netPath, query, parsedRequest, imageProps);
    }

    @Override
    public void swatch(@NotNull String netPath, @NotNull String query, @NotNull Request parsedRequest, @NotNull FvctxImageProps imageProps, boolean hasNestedFrame, boolean isMediaItemSwatch) throws ApplicationException {
        FvctxImageProps.updateImageDigest(this.imageDigest, imageProps);
        FvctxImageProps.updateMetaDigest(this.metaDigest, imageProps);
        this.getNext().swatch(netPath, query, parsedRequest, imageProps, hasNestedFrame, isMediaItemSwatch);
    }

    private void finishFrameset() {
        String image = DigestAdler32.createSignature((long)this.imageDigest.getValue());
        String meta = DigestAdler32.createSignature((long)this.metaDigest.getValue());
        this.getNext().endFrameset(this.framesetSizeCounter.getMostOftenSize(), image, meta, this.anonymousFrames);
    }
}