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 2008/04/02 21:53:36 UTC
svn commit: r644025 - in
/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html:
./ HtmlAttributes.java HtmlConstants.java HtmlStyleMap.java StyleClasses.java
Author: bommel
Date: Wed Apr 2 12:53:32 2008
New Revision: 644025
URL: http://svn.apache.org/viewvc?rev=644025&view=rev
Log:
readded files
Added:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java (with props)
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlConstants.java (with props)
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java (with props)
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/StyleClasses.java (with props)
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java?rev=644025&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java Wed Apr 2 12:53:32 2008
@@ -0,0 +1,77 @@
+package org.apache.myfaces.tobago.renderkit.html;
+
+/*
+ * 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.
+ */
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Sep 23, 2006
+ * Time: 10:01:48 AM
+ */
+public final class HtmlAttributes {
+ public static final String STYLE = "style";
+ public static final String TYPE = "type";
+ public static final String NAME = "name";
+ public static final String ID = "id";
+ public static final String VALUE = "value";
+ public static final String FOR = "for";
+ public static final String TITLE = "title";
+ public static final String DISABLED = "disabled";
+ public static final String ONCLICK = "onclick";
+ public static final String SELECTED = "selected";
+ public static final String HREF = "href";
+ public static final String SRC = "src";
+ public static final String ALT = "alt";
+ public static final String WIDTH = "width";
+ public static final String BORDER = "border";
+ public static final String CHECKED = "checked";
+ public static final String SUMMARY = "summary";
+ public static final String HEIGHT = "height";
+ public static final String READONLY = "readonly";
+ public static final String ONCHANGE = "onchange";
+ public static final String CELLPADDING = "cellpadding";
+ public static final String CELLSPACING = "cellspacing";
+ public static final String ALIGN = "align";
+ public static final String VALIGN = "valign";
+ public static final String ROWSPAN = "rowspan";
+ public static final String COLSPAN = "colspan";
+ public static final String ONMOUSEOVER = "onmouseover";
+ public static final String ONMOUSEOUT = "onmouseout";
+ public static final String AUTOCOMPLETE = "autocomplete";
+ public static final String TARGET = "target";
+ public static final String SIZE = "size";
+ public static final String MULTIPLE = "multiple";
+ public static final String ROWS = "rows";
+ public static final String REL = "rel";
+ public static final String MEDIA = "media";
+ public static final String ONLOAD = "onload";
+ public static final String SCROLL = "scroll";
+ public static final String ACTION = "action";
+ public static final String METHOD = "method";
+ public static final String ENCTYPE = "enctype";
+ public static final String ACCEPT_CHARSET = "accept-charset";
+ public static final String ONFOCUS = "onfocus";
+ public static final String ONBLUR = "onblur";
+ public static final String ONKEYDOWN = "onkeydown";
+ public static final String ONKEYPRESS = "onkeypress";
+ public static final String ONKEYUP = "onkeyup";
+ public static final String CLASS = "class";
+ public static final String MAXLENGTH = "maxlength";
+ public static final String LABEL = "label";
+}
+
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlAttributes.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlConstants.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlConstants.java?rev=644025&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlConstants.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlConstants.java Wed Apr 2 12:53:32 2008
@@ -0,0 +1,63 @@
+package org.apache.myfaces.tobago.renderkit.html;
+
+/*
+ * 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.
+ */
+
+public final class HtmlConstants {
+ public static final String LABEL = "label";
+ public static final String TABLE = "table";
+ public static final String FIELDSET = "fieldset";
+ public static final String STYLE = "style";
+ public static final String LEGEND = "legend";
+ public static final String DIV = "div";
+ public static final String BR = "br";
+ public static final String B = "b";
+ public static final String U = "u";
+ public static final String SPAN = "span";
+ public static final String IMG = "img";
+ public static final String TR = "tr";
+ public static final String TH = "th";
+ public static final String TD = "td";
+ public static final String BUTTON = "button";
+ public static final String INPUT = "input";
+ public static final String SELECT = "select";
+ public static final String OPTION = "option";
+ public static final String A = "a";
+ public static final String TEXTAREA = "textarea";
+ public static final String COLGROUP = "colgroup";
+ public static final String COL = "col";
+ public static final String UL = "ul";
+ public static final String LI = "li";
+ public static final String IFRAME = "iframe";
+ public static final String HTML = "html";
+ public static final String HEAD = "head";
+ public static final String HR = "hr";
+ public static final String TITLE = "title";
+ public static final String LINK = "link";
+ public static final String BODY = "body";
+ public static final String FORM = "form";
+ public static final String SCRIPT = "script";
+ public static final String META = "meta";
+ public static final String OPTGROUP = "optgroup";
+ public static final String AREA = "area";
+ public static final String PARAM = "param";
+ public static final String BASE = "base";
+
+ private HtmlConstants() {
+
+ }
+}
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlConstants.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java?rev=644025&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java Wed Apr 2 12:53:32 2008
@@ -0,0 +1,74 @@
+package org.apache.myfaces.tobago.renderkit.html;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Nov 24, 2006
+ * Time: 10:07:33 PM
+ */
+public class HtmlStyleMap extends HashMap<String, Object> {
+
+ private static final Log LOG = LogFactory.getLog(HtmlStyleMap.class);
+ private static final long serialVersionUID = 342607693971417143L;
+
+ public Object put(String s, Object o) {
+ if (o instanceof String && (s.equals("height") || s.equals("width"))) {
+ String str = (String) o;
+ if (str.endsWith("px")) {
+ LOG.error("", new Exception());
+ o = Integer.parseInt(str.substring(0, str.length() - 2));
+ }
+ }
+ return super.put(s, o);
+ }
+
+ public Integer getInt(Object o) {
+ Object obj = get(o);
+ if (obj instanceof Integer) {
+ return (Integer) obj;
+ }
+ if (obj == null) {
+ return null;
+ }
+ LOG.error("", new Exception());
+ return Integer.parseInt(obj.toString());
+ }
+
+ public String toString() {
+ StringBuilder buf = new StringBuilder();
+ for(Map.Entry<String, Object> style :entrySet()) {
+ buf.append(style.getKey());
+ buf.append(":");
+ buf.append(style.getValue());
+ if (style.getValue() instanceof Integer) {
+ buf.append("px; ");
+ } else {
+ buf.append("; ");
+ }
+ }
+ return buf.toString();
+ }
+}
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/StyleClasses.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/StyleClasses.java?rev=644025&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/StyleClasses.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/StyleClasses.java Wed Apr 2 12:53:32 2008
@@ -0,0 +1,276 @@
+package org.apache.myfaces.tobago.renderkit.html;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.collections.set.ListOrderedSet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_CLASS;
+import org.apache.myfaces.tobago.util.ComponentUtil;
+import org.apache.myfaces.tobago.component.SupportsMarkup;
+import org.apache.myfaces.tobago.context.ClientProperties;
+import org.apache.myfaces.tobago.context.Theme;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+/*
+ * Date: 2007-05-01
+ */
+
+public class StyleClasses implements Serializable {
+
+ private static final long serialVersionUID = 3738052927067803517L;
+
+ private static final Log LOG = LogFactory.getLog(StyleClasses.class);
+
+ public static final char SEPERATOR = '-';
+ public static final String PREFIX = "tobago" + SEPERATOR;
+ public static final String MARKUP = SEPERATOR + "markup" + SEPERATOR;
+
+ private ListOrderedSet classes;
+
+ public StyleClasses() {
+ classes = new ListOrderedSet();
+ }
+
+ private StyleClasses(StyleClasses base) {
+ this();
+ classes.addAll(base.classes);
+ }
+
+ public static StyleClasses ensureStyleClasses(UIComponent component) {
+ Map attributes = component.getAttributes();
+ StyleClasses classes = (StyleClasses) attributes.get(ATTR_STYLE_CLASS);
+ if (classes == null) {
+ classes = new StyleClasses();
+ attributes.put(ATTR_STYLE_CLASS, classes);
+ }
+ return classes;
+ }
+
+ public static StyleClasses ensureStyleClassesCopy(UIComponent component) {
+ return new StyleClasses(ensureStyleClasses(component));
+ }
+
+ @Deprecated
+ public void addFullQualifiedClass(String clazz) {
+ classes.add(clazz);
+ }
+
+ @Deprecated
+ public void removeFullQualifiedClass(String clazz) {
+ classes.remove(clazz);
+ }
+
+ public void addClass(String renderer, String sub) {
+ classes.add(nameOfClass(renderer, sub));
+ }
+
+ public void removeClass(String renderer, String sub) {
+ classes.remove(nameOfClass(renderer, sub));
+ }
+
+ public boolean isEmpty() {
+ return classes.isEmpty();
+ }
+
+ private String nameOfClass(String renderer, String sub) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(PREFIX);
+ builder.append(renderer);
+ builder.append(SEPERATOR);
+ builder.append(sub);
+ return builder.toString();
+ }
+
+ public void addMarkupClass(String renderer, String markup) {
+ addMarkupClass(renderer, null, markup);
+ }
+
+ public void removeMarkupClass(String renderer, String markup) {
+ removeMarkupClass(renderer, null, markup);
+ }
+
+ public void addMarkupClass(String renderer, String sub, String markup) {
+ classes.add(nameOfMarkupClass(renderer, sub, markup));
+ }
+
+ public void removeMarkupClass(String renderer, String sub, String markup) {
+ classes.remove(nameOfMarkupClass(renderer, sub, markup));
+ }
+
+ private String nameOfMarkupClass(String renderer, String sub, String markup) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(PREFIX);
+ builder.append(renderer);
+ if (sub != null) {
+ builder.append(SEPERATOR);
+ builder.append(sub);
+ }
+ builder.append(MARKUP);
+ builder.append(markup);
+ return builder.toString();
+ }
+
+ public void addMarkupClass(UIComponent component, String rendererName) {
+ if (component instanceof SupportsMarkup) {
+ addMarkupClass((SupportsMarkup) component, rendererName, null);
+ }
+ }
+
+ public void addMarkupClass(SupportsMarkup supportsMarkup, String rendererName, String sub) {
+ for (String markup : supportsMarkup.getMarkup()) {
+ if (!StringUtils.isBlank(markup)) {
+ Theme theme = ClientProperties.getInstance(FacesContext.getCurrentInstance().getViewRoot()).getTheme();
+ if (theme.getRenderersConfig().isMarkupSupported(rendererName, markup)) {
+ addMarkupClass(rendererName, sub, markup);
+ } else if (!"none".equals(markup)) {
+ LOG.warn("Unknown markup='" + markup + "'");
+ }
+ }
+ }
+ }
+
+ public void addAspectClass(String renderer, Aspect aspect) {
+ classes.add(nameOfAspectClass(renderer, aspect));
+ }
+
+ public void removeAspectClass(String renderer, Aspect aspect) {
+ classes.remove(nameOfAspectClass(renderer, aspect));
+ }
+
+ private String nameOfAspectClass(String renderer, Aspect aspect) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(PREFIX);
+ builder.append(renderer);
+ builder.append(aspect);
+ return builder.toString();
+ }
+
+
+ public void addAspectClass(String renderer, String sub, Aspect aspect) {
+ classes.add(nameOfAspectClass(renderer, sub, aspect));
+ }
+
+ public void removeAspectClass(String renderer, String sub, Aspect aspect) {
+ classes.remove(nameOfAspectClass(renderer, sub, aspect));
+ }
+
+ private String nameOfAspectClass(String renderer, String sub, Aspect aspect) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(PREFIX);
+ builder.append(renderer);
+ builder.append(SEPERATOR);
+ builder.append(sub);
+ builder.append(aspect);
+ return builder.toString();
+ }
+
+ public void addClasses(StyleClasses styleClasses) {
+ for (String clazz : (Iterable<String>) styleClasses.classes) {
+ classes.add(clazz);
+ }
+ }
+
+ public void removeClass(String clazz) {
+ classes.remove(clazz);
+ }
+
+ public void removeTobagoClasses(String rendererName) {
+ for (Iterator i = classes.iterator(); i.hasNext();) {
+ String clazz = (String) i.next();
+ if (clazz.startsWith(PREFIX + rendererName)) {
+ i.remove();
+ }
+ }
+ }
+
+ public void updateClassAttributeAndMarkup(UIComponent component, String rendererName) {
+ updateClassAttribute(component, rendererName);
+ addMarkupClass(component, rendererName);
+ }
+
+ public void updateClassAttribute(UIComponent component, String rendererName) {
+ // first remove old tobago-<rendererName>-<type> classes from class-attribute
+ removeTobagoClasses(rendererName);
+
+ addAspectClass(rendererName, Aspect.DEFAULT);
+ if (ComponentUtil.getBooleanAttribute(component, ATTR_DISABLED)) {
+ addAspectClass(rendererName, Aspect.DISABLED);
+ }
+ if (ComponentUtil.getBooleanAttribute(component, ATTR_READONLY)) {
+ addAspectClass(rendererName, Aspect.READONLY);
+ }
+ if (ComponentUtil.getBooleanAttribute(component, ATTR_INLINE)) {
+ addAspectClass(rendererName, Aspect.INLINE);
+ }
+ if (component instanceof UIInput) {
+ UIInput input = (UIInput) component;
+ if (ComponentUtil.isError(input)) {
+ addAspectClass(rendererName, Aspect.ERROR);
+ }
+ if (input.isRequired()) {
+ addAspectClass(rendererName, Aspect.REQUIRED);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ for (Iterator i = classes.iterator(); i.hasNext();) {
+ String clazz = (String) i.next();
+ buffer.append(clazz);
+ if (i.hasNext()) {
+ buffer.append(' ');
+ }
+ }
+ return buffer.toString();
+ }
+
+ public enum Aspect {
+
+ DEFAULT,
+ DISABLED,
+ READONLY,
+ INLINE,
+ ERROR,
+ REQUIRED;
+
+ private String aspect;
+
+ Aspect() {
+ aspect = '-' + name().toLowerCase(Locale.ENGLISH);
+ }
+
+ @Override
+ public String toString() {
+ return aspect;
+ }
+ }
+}
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/StyleClasses.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/StyleClasses.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL