001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.aui;
016    
017    import com.liferay.taglib.util.IncludeTag;
018    import com.liferay.util.TextFormatter;
019    
020    import javax.servlet.http.HttpServletRequest;
021    
022    /**
023     * @author Julio Camarero
024     * @author Jorge Ferrer
025     * @author Brian Wing Shun Chan
026     */
027    public class FieldWrapperTag extends IncludeTag {
028    
029            public void setCssClass(String cssClass) {
030                    _cssClass = cssClass;
031            }
032    
033            public void setFirst(boolean first) {
034                    _first = first;
035            }
036    
037            public void setHelpMessage(String helpMessage) {
038                    _helpMessage = helpMessage;
039            }
040    
041            public void setInlineField(boolean inlineField) {
042                    _inlineField = inlineField;
043            }
044    
045            public void setInlineLabel(String inlineLabel) {
046                    _inlineLabel = inlineLabel;
047            }
048    
049            public void setLabel(String label) {
050                    _label = label;
051            }
052    
053            public void setLast(boolean last) {
054                    _last = last;
055            }
056    
057            public void setName(String name) {
058                    _name = name;
059            }
060    
061            protected void cleanUp() {
062                    _cssClass = null;
063                    _first = false;
064                    _helpMessage = null;
065                    _inlineField = false;
066                    _inlineLabel = null;
067                    _label = null;
068                    _last = false;
069                    _name = null;
070            }
071    
072            protected String getEndPage() {
073                    return _END_PAGE;
074            }
075    
076            protected String getStartPage() {
077                    return _START_PAGE;
078            }
079    
080            protected boolean isCleanUpSetAttributes() {
081                    return _CLEAN_UP_SET_ATTRIBUTES;
082            }
083    
084            protected void setAttributes(HttpServletRequest request) {
085                    String label = _label;
086    
087                    if (label == null) {
088                            label = TextFormatter.format(_name, TextFormatter.K);
089                    }
090    
091                    request.setAttribute("aui:field-wrapper:cssClass", _cssClass);
092                    request.setAttribute(
093                            "aui:field-wrapper:dynamicAttributes", getDynamicAttributes());
094                    request.setAttribute("aui:field-wrapper:first", String.valueOf(_first));
095                    request.setAttribute("aui:field-wrapper:helpMessage", _helpMessage);
096                    request.setAttribute(
097                            "aui:field-wrapper:inlineField", String.valueOf(_inlineField));
098                    request.setAttribute("aui:field-wrapper:inlineLabel", _inlineLabel);
099                    request.setAttribute("aui:field-wrapper:label", label);
100                    request.setAttribute("aui:field-wrapper:last", String.valueOf(_last));
101                    request.setAttribute("aui:field-wrapper:name", _name);
102            }
103    
104            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
105    
106            private static final String _END_PAGE =
107                    "/html/taglib/aui/field_wrapper/end.jsp";
108    
109            private static final String _START_PAGE =
110                    "/html/taglib/aui/field_wrapper/start.jsp";
111    
112            private String _cssClass;
113            private boolean _first;
114            private String _helpMessage;
115            private boolean _inlineField;
116            private String _inlineLabel;
117            private String _label;
118            private boolean _last;
119            private String _name;
120    
121    }