You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2006/12/05 20:18:00 UTC

svn commit: r482743 - in /tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry: ./ dom/ internal/services/ services/

Author: hlship
Date: Tue Dec  5 11:17:57 2006
New Revision: 482743

URL: http://svn.apache.org/viewvc?view=rev&rev=482743
Log:
Rename toXML() on MarkupWriter and the DOM objects to be toMarkup().
Cleanup some comments inside ComponentMessagesSourceImpl.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Comment.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Document.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Element.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Node.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Text.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentMessagesSourceImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/MarkupWriterImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ComponentMessagesSource.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java Tue Dec  5 11:17:57 2006
@@ -12,69 +12,72 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry;
-
-import java.io.PrintWriter;
-
-import org.apache.tapestry.dom.Element;
-
-/**
- * An interface used by objects, such as Tapestry components, that need to render themselves as some
- * form of XML markup. A markup writer maintains the idea of a current element. Attributes are added
- * to the current element, and new text and elements are placed inside the current element. In this
- * way, the markup writer maintains a facade that XML markup is generated as a stream, even though
- * the implementation builds a kind of DOM tree. The DOM tree can be also be manipulated. This
- * solves a number of problems from Tapestry 4 (and earlier) where random access to the DOM was
- * desired and had to be simulated through complex buffering.
- * 
- * 
- */
-public interface MarkupWriter
-{
-    /**
-     * Begins a new element as a child of the current element. The new element becomes the current
-     * element. The new Element is returned and can be directly manipulated (possibly at a later
-     * date). Optionally, attributes for the new element can be specified directly.
-     * 
-     * @param name
-     *            the name of the element to create
-     * @param attributes
-     *            an even number of values, alternating names and values
-     * @return the new DOM Element node
-     * @see #attributes(Object[])
-     */
-    Element element(String name, Object... attributes);
-
-    /**
-     * Ends the current element. The new current element will be the parent element. Returns the new
-     * current element (which may be null when ending the root element for the document).
-     */
-
-    Element end();
-
-    /**
-     * Writes the text as a child of the current element.
-     * <p>
-     * TODO: Filtering of XML entities.
-     */
-
-    void write(String text);
-
-    /** Writes a formatted string. */
-    void writef(String format, Object... args);
-
-    /**
-     * Adds an XML comment. The text should be just the comment content, the comment delimiters will
-     * be provided.
-     */
-    void comment(String text);
-
-    /**
-     * Adds a series of attributes and values. Null values are quietly skipped. If a name already
-     * has a value, then the new value is <em>ignored</em>.
-     */
-    void attributes(Object... namesAndValues);
-
-    /** Converts the collected markup into an XML stream, sent to the writer. */
-    void toXML(PrintWriter writer);
-}
+package org.apache.tapestry;
+
+import java.io.PrintWriter;
+
+import org.apache.tapestry.dom.Document;
+import org.apache.tapestry.dom.Element;
+import org.apache.tapestry.dom.MarkupModel;
+
+/**
+ * An interface used by objects, such as Tapestry components, that need to render themselves as some
+ * form of XML markup. A markup writer maintains the idea of a current element. Attributes are added
+ * to the current element, and new text and elements are placed inside the current element. In this
+ * way, the markup writer maintains a facade that XML markup is generated as a stream, even though
+ * the implementation builds a kind of DOM tree. The DOM tree can be also be manipulated. This
+ * solves a number of problems from Tapestry 4 (and earlier) where random access to the DOM was
+ * desired and had to be simulated through complex buffering.
+ */
+public interface MarkupWriter
+{
+    /**
+     * Begins a new element as a child of the current element. The new element becomes the current
+     * element. The new Element is returned and can be directly manipulated (possibly at a later
+     * date). Optionally, attributes for the new element can be specified directly.
+     * 
+     * @param name
+     *            the name of the element to create
+     * @param attributes
+     *            an even number of values, alternating names and values
+     * @return the new DOM Element node
+     * @see #attributes(Object[])
+     */
+    Element element(String name, Object... attributes);
+
+    /**
+     * Ends the current element. The new current element will be the parent element. Returns the new
+     * current element (which may be null when ending the root element for the document).
+     */
+
+    Element end();
+
+    /**
+     * Writes the text as a child of the current element.
+     * <p>
+     * TODO: Filtering of XML entities.
+     */
+
+    void write(String text);
+
+    /** Writes a formatted string. */
+    void writef(String format, Object... args);
+
+    /**
+     * Adds an XML comment. The text should be just the comment content, the comment delimiters will
+     * be provided.
+     */
+    void comment(String text);
+
+    /**
+     * Adds a series of attributes and values. Null values are quietly skipped. If a name already
+     * has a value, then the new value is <em>ignored</em>.
+     */
+    void attributes(Object... namesAndValues);
+
+    /**
+     * Converts the collected markup into an markup stream (according to rules provided by the
+     * {@link Document}'s {@link MarkupModel}). The markup stream is sent to the writer.
+     */
+    void toMarkup(PrintWriter writer);
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Comment.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Comment.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Comment.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Comment.java Tue Dec  5 11:17:57 2006
@@ -33,7 +33,7 @@
     }
 
     @Override
