简体   繁体   English

速度模板和 Java 字符串

[英]Velocity Template and Java String

I develop jira report plugin.Velocity template shows ascii code single or double quote in java string.我开发了 jira 报告插件。Velocity 模板在 java 字符串中显示 ascii 代码单引号或双引号。

Java Code: Java代码:

Main:主要的:

    Map velocityParams = new HashMap();
    String horizontalAxis = convertKeysToWeekCategories(bugtrends.keySet());

    velocityParams.put("horizontalAxis", horizontalAxis);

convertKeysToWeekCategories method: convertKeysToWeekCategories 方法:

    StringBuilder build = new StringBuilder();

    for (Integer integer : keySet) {
        build.append("\'");
        build.append("W");
        build.append(integer.toString());
        build.append("\'");
        build.append(",");
    }

    String result = build.toString();

    result = result.substring(0, result.length() - 1);

    return result;

}

And I draw with HighChart api.我用 HighChart api 画画。

bugstrendview.vm: bugstrendview.vm:

<head >
    <meta charset="utf-8">
</head>

<script>AJS.$(document).ready(function(){ 


    chart = new Highcharts.Chart({

        chart: {
            type: 'spline',
            renderTo: 'container'
        },
        exporting: {
            enabled: true,
            filename: "open-bugs-trend-chart"
        },
        title: {
            text: 'Open Bugs Trend',
            x: -20 //center
        },
        subtitle: {
            text: 'results are displayed in weeks',
            x: -20 //center
        },
        xAxis: {
            categories: [$horizontalAxis],
            labels: {
                rotation: -90,
                align: 'right',
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        },

        tooltip: {

        formatter: function() {
            var myDates = $tooltipDates;
            return "<b>W"+(this.point.x+1)+"</b><br/>"+
            myDates[this.point.x]+" - "+myDates[this.point.x + 1]+
            "<br/>"+"Total Bugs : "+this.point.y ;

        },
    },


        yAxis: {
            gridLineWidth: 1,
            minorGridLineWidth: 1,
            title: {
                text: 'Number of Open Bugs'
            },
            min: 0,
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        plotOptions: {
            spline: {
                dataLabels: {
                    enabled: true
                },
                marker: {
                    enable: true
                }
            }
        },
        series: [
        {
            showInLegend: false,
            data: [$verticalAxis]
        }]
    });        });

</script>

Then shows in the bugstrendview.vm categories:[ &#39;然后在 bugstrendview.vm 类别中显示:[ &#39; W1 &#39; W1 &#39; ] as error 'Uncaught SyntaxError: Unexpected token &' and of course dont draw. ] 作为错误 'Uncaught SyntaxError: Unexpected token &' 当然不要画。

Why shows ascii code of single quote?为什么显示单引号的ascii代码?

Obviously the ' gets encoded to &#39;显然'被编码为&#39;

See this thread:看到这个线程:

https://answers.atlassian.com/questions/24351/how-to-prevent-velocity-escape-html https://answers.atlassian.com/questions/24351/how-to-prevent-velocity-escape-html

appending WithHtml to a variable name should prevent HTML escapingWithHtml附加到变量名应该可以防止 HTML 转义

You can do:你可以做:

#set($horizontalAxisWithHtml = $horizontalAxis)

and then use $horizontalAxisWithHtml然后使用$horizontalAxisWithHtml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM