You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by an...@apache.org on 2006/08/30 05:03:33 UTC

svn commit: r438332 - in /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry: Framework.library html/Relation.java html/Relation.jwc html/Shell.java html/Style.jwc

Author: andyhot
Date: Tue Aug 29 20:03:32 2006
New Revision: 438332

URL: http://svn.apache.org/viewvc?rev=438332&view=rev
Log:
TAPESTRY-274: New Style component - specialization of the Relation component. Apart from stylesheet files, it can also contribute inline styles 

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Style.jwc
Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/Framework.library
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.jwc
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/Framework.library
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/Framework.library?rev=438332&r1=438331&r2=438332&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/Framework.library (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/Framework.library Tue Aug 29 20:03:32 2006
@@ -75,6 +75,7 @@
     <component-type type="ServiceLink" specification-path="link/ServiceLink.jwc"/>
     <component-type type="Script" specification-path="html/Script.jwc"/>
     <component-type type="Shell" specification-path="html/Shell.jwc"/>
+	<component-type type="Style" specification-path="html/Style.jwc"/>    
     <component-type type="Submit" specification-path="form/Submit.jwc"/>
     <component-type type="TextArea" specification-path="form/TextArea.jwc"/>
     <component-type type="TextField" specification-path="form/TextField.jwc"/>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java?rev=438332&r1=438331&r2=438332&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java Tue Aug 29 20:03:32 2006
@@ -13,11 +13,16 @@
 // limitations under the License.
 package org.apache.tapestry.html;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.tapestry.AbstractComponent;
 import org.apache.tapestry.IAsset;
 import org.apache.tapestry.IMarkupWriter;
 import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.markup.MarkupWriterSource;
+import org.apache.tapestry.util.ContentType;
 
 /**
  * Works with the {@link Shell} component to define and append a 
@@ -42,34 +47,66 @@
                 throw new ApplicationRuntimeException(
                     HTMLMessages.shellComponentRequired(),
                     this.getLocation(), null);
-                    
-            Object href = getHref();
-            boolean ok = (href instanceof String) || (href instanceof IAsset);
-            if (!ok)
-                throw new ApplicationRuntimeException(
-                    HTMLMessages.stringOrIAssetExpected(),
-                    this.getLocation(), null); 
-                    
-            String url;
-            if (href instanceof String)
+                   
+            if (getUseBody() && getHref() == null)
             {
-                url = (String) href;
+                renderStyleTag(shell, writer, cycle);
             }
             else
             {
-                url = ((IAsset)href).buildURL();
+                renderLinkTag(shell, writer, cycle);
             }
-                    
-            RelationBean bean = new RelationBean();           
-            bean.setHref(url);
-            bean.setMedia(getMedia());
-            bean.setRel(getRel());
-            bean.setRev(getRev());
-            bean.setTitle(getTitle());
-            bean.setType(getType());
-            shell.addRelation(bean);
         }          
-    }
+    }    
+    
+    protected void renderLinkTag(Shell shell, IMarkupWriter writer, IRequestCycle cycle)
+    {
+        Object href = getHref();
+        boolean ok = (href instanceof String) || (href instanceof IAsset);            
+        if (!ok)
+            throw new ApplicationRuntimeException(
+                HTMLMessages.stringOrIAssetExpected(),
+                this.getLocation(), null); 
+                
+        String url;
+        if (href instanceof String)
+        {
+            url = (String) href;
+        }
+        else
+        {
+            url = ((IAsset)href).buildURL();
+        }
+                
+        RelationBean bean = new RelationBean();           
+        bean.setHref(url);
+        bean.setMedia(getMedia());
+        bean.setRel(getRel());
+        bean.setRev(getRev());
+        bean.setTitle(getTitle());
+        bean.setType(getType());
+        shell.addRelation(bean);        
+    }   
+    
+    protected void renderStyleTag(Shell shell, IMarkupWriter writer, IRequestCycle cycle)
+    {
+        StringWriter sWriter = new StringWriter();
+        IMarkupWriter nested = getMarkupWriterSource().newMarkupWriter(new PrintWriter(sWriter),
+                new ContentType(writer.getContentType()));
+        nested.begin("style");
+        nested.attribute("type", "text/css");
+        if (getMedia()!=null)
+            nested.attribute("media", getMedia());
+        if (getTitle()!=null)
+            nested.attribute("title", getTitle());        
+        
+        renderBody(nested, cycle);
+        nested.close();
+
+        shell.includeAdditionalContent(sWriter.toString());
+    }    
+    
+    public abstract boolean getUseBody();
     
     public abstract Object getHref();
 
@@ -81,6 +118,9 @@
     
     public abstract String getTitle();
         
-    public abstract String getMedia();    
+    public abstract String getMedia();
+    
+    /* injected */
+    public abstract MarkupWriterSource getMarkupWriterSource();
 
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.jwc?rev=438332&r1=438331&r2=438332&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.jwc (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.jwc Tue Aug 29 20:03:32 2006
@@ -66,4 +66,6 @@
     </description>
   </parameter>
   
+  <property name="useBody" initial-value="ognl:false"/>
+  
 </component-specification>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.java?rev=438332&r1=438331&r2=438332&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.java Tue Aug 29 20:03:32 2006
@@ -112,9 +112,9 @@
             if (relations != null)
                 writeRelations(writer, relations); 
             
-            StringBuffer inlineStyle = getStyleBuffer();
-            if (inlineStyle != null)
-                writeInlineStyle(writer, inlineStyle.toString());
+            StringBuffer additionalContent = getContentBuffer();
+            if (additionalContent != null)
+                writer.printRaw(additionalContent.toString());
             
             IAsset stylesheet = getStylesheet();
             
@@ -230,20 +230,7 @@
             writeAttributeIfNotNull(writer, "title", relationBean.getTitle());
             writeAttributeIfNotNull(writer, "href", relationBean.getHref());
             writer.println();
-    }
-    
-    private void writeInlineStyle(IMarkupWriter writer, String style)
-    {
-        writer.begin("style");
-        writer.attribute("type", "text/css");
-        writer.println();
-        
-        writer.printRaw(style);
-        writer.println();
-        
-        writer.end();
-        writer.println();
-    }
+    }    
     
     private void writeAttributeIfNotNull(IMarkupWriter writer, String name, String value)
     {
@@ -280,21 +267,21 @@
     }
 
     /**
-     * Adds additional styles to the header of a page.
-     * @param style
+     * Include additional content in the header of a page.
+     * @param style 
      *
      * @since 4.1.1
      */