-    public void toXML(PrintWriter writer)
+    public void toMarkup(PrintWriter writer)
     {
         writer.printf("<!-- %s -->", _comment);
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Document.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Document.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Document.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Document.java Tue Dec  5 11:17:57 2006
@@ -56,13 +56,13 @@
     }
 
     @Override
-    public void toXML(PrintWriter writer)
+    public void toMarkup(PrintWriter writer)
     {
         if (_rootElement == null)
             throw new IllegalStateException("No root element has been defined.");
 
         // TODO: XML declaration, plus lead-in comments, directives, DOCTYPE.
-        _rootElement.toXML(writer);
+        _rootElement.toMarkup(writer);
     }
 
     @Override

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Element.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Element.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Element.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Element.java Tue Dec  5 11:17:57 2006
@@ -148,7 +148,7 @@
     }
 
     @Override
-    public void toXML(PrintWriter writer)
+    public void toMarkup(PrintWriter writer)
     {
         writer.printf("<%s", _name);
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Node.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Node.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Node.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Node.java Tue Dec  5 11:17:57 2006
@@ -12,77 +12,77 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.dom;
-
+package org.apache.tapestry.dom;
+
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
-
-/**
- * A node within the DOM.
- */
-public abstract class Node
-{
-    private Node _container;
-
-    private List<Node> _children;
-
-    /**
-     * Creates a new node, setting its container to the provided value. Container may also be null,
-     * but that is only used for Document nodes (the topmost node of a DOM).
-     * 
-     * @param container
-     */
-    protected Node(Node container)
-    {
-        _container = container;
-    }
-
-    public Node getContainer()
-    {
-        return _container;
-    }
-    
-    protected void addChild(Node child)
-    {
-        if (_children == null)
-            _children = newList();
-
-        _children.add(child);
-    }
-
-    protected boolean hasChildren()
-    {
-        return _children != null && !_children.isEmpty();
-    }
-
-    protected void writeChildXML(PrintWriter writer)
-    {
-        if (_children == null)
-            return;
-
-        for (Node child : _children)
-            child.toXML(writer);
-    }
-
-    /**
-     * Invokes {@link #toXML(PrintWriter)}, collecting output in a string, which is returned.
-     */
-    @Override
-    public String toString()
-    {
-        StringWriter stringWriter = new StringWriter();
-        PrintWriter pw = new PrintWriter(stringWriter);
-
-        toXML(pw);
-
-        pw.close();
-
-        return stringWriter.toString();
-    }
-
-    /** Writes the XML for this node to the writer. */
-    public abstract void toXML(PrintWriter writer);
-}
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+
+/**
+ * A node within the DOM.
+ */
+public abstract class Node
+{
+    private Node _container;
+
+    private List<Node> _children;
+
+    /**
+     * Creates a new node, setting its container to the provided value. Container may also be null,
+     * but that is only used for Document nodes (the topmost node of a DOM).
+     * 
+     * @param container
+     */
+    protected Node(Node container)
+    {
+        _container = container;
+    }
+
+    public Node getContainer()
+    {
+        return _container;
+    }
+
+    protected void addChild(Node child)
+    {
+        if (_children == null)
+            _children = newList();
+
+        _children.add(child);
+    }
+
+    protected boolean hasChildren()
+    {
+        return _children != null && !_children.isEmpty();
+    }
+
+    protected void writeChildXML(PrintWriter writer)
+    {
+        if (_children == null)
+            return;
+
+        for (Node child : _children)
+            child.toMarkup(writer);
+    }
+
+    /**
+     * Invokes {@link #toMarkup(PrintWriter)}, collecting output in a string, which is returned.
+     */
+    @Override
+    public String toString()
+    {
+        StringWriter stringWriter = new StringWriter();
+        PrintWriter pw = new PrintWriter(stringWriter);
+
+        toMarkup(pw);
+
+        pw.close();
+
+        return stringWriter.toString();
+    }
+
+    /** Writes the markup for this node to the writer. */
+    public abstract void toMarkup(PrintWriter writer);
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Text.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Text.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Text.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/dom/Text.java Tue Dec  5 11:17:57 2006
@@ -48,7 +48,7 @@
     }
 
     @Override
-    public void toXML(PrintWriter writer)
+    public void toMarkup(PrintWriter writer)
     {
         writer.print(_buffer.toString());
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentMessagesSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentMessagesSourceImpl.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentMessagesSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentMessagesSourceImpl.java Tue Dec  5 11:17:57 2006
@@ -38,17 +38,21 @@
 import org.apache.tapestry.model.ComponentModel;
 import org.apache.tapestry.services.ComponentMessagesSource;
 
+/**
+ * Implementation of {@link ComponentMessagesSource} available as
+ * service:tapestry.ComponentMessagesSource or infrastructure:ComponentMessagesSource.
+ */
 public class ComponentMessagesSourceImpl extends InvalidationEventHubImpl implements
         ComponentMessagesSource, UpdateListener
 {
     private final URLChangeTracker _tracker;
 
-    /** Keyed on component class name + locale. */
-    private final Map<MultiKey, Messages> _messagesByClassAndLocaleCache = newThreadSafeMap();
+    /** Keyed on component class name and locale. */
+    private final Map<MultiKey, Messages> _messagesByClassAndLocale = newThreadSafeMap();
 
     /**
      * Keyed on component class name and locale, the coooked properties include properties inherited
-     * from less local-specific properties files, or inherited from base classes.
+     * from less locale-specific properties files, or inherited from base classes.
      */
     private final Map<MultiKey, Map<String, String>> _cookedProperties = newThreadSafeMap();
 
@@ -74,7 +78,7 @@
     {
         if (_tracker.containsChanges())
         {
-            _messagesByClassAndLocaleCache.clear();
+            _messagesByClassAndLocale.clear();
             _cookedProperties.clear();
             _rawProperties.clear();
 
@@ -88,12 +92,12 @@
     {
         MultiKey key = new MultiKey(componentModel.getComponentClassName(), locale);
 
-        Messages result = _messagesByClassAndLocaleCache.get(key);
+        Messages result = _messagesByClassAndLocale.get(key);
 
         if (result == null)
         {
             result = buildMessages(componentModel, locale);
-            _messagesByClassAndLocaleCache.put(key, result);
+            _messagesByClassAndLocale.put(key, result);
         }
 
         return result;
@@ -142,6 +146,9 @@
             localizations.add(localized);
         }
 
+        // We need them in least-specific to most-specific order, the opposite
+        // of how the LocalizedNameGenerator provides them.
+        
         Collections.reverse(localizations);
 
         // Localizations are now in least-specific to most-specific order.
@@ -176,8 +183,12 @@
         if (rawProperties.isEmpty())
             return base;
 
+        // Make a copy of the base Map
+        
         Map<String, String> result = newMap(base);
 
+        // Add or overwrite properties to the copy
+
         result.putAll(rawProperties);
 
         return result;
@@ -239,10 +250,7 @@
             String key = e.getKey().toString();
 
             String value = p.getProperty(key);
-
-            // Add new value, or overwrite value inherited from less-specific localization, or from
-            // parent component class.
-
+            
             result.put(key, value);
         }
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/MarkupWriterImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/MarkupWriterImpl.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/MarkupWriterImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/MarkupWriterImpl.java Tue Dec  5 11:17:57 2006
@@ -44,9 +44,9 @@
         _document = new Document(model);
     }
 
-    public void toXML(PrintWriter writer)
+    public void toMarkup(PrintWriter writer)
     {
-        _document.toXML(writer);
+        _document.toMarkup(writer);
     }
 
     @Override

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java Tue Dec  5 11:17:57 2006
@@ -57,7 +57,7 @@
 
         PrintWriter pw = response.getPrintWriter();
 
-        writer.toXML(pw);
+        writer.toMarkup(pw);
 
         pw.flush();
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ComponentMessagesSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ComponentMessagesSource.java?view=diff&rev=482743&r1=482742&r2=482743
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ComponentMessagesSource.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ComponentMessagesSource.java Tue Dec  5 11:17:57 2006
@@ -20,6 +20,7 @@
 import org.apache.tapestry.ioc.Messages;
 import org.apache.tapestry.model.ComponentModel;
 
+/** Used to connect a Tapestry component to its message catalog. */
 public interface ComponentMessagesSource extends InvalidationEventHub
 {
     /**
@@ -30,7 +31,7 @@
      * 
      * @param componentModel
      * @param locale
-     * @return
+     * @return the message catalog for the component, in the indicated locale
      */
     Messages getMessages(ComponentModel componentModel, Locale locale);
 }