You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2006/05/06 03:44:10 UTC

svn commit: r400221 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/internal/parser/ main/java/org/apache/tapestry/internal/structure/ main/resources/org/apache/tapestry/internal/parser/ te...

Author: hlship
Date: Fri May  5 18:44:07 2006
New Revision: 400221

URL: http://svn.apache.org/viewcvs?rev=400221&view=rev
Log:
Initial steps towards building the new template parser.

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/package.html
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageElement.java
      - copied, changed from r400104, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Component.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/basic.html
Removed:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Component.java
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Page.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageImpl.java

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java?rev=400221&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java Fri May  5 18:44:07 2006
@@ -0,0 +1,12 @@
+package org.apache.tapestry;
+
+/**
+ * An interface used by objects, such as Tapestry components, that need to render themselves as some
+ * form of XML markup.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface MarkupWriter
+{
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java?rev=400221&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java Fri May  5 18:44:07 2006
@@ -0,0 +1,11 @@
+package org.apache.tapestry.internal.parser;
+
+/**
+ * A parsed component template, containing all the tokens parsed from the template.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface ComponentTemplate
+{
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/package.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/package.html?rev=400221&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/package.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/package.html Fri May  5 18:44:07 2006
@@ -0,0 +1,5 @@
+<html>
+    <body>
+        Classes related to parsing of Tapestry component templates.
+    </body>
+</html>
\ No newline at end of file

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Page.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Page.java?rev=400221&r1=400220&r2=400221&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Page.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Page.java Fri May  5 18:44:07 2006
@@ -46,11 +46,8 @@
      * Invoked during page construction time to connect the page's root component to the page
      * instance.
      */
-    void setRootComponent(Component component);
+    void setRootElement(PageElement component);
 
     /** The root component of the page. */
-    Component getRootComponent();
-
-    /** Adds a lifecycle listener to the page. This is most often a component or a component peer. */
-    void addComponentLifecycle(ComponentLifecycle lifecycle);
+    PageElement getRootElement();
 }

Copied: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageElement.java (from r400104, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Component.java)
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageElement.java?p2=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageElement.java&p1=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Component.java&r1=400104&r2=400221&rev=400221&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/Component.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageElement.java Fri May  5 18:44:07 2006
@@ -15,14 +15,15 @@
 package org.apache.tapestry.internal.structure;
 
 /**
- * A component provides the structure of a page. Each component is aware of its immediate container,
- * and of the page that ultimately contains it.
+ * An element within a page. Page elements are placeholders that delegate much of their behavior to
+ * application-specific component classes. A page element will also, ultimately, provide
+ * {@link org.apache.tapestry.ComponentResources} to the component classes.
  * 
  * @author Howard M. Lewis Ship
  */
