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 2016/07/07 07:29:35 UTC
svn commit: r1751752 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/
tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/
tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/css/
tobago-th...
Author: lofwyr
Date: Thu Jul 7 07:29:35 2016
New Revision: 1751752
URL: http://svn.apache.org/viewvc?rev=1751752&view=rev
Log:
TOBAGO-1491: Clean up CSS class management
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Classes.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClass.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/css/ClassesUnitTest.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Classes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Classes.java?rev=1751752&r1=1751751&r2=1751752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Classes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Classes.java Thu Jul 7 07:29:35 2016
@@ -55,8 +55,11 @@ import javax.faces.context.FacesContext;
* markup</li> </ul> If the markup contains more than one name, there will be generated more than one output string.
* E.g.: UIIn with Markup [readonly, error] will get the class "tobago-in tobago-in-markup-readonly
* tobago-in-markup-error".
+ *
+ * @deprecated since Tobago 3.0.0
*/
-public final class Classes {
+@Deprecated
+public final class Classes implements CssItem {
private static final Logger LOG = LoggerFactory.getLogger(Classes.class);
@@ -146,7 +149,7 @@ public final class Classes {
this.stringValue = builder.toString();
}
- public String getStringValue() {
+ public String getName() {
return stringValue;
}
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClass.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClass.java?rev=1751752&r1=1751751&r2=1751752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClass.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClass.java Thu Jul 7 07:29:35 2016
@@ -29,7 +29,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * XXX preliminary
+ * Since Tobago 3.0.0
*/
public class CustomClass implements CssItem {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java?rev=1751752&r1=1751751&r2=1751752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java Thu Jul 7 07:29:35 2016
@@ -19,8 +19,6 @@
package org.apache.myfaces.tobago.webapp;
-import org.apache.myfaces.tobago.internal.util.StringUtils;
-import org.apache.myfaces.tobago.renderkit.css.Classes;
import org.apache.myfaces.tobago.renderkit.css.CssItem;
import org.apache.myfaces.tobago.renderkit.css.FontAwesomeIconEncoder;
import org.apache.myfaces.tobago.renderkit.css.IconEncoder;
@@ -151,56 +149,66 @@ public abstract class TobagoResponseWrit
/**
* Write the class attribute. The value will not escaped.
- * @param classes The abstract representation of the css class string, normally created by the renderer.
*/
- public void writeClassAttribute(final Classes classes) throws IOException {
- final String stringValue = classes.getStringValue();
- if (StringUtils.isNotBlank(stringValue)) {
- writeAttribute(HtmlAttributes.CLASS, stringValue, false);
- }
- }
-
public void writeClassAttribute(final CssItem first) throws IOException {
- writeClassAttribute(first, null, NO_CSS_ITEMS);
+ if (first != null) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(first.getName());
+ builder.append(' ');
+ writeAttribute(HtmlAttributes.CLASS, builder.deleteCharAt(builder.length() - 1).toString(), false);
+ }
}
+ /**
+ * Write the class attribute. The value will not escaped.
+ */
public void writeClassAttribute(final CssItem first, final CssItem second) throws IOException {
- writeClassAttribute(first, second, NO_CSS_ITEMS);
+ final StringBuilder builder = new StringBuilder();
+ boolean render = false;
+ if (first != null) {
+ builder.append(first.getName());
+ builder.append(' ');
+ render = true;
+ }
+ if (second != null) {
+ builder.append(second.getName());
+ builder.append(' ');
+ render = true;
+ }
+ if (render) {
+ writeAttribute(HtmlAttributes.CLASS, builder.deleteCharAt(builder.length() - 1).toString(), false);
+ }
}
+ /**
+ * Write the class attribute. The value will not escaped.
+ */
public void writeClassAttribute(final CssItem first, final CssItem second, final CssItem... others)
throws IOException {
- StringBuilder builder = new StringBuilder();
+ final StringBuilder builder = new StringBuilder();
+ boolean render = false;
if (first != null) {
builder.append(first.getName());
builder.append(' ');
+ render = true;
}
if (second != null) {
builder.append(second.getName());
builder.append(' ');
+ render = true;
}
for (CssItem other : others) {
if (other != null) {
builder.append(other.getName());
builder.append(' ');
+ render = true;
}
}
- if (builder.length() > 0) {
+ if (render) {
writeAttribute(HtmlAttributes.CLASS, builder.deleteCharAt(builder.length() - 1).toString(), false);
}
}
- public void writeClassAttribute(final Classes classes, final CssItem... others) throws IOException {
- StringBuilder builder = new StringBuilder(classes.getStringValue());
- for (CssItem other : others) {
- if (other != null) {
- builder.append(' ');
- builder.append(other.getName());
- }
- }
- writeAttribute(HtmlAttributes.CLASS, builder.toString(), false);
- }
-
/**
* Write the style attribute. The value may be escaped (depending of the content).
*/
Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/css/ClassesUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/css/ClassesUnitTest.java?rev=1751752&r1=1751751&r2=1751752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/css/ClassesUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/css/ClassesUnitTest.java Thu Jul 7 07:29:35 2016
@@ -37,14 +37,14 @@ public class ClassesUnitTest extends Abs
public void testSimple() {
final UIIn in = (UIIn) CreateComponentUtils.createComponent(
getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
- Assert.assertEquals("tobago-in-simple", Classes.create(in, "simple").getStringValue());
+ Assert.assertEquals("tobago-in-simple", Classes.create(in, "simple").getName());
}
@Test
public void testFull() {
final UIIn in = (UIIn) CreateComponentUtils.createComponent(
getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
- Assert.assertEquals("tobago-in", Classes.create(in).getStringValue());
+ Assert.assertEquals("tobago-in", Classes.create(in).getName());
}
@Test
@@ -53,7 +53,7 @@ public class ClassesUnitTest extends Abs
getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
in.setDisabled(true);
updateMarkup(in);
- Assert.assertEquals("tobago-in tobago-in-markup-disabled", Classes.create(in).getStringValue());
+ Assert.assertEquals("tobago-in tobago-in-markup-disabled", Classes.create(in).getName());
}
@Test
@@ -62,7 +62,7 @@ public class ClassesUnitTest extends Abs
getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
in.setReadonly(true);
updateMarkup(in);
- Assert.assertEquals("tobago-in tobago-in-markup-readonly", Classes.create(in).getStringValue());
+ Assert.assertEquals("tobago-in tobago-in-markup-readonly", Classes.create(in).getName());
}
@Test
@@ -73,7 +73,7 @@ public class ClassesUnitTest extends Abs
in.setReadonly(true);
updateMarkup(in);
Assert.assertEquals(
- "tobago-in tobago-in-markup-disabled tobago-in-markup-readonly", Classes.create(in).getStringValue());
+ "tobago-in tobago-in-markup-disabled tobago-in-markup-readonly", Classes.create(in).getName());
}
@Test
@@ -82,7 +82,7 @@ public class ClassesUnitTest extends Abs
getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
in.setValid(false);
updateMarkup(in);
- Assert.assertEquals("tobago-in tobago-in-markup-error", Classes.create(in).getStringValue());
+ Assert.assertEquals("tobago-in tobago-in-markup-error", Classes.create(in).getName());
}
@Test
@@ -91,14 +91,14 @@ public class ClassesUnitTest extends Abs
getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
in.setMarkup(Markup.valueOf("important"));
updateMarkup(in);
- Assert.assertEquals("tobago-in tobago-in-markup-important", Classes.create(in).getStringValue());
+ Assert.assertEquals("tobago-in tobago-in-markup-important", Classes.create(in).getName());
}
@Test
public void testSub() {
final UIIn in = (UIIn) CreateComponentUtils.createComponent(
getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
- Assert.assertEquals("tobago-in-sub", Classes.create(in, "sub").getStringValue());
+ Assert.assertEquals("tobago-in-sub", Classes.create(in, "sub").getName());
}
@Test
@@ -112,7 +112,7 @@ public class ClassesUnitTest extends Abs
updateMarkup(in);
Assert.assertEquals("tobago-in-sub tobago-in-sub-markup-important tobago-in-sub-markup-deleted "
+ "tobago-in-sub-markup-disabled tobago-in-sub-markup-readonly tobago-in-sub-markup-error",
- Classes.create(in, "sub").getStringValue());
+ Classes.create(in, "sub").getName());
}
private void updateMarkup(final UIComponent component) {
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java?rev=1751752&r1=1751751&r2=1751752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java Thu Jul 7 07:29:35 2016
@@ -61,6 +61,9 @@ public enum TobagoClass implements CssIt
POPUP("tobago-popup"),
SECTION__HEADER("tobago-section-header"),
SECTION__CONTENT("tobago-section-content"),
+ SHEET__HEADER("tobago-sheet-header"),
+ SHEET__BODY_TABLE("tobago-sheet-bodyTable"),
+ SHEET__HEADER_TABLE("tobago-sheet-headerTable"),
SHEET__PAGING_INPUT("tobago-sheet-pagingInput"),
SHEET__PAGING_OUTPUT("tobago-sheet-pagingOutput"),
SHEET__CELL__MARKUP__RIGHT("tobago-sheet-cell-markup-right"),
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java?rev=1751752&r1=1751751&r2=1751752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/CommandRendererBase.java Thu Jul 7 07:29:35 2016
@@ -135,6 +135,7 @@ public abstract class CommandRendererBas
writer.writeClassAttribute(
Classes.create(command),
+ null,
cssItems.toArray(new CssItem[cssItems.size()]));
final boolean defaultCommand = ComponentUtils.getBooleanAttribute(command, Attributes.defaultCommand);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java?rev=1751752&r1=1751751&r2=1751752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java Thu Jul 7 07:29:35 2016
@@ -283,39 +283,24 @@ public class SheetRenderer extends Rende
expandedValue = new StringBuilder(",");
}
- final List<CssItem> cssItems = new ArrayList<CssItem>();
- cssItems.add(BootstrapClass.TABLE);
- if (sheetMarkup.contains(Markup.INVERSE)) {
- cssItems.add(BootstrapClass.TABLE_INVERSE);
- }
- if (sheetMarkup.contains(Markup.STRIPED)) {
- cssItems.add(BootstrapClass.TABLE_STRIPED);
- }
- if (sheetMarkup.contains(Markup.BORDERED)) {
- cssItems.add(BootstrapClass.TABLE_BORDERED);
- }
- if (sheetMarkup.contains(Markup.HOVER)) {
- cssItems.add(BootstrapClass.TABLE_HOVER);
- }
- if (sheetMarkup.contains(Markup.SMALL)) {
- cssItems.add(BootstrapClass.TABLE_SM);
- }
- if (!autoLayout) {
- cssItems.add(TobagoClass.TABLE_LAYOUT__FIXED);
- }
-
// BEGIN RENDER BODY CONTENT
if (showHeader && !autoLayout) {
// if no autoLayout, we render the header in a separate table.
writer.startElement(HtmlElements.HEADER);
- writer.writeClassAttribute(Classes.create(sheet, "header"));
+ writer.writeClassAttribute(TobagoClass.SHEET__HEADER);
writer.startElement(HtmlElements.TABLE);
writer.writeAttribute(HtmlAttributes.CELLSPACING, "0", false);
writer.writeAttribute(HtmlAttributes.CELLPADDING, "0", false);
writer.writeAttribute(HtmlAttributes.SUMMARY, "", false);
- writer.writeClassAttribute(Classes.create(sheet, "headerTable"), cssItems.toArray(new CssItem[cssItems.size()]));
+ writer.writeClassAttribute(
+ BootstrapClass.TABLE,
+ TobagoClass.SHEET__HEADER_TABLE,
+ sheetMarkup.contains(Markup.INVERSE) ? BootstrapClass.TABLE_INVERSE : null,
+ sheetMarkup.contains(Markup.BORDERED) ? BootstrapClass.TABLE_BORDERED : null,
+ sheetMarkup.contains(Markup.SMALL) ? BootstrapClass.TABLE_SM : null,
+ !autoLayout ? TobagoClass.TABLE_LAYOUT__FIXED : null);
writeColgroup(writer, columnWidths, columns);
@@ -334,7 +319,15 @@ public class SheetRenderer extends Rende
writer.writeAttribute(HtmlAttributes.CELLSPACING, "0", false);
writer.writeAttribute(HtmlAttributes.CELLPADDING, "0", false);
writer.writeAttribute(HtmlAttributes.SUMMARY, "", false);
- writer.writeClassAttribute(Classes.create(sheet, "bodyTable"), cssItems.toArray(new CssItem[cssItems.size()]));
+ writer.writeClassAttribute(
+ BootstrapClass.TABLE,
+ TobagoClass.SHEET__BODY_TABLE,
+ sheetMarkup.contains(Markup.INVERSE) ? BootstrapClass.TABLE_INVERSE : null,
+ sheetMarkup.contains(Markup.STRIPED) ? BootstrapClass.TABLE_STRIPED : null,
+ sheetMarkup.contains(Markup.BORDERED) ? BootstrapClass.TABLE_BORDERED : null,
+ sheetMarkup.contains(Markup.HOVER) ? BootstrapClass.TABLE_HOVER : null,
+ sheetMarkup.contains(Markup.SMALL) ? BootstrapClass.TABLE_SM : null,
+ !autoLayout ? TobagoClass.TABLE_LAYOUT__FIXED : null);
if (autoLayout) {
writer.startElement(HtmlElements.THEAD);