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

com.github.gkutiel.flip.web.FileHandler Maven / Gradle / Ivy

package com.github.gkutiel.flip.web;

import java.io.IOException;

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

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

import com.github.gkutiel.flip.utils.Utils;

// TODO (gilad) set mime type
class FileHandler extends AbstractHandler {
	private final String target;
	private final String content;

	public static final FileHandler FAVICON_ICO = new FileHandler("/favicon.ico", "");
	public static final FileHandler FLIP_JS = new FileHandler("/flip.js", Utils.Resource.load("flip.js"));

	private FileHandler(final String target, final String content) {
		this.target = target;
		this.content = content;
	}

	@Override
	public void handle(final String target, final Request bReq, final HttpServletRequest req, final HttpServletResponse res) throws IOException {
		if (!this.target.equals(target)) return;
		bReq.setHandled(true);
		res.getWriter().write(this.content);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy