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

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

package com.wiris.plugin.dispatchers;

import com.wiris.plugin.LibWIRIS;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import java.net.URL;

import java.util.Enumeration;
import java.util.Properties;

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


public class ServiceDispatcher {
    public static void dispatch(Properties config, HttpServletRequest request, 
                                HttpServletResponse response) throws IOException {
        response.setContentType("text/plain; charset=utf-8");
        PrintWriter out = response.getWriter();
        String service = request.getParameter("service");

        if (service != null) {
            URL url = LibWIRIS.getImageServiceURL(config, service);
            Properties data = new Properties();
            
            Enumeration i = request.getParameterNames();

            while (i.hasMoreElements()) {
                String key = i.nextElement();

                if (!key.equals("service")) {
                    data.setProperty(key, request.getParameter(key));
                }
            }

            try {
                InputStream inputStream = LibWIRIS.getContents(url, data, LibWIRIS.getReferer(request));
                ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
                LibWIRIS.flow(inputStream, dataStream);
                out.print(dataStream.toString("UTF-8"));
            } catch (Exception e) {
                out.print("Error connecting to the latex translator service.");
            }
        }

        out.close();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy