<?xml version="1.0" encoding="UTF-8"?>

<ruleset name="Error Prone"
         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

    <description>
Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
    </description>

    <rule name="JspEncoding"
          language="jsp"
          since="4.0"
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          message="JSP file should use UTF-8 encoding"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_jsp_errorprone.html#jspencoding">
        <description>
A missing 'meta' tag or page directive will trigger this rule, as well as a non-UTF-8 charset.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//CompilationUnit/Content[
not(Element[@Name="meta"][
   Attribute[@Name="content"]/AttributeValue[contains(lower-case(@Value),"charset=utf-8")]
])
and
    not(JspDirective[@Name='page']/JspDirectiveAttribute[@Name='contentType'][contains(lower-case(@Value),"charset=utf-8")])
]
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
Most browsers should be able to interpret the following headers:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8" />
]]>
        </example>
    </rule>

</ruleset>
