Author: remy.maucherat(a)jboss.com
Date: 2009-11-12 23:23:25 -0500 (Thu, 12 Nov 2009)
New Revision: 1267
Modified:
trunk/java/org/apache/jasper/compiler/Generator.java
trunk/java/org/apache/jasper/compiler/Node.java
trunk/java/org/apache/jasper/compiler/Parser.java
trunk/java/org/apache/jasper/compiler/Validator.java
Log:
- Error on undeclared namespace.
- Omit support for jsp:attribute.
Modified: trunk/java/org/apache/jasper/compiler/Generator.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Generator.java 2009-11-13 01:25:12 UTC (rev
1266)
+++ trunk/java/org/apache/jasper/compiler/Generator.java 2009-11-13 04:23:25 UTC (rev
1267)
@@ -1900,14 +1900,29 @@
Node.JspAttribute[] attrs = n.getJspAttributes();
for (int i = 0; attrs != null && i < attrs.length; i++) {
String attrStr = null;
+ String omit = null;
if (attrs[i].isNamedAttribute()) {
+ Node.JspAttribute omitAttribute =
attrs[i].getNamedAttributeNode().getOmitAttribute();
+ if (omitAttribute != null) {
+ if (omitAttribute.isLiteral()) {
+ if (JspUtil.booleanValue(omitAttribute.getValue())) {
+ continue;
+ }
+ } else {
+ omit = "(!" +
attributeValue(attrs[i].getNamedAttributeNode().getOmitAttribute(), false, Boolean.class)
+ ") ? ";
+ }
+ }
attrStr = generateNamedAttributeValue(attrs[i]
.getNamedAttributeNode());
} else {
attrStr = attributeValue(attrs[i], false, Object.class);
}
- String s = " + \" " + attrs[i].getName() +
"=\\\"\" + "
- + attrStr + " + \"\\\"\"";
+ String s = null;
+ if (omit == null) {
+ s = " + \" " + attrs[i].getName() +
"=\\\"\" + " + attrStr + " + \"\\\"\"";
+ } else {
+ s = " + (" + omit + "(\" " +
attrs[i].getName() + "=\\\"\" + " + attrStr + " +
\"\\\"\") : (\"\"))";
+ }
map.put(attrs[i].getName(), s);
}
Modified: trunk/java/org/apache/jasper/compiler/Node.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Node.java 2009-11-13 01:25:12 UTC (rev 1266)
+++ trunk/java/org/apache/jasper/compiler/Node.java 2009-11-13 04:23:25 UTC (rev 1267)
@@ -1869,11 +1869,15 @@
private ChildInfo childInfo;
private String name;
+
+ private String omit;
private String localName;
private String prefix;
+ private JspAttribute omitAttribute;
+
public NamedAttribute(Attributes attrs, Mark start, Node parent) {
this(JSP_ATTRIBUTE_ACTION, attrs, null, null, start, parent);
}
@@ -1900,6 +1904,8 @@
localName = name.substring(index + 1);
}
}
+ if (parent instanceof JspElement)
+ omit = this.getAttributeValue("omit");
}
public void accept(Visitor v) throws JasperException {
@@ -1926,6 +1932,18 @@
return trim;
}
+ public String getOmit() {
+ return this.omit;
+ }
+
+ public JspAttribute getOmitAttribute() {
+ return omitAttribute;
+ }
+
+ public void setOmitAttribute(JspAttribute omitAttribute) {
+ this.omitAttribute = omitAttribute;
+ }
+
/**
* @return A unique temporary variable name to store the result in.
* (this probably could go elsewhere, but it's convenient here)
@@ -2288,7 +2306,7 @@
* time.
*/
public boolean isLiteral() {
- return !expression && (el != null) && !namedAttribute;
+ return !expression && (el == null) && !namedAttribute;
}
/**
Modified: trunk/java/org/apache/jasper/compiler/Parser.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Parser.java 2009-11-13 01:25:12 UTC (rev 1266)
+++ trunk/java/org/apache/jasper/compiler/Parser.java 2009-11-13 04:23:25 UTC (rev 1267)
@@ -1214,6 +1214,9 @@
// Check if this is a user-defined tag.
String uri = pageInfo.getURI(prefix);
if (uri == null) {
+ if (pageInfo.isErrorOnUndeclaredNamespace()) {
+ err.jspError(start, "jsp.error.bad_tag", shortTagName,
prefix);
+ }
reader.reset(start);
// Remember the prefix for later error checking
pageInfo.putNonCustomTagPrefix(prefix, reader.mark());
Modified: trunk/java/org/apache/jasper/compiler/Validator.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Validator.java 2009-11-13 01:25:12 UTC (rev
1266)
+++ trunk/java/org/apache/jasper/compiler/Validator.java 2009-11-13 04:23:25 UTC (rev
1267)
@@ -478,6 +478,7 @@
private static final JspUtil.ValidAttribute[] attributeAttrs = {
new JspUtil.ValidAttribute("name", true),
+ new JspUtil.ValidAttribute("omit"),
new JspUtil.ValidAttribute("trim") };
private static final JspUtil.ValidAttribute[] invokeAttrs = {
@@ -674,6 +675,17 @@
public void visit(Node.NamedAttribute n) throws JasperException {
JspUtil.checkAttributes("Attribute", n, attributeAttrs, err);
visitBody(n);
+ if (n.getOmit() != null) {
+ Attributes attrs = n.getAttributes();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ if ("omit".equals(attrs.getLocalName(i))) {
+ n.setOmitAttribute(getJspAttribute(null, attrs.getQName(i),
+ attrs.getURI(i), attrs.getLocalName(i),
+ attrs.getValue(i), java.lang.Boolean.class,
+ n, false));
+ }
+ }
+ }
}
public void visit(Node.JspBody n) throws JasperException {