You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by lu...@apache.org on 2002/07/19 19:12:58 UTC
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources messages.properties
luehe 2002/07/19 10:12:58
Modified: jasper2/src/share/org/apache/jasper/compiler Generator.java
Node.java Validator.java
jasper2/src/share/org/apache/jasper/resources
messages.properties
Log:
Added support for dynamic attributes
Revision Changes Path
1.43 +49 -22 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
Index: Generator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- Generator.java 18 Jul 2002 21:17:27 -0000 1.42
+++ Generator.java 19 Jul 2002 17:12:57 -0000 1.43
@@ -90,6 +90,7 @@
public class Generator {
+ private static final Class[] OBJECT_CLASS = { Object.class};
private ServletWriter out;
private MethodsBuffer methodsBuffer;
private FragmentHelperClass fragmentHelperClass;
@@ -2207,34 +2208,60 @@
}
}
String attrName = attrs[i].getName();
- Method m = handlerInfo.getSetterMethod(attrName);
- if (m == null) {
- err.jspError(n, "jsp.error.unable.to_find_method",
- attrName);
- }
- Class c[] = m.getParameterTypes();
- // XXX assert(c.length > 0)
+ Method m = null;
+ Class[] c = null;
+ if (attrs[i].isDynamic()) {
+ c = OBJECT_CLASS;
+ } else {
+ m = handlerInfo.getSetterMethod(attrName);
+ if (m == null) {
+ err.jspError(n, "jsp.error.unable.to_find_method",
+ attrName);
+ }
+ c = m.getParameterTypes();
+ // XXX assert(c.length > 0)
+ }
if (attrs[i].isExpression() || attrs[i].isNamedAttribute()) {
// Do nothing
- }
- else if (attrs[i].isELInterpreterInput()) {
+ } else if (attrs[i].isELInterpreterInput()) {
// run attrValue through the expression interpreter
attrValue = JspUtil.interpreterCall( attrValue,
c[0], "_jspx_fnmap", n.getPrefix() );
- }
- else {
- attrValue = convertString(c[0], attrValue, attrName,
- handlerInfo.getPropertyEditorClass(attrName));
+ } else {
+ attrValue = convertString(
+ c[0], attrValue, attrName,
+ handlerInfo.getPropertyEditorClass(attrName));
}
- out.printin(tagHandlerVar);
- out.print(".");
- out.print(m.getName());
- out.print("(");
- out.print(attrValue);
- out.println(");");
+ if (attrs[i].isDynamic()) {
+ out.printil("try {");
+ out.pushIndent();
+ out.printin(tagHandlerVar);
+ out.print(".");
+ out.print("setDynamicAttribute(\"");
+ out.print(attrs[i].getURI());
+ out.print("\", \"");
+ out.print(attrs[i].getLocalName());
+ out.print("\", ");
+ out.print(attrValue);
+ out.println(");");
+ out.popIndent();
+ out.printin("}"); // catch
+ out.println(" catch (javax.servlet.jsp.tagext.AttributeNotSupportedException e) {");
+ out.pushIndent();
+ out.printil("throw new javax.servlet.jsp.JspException(e);");
+ out.popIndent();
+ out.printil("}"); // catch
+ } else {
+ out.printin(tagHandlerVar);
+ out.print(".");
+ out.print(m.getName());
+ out.print("(");
+ out.print(attrValue);
+ out.println(");");
+ }
}
}
1.19 +44 -6 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
Index: Node.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Node.java 18 Jul 2002 21:17:27 -0000 1.18
+++ Node.java 19 Jul 2002 17:12:57 -0000 1.19
@@ -798,6 +798,7 @@
private boolean implementsBodyTag;
private boolean implementsTryCatchFinally;
private boolean implementsSimpleTag;
+ private boolean implementsDynamicAttributes;
public CustomTag(Attributes attrs, Mark start, String name,
String prefix, String shortName,
@@ -819,6 +820,8 @@
TryCatchFinally.class.isAssignableFrom(tagHandlerClass);
this.implementsSimpleTag =
SimpleTag.class.isAssignableFrom(tagHandlerClass);
+ this.implementsDynamicAttributes =
+ DynamicAttributes.class.isAssignableFrom(tagHandlerClass);
}
public void accept(Visitor v) throws JasperException {
@@ -900,6 +903,10 @@
return implementsSimpleTag;
}
+ public boolean implementsDynamicAttributes() {
+ return implementsDynamicAttributes;
+ }
+
public TagVariableInfo[] getTagVariableInfos() {
return tagInfo.getTagVariableInfos();
}
@@ -1200,21 +1207,28 @@
public static class JspAttribute {
private String name;
+ private String uri;
+ private String localName;
private String value;
private boolean expression;
private boolean el;
+ private boolean dynamic;
- // If true, this JapAttribute represents a <jsp:attribute>
+ // If true, this JspAttribute represents a <jsp:attribute>
private boolean namedAttribute;
// The node in the parse tree for the NamedAttribute
private NamedAttribute namedAttributeNode;
- JspAttribute(String name, String value, boolean expr, boolean el ) {
+ JspAttribute(String name, String uri, String localName, String value,
+ boolean expr, boolean el, boolean dyn ) {
this.name = name;
+ this.uri = uri;
+ this.localName = localName;
this.value = value;
this.namedAttributeNode = null;
this.expression = expr;
this.el = el;
+ this.dynamic = dyn;
this.namedAttribute = false;
}
@@ -1223,12 +1237,14 @@
* named attribute. In this case, we have to store the nodes of
* the body of the attribute.
*/
- JspAttribute( String name, NamedAttribute namedAttributeNode ) {
+ JspAttribute( String name, NamedAttribute namedAttributeNode,
+ boolean dyn ) {
this.name = name;
this.value = null;
this.namedAttributeNode = namedAttributeNode;
this.expression = false;
this.el = false;
+ this.dynamic = dyn;
this.namedAttribute = true;
}
@@ -1240,6 +1256,21 @@
}
/**
+ * @return The local name of the attribute
+ */
+ public String getLocalName() {
+ return localName;
+ }
+
+ /**
+ * @return The namespace of the attribute, or null if in the default
+ * namespace
+ */
+ public String getURI() {
+ return uri;
+ }
+
+ /**
* Only makes sense if namedAttribute is false.
*
* @return the value for the attribute, or the expression string
@@ -1289,6 +1320,13 @@
*/
public boolean isLiteral() {
return !expression && !el && !namedAttribute;
+ }
+
+ /**
+ * XXX
+ */
+ public boolean isDynamic() {
+ return dynamic;
}
}
1.13 +102 -44 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java
Index: Validator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Validator.java 16 Jul 2002 19:30:51 -0000 1.12
+++ Validator.java 19 Jul 2002 17:12:57 -0000 1.13
@@ -359,22 +359,25 @@
public void visit(Node.ParamAction n) throws JasperException {
JspUtil.checkAttributes("Param action", n,
paramActionAttrs, err);
- n.setValue(getJspAttribute("value", n.getAttributeValue("value"),
- n));
+ n.setValue(getJspAttribute("value", null, null,
+ n.getAttributeValue("value"),
+ n, false));
visitBody(n);
}
public void visit(Node.IncludeAction n) throws JasperException {
JspUtil.checkAttributes("Include action", n,
includeActionAttrs, err);
- n.setPage(getJspAttribute("page", n.getAttributeValue("page"), n));
+ n.setPage(getJspAttribute("page", null, null,
+ n.getAttributeValue("page"), n, false));
visitBody(n);
};
public void visit(Node.ForwardAction n) throws JasperException {
JspUtil.checkAttributes("Forward", n,
forwardActionAttrs, err);
- n.setPage(getJspAttribute("page", n.getAttributeValue("page"), n));
+ n.setPage(getJspAttribute("page", null, null,
+ n.getAttributeValue("page"), n, false));
visitBody(n);
}
@@ -391,7 +394,7 @@
String param = n.getAttributeValue("param");
String value = n.getAttributeValue("value");
- n.setValue(getJspAttribute("value", value, n));
+ n.setValue(getJspAttribute("value", null, null, value, n, false));
boolean valueSpecified = n.getValue() != null;
@@ -426,8 +429,9 @@
err.jspError(n, "jsp.error.useBean.noSession");
Node.JspAttribute jattr
- = getJspAttribute("beanName", n.getAttributeValue("beanName"),
- n);
+ = getJspAttribute("beanName", null, null,
+ n.getAttributeValue("beanName"),
+ n, false);
n.setBeanName(jattr);
if (className != null && jattr != null)
err.jspError(n, "jsp.error.useBean.notBoth");
@@ -460,18 +464,22 @@
if (n.getAttributeValue("code") == null)
err.jspError(n, "jsp.error.plugin.nocode");
- Node.JspAttribute width = getJspAttribute("width",
- n.getAttributeValue("width"), n);
+ Node.JspAttribute width
+ = getJspAttribute("width", null, null,
+ n.getAttributeValue("width"), n, false);
n.setWidth( width );
- Node.JspAttribute height = getJspAttribute("height",
- n.getAttributeValue("height"), n);
+ Node.JspAttribute height
+ = getJspAttribute("height", null, null,
+ n.getAttributeValue("height"), n, false);
n.setHeight( height );
- n.setHeight(getJspAttribute("height", n.getAttributeValue("height"),
- n));
- n.setWidth(getJspAttribute("width", n.getAttributeValue("width"),
- n));
+ n.setHeight(getJspAttribute("height", null, null,
+ n.getAttributeValue("height"), n,
+ false));
+ n.setWidth(getJspAttribute("width", null, null,
+ n.getAttributeValue("width"), n,
+ false));
visitBody(n);
}
@@ -484,8 +492,9 @@
public void visit(Node.JspBody n) throws JasperException {
JspUtil.checkAttributes("Body", n,
bodyAttrs, err);
- n.setValue(getJspAttribute("value", n.getAttributeValue("value"),
- n));
+ n.setValue(getJspAttribute("value", null, null,
+ n.getAttributeValue("value"), n,
+ false));
visitBody(n);
}
@@ -523,6 +532,17 @@
}
/*
+ * If the tag handler declares in the TLD that it supports dynamic
+ * attributes, it also must implement the DynamicAttributes
+ * interface.
+ */
+ if (tagInfo.hasDynamicAttributes()
+ && !n.implementsDynamicAttributes()) {
+ err.jspError(n, "jsp.error.dynamic.attributes.not.implemented",
+ n.getName());
+ }
+
+ /*
* Make sure all required attributes are present, either as
* attributes or named attributes (<jsp:attribute>).
*/
@@ -544,8 +564,8 @@
Node.Nodes namedAttributeNodes = n.getNamedAttributeNodes();
Hashtable tagDataAttrs = new Hashtable(attrs.getLength());
Node.JspAttribute[] jspAttrs
- = new Node.JspAttribute[attrs.getLength() +
- namedAttributeNodes.size()];
+ = new Node.JspAttribute[attrs.getLength()
+ + namedAttributeNodes.size()];
for (int i=0; i<attrs.getLength(); i++) {
boolean found = false;
for (int j=0; j<tldAttrs.length; j++) {
@@ -553,13 +573,20 @@
if (tldAttrs[j].canBeRequestTime()) {
jspAttrs[i]
= getJspAttribute(attrs.getQName(i),
+ attrs.getURI(i),
+ attrs.getLocalName(i),
attrs.getValue(i),
- n);
+ n,
+ false);
} else {
jspAttrs[i]
= new Node.JspAttribute(attrs.getQName(i),
+ attrs.getURI(i),
+ attrs.getLocalName(i),
attrs.getValue(i),
- false, false);
+ false,
+ false,
+ false);
}
if (jspAttrs[i].isExpression()) {
tagDataAttrs.put(attrs.getQName(i),
@@ -573,8 +600,17 @@
}
}
if (!found) {
- err.jspError(n, "jsp.error.bad_attribute",
- attrs.getQName(i));
+ if (tagInfo.hasDynamicAttributes()) {
+ jspAttrs[i] = getJspAttribute(attrs.getQName(i),
+ attrs.getURI(i),
+ attrs.getLocalName(i),
+ attrs.getValue(i),
+ n,
+ true);
+ } else {
+ err.jspError(n, "jsp.error.bad_attribute",
+ attrs.getQName(i));
+ }
}
}
@@ -590,7 +626,8 @@
if (na.getName().equals(tldAttrs[j].getName())) {
if (tldAttrs[j].canBeRequestTime()) {
jspAttrs[attrs.getLength() + i]
- = getJspAttribute(na.getName(), null, n);
+ = getJspAttribute(na.getName(), null, null,
+ null, n, false);
} else {
err.jspError( n,
"jsp.error.named.attribute.not.rt",
@@ -608,7 +645,8 @@
for (int j=0; j<tfais.length; j++) {
if (na.getName().equals(tfais[j].getName())) {
jspAttrs[attrs.getLength() + i]
- = getJspAttribute(na.getName(), null, n);
+ = getJspAttribute(na.getName(), null, null,
+ null, n, false);
tagDataAttrs.put(na.getName(),
TagData.REQUEST_TIME_VALUE);
found = true;
@@ -617,8 +655,14 @@
}
}
if (!found) {
- err.jspError(n, "jsp.error.bad_attribute",
- na.getName());
+ if (tagInfo.hasDynamicAttributes()) {
+ jspAttrs[attrs.getLength() + i]
+ = getJspAttribute(na.getName(), null, null, null,
+ n, true);
+ } else {
+ err.jspError(n, "jsp.error.bad_attribute",
+ na.getName());
+ }
}
}
@@ -637,9 +681,12 @@
* NamedAttribute subelements in the tree node, and if so,
* constructs a JspAttribute out of a child NamedAttribute node.
*/
- private Node.JspAttribute getJspAttribute(String name,
+ private Node.JspAttribute getJspAttribute(String qName,
+ String uri,
+ String localName,
String value,
- Node n)
+ Node n,
+ boolean dynamic)
throws JasperException {
Node.JspAttribute result = null;
@@ -651,17 +698,23 @@
if (value != null) {
if (n.isXmlSyntax() && value.startsWith("%=")) {
result = new Node.JspAttribute(
- name,
- value.substring(2,
- value.length()-1),
- true, false);
+ qName,
+ uri,
+ localName,
+ value.substring(2, value.length()-1),
+ true,
+ false,
+ dynamic);
}
else if(!n.isXmlSyntax() && value.startsWith("<%=")) {
result = new Node.JspAttribute(
- name,
- value.substring(3,
- value.length()-2),
- true, false);
+ qName,
+ uri,
+ localName,
+ value.substring(3, value.length()-2),
+ true,
+ false,
+ dynamic);
}
else {
// The attribute can contain expressions but is not an
@@ -677,9 +730,13 @@
// expression(s)
if (value.indexOf("${") != -1 /* && isELEnabled */) {
JspUtil.validateExpressions(n.getStart(), value, err);
- result = new Node.JspAttribute(name, value, false, true);
+ result = new Node.JspAttribute(qName, uri, localName,
+ value, false, true,
+ dynamic);
} else {
- result = new Node.JspAttribute(name, value, false, false);
+ result = new Node.JspAttribute(qName, uri, localName,
+ value, false, false,
+ dynamic);
}
}
}
@@ -689,9 +746,10 @@
// Otherwise, the attribute wasn't found so we return null.
Node.NamedAttribute namedAttributeNode =
- n.getNamedAttributeNode( name );
+ n.getNamedAttributeNode( qName );
if( namedAttributeNode != null ) {
- result = new Node.JspAttribute(name, namedAttributeNode);
+ result = new Node.JspAttribute(qName, namedAttributeNode,
+ dynamic);
}
}
1.11 +3 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties
Index: messages.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- messages.properties 16 Jul 2002 19:30:52 -0000 1.10
+++ messages.properties 19 Jul 2002 17:12:57 -0000 1.11
@@ -267,3 +267,5 @@
jsp.error.internal.unexpected_node_type=Internal Error: Unexpected node type encountered
jsp.error.tld.fn.invalid.signature=Invalid syntax for function signature in TLD. Tag Library: {0}, Function: {1}
+
+jsp.error.dynamic.attributes.not.implemented=The {0} tag declares that it accepts dynamic attributes but does not implement the required interface
\ No newline at end of file
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>