You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/05/12 22:32:04 UTC

svn commit: r537509 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ core/src/main/java/org/apache/myfaces/tobago/webapp/ sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/wml/standard/standard/tag/ theme...

Author: bommel
Date: Sat May 12 13:32:03 2007
New Revision: 537509

URL: http://svn.apache.org/viewvc?view=rev&rev=537509
Log:
TOBAGO-393: Create OptimizedResponseWriter to move the non-standard-compliant optimization stuff to

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterWrapper.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/wml/standard/standard/tag/PageRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java?view=diff&rev=537509&r1=537508&r2=537509
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java Sat May 12 13:32:03 2007
@@ -42,6 +42,7 @@
 import org.apache.myfaces.tobago.renderkit.RendererBaseWrapper;
 import org.apache.myfaces.tobago.util.LayoutUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriterWrapper;
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
@@ -460,8 +461,7 @@
     if (writer instanceof TobagoResponseWriter) {
       return (TobagoResponseWriter) writer;
     } else {
-      // todo: return new TobagoResponseWriterWrapper(writer);
-      throw new UnsupportedOperationException("No TobagoResponseWriterWrapper implementation found!");
+      return new TobagoResponseWriterWrapper(writer);
     }
   }
 

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java?view=diff&rev=537509&r1=537508&r2=537509
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java Sat May 12 13:32:03 2007
@@ -19,6 +19,8 @@
 
 import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
 import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
+import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.ResponseWriter;
@@ -32,32 +34,32 @@
  * User: lofwyr
  * Date: 08.05.2007 13:51:43
  */
