~ubuntu-branches/ubuntu/natty/tomcat6/natty-proposed

« back to all changes in this revision

Viewing changes to java/org/apache/jasper/compiler/Validator.java

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2010-05-21 13:51:15 UTC
  • mfrom: (2.2.12 sid)
  • Revision ID: james.westby@ubuntu.com-20100521135115-qfwnf24lzvi3644v
Tags: 6.0.26-2
* debian/tomcat6.{postinst,prerm}: Respect TOMCAT6_USER and TOMCAT6_GROUP
  as defined in /etc/default/tomcat6 when setting directory permissions and
  authbind configuration (Closes: #581018, LP: #557300)
* debian/tomcat6.postinst: Use group "tomcat6" instead of "adm" for
  permissions in /var/lib/tomcat6, so that group "adm" doesn't get write
  permissions over /var/lib/tomcat6/webapps (LP: #569118)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
import javax.servlet.jsp.tagext.ValidationMessage;
38
38
 
39
39
import org.apache.el.lang.ELSupport;
40
 
import org.apache.jasper.Constants;
41
40
import org.apache.jasper.JasperException;
42
41
import org.apache.jasper.el.ELContextImpl;
43
42
import org.xml.sax.Attributes;
45
44
/**
46
45
 * Performs validation on the page elements. Attributes are checked for
47
46
 * mandatory presence, entry value validity, and consistency. As a side effect,
48
 
 * some page global value (such as those from page direcitves) are stored, for
 
47
 * some page global value (such as those from page directives) are stored, for
49
48
 * later use.
50
49
 * 
51
50
 * @author Kin-man Chung
416
415
 
417
416
        private ErrorDispatcher err;
418
417
 
419
 
        private TagInfo tagInfo;
420
 
 
421
418
        private ClassLoader loader;
422
419
 
423
420
        private final StringBuffer buf = new StringBuffer(32);
504
501
        ValidateVisitor(Compiler compiler) {
505
502
            this.pageInfo = compiler.getPageInfo();
506
503
            this.err = compiler.getErrorDispatcher();
507
 
            this.tagInfo = compiler.getCompilationContext().getTagInfo();
508
504
            this.loader = compiler.getCompilationContext().getClassLoader();
509
505
        }
510
506
 
706
702
 
707
703
            // JSP.2.2 - '#{' not allowed in template text
708
704
            if (n.getType() == '#') {
709
 
                if (!pageInfo.isDeferredSyntaxAllowedAsLiteral()
710
 
                        && (tagInfo == null 
711
 
                                || ((tagInfo != null) && !(tagInfo.getTagLibrary().getRequiredVersion().equals("2.0")
712
 
                                        || tagInfo.getTagLibrary().getRequiredVersion().equals("1.2"))))) {
 
705
                if (!pageInfo.isDeferredSyntaxAllowedAsLiteral()) {
713
706
                    err.jspError(n, "jsp.error.el.template.deferred");
714
707
                } else {
715
708
                    return;
720
713
            StringBuffer expr = this.getBuffer();
721
714
            expr.append(n.getType()).append('{').append(n.getText())
722
715
                    .append('}');
723
 
            ELNode.Nodes el = ELParser.parse(expr.toString());
 
716
            ELNode.Nodes el = ELParser.parse(expr.toString(), pageInfo
 
717
                    .isDeferredSyntaxAllowedAsLiteral());
724
718
 
725
719
            // validate/prepare expression
726
720
            prepareExpression(el, n, expr.toString());
1051
1045
            TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
1052
1046
            Attributes attrs = n.getAttributes();
1053
1047
 
1054
 
            boolean checkDeferred = !pageInfo.isDeferredSyntaxAllowedAsLiteral()
1055
 
                && !(tagInfo.getTagLibrary().getRequiredVersion().equals("2.0")
1056
 
                        || tagInfo.getTagLibrary().getRequiredVersion().equals("1.2"));
1057
 
 
1058
1048
            for (int i = 0; attrs != null && i < attrs.getLength(); i++) {
1059
1049
                boolean found = false;
1060
1050
                
1062
1052
                        || (!n.getRoot().isXmlSyntax() && attrs.getValue(i).startsWith("<%=")));
1063
1053
                boolean elExpression = false;
1064
1054
                boolean deferred = false;
1065
 
                boolean deferredValueIsLiteral = false;
 
1055
                double libraryVersion = Double.parseDouble(
 
1056
                        tagInfo.getTagLibrary().getRequiredVersion());
 
1057
                boolean deferredSyntaxAllowedAsLiteral =
 
1058
                    pageInfo.isDeferredSyntaxAllowedAsLiteral() ||
 
1059
                    libraryVersion < 2.1;
1066
1060
 
1067
1061
                ELNode.Nodes el = null;
1068
 
                if (!runtimeExpression) {
1069
 
                    el = ELParser.parse(attrs.getValue(i));
 
1062
                if (!runtimeExpression && !pageInfo.isELIgnored()) {
 
1063
                    el = ELParser.parse(attrs.getValue(i),
 
1064
                            deferredSyntaxAllowedAsLiteral);
1070
1065
                    Iterator<ELNode> nodes = el.iterator();
1071
1066
                    while (nodes.hasNext()) {
1072
1067
                        ELNode node = nodes.next();
1073
1068
                        if (node instanceof ELNode.Root) {
1074
1069
                            if (((ELNode.Root) node).getType() == '$') {
 
1070
                                if (elExpression && deferred) {
 
1071
                                    err.jspError(n,
 
1072
                                            "jsp.error.attribute.deferredmix");
 
1073
                                }
1075
1074
                                elExpression = true;
1076
 
                            } else if (checkDeferred && ((ELNode.Root) node).getType() == '#') {
 
1075
                            } else if (((ELNode.Root) node).getType() == '#') {
 
1076
                                if (elExpression && !deferred) {
 
1077
                                    err.jspError(n,
 
1078
                                            "jsp.error.attribute.deferredmix");
 
1079
                                }
1077
1080
                                elExpression = true;
1078
1081
                                deferred = true;
1079
 
                                if (pageInfo.isELIgnored()) {
1080
 
                                    deferredValueIsLiteral = true;
1081
 
                                }
1082
1082
                            }
1083
1083
                        }
1084
1084
                    }
1085
1085
                }
1086
1086
 
1087
 
                boolean expression = runtimeExpression 
1088
 
                    || (elExpression  && (!pageInfo.isELIgnored() || (!"true".equalsIgnoreCase(pageInfo.getIsELIgnored()) && checkDeferred && deferred)));
1089
 
                
 
1087
                boolean expression = runtimeExpression || elExpression;
 
1088
 
1090
1089
                for (int j = 0; tldAttrs != null && j < tldAttrs.length; j++) {
1091
1090
                    if (attrs.getLocalName(i).equals(tldAttrs[j].getName())
1092
1091
                            && (attrs.getURI(i) == null
1093
1092
                                    || attrs.getURI(i).length() == 0 || attrs
1094
1093
                                    .getURI(i).equals(n.getURI()))) {
1095
 
                        
1096
 
                        if (tldAttrs[j].canBeRequestTime()
1097
 
                                || tldAttrs[j].isDeferredMethod() || tldAttrs[j].isDeferredValue()) { // JSP 2.1
 
1094
 
 
1095
                        TagAttributeInfo tldAttr = tldAttrs[j];
 
1096
                        if (tldAttr.canBeRequestTime()
 
1097
                                || tldAttr.isDeferredMethod() || tldAttr.isDeferredValue()) { // JSP 2.1
1098
1098
                            
1099
1099
                            if (!expression) {
1100
 
                                
1101
 
                                if (deferredValueIsLiteral && !pageInfo.isDeferredSyntaxAllowedAsLiteral()) {
1102
 
                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
1103
 
                                            tldAttrs[j].getName());
1104
 
                                }
1105
 
                                
 
1100
 
1106
1101
                                String expectedType = null;
1107
 
                                if (tldAttrs[j].isDeferredMethod()) {
 
1102
                                if (tldAttr.isDeferredMethod()) {
1108
1103
                                    // The String literal must be castable to what is declared as type
1109
1104
                                    // for the attribute
1110
 
                                    String m = tldAttrs[j].getMethodSignature();
 
1105
                                    String m = tldAttr.getMethodSignature();
1111
1106
                                    if (m != null) {
1112
 
                                        int rti = m.trim().indexOf(' ');
 
1107
                                        m = m.trim();
 
1108
                                        int rti = m.indexOf(' ');
1113
1109
                                        if (rti > 0) {
1114
1110
                                            expectedType = m.substring(0, rti).trim();
1115
1111
                                        }
1122
1118
                                        // of void - JSP.2.3.4
1123
1119
                                        err.jspError(n,
1124
1120
                                                "jsp.error.literal_with_void",
1125
 
                                                tldAttrs[j].getName());
 
1121
                                                tldAttr.getName());
1126
1122
                                    }
1127
1123
                                }
1128
 
                                if (tldAttrs[j].isDeferredValue()) {
 
1124
                                if (tldAttr.isDeferredValue()) {
1129
1125
                                    // The String litteral must be castable to what is declared as type
1130
1126
                                    // for the attribute
1131
 
                                    expectedType = tldAttrs[j].getExpectedTypeName();
 
1127
                                    expectedType = tldAttr.getExpectedTypeName();
1132
1128
                                }
1133
1129
                                if (expectedType != null) {
1134
1130
                                    Class expectedClass = String.class;
1137
1133
                                    } catch (ClassNotFoundException e) {
1138
1134
                                        err.jspError
1139
1135
                                            (n, "jsp.error.unknown_attribute_type",
1140
 
                                             tldAttrs[j].getName(), expectedType);
 
1136
                                             tldAttr.getName(), expectedType);
1141
1137
                                    }
1142
1138
                                    // Check casting
1143
1139
                                    try {
1145
1141
                                    } catch (Exception e) {
1146
1142
                                        err.jspError
1147
1143
                                            (n, "jsp.error.coerce_to_type",
1148
 
                                             tldAttrs[j].getName(), expectedType, attrs.getValue(i));
 
1144
                                             tldAttr.getName(), expectedType, attrs.getValue(i));
1149
1145
                                    }
1150
1146
                                }
1151
1147
 
1152
 
                                jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
 
1148
                                jspAttrs[i] = new Node.JspAttribute(tldAttr,
1153
1149
                                        attrs.getQName(i), attrs.getURI(i), attrs
1154
1150
                                                .getLocalName(i),
1155
1151
                                        attrs.getValue(i), false, null, false);
1156
1152
                            } else {
1157
 
                                
1158
 
                                if (deferred && !tldAttrs[j].isDeferredMethod() && !tldAttrs[j].isDeferredValue()) {
 
1153
 
 
1154
                                if (deferred && !tldAttr.isDeferredMethod() && !tldAttr.isDeferredValue()) {
1159
1155
                                    // No deferred expressions allowed for this attribute
1160
1156
                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
1161
 
                                            tldAttrs[j].getName());
 
1157
                                            tldAttr.getName());
1162
1158
                                }
1163
 
                                if (!deferred && !tldAttrs[j].canBeRequestTime()) {
 
1159
                                if (!deferred && !tldAttr.canBeRequestTime()) {
1164
1160
                                    // Only deferred expressions are allowed for this attribute
1165
1161
                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
1166
 
                                            tldAttrs[j].getName());
 
1162
                                            tldAttr.getName());
1167
1163
                                }
1168
1164
                                
1169
1165
                                Class expectedType = String.class;
1170
1166
                                try {
1171
 
                                    String typeStr = tldAttrs[j].getTypeName();
1172
 
                                    if (tldAttrs[j].isFragment()) {
 
1167
                                    String typeStr = tldAttr.getTypeName();
 
1168
                                    if (tldAttr.isFragment()) {
1173
1169
                                        expectedType = JspFragment.class;
1174
1170
                                    } else if (typeStr != null) {
1175
1171
                                        expectedType = JspUtil.toClass(typeStr,
1178
1174
                                    if (elExpression) {
1179
1175
                                        // El expression
1180
1176
                                        validateFunctions(el, n);
1181
 
                                        jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
 
1177
                                        jspAttrs[i] = new Node.JspAttribute(tldAttr,
1182
1178
                                                attrs.getQName(i), attrs.getURI(i), 
1183
1179
                                                attrs.getLocalName(i),
1184
1180
                                                attrs.getValue(i), false, el, false);
1193
1189
                                        }
1194
1190
                                    } else {
1195
1191
                                        // Runtime expression
1196
 
                                        jspAttrs[i] = getJspAttribute(tldAttrs[j],
 
1192
                                        jspAttrs[i] = getJspAttribute(tldAttr,
1197
1193
                                                attrs.getQName(i), attrs.getURI(i),
1198
1194
                                                attrs.getLocalName(i), attrs
1199
1195
                                                .getValue(i), expectedType, n,
1202
1198
                                } catch (ClassNotFoundException e) {
1203
1199
                                    err.jspError
1204
1200
                                        (n, "jsp.error.unknown_attribute_type",
1205
 
                                         tldAttrs[j].getName(), tldAttrs[j].getTypeName());
 
1201
                                         tldAttr.getName(), tldAttr.getTypeName());
1206
1202
                                }
1207
1203
                            }
1208
1204
                            
1211
1207
                            // Make sure its value does not contain any.
1212
1208
                            if (expression) {
1213
1209
                                err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
1214
 
                                                tldAttrs[j].getName());
 
1210
                                                tldAttr.getName());
1215
1211
                            }
1216
 
                            jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
 
1212
                            jspAttrs[i] = new Node.JspAttribute(tldAttr,
1217
1213
                                    attrs.getQName(i), attrs.getURI(i), attrs
1218
1214
                                            .getLocalName(i),
1219
1215
                                    attrs.getValue(i), false, null, false);
1334
1330
                    result = new Node.JspAttribute(tai, qName, uri, localName,
1335
1331
                            value.substring(3, value.length() - 2), true, null,
1336
1332
                            dynamic);
 
1333
                } else if (pageInfo.isELIgnored()) {
 
1334
                    result = new Node.JspAttribute(tai, qName, uri, localName,
 
1335
                            value, false, null, dynamic);
1337
1336
                } else {
1338
1337
                    // The attribute can contain expressions but is not a
1339
1338
                    // scriptlet expression; thus, we want to run it through
1341
1340
 
1342
1341
                    // validate expression syntax if string contains
1343
1342
                    // expression(s)
1344
 
                    ELNode.Nodes el = ELParser.parse(value);
1345
 
                    
1346
 
                    boolean deferred = false;
1347
 
                    Iterator<ELNode> nodes = el.iterator();
1348
 
                    while (nodes.hasNext()) {
1349
 
                        ELNode node = nodes.next();
1350
 
                        if (node instanceof ELNode.Root) {
1351
 
                            if (((ELNode.Root) node).getType() == '#') {
1352
 
                                deferred = true;
1353
 
                            }
1354
 
                        }
1355
 
                    }
 
1343
                    ELNode.Nodes el = ELParser.parse(value, pageInfo
 
1344
                            .isDeferredSyntaxAllowedAsLiteral());
1356
1345
 
1357
 
                    if (el.containsEL() && !pageInfo.isELIgnored()
1358
 
                            && ((!pageInfo.isDeferredSyntaxAllowedAsLiteral() && deferred)
1359
 
                                    || !deferred)) {
 
1346
                    if (el.containsEL()) {
1360
1347
 
1361
1348
                        validateFunctions(el, n);
1362
1349
 
1415
1402
            boolean elExpression = false;
1416
1403
 
1417
1404
            if (!runtimeExpression && !pageInfo.isELIgnored()) {
1418
 
                Iterator<ELNode> nodes = ELParser.parse(value).iterator();
 
1405
                Iterator<ELNode> nodes = ELParser.parse(value,
 
1406
                        pageInfo.isDeferredSyntaxAllowedAsLiteral()).iterator();
1419
1407
                while (nodes.hasNext()) {
1420
1408
                    ELNode node = nodes.next();
1421
1409
                    if (node instanceof ELNode.Root) {