myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject [myfaces-tobago] branch tobago-3.0.x updated: TOBAGO-1903: new attribute keepLineBreaks: tc:out should be usable without rendering a <br> for a \n
Date Wed, 20 Jun 2018 11:30:32 GMT
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch tobago-3.0.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/tobago-3.0.x by this push:
     new b7181d0  TOBAGO-1903: new attribute keepLineBreaks: tc:out should be usable without
rendering a <br> for a \n
b7181d0 is described below

commit b7181d093645cef5b41321bf90154bc66813ef51
Author: Udo Schnurpfeil <lofwyr@apache.org>
AuthorDate: Wed Jun 6 13:33:16 2018 +0200

    TOBAGO-1903: new attribute keepLineBreaks: tc:out should be usable without rendering a
<br> for a \n
    
    (cherry picked from commit 685d1a0)
---
 .../java/org/apache/myfaces/tobago/component/Attributes.java |  1 +
 .../myfaces/tobago/internal/component/AbstractUIOut.java     | 10 ++++++++++
 .../tobago/internal/renderkit/renderer/OutRenderer.java      | 12 +++++++++---
 .../tobago/internal/taglib/component/OutTagDeclaration.java  |  9 +++++++++
 .../tobago-example-demo/src/main/webapp/main.xhtml           |  2 +-
 5 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
index 255c2b3..f0ab5ac 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
@@ -98,6 +98,7 @@ public enum Attributes {
   itemLabel,
   itemImage,
   itemValue,
+  keepLineBreaks,
   label,
   labelLayout,
   labelPosition,
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
index ac0a910..8d24db8 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
@@ -21,8 +21,18 @@ package org.apache.myfaces.tobago.internal.component;
 
 import org.apache.myfaces.tobago.component.SupportsLabelLayout;
 import org.apache.myfaces.tobago.component.Visual;
+import org.apache.myfaces.tobago.sanitizer.SanitizeMode;
 
 import javax.faces.component.UIOutput;
 
 public abstract class AbstractUIOut extends UIOutput implements SupportsLabelLayout, Visual
{
+
+  public abstract boolean isEscape();
+
+  public abstract boolean isKeepLineBreaks();
+
+  public abstract boolean isCreateSpan();
+
+  public abstract SanitizeMode getSanitize();
+
 }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
index 6347bf6..bb2883e 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
@@ -21,12 +21,13 @@ package org.apache.myfaces.tobago.internal.renderkit.renderer;
 
 import org.apache.myfaces.tobago.component.UIOut;
 import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.internal.component.AbstractUIOut;
+import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.internal.util.RenderUtils;
 import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
 import org.apache.myfaces.tobago.renderkit.css.Classes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
-import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.internal.util.RenderUtils;
 import org.apache.myfaces.tobago.sanitizer.SanitizeMode;
 import org.apache.myfaces.tobago.sanitizer.Sanitizer;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -41,7 +42,7 @@ public class OutRenderer extends LabelLayoutRendererBase {
   @Override
   public void encodeBeginField(final FacesContext facesContext, final UIComponent component)
throws IOException {
 
-    final UIOut out = (UIOut) component;
+    final AbstractUIOut out = (AbstractUIOut) component;
 
     String text = RenderUtils.currentValue(out);
     if (text == null) {
@@ -51,6 +52,7 @@ public class OutRenderer extends LabelLayoutRendererBase {
     final TobagoResponseWriter writer = getResponseWriter(facesContext);
 
     final boolean escape = out.isEscape();
+    final boolean keepLineBreaks = out.isKeepLineBreaks();
     final boolean createSpan = out.isCreateSpan();
 
     if (createSpan) {
@@ -64,6 +66,7 @@ public class OutRenderer extends LabelLayoutRendererBase {
       }
     }
     if (escape) {
+      if (keepLineBreaks) {
       final StringTokenizer tokenizer = new StringTokenizer(text, "\r\n");
       while (tokenizer.hasMoreTokens()) {
         final String token = tokenizer.nextToken();
@@ -73,6 +76,9 @@ public class OutRenderer extends LabelLayoutRendererBase {
           writer.endElement(HtmlElements.BR);
         }
       }
+      } else {
+        writer.writeText(text);
+      }
     } else { // escape="false"
       writer.writeText("", null); // to ensure the closing > of the <span> start
tag.
       if (SanitizeMode.auto == out.getSanitize()) {
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
index 90a063e..9fdc562 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
@@ -62,6 +62,15 @@ public interface OutTagDeclaration
   void setEscape(String escape);
 
   /**
+   * Flag indicating that new-line characters will be converted to HTML &lt;br&gt;.
+   * This is useful for pre-formatted plain text.
+   * This has only an effect, with escape="true".
+   */
+  @TagAttribute
+  @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
+  void setKeepLineBreaks(String keepLineBreaks);
+
+  /**
    * Indicates that the renderer should create an element in the output language
    * (e. g. an span or div tag around the output text).
    * Use true, if you enable the possibility to apply styles to the output.
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
index 300414a..a6b2ed6 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
@@ -63,7 +63,7 @@
 
         <tc:panel rendered="#{navigationState.viewSource}">
           <pre><code class="language-markup" id="demo-view-source">
-            <tc:out value="#{navigationTree.source}"/>
+            <tc:out keepLineBreaks="false" value="#{navigationTree.source}"/>
           </code></pre>
         </tc:panel>
 


Mime
View raw message