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 2006/09/25 00:35:16 UTC

svn commit: r449516 - in /myfaces/tobago/trunk: ./ core/src/main/java/org/apache/myfaces/tobago/component/ core/src/main/java/org/apache/myfaces/tobago/context/ core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ theme/standard/src/main/resour...

Author: bommel
Date: Sun Sep 24 15:35:15 2006
New Revision: 449516

URL: http://svn.apache.org/viewvc?view=rev&rev=449516
Log:
TOBAGO-119 support customizing of markup

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/SupportsMarkup.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfig.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfigImpl.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/RendererMarkup.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIOutput.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/Theme.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
    myfaces/tobago/trunk/pom.xml
    myfaces/tobago/trunk/theme/standard/src/main/resources/META-INF/tobago-theme.xml

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/SupportsMarkup.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/SupportsMarkup.java?view=auto&rev=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/SupportsMarkup.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/SupportsMarkup.java Sun Sep 24 15:35:15 2006
@@ -0,0 +1,29 @@
+package org.apache.myfaces.tobago.component;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Sep 24, 2006
+ * Time: 12:10:58 PM
+ */
+public interface SupportsMarkup {
+
+
+  String getMarkup();
+}

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIOutput.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIOutput.java?view=diff&rev=449516&r1=449515&r2=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIOutput.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIOutput.java Sun Sep 24 15:35:15 2006
@@ -30,7 +30,7 @@
 * Time: 23:53:37
 * To change this template use File | Settings | File Templates.
 */
-public class UIOutput extends javax.faces.component.UIOutput {
+public class UIOutput extends javax.faces.component.UIOutput implements SupportsMarkup {
   public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Output";
   private Boolean escape;
   private String markup;

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfig.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfig.java?view=auto&rev=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfig.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfig.java Sun Sep 24 15:35:15 2006
@@ -0,0 +1,31 @@
+package org.apache.myfaces.tobago.context;
+
+import java.util.Collection;
+
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Sep 24, 2006
+ * Time: 12:32:35 PM
+ */
+public interface MarkupConfig {
+
+  boolean isMarkupSupported(String rendererName, String markup);
+
+}

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfigImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfigImpl.java?view=auto&rev=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfigImpl.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/MarkupConfigImpl.java Sun Sep 24 15:35:15 2006
@@ -0,0 +1,70 @@
+package org.apache.myfaces.tobago.context;
+
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collection;
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Sep 24, 2006
+ * Time: 3:46:11 PM
+ */
+public class MarkupConfigImpl implements MarkupConfig {
+
+  private static final Log LOG = LogFactory.getLog(MarkupConfigImpl.class);
+
+  private Map<String,RendererMarkup> renderer = new HashMap<String,RendererMarkup>();
+
+  Collection<RendererMarkup>  getRendererMarkups() {
+    return renderer.values();
+  }
+
+  public void addRenderer(RendererMarkup rendererMarkup) {
+    if (!renderer.containsKey(rendererMarkup.getName())) {
+      renderer.put(rendererMarkup.getName(), rendererMarkup);
+    }
+  }
+
+  public boolean isMarkupSupported(String rendererName, String markup) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("calling isMarkupSupported" + rendererName + " " +markup);
+    }
+    RendererMarkup rendererMarkup = renderer.get(rendererName);
+    if (rendererMarkup != null) {
+      return rendererMarkup.contains(markup);
+    } else {
+      LOG.error("Calling isMarkupSupported" + rendererName + " " +markup + "but no configuration found.");
+      return false;
+    }
+  }
+
+  void merge(MarkupConfigImpl markupConfig) {
+    Collection<RendererMarkup> markups = markupConfig.getRendererMarkups();
+    for (RendererMarkup markup: markups) {
+      addRenderer(markup);
+    }
+  }
+
+  public String toString() {
+    return renderer.toString();
+  }
+}

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/RendererMarkup.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/RendererMarkup.java?view=auto&rev=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/RendererMarkup.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/RendererMarkup.java Sun Sep 24 15:35:15 2006
@@ -0,0 +1,72 @@
+package org.apache.myfaces.tobago.context;
+
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 java.util.Set;
+import java.util.HashSet;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Sep 24, 2006
+ * Time: 10:09:35 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class RendererMarkup {
+  private String name;
+  private Set<String> markups = new HashSet<String>();
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public boolean contains(String markup) {
+    return markups.contains(markup);
+  }
+
+  public void addMarkup(String markup) {
+    this.markups.add(markup);
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+
+    final RendererMarkup that = (RendererMarkup) o;
+
+    return name.equals(that.name);
+
+  }
+
+  public int hashCode() {
+    return name.hashCode();
+  }
+
+  public String toString() {
+    return "RendererMarkup " + name + " markup " + markups;
+  }
+
+}

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/Theme.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/Theme.java?view=diff&rev=449516&r1=449515&r2=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/Theme.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/Theme.java Sun Sep 24 15:35:15 2006
@@ -30,4 +30,6 @@
   String getDisplayName();
 
   String getResourcePath();
+
+  MarkupConfig getMarkupConfig();
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java?view=diff&rev=449516&r1=449515&r2=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java Sun Sep 24 15:35:15 2006
@@ -49,6 +49,9 @@
     for (ThemeImpl theme : availableThemes) {
       theme.resolveFallbacks();
     }
