• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aspectran / aspectran / #4057

11 Feb 2025 06:00AM CUT coverage: 35.269% (+1.9%) from 33.377%
#4057

push

github

topframe
Update

13 of 42 new or added lines in 7 files covered. (30.95%)

4 existing lines in 3 files now uncovered.

14247 of 40395 relevant lines covered (35.27%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.62
/core/src/main/java/com/aspectran/core/activity/ActivityStringifyContext.java
1
/*
2
 * Copyright (c) 2008-2025 The Aspectran Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.aspectran.core.activity;
17

18
import com.aspectran.utils.BooleanUtils;
19
import com.aspectran.utils.StringUtils;
20
import com.aspectran.utils.StringifyContext;
21
import com.aspectran.utils.annotation.jsr305.NonNull;
22
import com.aspectran.utils.logging.Logger;
23
import com.aspectran.utils.logging.LoggerFactory;
24

25
/**
26
 * <p>Created: 2019-07-06</p>
27
 */
28
public class ActivityStringifyContext extends StringifyContext {
29

30
    private static final Logger logger = LoggerFactory.getLogger(ActivityStringifyContext.class);
1✔
31

32
    static final int MAX_INDENT_SIZE = 8;
33

34
    public static final String FORMAT_PRETTY_PRINT = "format.prettyPrint";
35

36
    public static final String FORMAT_INDENT_STYLE = "format.indentStyle";
37

38
    private static final String FORMAT_INDENT_STYLE_TAB = "tab";
39

40
    public static final String FORMAT_INDENT_SIZE = "format.indentSize";
41

42
    public static final String FORMAT_NULL_WRITABLE = "format.nullWritable";
43

44
    public static final String FORMAT_DATETIME_FORMAT = "format.dateTimeFormat";
45

46
    public static final String FORMAT_DATE_FORMAT = "format.dateFormat";
47

48
    public static final String FORMAT_TIME_FORMAT = "format.timeFormat";
49

50
    ActivityStringifyContext(@NonNull Activity activity) {
1✔
51
        String indentStyle = activity.getSetting(FORMAT_INDENT_STYLE);
1✔
52
        String dateTimeFormat = activity.getSetting(FORMAT_DATETIME_FORMAT);
1✔
53
        String dateFormat = activity.getSetting(FORMAT_DATE_FORMAT);
1✔
54
        String timeFormat = activity.getSetting(FORMAT_TIME_FORMAT);
1✔
55

56
        Object prettyPrint = activity.getSetting(FORMAT_PRETTY_PRINT);
1✔
57
        Boolean prettyPrintToUse = null;
1✔
58
        if (prettyPrint instanceof Boolean prettyPrintInBool) {
1✔
59
            prettyPrintToUse = prettyPrintInBool;
1✔
60
        } else if (prettyPrint != null) {
1✔
NEW
61
            prettyPrintToUse = BooleanUtils.toBooleanObject(prettyPrint.toString());
×
62
        }
63

64
        Object indentSize = activity.getSetting(FORMAT_INDENT_SIZE);
1✔
65
        int indentSizeToUse = 0;
1✔
66
        if (indentSize instanceof Number number) {
1✔
67
            indentSizeToUse = number.intValue();
×
68
        } else if (indentSize != null) {
1✔
69
            indentSizeToUse = parseIndentSize(indentSize.toString());
×
70
        }
71

72
        Object nullWritable = activity.getSetting(FORMAT_NULL_WRITABLE);
1✔
73
        Boolean nullWritableToUse = null;
1✔
74
        if (nullWritable instanceof Boolean nullWritableInBool) {
1✔
75
            nullWritableToUse = nullWritableInBool;
×
76
        } else if (nullWritable != null) {
1✔
77
            nullWritableToUse = BooleanUtils.toBooleanObject(nullWritable.toString());
×
78
        }
79

80
        if (FORMAT_INDENT_STYLE_TAB.equalsIgnoreCase(indentStyle)) {
1✔
81
            setIndentTab(true);
×
82
            setIndentSize(1);
×
83
        } else if (indentSizeToUse > 0) {
1✔
84
            setIndentSize(indentSizeToUse);
×
85
        }
86
        if (prettyPrintToUse != null) {
1✔
87
            setPrettyPrint(prettyPrintToUse);
1✔
88
        } else if (getIndentSize() > 0) {
1✔
NEW
89
            setPrettyPrint(true);
×
90
        }
91
        if (nullWritableToUse != null) {
1✔
92
            setNullWritable(nullWritableToUse);
×
93
        }
94
        if (StringUtils.hasLength(dateTimeFormat)) {
1✔
95
            setDateTimeFormat(dateTimeFormat);
×
96
        }
97
        if (StringUtils.hasLength(dateFormat)) {
1✔
98
            setDateFormat(dateFormat);
×
99
        }
100
        if (StringUtils.hasLength(timeFormat)) {
1✔
101
            setTimeFormat(timeFormat);
×
102
        }
103
        if (activity.getRequestAdapter() != null) {
1✔
104
            setLocale(activity.getRequestAdapter().getLocale());
1✔
105
        }
106
    }
1✔
107

108
    private static int parseIndentSize(String indentSize) {
109
        try {
110
            int size = Integer.parseInt(indentSize);
×
111
            if (size > MAX_INDENT_SIZE) {
×
112
                if (logger.isDebugEnabled()) {
×
113
                    logger.debug("Indent size should be less than " + MAX_INDENT_SIZE);
×
114
                }
115
                size = MAX_INDENT_SIZE;
×
116
            }
117
            return size;
×
118
        } catch (NumberFormatException e) {
×
119
            // ignore
120
        }
121
        return 0;
×
122
    }
123

124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc