All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wiris.plugin.dispatchers.CreateCASImageDispatcher Maven / Gradle / Ivy

package com.wiris.plugin.dispatchers;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wiris.plugin.Base64;
import com.wiris.plugin.storage.StorageAndCache;

public abstract class CreateCASImageDispatcher {
    private static byte[] CharacterMap = new byte[128];

    public static void dispatch(HttpServletRequest request, HttpServletResponse response, StorageAndCache storage) throws IOException {
        String currentPath = request.getContextPath() + "/";
        response.setContentType("text/plain; charset=utf-8");
        PrintWriter out = response.getWriter();
        String imageParameter = request.getParameter("image");

        if (imageParameter != null) {
            try {
                byte[] dataDecoded = Base64.decode(imageParameter);
                String digest = storage.codeDigest(imageParameter);
                storage.storeData(digest, dataDecoded);
                out.print(currentPath + "app/showcasimage?formula=" + digest + ".png");
            } catch (Error e) {
                out.print(currentPath + "../resources/cas.gif");
            }
        } else {
            out.print(currentPath + "../resources/cas.gif");
        }

        out.close();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy