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

com.firefly.mvc.web.view.TextView Maven / Gradle / Ivy

There is a newer version: 4.0.3.2
Show newest version
package com.firefly.mvc.web.view;

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

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

import com.firefly.mvc.web.View;

public class TextView implements View {

	private static String ENCODING;
	private final String text;

	public static void setEncoding(String encoding) {
		if (ENCODING == null && encoding != null)
			ENCODING = encoding;
	}

	public TextView(String text) {
		this.text = text;
	}

	@Override
	public void render(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding(ENCODING);
		response.setHeader("Content-Type", "text/plain; charset=" + ENCODING);
		PrintWriter writer = response.getWriter();
		try {
			writer.print(text);
		} finally {
			writer.close();
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy