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 2017/09/07 10:55:26 UTC
svn commit: r1807585 - in
/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal:
renderkit/renderer/ProgressRenderer.java
renderkit/renderer/StyleRenderer.java util/StyleRenderUtils.java
Author: lofwyr
Date: Thu Sep 7 10:55:26 2017
New Revision: 1807585
URL: http://svn.apache.org/viewvc?rev=1807585&view=rev
Log:
TOBAGO-1786: Selector to address UIStyle
Added:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StyleRenderUtils.java
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ProgressRenderer.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/StyleRenderer.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ProgressRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ProgressRenderer.java?rev=1807585&r1=1807584&r2=1807585&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ProgressRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ProgressRenderer.java Thu Sep 7 10:55:26 2017
@@ -25,6 +25,7 @@ import org.apache.myfaces.tobago.interna
import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.internal.util.JsonUtils;
import org.apache.myfaces.tobago.internal.util.RenderUtils;
+import org.apache.myfaces.tobago.internal.util.StyleRenderUtils;
import org.apache.myfaces.tobago.layout.Measure;
import org.apache.myfaces.tobago.renderkit.RendererBase;
import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
@@ -77,7 +78,7 @@ public class ProgressRenderer extends Re
final UIStyle style = (UIStyle) facesContext.getApplication()
.createComponent(facesContext, UIStyle.COMPONENT_TYPE, RendererTypes.Style.name());
style.setTransient(true);
- style.setSelector("#" + clientId.replaceAll(":", "\\\\:") + ">." + BootstrapClass.PROGRESS_BAR.getName());
+ style.setSelector(StyleRenderUtils.encodeSelector("#", clientId, ">.", BootstrapClass.PROGRESS_BAR.getName()));
style.setWidth(new Measure(percent * 100, Measure.Unit.PERCENT));
progress.getChildren().add(style);
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/StyleRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/StyleRenderer.java?rev=1807585&r1=1807584&r2=1807585&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/StyleRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/StyleRenderer.java Thu Sep 7 10:55:26 2017
@@ -22,6 +22,7 @@ package org.apache.myfaces.tobago.intern
import org.apache.myfaces.tobago.internal.component.AbstractUIStyle;
import org.apache.myfaces.tobago.internal.context.Nonce;
import org.apache.myfaces.tobago.internal.util.StringUtils;
+import org.apache.myfaces.tobago.internal.util.StyleRenderUtils;
import org.apache.myfaces.tobago.layout.Display;
import org.apache.myfaces.tobago.layout.Measure;
import org.apache.myfaces.tobago.layout.Overflow;
@@ -119,12 +120,10 @@ public class StyleRenderer extends Rende
writer.writeIdAttribute(style.getClientId(facesContext));
final String selector = style.getSelector();
if (selector != null) {
- // not using writeText, because > must not be encoded!
- writer.write(selector);
+ StyleRenderUtils.writeSelector(writer, selector);
} else {
final String parentId = style.getParent().getClientId(facesContext);
- writer.writeText("#");
- writer.writeText(parentId.replaceAll(":", "\\\\:"));
+ StyleRenderUtils.writeIdSelector(writer, parentId);
}
writer.writeText("{");
if (width != null) {
Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StyleRenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StyleRenderUtils.java?rev=1807585&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StyleRenderUtils.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StyleRenderUtils.java Thu Sep 7 10:55:26 2017
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package org.apache.myfaces.tobago.internal.util;
+
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+
+import java.io.IOException;
+
+/**
+ * PRELIMINARY: MAY BE INTEGRATED IN THE {@link TobagoResponseWriter}
+ * TBD
+ */
+public class StyleRenderUtils {
+
+ private StyleRenderUtils() {
+ // to prevent instantiation
+ }
+
+
+ public static void writeIdSelector(TobagoResponseWriter writer, String id) throws IOException {
+
+ writer.writeText("#");
+
+ final char[] chars = id.toCharArray();
+ int last = 0;
+ for (int i = 0; i < chars.length; i++) {
+ char c = chars[i];
+ if (c == ':') {
+ writer.writeText(chars, last, i);
+ writer.writeText("\\\\:");
+ last = i;
+ }
+ }
+ }
+
+ // not using writeText, because > must not be encoded!
+ public static void writeSelector(TobagoResponseWriter writer, String selector) throws IOException {
+ writer.write(selector);
+ }
+
+ public static String encodeSelector(String... selector) {
+ StringBuilder builder = new StringBuilder();
+ for (String s : selector) {
+ builder.append(s.replaceAll(":", "\\\\:"));
+ }
+ return builder.toString();
+ }
+
+}