kinman 2002/07/22 13:35:27
Modified: jasper2/src/share/org/apache/jasper/compiler Node.java
PageInfo.java Parser.java ParserController.java
Validator.java
jasper2/src/share/org/apache/jasper/resources
messages.properties
Log:
- First batch of mods in support of tag files.
Revision Changes Path
1.20 +75 -3
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.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Node.java 19 Jul 2002 17:12:57 -0000 1.19
+++ Node.java 22 Jul 2002 20:35:27 -0000 1.20
@@ -389,6 +389,62 @@
}
/**
+ * Represents a tag directive
+ */
+ public static class TagDirective extends Node {
+
+ public TagDirective(Attributes attrs, Mark start, Node parent) {
+ super(attrs, start, parent);
+ }
+
+ public void accept(Visitor v) throws JasperException {
+ v.visit(this);
+ }
+ }
+
+ /**
+ * Represents an attribute directive
+ */
+ public static class AttributeDirective extends Node {
+
+ public AttributeDirective(Attributes attrs, Mark start, Node parent) {
+ super(attrs, start, parent);
+ }
+
+ public void accept(Visitor v) throws JasperException {
+ v.visit(this);
+ }
+ }
+
+ /**
+ * Represents a variable directive
+ */
+ public static class VariableDirective extends Node {
+
+ public VariableDirective(Attributes attrs, Mark start, Node parent) {
+ super(attrs, start, parent);
+ }
+
+ public void accept(Visitor v) throws JasperException {
+ v.visit(this);
+ }
+ }
+
+ /**
+ * Represents a fragment-input directive
+ */
+ public static class FragmentInputDirective extends Node {
+
+ public FragmentInputDirective(Attributes attrs, Mark start, Node parent) {
+ super(attrs, start, parent);
+ }
+
+ public void accept(Visitor v) throws JasperException {
+ v.visit(this);
+ }
+ }
+
+ /**
* Represents a Jsp comment
* Comments are kept for completeness.
*/
@@ -1426,12 +1482,28 @@
doVisit(n);
}
+ public void visit(TagDirective n) throws JasperException {
+ doVisit(n);
+ }
+
public void visit(IncludeDirective n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(TaglibDirective n) throws JasperException {
+ doVisit(n);
+ }
+
+ public void visit(AttributeDirective n) throws JasperException {
+ doVisit(n);
+ }
+
+ public void visit(VariableDirective n) throws JasperException {
+ doVisit(n);
+ }
+
+ public void visit(FragmentInputDirective n) throws JasperException {
doVisit(n);
}
1.7 +21 -3
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageInfo.java
Index: PageInfo.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageInfo.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PageInfo.java 16 Jul 2002 19:30:51 -0000 1.6
+++ PageInfo.java 22 Jul 2002 20:35:27 -0000 1.7
@@ -91,6 +91,8 @@
private int maxTagNesting = 0;
private boolean scriptless = false;
private boolean scriptingEnabled = true;
+ private boolean elEnabled = true;
+ private boolean tagFile = false;
PageInfo(BeanRepository beanRepository) {
this.beanRepository = beanRepository;
@@ -229,5 +231,21 @@
public boolean isScriptingEnabled() {
return scriptingEnabled;
+ }
+
+ public void setELEnabled(boolean s) {
+ elEnabled = s;
+ }
+
+ public boolean isELEnabled() {
+ return elEnabled;
+ }
+
+ public void setTagFile(boolean s) {
+ tagFile = s;
+ }
+
+ public boolean isTagFile() {
+ return tagFile;
}
}
1.11 +95 -7
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Parser.java 18 Jul 2002 20:18:10 -0000 1.10
+++ Parser.java 22 Jul 2002 20:35:27 -0000 1.11
@@ -92,6 +92,7 @@
private Hashtable taglibs;
private ErrorDispatcher err;
private int scriptlessCount;
+ private boolean isTagFile;
// Virtual body content types, to make parsing a little easier.
// These are not accessible from outside the parser.
@@ -103,7 +104,7 @@
/**
* The constructor
*/
- private Parser(ParserController pc, JspReader reader) {
+ private Parser(ParserController pc, JspReader reader, boolean isTagFile) {
this.parserController = pc;
this.ctxt = pc.getJspCompilationContext();
this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries();
@@ -111,6 +112,8 @@
this.reader = reader;
this.currentFile = reader.mark().getFile();
this.scriptlessCount = 0;
+ this.isTagFile = isTagFile;
+ pc.getCompiler().getPageInfo().setTagFile(isTagFile);
start = reader.mark();
}
@@ -125,8 +128,13 @@
*/
public static Node.Nodes parse(ParserController pc,
JspReader reader,
- Node parent) throws JasperException {
- Parser parser = new Parser(pc, reader);
+ Node parent,
+ boolean isTagFile) throws JasperException {
+ Parser parser = new Parser(pc, reader, isTagFile);
+
+ // Tag files takes only scriptless body.
+ if (isTagFile)
+ parser.scriptlessCount++;
Node.Root root = new Node.Root(null, reader.mark(), parent);
@@ -157,7 +165,7 @@
public static Attributes parseAttributes(ParserController pc,
JspReader reader)
throws JasperException {
- Parser tmpParser = new Parser(pc, reader);
+ Parser tmpParser = new Parser(pc, reader, false);
return tmpParser.parseAttributes();
}
@@ -377,6 +385,14 @@
* | 'include' IncludeDirective
* | 'taglib' TagLibDirective)
* S? '%>'
+ *
+ * TagDirective ::= S? ('tag' PageDirective
+ * | 'include' IncludeDirective
+ * | 'taglib' TagLibDirective)
+ * | 'attribute AttributeDirective
+ * | 'variable VariableDirective
+ * | 'fragment-input FragmentInputDirective
+ * S? '%>'
*/
private void parseDirective(Node parent) throws JasperException {
reader.skipSpaces();
@@ -384,6 +400,10 @@
String directive = null;
if (reader.matches("page")) {
directive = "<%@ page";
+ if (isTagFile) {
+ err.jspError(reader.mark(), "jsp.error.directive.istagfile",
+ directive);
+ }
parsePageDirective(parent);
} else if (reader.matches("include")) {
directive = "<%@ include";
@@ -391,6 +411,34 @@
} else if (reader.matches("taglib")) {
directive = "<%@ taglib";
parseTaglibDirective(parent);
+ } else if (reader.matches("tag")) {
+ directive = "<%@ page";
+ if (!isTagFile) {
+ err.jspError(reader.mark(), "jsp.error.directive.isnottagfile",
+ directive);
+ }
+ parsePageDirective(parent);
+ } else if (reader.matches("attribute")) {
+ directive = "<%@ attribute";
+ if (!isTagFile) {
+ err.jspError(reader.mark(), "jsp.error.directive.isnottagfile",
+ directive);
+ }
+ parseAttributeDirective(parent);
+ } else if (reader.matches("variable")) {
+ directive = "<%@ variable";
+ if (!isTagFile) {
+ err.jspError(reader.mark(), "jsp.error.directive.isnottagfile",
+ directive);
+ }
+ parseVariableDirective(parent);
+ } else if (reader.matches("fragment-input")) {
+ directive = "<%@ fragment-input";
+ if (!isTagFile) {
+ err.jspError(reader.mark(), "jsp.error.directive.isnottagfile",
+ directive);
+ }
+ parseFragmentInputDirective(parent);
} else {
err.jspError(reader.mark(), "jsp.error.invalid.directive");
}
@@ -401,6 +449,46 @@
}
}
+ /*
+ * Parses a tag directive with the following syntax:
+ * PageDirective ::= ( S Attribute)*
+ */
+ private void parseTagDirective(Node parent) throws JasperException {
+ Attributes attrs = parseAttributes();
+ Node.TagDirective n = new Node.TagDirective(attrs, start, parent);
+ }
+
+ /*
+ * Parses a attribute directive with the following syntax:
+ * AttributeDirective ::= ( S Attribute)*
+ */
+ private void parseAttributeDirective(Node parent) throws JasperException {
+ Attributes attrs = parseAttributes();
+ Node.AttributeDirective n =
+ new Node.AttributeDirective(attrs, start, parent);
+ }
+
+ /*
+ * Parses a variable directive with the following syntax:
+ * PageDirective ::= ( S Attribute)*
+ */
+ private void parseVariableDirective(Node parent) throws JasperException {
+ Attributes attrs = parseAttributes();
+ Node.VariableDirective n =
+ new Node.VariableDirective(attrs, start, parent);
+ }
+
+ /*
+ * Parses a fragment input directive with the following syntax:
+ * PageDirective ::= ( S Attribute)*
+ */
+ private void parseFragmentInputDirective(Node parent)
+ throws JasperException {
+ Attributes attrs = parseAttributes();
+ Node.FragmentInputDirective n =
+ new Node.FragmentInputDirective(attrs, start, parent);
+ }
+
/*
* JSPCommentBody ::= (Char* - (Char* '--%>')) '--%>'
*/
1.6 +8 -2
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java
Index: ParserController.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ParserController.java 18 Jul 2002 18:03:49 -0000 1.5
+++ ParserController.java 22 Jul 2002 20:35:27 -0000 1.6
@@ -110,6 +110,11 @@
private boolean isTopFile = true;
/*
+ * Tells if this is a regular jsp page or tag file.
+ */
+ private boolean isTagFile = false;
+
+ /*
* The encoding of the "top" file. This encoding is used
* for included files by default.
* Defaults to "ISO-8859-1" per JSP spec.
@@ -196,7 +201,7 @@
JspReader r = new JspReader(ctxt, absFileName, encoding,
reader,
compiler.getErrorDispatcher());
- parsedPage = Parser.parse(this, r, parent);
+ parsedPage = Parser.parse(this, r, parent, isTagFile);
}
baseDirStack.pop();
} finally {
@@ -249,7 +254,8 @@
jspReader.reset(startMark);
while (jspReader.skipUntil("<%@") != null) {
jspReader.skipSpaces();
- if (jspReader.matches("page")) {
+ isTagFile = jspReader.matches("tag");
+ if (isTagFile || jspReader.matches("page")) {
jspReader.skipSpaces();
Attributes attrs = Parser.parseAttributes(this, jspReader);
String attribute = "pageEncoding";
1.14 +65 -8
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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Validator.java 19 Jul 2002 17:12:57 -0000 1.13
+++ Validator.java 22 Jul 2002 20:35:27 -0000 1.14
@@ -93,7 +93,7 @@
/**
* A visitor to validate and extract page directive info
*/
- static class PageDirectiveVisitor extends Node.Visitor {
+ static class DirectiveVisitor extends Node.Visitor {
private PageInfo pageInfo;
private ErrorDispatcher err;
@@ -113,6 +113,42 @@
new JspUtil.ValidAttribute("pageEncoding"),
new JspUtil.ValidAttribute("isScriptingEnabled") };
+ private static final JspUtil.ValidAttribute[] tagDirectiveAttrs = {
+ new JspUtil.ValidAttribute("name"),
+ new JspUtil.ValidAttribute("dispaly-name"),
+ new JspUtil.ValidAttribute("body-content"),
+ new JspUtil.ValidAttribute("small-icon"),
+ new JspUtil.ValidAttribute("large-icon"),
+ new JspUtil.ValidAttribute("description"),
+ new JspUtil.ValidAttribute("example"),
+ new JspUtil.ValidAttribute("pageEncoding") };
+
+ private static final JspUtil.ValidAttribute[] attributeDirectiveAttrs = {
+ new JspUtil.ValidAttribute("name", true),
+ new JspUtil.ValidAttribute("required"),
+ new JspUtil.ValidAttribute("fragment"),
+ new JspUtil.ValidAttribute("rtexprvalue"),
+ new JspUtil.ValidAttribute("type"),
+ new JspUtil.ValidAttribute("description")
+ };
+
+ private static final JspUtil.ValidAttribute[] variableDirectiveAttrs = {
+ new JspUtil.ValidAttribute("name-given"),
+ new JspUtil.ValidAttribute("name-from"),
+ new JspUtil.ValidAttribute("variable-class"),
+ new JspUtil.ValidAttribute("scope"),
+ new JspUtil.ValidAttribute("declare"),
+ new JspUtil.ValidAttribute("description")
+ };
+
+ private static final JspUtil.ValidAttribute[] fragmentInputDirectiveAttrs = {
+ new JspUtil.ValidAttribute("name", true),
+ new JspUtil.ValidAttribute("fragment", true),
+ new JspUtil.ValidAttribute("required"),
+ new JspUtil.ValidAttribute("type"),
+ new JspUtil.ValidAttribute("description")
+ };
+
private boolean languageSeen = false;
private boolean extendsSeen = false;
private boolean sessionSeen = false;
@@ -128,7 +164,7 @@
/*
* Constructor
*/
- PageDirectiveVisitor(Compiler compiler) {
+ DirectiveVisitor(Compiler compiler) {
this.pageInfo = compiler.getPageInfo();
this.err = compiler.getErrorDispatcher();
}
@@ -261,6 +297,26 @@
// the parsers, just add them to pageInfo.
pageInfo.addImports(n.getImports());
}
+
+ public void visit(Node.TagDirective n) throws JasperException {
+ JspUtil.checkAttributes("Tag directive", n,
+ tagDirectiveAttrs, err);
+ }
+
+ public void visit(Node.AttributeDirective n) throws JasperException {
+ JspUtil.checkAttributes("Attribute directive", n,
+ attributeDirectiveAttrs, err);
+ }
+
+ public void visit(Node.VariableDirective n) throws JasperException {
+ JspUtil.checkAttributes("Variable directive", n,
+ variableDirectiveAttrs, err);
+ }
+
+ public void visit(Node.FragmentInputDirective n) throws JasperException{
+ JspUtil.checkAttributes("Fragment-input directive", n,
+ fragmentInputDirectiveAttrs, err);
+ }
}
/**
@@ -793,16 +849,17 @@
Node.Nodes page) throws JasperException {
/*
- * Visit the page directives first, as they are global to the page
+ * Visit the page/tag directives first, as they are global to the page
* and are position independent.
*/
- page.visit(new PageDirectiveVisitor(compiler));
+ page.visit(new DirectiveVisitor(compiler));
// Determine the default output content type, per errata_a
//
http://jcp.org/aboutJava/communityprocess/maintenance/jsr053/errata_1_2_a_20020321.html
PageInfo pageInfo = compiler.getPageInfo();
String contentType = pageInfo.getContentType();
- if (contentType == null || contentType.indexOf("charset=") < 0) {
+ if (!pageInfo.isTagFile() &&
+ (contentType == null || contentType.indexOf("charset=") < 0)) {
boolean isXml = page.getRoot().isXmlSyntax();
String defaultType;
if (contentType == null) {
1.12 +4 -2
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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- messages.properties 19 Jul 2002 17:12:57 -0000 1.11
+++ messages.properties 22 Jul 2002 20:35:27 -0000 1.12
@@ -65,6 +65,8 @@
jsp.error.unknownException=Unhandled error! You might want to consider having an
error page \
to report such errors more gracefully
jsp.error.invalid.directive=Invalid directive
+jsp.error.idirective.istagfile={0} directive cannot be used in a tag file
+jsp.error.idirective.isnottagfile={0} directive can only be used in a tag file
jsp.error.unterminated=Unterminated {0} tag
jsp.error.usebean.notinsamefile=useBean tag must begin and end in the same physical
file
jsp.error.unable.loadclass=Unable to load class {0}
@@ -268,4 +270,4 @@
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
+jsp.error.dynamic.attributes.not.implemented=The {0} tag declares that it accepts
dynamic attributes but does not implement the required interface
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>