<commit_before>package org.nutz.mvc.view;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

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

import org.nutz.lang.Mirror;
import org.nutz.lang.Strings;
import org.nutz.lang.segment.CharSegment;
import org.nutz.lang.segment.Segment;
import org.nutz.mvc.View;

/**
 * 重定向视图
 * <p>
 * 在入口函数上声明：
 * <p>
 * '@Ok("redirect:/pet/list.nut")'
 * <p>
 * 实际上相当于：<br>
 * new ServerRedirectView("/pet/list.nut");
 * 
 * @author zozoh(<EMAIL>)
 */
public class ServerRedirectView implements View {

	private Segment dest;

	public ServerRedirectView(String dest) {
		this.dest = new CharSegment(Strings.trim(dest));
	}

	// TODO 这个函数写的有点烂，有时间重构一下
	public void render(HttpServletRequest req, HttpServletResponse resp, Object obj)
			throws Exception {
		Mirror<?> mirror = Mirror.me(obj);
		boolean isMap = null != obj && obj instanceof Map<?, ?>;
		Map<?, ?> map = isMap ? null : (Map<?, ?>) obj;

		// Fill path
		Set<String> keySet = dest.keys();
		Iterator<String> it = keySet.iterator();
		while (it.hasNext()) {
			String key = it.next();
			Object value = null;
			int length = key.length();
			if (key.startsWith("p.") && length > 2) {
				value = req.getParameter(key.substring(2));
			}
			// Map
			else if (isMap && key.startsWith("obj.") && length > 4) {
				value = map.get(key);
			}
			// POJO
			else if (null != mirror && key.startsWith("obj.") && length > 4) {
				value = mirror.getValue(obj, key.substring(4));
			}
			// Normal value
			else {
				value = obj;<commit_msg>fix issue 227<commit_after>package org.nutz.mvc.view;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

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

import org.nutz.lang.Mirror;
import org.nutz.lang.Strings;
import org.nutz.lang.segment.CharSegment;
import org.nutz.lang.segment.Segment;
import org.nutz.mvc.View;

/**
 * 重定向视图
 * <p>
 * 在入口函数上声明：
 * <p>
 * '@Ok("redirect:/pet/list.nut")'
 * <p>
 * 实际上相当于：<br>
 * new ServerRedirectView("/pet/list.nut");
 * 
 * @author zozoh(<EMAIL>)
 */
public class ServerRedirectView implements View {

	private Segment dest;

	public ServerRedirectView(String dest) {
		this.dest = new CharSegment(Strings.trim(dest));
	}

	// TODO 这个函数写的有点烂，有时间重构一下
	public void render(HttpServletRequest req, HttpServletResponse resp, Object obj)
			throws Exception {
		Mirror<?> mirror = Mirror.me(obj);
		boolean isMap = null != obj && obj instanceof Map<?, ?>;
		Map<?, ?> map = isMap ? (Map<?, ?>) obj : null;

		// Fill path
		Set<String> keySet = dest.keys();
		Iterator<String> it = keySet.iterator();
		while (it.hasNext()) {
			String key = it.next();
			Object value = null;
			int length = key.length();
			if (key.startsWith("p.") && length > 2) {
				value = req.getParameter(key.substring(2));
			}
			// Map
			else if (isMap && key.startsWith("obj.") && length > 4) {
				value = map.get(key);
			}
			// POJO
			else if (null != mirror && key.startsWith("obj.") && length > 4) {
				value = mirror.getValue(obj, key.substring(4));
			}
			// Normal value
			else {
				value = obj;
{'fraction_non_alphanumeric': 0.16426332288401255, 'fraction_numerical': 0.0040752351097178684, 'mean_word_length': 3.539118065433855, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4432208', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1159, 'n_words': 251}