You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/10/30 17:26:14 UTC
svn commit: r831375 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/renderkit/
core/src/main/java/org/apache/myfaces/tobago/webapp/
core/src/test/java/org/apache/myfaces/tobago/webapp/
theme/scarborough/src/main/java/org/apache...
Author: lofwyr
Date: Fri Oct 30 16:26:13 2009
New Revision: 831375
URL: http://svn.apache.org/viewvc?rev=831375&view=rev
Log:
TOBAGO-813: Possibility to render the output as XHTML
(is switched off in the moment, cat be activated in TobagoRendererKit)
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.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/core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java?rev=831375&r1=831374&r2=831375&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java Fri Oct 30 16:26:13 2009
@@ -19,8 +19,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.tobago.webapp.TobagoResponseWriterImpl;
import org.apache.myfaces.tobago.webapp.TobagoResponseJsonWriterImpl;
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriterImpl;
import javax.faces.FactoryFinder;
import javax.faces.context.FacesContext;
@@ -32,8 +32,8 @@
import javax.faces.render.ResponseStateManager;
import java.io.OutputStream;
import java.io.Writer;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
public class TobagoRenderKit extends RenderKit {
@@ -91,12 +91,23 @@
contentType = "text/fo";
LOG.warn("patching content type from " + contentTypeList + " to " + contentType + "'");
} else if (contentTypeList.indexOf("application/json") > -1) {
- return new TobagoResponseJsonWriterImpl(writer, "application/json", characterEncoding);
+ return new TobagoResponseJsonWriterImpl(writer, "application/json", characterEncoding, false);
} else {
contentType = "text/html";
LOG.warn("Content-Type '" + contentTypeList + "' not supported! Using text/html");
}
- return new TobagoResponseWriterImpl(writer, contentType, characterEncoding);
+
+ boolean xml = false;
+ if ("application/xhtml".equals(contentType)
+ || "application/xml".equals(contentType)
+ || "text/xml".equals(contentType)) {
+ xml = true;
+ }
+ // XXX for XHTML 1.0 the content type must be set to "text/html" for IE6
+ // XXX so at this time we can't differ ...
+// xml = true;
+
+ return new TobagoResponseWriterImpl(writer, contentType, characterEncoding, xml);
}
@Override
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java?rev=831375&r1=831374&r2=831375&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java Fri Oct 30 16:26:13 2009
@@ -17,25 +17,26 @@
* limitations under the License.
*/
-import org.apache.myfaces.tobago.util.FastStringWriter;
-import org.apache.myfaces.tobago.util.XmlUtils;
-import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
+import org.apache.myfaces.tobago.util.FastStringWriter;
+import org.apache.myfaces.tobago.util.XmlUtils;
import javax.faces.component.UIComponent;
-import java.io.Writer;
import java.io.IOException;
+import java.io.Writer;
import java.util.EmptyStackException;
public class TobagoResponseJsonWriterImpl extends TobagoResponseWriterImpl {
+
private static final Log LOG = LogFactory.getLog(TobagoResponseWriterImpl.class);
private Writer javascriptWriter;
private boolean javascriptMode;
- public TobagoResponseJsonWriterImpl(Writer writer, String contentType, String characterEncoding) {
- super(writer, contentType, characterEncoding);
+ public TobagoResponseJsonWriterImpl(Writer writer, String contentType, String characterEncoding, boolean xml) {
+ super(writer, contentType, characterEncoding, xml);
this.javascriptWriter = new FastStringWriter();
}
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?rev=831375&r1=831374&r2=831375&view=diff
==============================================================================
--- 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 Fri Oct 30 16:26:13 2009
@@ -49,6 +49,8 @@
public abstract void endElement(String name) throws IOException;
+ public abstract boolean isXml();
+
public abstract void write(String string) throws IOException;
public abstract void writeComment(Object comment) throws IOException;
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?rev=831375&r1=831374&r2=831375&view=diff
==============================================================================
--- 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 Fri Oct 30 16:26:13 2009
@@ -79,8 +79,8 @@
private HtmlWriterUtil helper;
- public TobagoResponseWriterImpl(final Writer writer, final String contentType,
- final String characterEncoding) {
+ public TobagoResponseWriterImpl(
+ Writer writer, String contentType, String characterEncoding, boolean xml) {
// LOG.info("new TobagoResponseWriterImpl!");
// final StackTraceElement[] stackTrace = new Exception().getStackTrace();
// for (int i = 1; i < stackTrace.length && i < 5; i++) {
@@ -90,14 +90,9 @@
this.component = null;
this.stack = new Stack<String>();
this.contentType = contentType;
- this.characterEncoding
- = characterEncoding != null ? characterEncoding : "UTF-8";
- if ("application/xhtml".equals(contentType)
- || "application/xml".equals(contentType)
- || "text/xml".equals(contentType)) {
- xml = true;
- }
- helper = new HtmlWriterUtil(writer, characterEncoding);
+ this.characterEncoding = characterEncoding != null ? characterEncoding : "UTF-8";
+ this.xml = xml;
+ this.helper = new HtmlWriterUtil(writer, characterEncoding);
}
protected final UIComponent getComponent() {
@@ -337,7 +332,7 @@
public ResponseWriter cloneWithWriter(final Writer originalWriter) {
return new TobagoResponseWriterImpl(
- originalWriter, getContentType(), getCharacterEncoding());
+ originalWriter, getContentType(), getCharacterEncoding(), isXml());
}
public void writeAttribute(final String name, final Object value, final String property)
Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java?rev=831375&r1=831374&r2=831375&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java (original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java Fri Oct 30 16:26:13 2009
@@ -30,7 +30,7 @@
protected void setUp() throws Exception {
super.setUp();
stringWriter = new StringWriter();
- writer = new TobagoResponseWriterImpl(stringWriter, "", "UTF-8"/*, false*/);
+ writer = new TobagoResponseWriterImpl(stringWriter, "", "UTF-8", false);
}
public void testDocument() throws IOException {
@@ -96,7 +96,7 @@
}
public void testNonUtf8() throws IOException {
- TobagoResponseWriterImpl writer1 = new TobagoResponseWriterImpl(stringWriter, "", "ISO-8859-1"/*, false*/);
+ TobagoResponseWriterImpl writer1 = new TobagoResponseWriterImpl(stringWriter, "", "ISO-8859-1", false);
writer1.startElement("input", null);
writer1.writeAttribute("value", "Gutschein über 100 â¬.", null);
writer1.writeAttribute("readonly", true);
@@ -106,7 +106,7 @@
}
public void testCharArray() throws IOException {
- TobagoResponseWriterImpl writer = new TobagoResponseWriterImpl(stringWriter, "text/xml", "ISO-8859-1"/*, true*/);
+ TobagoResponseWriterImpl writer = new TobagoResponseWriterImpl(stringWriter, "text/xml", "ISO-8859-1", true);
writer.writeText("123".toCharArray(), 0, 3);
assertEquals("123", stringWriter.toString());
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?rev=831375&r1=831374&r2=831375&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Fri Oct 30 16:26:13 2009
@@ -50,6 +50,8 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -62,12 +64,14 @@
private static final Log LOG = LogFactory.getLog(PageRenderer.class);
- private static final String DOCTYPE_STRICT =
+ private static final String XHTML_DOCTYPE =
+ "<!DOCTYPE html "
+ + " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
+ + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
+
+ private static final String HTML_DOCTYPE =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
+ " \"http://www.w3.org/TR/html4/strict.dtd\">";
-// "<!DOCTYPE html "
-// + " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
-// + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
private static final String CLIENT_DEBUG_SEVERITY = "clientDebugSeverity";
private static final String LAST_FOCUS_ID = "lastFocusId";
@@ -105,12 +109,12 @@
// LAYOUT Begin
-// try {
- LayoutContext2 layoutContext = new LayoutContext2(page);
- layoutContext.layout();
-// } catch (Throwable e) {
-// LOG.info("testing... ", e);
-// }
+ long begin = System.nanoTime();
+ LayoutContext2 layoutContext = new LayoutContext2(page);
+ layoutContext.layout();
+ long end = System.nanoTime();
+ NumberFormat format = new DecimalFormat("#,##0");
+ LOG.info("layouting takes: " + format.format(end-begin) + " ns");
// LAYOUT End
@@ -141,11 +145,17 @@
String title = (String) page.getAttributes().get(Attributes.LABEL);
- writer.write(DOCTYPE_STRICT);
+ if (writer.isXml()) {
+ writer.write(XHTML_DOCTYPE);
+ } else {
+ writer.write(HTML_DOCTYPE);
+ }
writer.write('\n');
writer.startElement(HtmlConstants.HTML, null);
-// writer.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml", false);
+ if (writer.isXml()) {
+ writer.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml", false);
+ }
writer.startElement(HtmlConstants.HEAD, null);
final boolean debugMode = ClientProperties.getInstance(facesContext.getViewRoot()).isDebugMode();