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/06/29 17:09:37 UTC

svn commit: r1800304 - in /myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago: component/ internal/component/ internal/renderkit/renderer/ internal/taglib/component/ renderkit/html/

Author: lofwyr
Date: Thu Jun 29 17:09:37 2017
New Revision: 1800304

URL: http://svn.apache.org/viewvc?rev=1800304&view=rev
Log:
TOBAGO-1751: Add META-tags to <head>-tag

Added:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/MetaRenderer.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/MetaTagDeclaration.java
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java?rev=1800304&r1=1800303&r2=1800304&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java Thu Jun 29 17:09:37 2017
@@ -67,6 +67,7 @@ public enum Attributes {
   columns,
   compact,
   confirmation,
+  content,
   converter,
   customClass,
   createSpan,
@@ -99,6 +100,7 @@ public enum Attributes {
   height,
   hidden,
   hover,
+  httpEquiv,
   i18n,
   iconSize,
   id,
@@ -118,6 +120,7 @@ public enum Attributes {
   large,
   layoutOrder,
   left,
+  lang,
   link,
   /** @deprecated since Tobago 2.0.0 */
   @Deprecated

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java?rev=1800304&r1=1800303&r2=1800304&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java Thu Jun 29 17:09:37 2017
@@ -54,6 +54,7 @@ public enum RendererTypes {
   LinksInsideBar,
   Label,
   Messages,
+  Meta,
   Object,
   Operation,
   Out,
@@ -132,6 +133,7 @@ public enum RendererTypes {
   public static final String LINKS_INSIDE_BAR = "LinksInsideBar";
   public static final String LABEL = "Label";
   public static final String MESSAGES = "Messages";
+  public static final String META = "Meta";
   public static final String OBJECT = "Object";
   public static final String OPERATION = "Operation";
   public static final String OUT = "Out";

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java?rev=1800304&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java Thu Jun 29 17:09:37 2017
@@ -0,0 +1,48 @@
+/*
+ * 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.component;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ListenerFor;
+import javax.faces.event.PostAddToViewEvent;
+
+@ListenerFor(systemEventClass = PostAddToViewEvent.class)
+public abstract class AbstractUIMeta extends UIComponentBase {
+
+  @Override
+  public void processEvent(final ComponentSystemEvent event) {
+    final FacesContext facesContext = getFacesContext();
+    final UIViewRoot root = facesContext.getViewRoot();
+    root.addComponentResource(facesContext, this);
+  }
+
+  public abstract String getCharset();
+
+  public abstract String getHttpEquiv();
+
+  public abstract String getName();
+
+  public abstract String getLang();
+
+  public abstract String getContent();
+}

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/MetaRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/MetaRenderer.java?rev=1800304&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/MetaRenderer.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/MetaRenderer.java Thu Jun 29 17:09:37 2017
@@ -0,0 +1,48 @@
+/*
+ * 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.renderkit.renderer;
+
+import org.apache.myfaces.tobago.internal.component.AbstractUIMeta;
+import org.apache.myfaces.tobago.renderkit.RendererBase;
+import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+
+public class MetaRenderer extends RendererBase {
+
+  @Override
+  public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
+
+    final AbstractUIMeta meta = (AbstractUIMeta) component;
+    final TobagoResponseWriter writer = getResponseWriter(facesContext);
+
+    writer.startElement(HtmlElements.META);
+    writer.writeAttribute(HtmlAttributes.NAME, meta.getName(), true);
+    writer.writeAttribute(HtmlAttributes.LANG, meta.getLang(), true);
+    writer.writeAttribute(HtmlAttributes.CHARSET, meta.getCharset(), true);
+    writer.writeAttribute(HtmlAttributes.HTTP_EQUIV, meta.getHttpEquiv(), true);
+    writer.writeAttribute(HtmlAttributes.CONTENT, meta.getContent(), true);
+    writer.endElement(HtmlElements.META);
+  }
+}

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java?rev=1800304&r1=1800303&r2=1800304&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java Thu Jun 29 17:09:37 2017
@@ -20,12 +20,15 @@
 package org.apache.myfaces.tobago.internal.renderkit.renderer;
 
 import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.component.UIMeta;
 import org.apache.myfaces.tobago.component.UIPage;
 import org.apache.myfaces.tobago.config.TobagoConfig;
 import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.context.Theme;
 import org.apache.myfaces.tobago.context.TobagoContext;
 import org.apache.myfaces.tobago.context.TobagoResourceBundle;
+import org.apache.myfaces.tobago.internal.component.AbstractUIMeta;
 import org.apache.myfaces.tobago.internal.component.AbstractUIPage;
 import org.apache.myfaces.tobago.internal.util.AccessKeyLogger;
 import org.apache.myfaces.tobago.internal.util.CookieUtils;
@@ -174,17 +177,26 @@ public class PageRenderer extends Render
       writer.startElement(HtmlElements.HEAD);
 
       // meta tags
+      final List<UIComponent> headComponents = viewRoot.getComponentResources(facesContext, "head");
 
-      // this is needed, because websphere 6.0? ignores the setting of the content type on the response
-      writer.startElement(HtmlElements.META);
-      writer.writeAttribute(HtmlAttributes.HTTP_EQUIV, "Content-Type", false);
-      writer.writeAttribute(HtmlAttributes.CONTENT, contentType, false);
-      writer.endElement(HtmlElements.META);
-
-      writer.startElement(HtmlElements.META);
-      writer.writeAttribute(HtmlAttributes.NAME, "viewport", false);
-      writer.writeAttribute(HtmlAttributes.CONTENT, page.getViewport(), true);
-      writer.endElement(HtmlElements.META);
+      if (!containsCharset(headComponents)) {
+        final UIMeta charset = (UIMeta) facesContext.getApplication()
+            .createComponent(facesContext, UIMeta.COMPONENT_TYPE, RendererTypes.Meta.name());
+        charset.setCharset(writer.getCharacterEncoding());
+        charset.encodeAll(facesContext);
+      }
+
+      if (!containsNameViewport(headComponents)) {
+        final UIMeta viewport = (UIMeta) facesContext.getApplication()
+            .createComponent(facesContext, UIMeta.COMPONENT_TYPE, RendererTypes.Meta.name());
+        viewport.setName("viewport");
+        viewport.setContent(page.getViewport());
+        viewport.encodeAll(facesContext);
+      }
+
+      for (UIComponent headResource : headComponents) {
+        headResource.encodeAll(facesContext);
+      }
 
       // title
       writer.startElement(HtmlElements.TITLE);
@@ -334,6 +346,26 @@ public class PageRenderer extends Render
 */
   }
 
+  private boolean containsCharset(final List<UIComponent> headComponents) {
+    for (UIComponent headComponent : headComponents) {
+      if (headComponent instanceof AbstractUIMeta
+          && ((AbstractUIMeta) headComponent).getCharset() != null) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private boolean containsNameViewport(final List<UIComponent> headComponents) {
+    for (UIComponent headComponent : headComponents) {
+      if (headComponent instanceof AbstractUIMeta
+          && "viewport".equals(((AbstractUIMeta) headComponent).getName())) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   private void checkDuplicates(final String[] resources, final Collection<String> files) {
     for (final String resource : resources) {
       if (files.contains(resource)) {

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/MetaTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/MetaTagDeclaration.java?rev=1800304&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/MetaTagDeclaration.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/MetaTagDeclaration.java Thu Jun 29 17:09:37 2017
@@ -0,0 +1,70 @@
+/*
+ * 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.taglib.component;
+
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
+
+import javax.faces.component.UIOutput;
+
+/**
+ * This tag a meta tag in the header of the HTML output.
+ * It's not possible to add more than one tag with the same
+ * <ul>
+ * <li>name + lang combination</li>
+ * <li>httpEquiv</li>
+ * <li>charset</li>
+ * </ul>
+ * The last inserted wins.
+ * So, you may override the default Tobago meta tag in this way.
+ */
+@Tag(name = "meta")
+@UIComponentTag(
+    uiComponent = "org.apache.myfaces.tobago.component.UIMeta",
+    uiComponentBaseClass = "org.apache.myfaces.tobago.internal.component.AbstractUIMeta",
+    componentFamily = UIOutput.COMPONENT_FAMILY,
+    rendererType = RendererTypes.META,
+    allowedChildComponenents = "NONE")
+public interface MetaTagDeclaration extends HasIdBindingAndRendered {
+
+  @TagAttribute
+  @UIComponentTagAttribute
+  void setName(String name);
+
+  @TagAttribute
+  @UIComponentTagAttribute
+  void setLang(String lang);
+
+  @TagAttribute
+  @UIComponentTagAttribute
+  void setCharset(String charset);
+
+  @TagAttribute
+  @UIComponentTagAttribute
+  void setHttpEquiv(String httpEquiv);
+
+  @TagAttribute
+  @UIComponentTagAttribute
+  void setContent(String content);
+}

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java?rev=1800304&r1=1800303&r2=1800304&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java Thu Jun 29 17:09:37 2017
@@ -30,6 +30,7 @@ public enum HtmlAttributes implements Ma
   AUTOCOMPLETE("autocomplete"),
   AUTOFOCUS("autofocus"),
   BORDER("border"),
+  CHARSET("charset"),
   CELLPADDING("cellpadding"),
   CELLSPACING("cellspacing"),
   CHECKED("checked"),