-public interface TobagoResponseWriter {
+public abstract class TobagoResponseWriter extends ResponseWriter {
 
   // same as in ResponseWriter
 
-  void startElement(String name, UIComponent component) throws IOException;
+  public abstract void startElement(String name, UIComponent component) throws IOException;
 
-  void endElement(String name) throws IOException;
+  public abstract void endElement(String name) throws IOException;
 
-  void write(String string) throws IOException;
+  public abstract void write(String string) throws IOException;
 
-  void writeComment(Object obj) throws IOException;
+  public abstract void writeComment(Object comment) throws IOException;
 
-  ResponseWriter cloneWithWriter(Writer content);
+  public abstract ResponseWriter cloneWithWriter(Writer writer);
   /**
    * @deprecated Should not directly called via this interface. There is be a special method which might be better.
    */
   @Deprecated
-  void writeAttribute(String name, Object value, final String property) throws IOException;
+  public abstract void writeAttribute(String name, Object value, final String property) throws IOException;
 
   /**
    * @deprecated Should not directly called via this interface. There is be a special method which might be better.
    */
   @Deprecated
-  void writeText(Object text, String property) throws IOException;
+  public abstract void writeText(Object text, String property) throws IOException;
 
-  void flush() throws IOException;
+  public abstract void flush() throws IOException;
 
   // others (not from ResponseWriter)
 
@@ -65,73 +67,106 @@
    * Writes a string attribute. The renderer may set escape=false to switch of escaping of the string,
    * if it is not necessary.
    */
-  void writeAttribute(String name, String string, boolean escape) throws IOException;
+  public abstract void writeAttribute(String name, String string, boolean escape) throws IOException;
 
   /**
    * Writes a boolean attribute. The value will not escaped.
    */
-  void writeAttribute(String name, boolean on) throws IOException;
+  public void writeAttribute(String name, boolean on) throws IOException {
+    if (on) {
+      writeAttribute(name, name, false);
+    }
+  }
 
   /**
    * Writes a integer attribute. The value will not escaped.
    */
-  void writeAttribute(String name, int number) throws IOException;
+  public void writeAttribute(String name, int number) throws IOException {
+    writeAttribute(name, Integer.toString(number), false);
+  }
 
   /**
    * Writes a propery as attribute. The value will be escaped.
    */
-  void writeAttributeFromComponent(String name, String property) throws IOException;
+  public void writeAttributeFromComponent(String name, String property) throws IOException {
+    writeAttribute(name, null, property);
+  }
 
   /**
    * Write the id attribute. The value will not escaped.
    */
-  void writeIdAttribute(String id) throws IOException;
+  public void writeIdAttribute(String id) throws IOException {
+    writeAttribute(HtmlAttributes.ID, id, false);
+  }
 
   /**
    * Write the name attribute. The value will not escaped.
    */
-  void writeNameAttribute(String name) throws IOException;
+  public void writeNameAttribute(String name) throws IOException {
+    writeAttribute(HtmlAttributes.NAME, name, false);
+  }
 
   /**
    * Write the class attribute. The value will not escaped.
    */
-  void writeClassAttribute(String cssClass) throws IOException;
+  public void writeClassAttribute(String cssClass) throws IOException {
+    writeAttribute(HtmlAttributes.CLASS, cssClass, false);
+  }
 
   /**
    * Write the class attribute. The value will not escaped.
    */
-  void writeClassAttribute(StyleClasses cssClass) throws IOException;
+  public void writeClassAttribute(StyleClasses styleClasses) throws IOException {
+     writeAttribute(HtmlAttributes.CLASS, styleClasses.toString(), false);
+  }
 
   /**
    * Write the class attribute. The value will not escaped.
    */
-  void writeClassAttribute() throws IOException;
+  public abstract void writeClassAttribute() throws IOException;
 
   /**
    * Write the style attribute. The value will not escaped.
    */
-  void writeStyleAttribute(HtmlStyleMap style) throws IOException;
+  public void writeStyleAttribute(HtmlStyleMap style) throws IOException {
+    if (style != null) {
+      writeAttribute(HtmlAttributes.STYLE, style.toString(), false);
+    }
+  }
 
   /**
    * Write the style attribute. The value will not escaped.
    */
-  void writeStyleAttribute(String style) throws IOException;
+  public void writeStyleAttribute(String style) throws IOException {
+    writeAttribute(HtmlAttributes.STYLE, style, false);
+  }
 
   /**
    * Write the style attribute. The value will not escaped.
    */
-  void writeStyleAttribute() throws IOException;
+  public abstract void writeStyleAttribute() throws IOException;
 
-  void writeJavascript(String script) throws IOException;
+  public void writeJavascript(String script) throws IOException {
+    startElement(HtmlConstants.SCRIPT, null);
+    writeAttribute(HtmlAttributes.TYPE, "text/javascript", false);
+    write("\n<!--\n");
+    write(script);
+    write("\n// -->\n");
+    endElement(HtmlConstants.SCRIPT);
+  }
 
   /**
    * Write text content. The text will be escaped.
    */
-  void writeText(String text) throws IOException;
+  public void writeText(String text) throws IOException {
+    writeText(text, null);
+  }
 
   /**
    * Writes a propery as text. The text will be escaped.
    */
-  void writeTextFromComponent(String property) throws IOException;
+  public void writeTextFromComponent(String property) throws IOException {
+    writeText(null, property);
+  }
 
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java?view=diff&rev=537509&r1=537508&r2=537509
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java Sat May 12 13:32:03 2007
@@ -24,8 +24,6 @@
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_CLASS;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
-import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
-import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
 import org.apache.myfaces.tobago.util.HtmlWriterUtil;
 import org.apache.myfaces.tobago.util.XmlUtils;
 
@@ -38,7 +36,7 @@
 import java.util.Set;
 import java.util.Stack;
 
-public class TobagoResponseWriterImpl extends ResponseWriter implements TobagoResponseWriter {
+public class TobagoResponseWriterImpl extends TobagoResponseWriter {
 
   private static final Log LOG = LogFactory.getLog(TobagoResponseWriterImpl.class);
 
@@ -330,37 +328,6 @@
     }
   }
 
-  public void writeAttribute(final String name, final boolean on) throws IOException {
-    if (on) {
-      writeAttribute(name, name, false);
-    }
-  }
-
-  public void writeAttribute(final String name, final int number) throws IOException {
-      writeAttribute(name, Integer.toString(number), false);
-  }
-
-
-  public void writeAttributeFromComponent(String name, String property) throws IOException {
-    writeAttribute(name, null, property);
-  }
-
-  public void writeIdAttribute(final String id) throws IOException {
-    writeAttribute(HtmlAttributes.ID, id, false);
-  }
-
-  public void writeNameAttribute(final String name) throws IOException {
-    writeAttribute(HtmlAttributes.NAME, name, false);
-  }
-
-  public void writeClassAttribute(final String cssClass) throws IOException {
-    writeAttribute(HtmlAttributes.CLASS, cssClass, false);
-  }
-
-  public void writeClassAttribute(StyleClasses styleClasses) throws IOException {
-    writeAttribute(HtmlAttributes.CLASS, styleClasses.toString(), false);
-  }
-
   public void writeClassAttribute() throws IOException {
     Object clazz = component.getAttributes().get(ATTR_STYLE_CLASS);
     if (clazz != null) {
@@ -368,39 +335,10 @@
     }
   }
 
-  public void writeStyleAttribute(HtmlStyleMap style) throws IOException {
-    if (style != null) {
-      writeAttribute(HtmlAttributes.STYLE, style.toString(), false);
-    }
-  }
-
-  public void writeStyleAttribute(String style) throws IOException {
-    writeAttribute(HtmlAttributes.STYLE, style, false);
-  }
-
   public void writeStyleAttribute() throws IOException {
     Object style = component.getAttributes().get(ATTR_STYLE);
     if (style != null) {
       writeAttribute(HtmlAttributes.STYLE, style.toString(), false);
     }
-  }
-
-  public void writeText(String text) throws IOException {
-    // xxx optimize
-    writeText(text, null);
-  }
-
-   public void writeTextFromComponent(String property) throws IOException {
-    // xxx optimize
-    writeText(null, property);
-  }
-
-  public void writeJavascript(String script) throws IOException {
-    startElement(HtmlConstants.SCRIPT, null);
-    writeAttribute(HtmlAttributes.TYPE, "text/javascript", false);
-    write("\n<!--\n");
-    write(script);
-    write("\n// -->\n");
-    endElement(HtmlConstants.SCRIPT);
   }
 }

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterWrapper.java?view=auto&rev=537509
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterWrapper.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterWrapper.java Sat May 12 13:32:03 2007
@@ -0,0 +1,117 @@
+package org.apache.myfaces.tobago.webapp;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_CLASS;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+/*
+ * Date: May 12, 2007
+ * Time: 8:20:51 PM
+ */
+public class TobagoResponseWriterWrapper extends TobagoResponseWriter {
+  private ResponseWriter responseWriter;
+
+  public TobagoResponseWriterWrapper(ResponseWriter responseWriter) {
+    this.responseWriter = responseWriter;
+  }
+
+  public void startElement(String name, UIComponent component) throws IOException {
+    responseWriter.startElement(name, component);
+  }
+
+  public void endElement(String name) throws IOException {
+    responseWriter.endElement(name);
+  }
+
+  public void write(String string) throws IOException {
+    responseWriter.write(string);
+  }
+
+  public void writeComment(Object comment) throws IOException {
+    responseWriter.writeComment(comment);
+  }
+
+  public ResponseWriter cloneWithWriter(Writer writer) {
+    return responseWriter.cloneWithWriter(writer);
+  }
+
+  @Deprecated
+  public void writeAttribute(String name, Object value, String property) throws IOException {
+    responseWriter.writeAttribute(name, value,property);
+  }
+
+  @Deprecated
+  public void writeText(Object text, String property) throws IOException {
+    responseWriter.writeText(text, property);
+  }
+
+  public void flush() throws IOException {
+    responseWriter.flush();
+  }
+
+  public void writeAttribute(String name, String value, boolean escape) throws IOException {
+    responseWriter.writeAttribute(name, value, null);
+  }
+
+  public void writeClassAttribute() throws IOException {
+    responseWriter.writeAttribute(HtmlAttributes.CLASS, null,ATTR_STYLE_CLASS);
+  }
+
+  public void writeStyleAttribute() throws IOException {
+    responseWriter.writeAttribute(HtmlAttributes.STYLE, null, ATTR_STYLE);
+  }
+
+  public String getContentType() {
+    return responseWriter.getContentType();
+  }
+
+  public String getCharacterEncoding() {
+    return responseWriter.getCharacterEncoding();
+  }
+
+  public void startDocument() throws IOException {
+    responseWriter.startDocument();
+  }
+
+  public void endDocument() throws IOException {
+    responseWriter.endDocument();
+  }
+
+  public void writeURIAttribute(String name, Object value, String property) throws IOException {
+    responseWriter.writeURIAttribute(name, value, property);
+  }
+
+  public void writeText(char[] text, int off, int len) throws IOException {
+    responseWriter.writeText(text, off, len);
+  }
+
+  public void write(char[] chars, int i, int i1) throws IOException {
+    responseWriter.write(chars, i, i1);
+  }
+
+  public void close() throws IOException {
+    responseWriter.close();
+  }
+}

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/wml/standard/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/wml/standard/standard/tag/PageRenderer.java?view=diff&rev=537509&r1=537508&r2=537509
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/wml/standard/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/wml/standard/standard/tag/PageRenderer.java Sat May 12 13:32:03 2007
@@ -25,7 +25,6 @@
 import org.apache.myfaces.tobago.component.UIPage;
 import org.apache.myfaces.tobago.renderkit.PageRendererBase;
 import org.apache.myfaces.tobago.renderkit.RenderUtil;
-import org.apache.myfaces.tobago.webapp.TobagoResponseWriterImpl;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -49,8 +48,7 @@
 
     // replace responseWriter and render page content
     StringWriter content = new StringWriter();
-    ResponseWriter contentWriter = new TobagoResponseWriterImpl(
-        content, writer.getContentType(), writer.getCharacterEncoding());
+    ResponseWriter contentWriter = writer.cloneWithWriter(writer);
     facesContext.setResponseWriter(contentWriter);
 
     RenderUtil.encodeChildren(facesContext, page);

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java?view=diff&rev=537509&r1=537508&r2=537509
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java Sat May 12 13:32:03 2007
@@ -51,7 +51,6 @@
 import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
 import org.apache.myfaces.tobago.util.AccessKeyMap;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-import org.apache.myfaces.tobago.webapp.TobagoResponseWriterImpl;
 
 import javax.faces.component.UICommand;
 import javax.faces.component.UIComponent;
@@ -229,9 +228,9 @@
       throws IOException {
     ResponseWriter savedWriter = facesContext.getResponseWriter();
     StringWriter stringWriter = new StringWriter();
-    TobagoResponseWriterImpl writer
-        = (TobagoResponseWriterImpl) savedWriter.cloneWithWriter(stringWriter);
-    facesContext.setResponseWriter(writer);
+    ResponseWriter newWriter = savedWriter.cloneWithWriter(stringWriter);
+    facesContext.setResponseWriter(newWriter);
+    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
 
     writeMenuEntry(facesContext, writer, uiPanel);
 
@@ -468,9 +467,9 @@
 
     ResponseWriter savedWriter = facesContext.getResponseWriter();
     StringWriter stringWriter = new StringWriter();
-    TobagoResponseWriterImpl writer = (TobagoResponseWriterImpl) savedWriter.cloneWithWriter(stringWriter);
-    facesContext.setResponseWriter(writer);
-
+    ResponseWriter newWriter = savedWriter.cloneWithWriter(stringWriter);
+    facesContext.setResponseWriter(newWriter);
+    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
     addImage(writer, facesContext, image, disabled);
 
     writer.startElement(HtmlConstants.A, null);