-    public void addInlineStyle(String style)
+    public void includeAdditionalContent(String content)
     {
-        if (HiveMind.isBlank(style))
+        if (HiveMind.isBlank(content))
             return;
-        StringBuffer buffer = getStyleBuffer();
+        StringBuffer buffer = getContentBuffer();
         if (buffer == null)
             buffer = new StringBuffer();
         
-        buffer.append(style);        
-        setStyleBuffer(buffer);
+        buffer.append(content);        
+        setContentBuffer(buffer);
     }
     
     public abstract boolean isDisableCaching();
@@ -348,10 +335,10 @@
     
     /** @since 4.1.1 */
     
-    public abstract StringBuffer getStyleBuffer();
+    public abstract StringBuffer getContentBuffer();
     
     /** @since 4.1.1 */
     
-    public abstract void setStyleBuffer(StringBuffer buffer);    
+    public abstract void setContentBuffer(StringBuffer buffer);    
 
 }

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Style.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Style.jwc?rev=438332&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Style.jwc (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Style.jwc Tue Aug 29 20:03:32 2006
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+   Copyright 2004, 2005 The Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+
+<!DOCTYPE component-specification PUBLIC
+  "-//Apache Software Foundation//Tapestry Specification 4.0//EN" 
+  "http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">
+	
+<component-specification class="org.apache.tapestry.html.Relation" 
+	allow-body="yes" 
+	allow-informal-parameters="no">
+
+  <description>
+    Declares a stylesheet to be included in the current page. 
+  </description>
+
+  <parameter name="href">
+    <description>
+    The target URL of the stylesheet. Can either be a String or an IAsset.
+    </description>
+  </parameter> 
+  
+  <parameter name="rel"
+      		 default-value="literal:stylesheet">
+    <description>
+	By default this is 'stylesheet' but you can also use 'alternate stylesheet'.
+    </description>
+  </parameter>    
+  
+  <parameter name="title">
+    <description>
+    Title of the stylesheet.
+    </description>
+  </parameter>     
+  
+  <parameter name="media">
+    <description>
+    Specifies on what device this stylesheet will apply.
+    </description>
+  </parameter>
+  
+  <property name="type" initial-value="literal:text/css"/>
+  <property name="useBody" initial-value="ognl:true"/>
+  
+  <inject property="markupWriterSource" object="service:tapestry.markup.MarkupWriterSource"/>
+  
+</component-specification>
\ No newline at end of file