luehe       2003/02/19 17:02:52

  Modified:    jasper2/src/share/org/apache/jasper/compiler
                        JspDocumentParser.java Node.java PageDataImpl.java
                        Parser.java
  Log:
  - When adding a jsp:root element to the XML view of a JSP document, do not
    populate it with an "xmlns:jsp=..." attribute (add this attribute only to
    the jsp:root element of the XML view of a JSP page in *standard* syntax).
  
  - Added support for jsp:element to XML view
  
  Revision  Changes    Path
  1.40      +5 -7      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
  
  Index: JspDocumentParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- JspDocumentParser.java    19 Feb 2003 23:39:15 -0000      1.39
  +++ JspDocumentParser.java    20 Feb 2003 01:02:51 -0000      1.40
  @@ -162,14 +162,12 @@
        }
   
        Node.Nodes pageNodes = null;
  -     Node.JspRoot jspRoot = null;
  +     Node.Root jspRoot = null;
   
        try {
            if (parent == null) {
                // create dummy <jsp:root> element
  -             AttributesImpl rootAttrs = new AttributesImpl();
  -             rootAttrs.addAttribute("", "", "version", "CDATA", "2.0");
  -             jspRoot = new Node.JspRoot(rootAttrs, null, null, null);
  +             jspRoot = new Node.Root();
                handler.current = jspRoot;
            } else {
                handler.isTop = false;
  
  
  
  1.58      +16 -7     
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.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- Node.java 19 Feb 2003 23:39:15 -0000      1.57
  +++ Node.java 20 Feb 2003 01:02:51 -0000      1.58
  @@ -343,8 +343,16 @@
   
        private Root parentRoot;
   
  -     Root(Attributes attrs, Mark start, Node parent) {
  -         super(attrs, start, parent);
  +     /*
  +      * Constructor for dummy root.
  +      */
  +     Root() {}
  +
  +     /*
  +      * Constructor.
  +      */
  +     Root(Mark start, Node parent) {
  +         super(start, parent);
   
            // Figure out and set the parent root
            Node r = parent;
  @@ -362,7 +370,7 @@
        }
   
        /**
  -      * @return The enclosing root to this root.  Usually represents the
  +      * @return The enclosing root to this root. Usually represents the
         * page that includes this one.
         */
        public Root getParentRoot() {
  @@ -377,7 +385,8 @@
   
        public JspRoot(Attributes attrs, Attributes xmlnsAttrs, Mark start,
                       Node parent) {
  -         super(attrs, start, parent);
  +         super(start, parent);
  +         this.attrs = attrs;
            this.xmlnsAttrs = xmlnsAttrs;
        }
   
  
  
  
  1.22      +42 -43    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java
  
  Index: PageDataImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- PageDataImpl.java 19 Feb 2003 23:39:15 -0000      1.21
  +++ PageDataImpl.java 20 Feb 2003 01:02:51 -0000      1.22
  @@ -97,24 +97,9 @@
       private static final String CDATA_START_SECTION = "<![CDATA[\n";
       private static final String CDATA_END_SECTION = "]]>\n";
   
  -    // default "xmlns:jsp" and "version" attributes of jsp:root element
  -    private static AttributesImpl defaultJspRootAttrs;
  -
       // string buffer used to build XML view
       private StringBuffer buf;
   
  -    /*
  -     * Static initializer which sets the "xmlns:jsp" and "version" 
  -     * attributes of the jsp:root element to their default values.
  -     */
  -    static {
  -     defaultJspRootAttrs = new AttributesImpl();
  -     defaultJspRootAttrs.addAttribute("", "", "xmlns:jsp", "CDATA",
  -                                      JSP_NAMESPACE);
  -     defaultJspRootAttrs.addAttribute("", "", "version", "CDATA",
  -                                      JSP_VERSION);
  -    }
  -
       /**
        * Constructor.
        *
  @@ -124,15 +109,16 @@
                throws JasperException {
   
        // First pass
  -     FirstPassVisitor firstPassVisitor
  -         = new FirstPassVisitor(page.getRoot());
  -     page.visit(firstPassVisitor);
  +     boolean isXml = compiler.getPageInfo().isXml();
  +     FirstPassVisitor firstPass = new FirstPassVisitor(page.getRoot(),
  +                                                       isXml);
  +     page.visit(firstPass);
   
        // Second pass
        buf = new StringBuffer();
  -     SecondPassVisitor secondPassVisitor
  -         = new SecondPassVisitor(page.getRoot(), buf, compiler);
  -     page.visit(secondPassVisitor);
  +     SecondPassVisitor secondPass = new SecondPassVisitor(page.getRoot(),
  +                                                          buf, compiler);
  +     page.visit(secondPass);
       }
   
       /**
  @@ -169,9 +155,15 @@
        /*
         * Constructor
         */
  -     public FirstPassVisitor(Node.Root root) {
  +     public FirstPassVisitor(Node.Root root, boolean isXml) {
            this.root = root;
  -         this.rootAttrs = new AttributesImpl(defaultJspRootAttrs);
  +         this.rootAttrs = new AttributesImpl();
  +         this.rootAttrs.addAttribute("", "", "version", "CDATA",
  +                                     JSP_VERSION);
  +         if (!isXml) {
  +             this.rootAttrs.addAttribute("", "", "xmlns:jsp", "CDATA",
  +                                         JSP_NAMESPACE);
  +         } 
        }
   
        public void visit(Node.Root n) throws JasperException {
  @@ -183,24 +175,11 @@
        }
   
        public void visit(Node.JspRoot n) throws JasperException {
  -         Attributes attrs = n.getAttributes();
  -         if (attrs == null) {
  -             throw new JasperException("Missing attributes in jsp:root");
  -         }
  -         int len = attrs.getLength();
  -         for (int i=0; i<len; i++) {
  -             String qName = attrs.getQName(i);
  -             if ((qName.startsWith("xmlns:jsp")
  -                  || qName.equals("version"))) {
  -                 continue;
  -             }
  -             rootAttrs.addAttribute(attrs.getURI(i),
  -                                    attrs.getLocalName(i),
  -                                    attrs.getQName(i),
  -                                    attrs.getType(i),
  -                                    attrs.getValue(i));
  -         }
  +         addAttributes(n.getXmlnsAttributes());
  +         addAttributes(n.getAttributes());
  +
            visitBody(n);
  +
            if (n == this.root) {
                // top-level jsp:root element
                this.root.setAttributes(rootAttrs);
  @@ -225,6 +204,22 @@
                }
            }
        }
  +
  +     private void addAttributes(Attributes attrs) {
  +         if (attrs != null) {
  +             int len = attrs.getLength();
  +             for (int i=0; i<len; i++) {
  +                 if ("version".equals(attrs.getQName(i))) {
  +                     continue;
  +                 }
  +                 rootAttrs.addAttribute(attrs.getURI(i),
  +                                        attrs.getLocalName(i),
  +                                        attrs.getQName(i),
  +                                        attrs.getType(i),
  +                                        attrs.getValue(i));
  +             }
  +         }
  +     }
       }
   
   
  @@ -304,6 +299,10 @@
   
        public void visit(Node.Scriptlet n) throws JasperException {
            appendTag(JSP_SCRIPTLET, n);
  +     }
  +
  +     public void visit(Node.JspElement n) throws JasperException {
  +         appendTag(JSP_ELEMENT, n);
        }
   
        public void visit(Node.ELExpression n) throws JasperException {
  
  
  
  1.61      +4 -4      
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.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- Parser.java       8 Feb 2003 00:06:40 -0000       1.60
  +++ Parser.java       20 Feb 2003 01:02:51 -0000      1.61
  @@ -148,7 +148,7 @@
        Parser parser = new Parser(pc, reader, isTagFile, directivesOnly,
                                   jarFile);
   
  -     Node.Root root = new Node.Root(null, reader.mark(), parent);
  +     Node.Root root = new Node.Root(reader.mark(), parent);
   
        if (directivesOnly) {
            parser.parseTagFileDirectives(root);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to