-public interface Component
+public interface PageElement
 {
     Page getPage();
 
-    Component getContainer();
+    PageElement getContainer();
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageImpl.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageImpl.java?rev=400221&r1=400220&r2=400221&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/PageImpl.java Fri May  5 18:44:07 2006
@@ -14,13 +14,8 @@
 
 package org.apache.tapestry.internal.structure;
 
-import java.util.List;
 import java.util.Locale;
 
-import org.apache.tapestry.runtime.ComponentLifecycle;
-
-import static org.apache.tapestry.util.CollectionFactory.newList;
-
 /** @author Howard M. Lewis Ship */
 public class PageImpl implements Page
 {
@@ -28,9 +23,7 @@
 
     private final Locale _locale;
 
-    private final List<ComponentLifecycle> _lifecycles = newList();
-
-    private Component _rootComponent;
+    private PageElement _rootElement;
 
     public PageImpl(String name, Locale locale)
     {
@@ -48,19 +41,13 @@
         return _locale;
     }
 
-    public void setRootComponent(Component component)
+    public void setRootElement(PageElement component)
     {
-        _rootComponent = component;
+        _rootElement = component;
     }
 
-    public Component getRootComponent()
+    public PageElement getRootElement()
     {
-        return _rootComponent;
+        return _rootElement;
     }
-
-    public void addComponentLifecycle(ComponentLifecycle lifecycle)
-    {
-        _lifecycles.add(lifecycle);
-    }
-
 }

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd?rev=400221&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd Fri May  5 18:44:07 2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
+    targetNamespace="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    <xs:element name="comp">
+        <xs:complexType mixed="true">
+            <xs:attribute name="id" use="required" type="xs:ID"/>
+            <xs:attribute name="type" type="xs:string"/>
+            <xs:anyAttribute/>
+        </xs:complexType>
+    </xs:element>
+</xs:schema>

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java?rev=400221&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java Fri May  5 18:44:07 2006
@@ -0,0 +1,165 @@
+package org.apache.tapestry.internal.parser;
+
+import java.io.BufferedInputStream;
+import java.net.URL;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/** Used to experiment with namespace aware SAX parsers. */
+public class ParserExperiment extends DefaultHandler
+{
+    public static void main(String[] args) throws Exception
+    {
+        new ParserExperiment().parse("basic.html");
+    }
+
+    public void parse(String file) throws Exception
+    {
+        parse(getClass().getResource(file));
+    }
+
+    public void parse(URL document) throws Exception
+    {
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+
+        factory.setNamespaceAware(true);
+        // Equivalent:
+        // factory.setFeature("http://xml.org/sax/features/namespaces", true);
+
+        //  Doesn't seem to do anything:
+        factory.setFeature(
+                "http://apache.org/xml/features/validation/schema/normalized-value",
+                true);
+        
+        factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+
+        // A non-validation parser is fine!
+
+        SAXParser parser = factory.newSAXParser();
+
+        InputSource source = new InputSource(new BufferedInputStream(document.openStream()));
+
+        parser.parse(source, this);
+    }
+
+    private void log(String methodName, String... details)
+    {
+        StringBuffer buffer = new StringBuffer();
+
+        buffer.append(String.format("%25s", methodName));
+
+        for (int i = 0; i < details.length; i++)
+        {
+            if (i == 0)
+                buffer.append(": ");
+            else
+                buffer.append("\n                           ");
+
+            buffer.append(details[i]);
+        }
+
+        System.out.println(buffer.toString());
+    }
+
+    @Override
+    public void characters(char[] ch, int start, int length) throws SAXException
+    {
+        String string = new String(ch, start, length);
+        String loggable = string.replaceAll("![\\w -]", ".").trim();
+
+        log("characters", "start=" + start, "length=" + length, loggable);
+    }
+
+    @Override
+    public void endDocument() throws SAXException
+    {
+        log("endDocument");
+    }
+
+    @Override
+    public void endElement(String uri, String localName, String qName) throws SAXException
+    {
+        log("endElement", localName, "uri=" + uri, "qName=" + qName);
+    }
+
+    @Override
+    public void endPrefixMapping(String prefix) throws SAXException
+    {
+        log("endPrefixMapping", prefix);
+    }
+
+    @Override
+    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
+    {
+        log("ignorableWhitespace", "start=" + start, "length=" + length);
+    }
+
+    @Override
+    public void notationDecl(String name, String publicId, String systemId) throws SAXException
+    {
+        log("notationDecl", name, "publicId=" + publicId, "systemId=" + systemId);
+    }
+
+    @Override
+    public void processingInstruction(String target, String data) throws SAXException
+    {
+        log("pi", "target=" + target, "data=" + data);
+    }
+
+    @Override
+    public void setDocumentLocator(Locator locator)
+    {
+        log("setDocumentLocator", locator.toString());
+    }
+
+    @Override
+    public void skippedEntity(String name) throws SAXException
+    {
+        log("skippedEntity", name);
+    }
+
+    @Override
+    public void startDocument() throws SAXException
+    {
+        log("startDocument");
+    }
+
+    @Override
+    public void startElement(String uri, String localName, String qName, Attributes attributes)
+            throws SAXException
+    {
+        log("startElement", localName, "uri=" + uri, "qName=" + qName);
+
+        int count = attributes.getLength();
+
+        for (int i = 0; i < count; i++)
+        {
+            log(
+                    "attribute",
+                    attributes.getLocalName(i),
+                    "value=" + attributes.getValue(i),
+                    "qName=" + attributes.getQName(i));
+        }
+    }
+
+    @Override
+    public void startPrefixMapping(String prefix, String uri) throws SAXException
+    {
+        log("startPrefixMapping", "prefix=" + prefix, "uri=" + uri);
+    }
+
+    @Override
+    public void unparsedEntityDecl(String name, String publicId, String systemId,
+            String notationName) throws SAXException
+    {
+        log("unparsedEntityDecl", name, "publicId=" + publicId, "systemId=" + systemId);
+    }
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/basic.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/basic.html?rev=400221&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/basic.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/basic.html Fri May  5 18:44:07 2006
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    <head>
+        <title>Test</title>
+    </head>
+    <body>
+        <t:comp id="fred" type="If" value="foo">
+            <p>You have been served!</p>
+        </t:comp>
+        <p t:id="barney">
+            You are barney!
+        </p>
+    </body>
+</html>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org