+    for (ThemeImpl theme : availableThemes) {
+      theme.resolveMarkupConfig();
+    }
     Map<String, Theme> result = new HashMap<String, Theme>();
     for (ThemeImpl theme : availableThemes) {
       result.put(theme.getName(), theme);

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java?view=diff&rev=449516&r1=449515&r2=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java Sun Sep 24 15:35:15 2006
@@ -42,6 +42,8 @@
 
   private List<Theme> fallbackList;
 
+  private MarkupConfigImpl markupConfig;
+
   public String getName() {
     return name;
   }
@@ -105,8 +107,40 @@
     }
   }
 
+  public void resolveMarkupConfig() {
+    if (markupConfig == null) {
+      markupConfig = new MarkupConfigImpl();
+    }
+    ThemeImpl fallback  = this.getFallback();
+    if (fallback != null) {
+      fallback.resolveMarkupConfig();
+      MarkupConfigImpl fallbackMarkupConfig = fallback.getMarkupConfigImpl();
+      if (fallbackMarkupConfig != null) {
+        markupConfig.merge(fallbackMarkupConfig);
+      }
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("merge markupconfig from " + fallback.getName() + " for " + getName());
+      }
+    }
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(getName() + " " +markupConfig);
+    }
+  }
+
   public String toString() {
 //    LOG.warn("Should not be called!", new Exception());
     return name;
+  }
+
+  public void setMarkupConfig(MarkupConfigImpl markupConfig) {
+    this.markupConfig = markupConfig;
+  }
+
+  public MarkupConfig getMarkupConfig() {
+    return markupConfig;
+  }
+
+  MarkupConfigImpl getMarkupConfigImpl() {
+    return markupConfig;
   }
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java?view=diff&rev=449516&r1=449515&r2=449516
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java Sun Sep 24 15:35:15 2006
@@ -53,6 +53,12 @@
     digester.addCallMethod("tobago-theme/deprecated-name", "setDeprecatedName", 0);
     digester.addCallMethod("tobago-theme/resource-path", "setResourcePath", 0);
     digester.addCallMethod("tobago-theme/fallback", "setFallbackName", 0);
+    digester.addObjectCreate("tobago-theme/supported-markup", MarkupConfigImpl.class);
+    digester.addSetNext("tobago-theme/supported-markup", "setMarkupConfig");
+    digester.addObjectCreate("tobago-theme/supported-markup/renderer",  RendererMarkup.class);
+    digester.addSetNext("tobago-theme/supported-markup/renderer", "addRenderer");
+    digester.addCallMethod("tobago-theme/supported-markup/renderer/name", "setName", 0);
+    digester.addCallMethod("tobago-theme/supported-markup/renderer/markup", "addMarkup" , 0);
 
     return digester;
   }

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=449516&r1=449515&r2=449516
==============================================================================
--- 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 Sun Sep 24 15:35:15 2006
@@ -42,7 +42,10 @@
 import static org.apache.myfaces.tobago.TobagoConstants.TOBAGO_CSS_CLASS_SUFFIX_READONLY;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UIPage;
+import org.apache.myfaces.tobago.component.SupportsMarkup;
 import org.apache.myfaces.tobago.context.ResourceManagerUtil;
+import org.apache.myfaces.tobago.context.ClientProperties;
+import org.apache.myfaces.tobago.context.Theme;
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
 import org.apache.myfaces.tobago.util.LayoutUtil;
@@ -427,12 +430,16 @@
     if (ComponentUtil.isError(component)) {
       tobagoClass.append(prefix).append(TOBAGO_CSS_CLASS_SUFFIX_ERROR);
     }
-    String markup = ComponentUtil.getStringAttribute(component, ATTR_MARKUP);
-    if (StringUtils.isNotEmpty(markup)) {
-      if (markup.equals("strong") || markup.equals("deleted")) {
-        tobagoClass.append(prefix).append("-markup-").append(markup).append(" ");
-      } else {
-        LOG.warn("Unknown markup='" + markup + "'");
+
+    if (component instanceof SupportsMarkup) {
+      String markup = ComponentUtil.getStringAttribute(component, ATTR_MARKUP);
+      if (StringUtils.isNotEmpty(markup)) {
+        Theme theme = ClientProperties.getInstance(FacesContext.getCurrentInstance().getViewRoot()).getTheme();
+        if (theme.getMarkupConfig().isMarkupSupported(rendererName, markup)) {
+          tobagoClass.append(prefix).append("-markup-").append(markup).append(" ");
+        } else {
+          LOG.warn("Unknown markup='" + markup + "'");
+        }
       }
     }
 

Modified: myfaces/tobago/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/pom.xml?view=diff&rev=449516&r1=449515&r2=449516
==============================================================================
--- myfaces/tobago/trunk/pom.xml (original)
+++ myfaces/tobago/trunk/pom.xml Sun Sep 24 15:35:15 2006
@@ -323,7 +323,7 @@
       <dependency>
         <groupId>commons-digester</groupId>
         <artifactId>commons-digester</artifactId>
-        <version>1.6</version>
+        <version>1.7</version>
       </dependency>
       <dependency>
         <groupId>commons-fileupload</groupId>

Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/META-INF/tobago-theme.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/META-INF/tobago-theme.xml?view=diff&rev=449516&r1=449515&r2=449516
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/META-INF/tobago-theme.xml (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/META-INF/tobago-theme.xml Sun Sep 24 15:35:15 2006
@@ -24,4 +24,11 @@
   <name>standard</name>
   <deprecated-name>org.apache.myfaces.tobago.context.StandardTheme</deprecated-name>
   <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+  <supported-markup>
+    <renderer>
+      <name>out</name>
+      <markup>strong</markup>
+      <markup>deleted</markup>
+    </renderer>
+  </supported-markup>
 </tobago-theme>