<commit_before>package app.hongs.util.verify;

import app.hongs.Core;
import app.hongs.action.ActionHelper;
import app.hongs.util.Synt;
import app.hongs.util.Dict;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 默认取值
 * <pre>
 * 规则参数:
 *  default 默认值, 可使用 =@请求参数 =$会话属性, =%应用属性, =%now+-偏移毫秒
 *  deforce 强制写, 控制不同阶段, create 创建时, update 更新时, always 任何时
 * </pre>
 * @author Hongs
 */
public class Default extends Rule {
    @Override
    public Object verify(Object value) {
        Object force = params.get("deforce");
        if ( "update".equals(force)) {
            if (helper.isUpdate() != true) {
                return BLANK;
            }
        } else
        if ( "create".equals(force)) {
            if (helper.isUpdate() == true) {
                return BLANK;
            }
        } else
        if (!"always".equals(force)) {
            if (helper.isUpdate() && value == null) {
                return BLANK;
            }
            if (!"".equals(value) && value != null) {
                return value;
            }
        }

        value = params.get("default");
        String  def = Synt.declare(value, "").trim();

        // 动作选项
        if (def.equals("=%zone")) {
            return Core.ACTION_ZONE.get();
        }
        if (def.equals("=%lang")) {
            return Core.ACTION_LANG.get();
        }
        if (def.equals("=%addr")) {
            return Core.CLIENT_ADDR.get();
        }

        // 默认时间
        Matcher mat = NOW.matcher(def);
        if (mat.matches()) {
           Date now = new Date();
            if (mat.group(1).equals("time") ) {
                now.setTime( Core.ACTION_TIME.get());
            }
            if (mat.group(2) != null) {
               Long msc = Synt.declare( mat.group(4), 0L );
                if ("+".equals(mat.group(3))) {
                    now.setTime(now.getTime() + msc);
                } else {
                    now.setTime(now.getTime() - msc);
                }
            }
            return  now;
        }

        // 别名属性
        if (def.startsWith("=@")) {
            def= def.substring(2);
            Object val;
            val= Dict.get(cleans, BLANK, def);
            if ( val  !=  null  ) return val ;
            val= Dict.get(values, BLANK, def);
            return val;
        }

        // 会话属性
        if (def.startsWith("=$")) {
            return Core.getInstance(ActionHelper.class).getSessibute(def.substring(2));
        }

        // 应用属性
        if (def.startsWith("=%")) {
            return Core.getInstance(ActionHelper.class).getAttribute(def.substring(2));
        }<commit_msg>取别名修改为可从数据中提取多层以下的值<commit_after>package app.hongs.util.verify;

import app.hongs.Core;
import app.hongs.action.ActionHelper;
import app.hongs.util.Synt;
import app.hongs.util.Dict;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 默认取值
 * <pre>
 * 规则参数:
 *  default 默认值, 可使用 =@别名字段 =$会话属性, =%应用属性, =%now+-偏移毫秒
 *  deforce 强制写, 控制不同阶段, create 创建时, update 更新时, always 任何时
 * </pre>
 * @author Hongs
 */
public class Default extends Rule {
    @Override
    public Object verify(Object value) {
        Object force = params.get("deforce");
        if ( "update".equals(force)) {
            if (helper.isUpdate() != true) {
                return BLANK;
            }
        } else
        if ( "create".equals(force)) {
            if (helper.isUpdate() == true) {
                return BLANK;
            }
        } else
        if (!"always".equals(force)) {
            if (helper.isUpdate() && value == null) {
                return BLANK;
            }
            if (!"".equals(value) && value != null) {
                return value;
            }
        }

        value = params.get("default");
        String  def = Synt.declare(value, "").trim();

        // 动作选项
        if (def.equals("=%zone")) {
            return Core.ACTION_ZONE.get();
        }
        if (def.equals("=%lang")) {
            return Core.ACTION_LANG.get();
        }
        if (def.equals("=%addr")) {
            return Core.CLIENT_ADDR.get();
        }

        // 默认时间
        Matcher mat = NOW.matcher(def);
        if (mat.matches()) {
           Date now = new Date();
            if (mat.group(1).equals("time") ) {
                now.setTime( Core.ACTION_TIME.get());
            }
            if (mat.group(2) != null) {
               Long msc = Synt.declare( mat.group(4), 0L );
                if ("+".equals(mat.group(3))) {
                    now.setTime(now.getTime() + msc);
                } else {
                    now.setTime(now.getTime() - msc);
                }
            }
            return  now;
        }

        // 别名字段
        if (def.startsWith("=@")) {
            return Dict.get(cleans, BLANK, def.substring(2));
        }

        // 会话属性
        if (def.startsWith("=$")) {
            return Core.getInstance(ActionHelper.class).getSessibute(def.substring(2));
        }

        // 应用属性
        if (def.startsWith("=%")) {
            return Core.getInstance(ActionHelper.class).getAttribute(def.substring(2));
        }
{'fraction_non_alphanumeric': 0.1512979465323518, 'fraction_numerical': 0.0030995738086013174, 'mean_word_length': 1.5111867704280155, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7389567', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1721, 'n_words': 311}