001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.dao.search;
016    
017    import com.liferay.portal.kernel.util.HtmlUtil;
018    import com.liferay.portal.kernel.util.StringBundler;
019    import com.liferay.portal.kernel.util.Validator;
020    
021    import javax.servlet.jsp.PageContext;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class TextSearchEntry extends SearchEntry {
027    
028            public TextSearchEntry(String align, String valign, String name) {
029                    this(align, valign, DEFAULT_COLSPAN, name, null);
030            }
031    
032            public TextSearchEntry(
033                    String align, String valign, int colspan, String name) {
034    
035                    this(align, valign, colspan, name, null);
036            }
037    
038            public TextSearchEntry(
039                    String align, String valign, String name, String href) {
040    
041                    this(align, valign, DEFAULT_COLSPAN, name, href, null, null);
042            }
043    
044            public TextSearchEntry(
045                    String align, String valign, int colspan, String name, String href) {
046    
047                    this(align, valign, colspan, name, href, null, null);
048            }
049    
050            public TextSearchEntry(
051                    String align, String valign, String name, String href, String target,
052                    String title) {
053    
054                    this(align, valign, DEFAULT_COLSPAN, name, href, target, title);
055            }
056    
057            public TextSearchEntry(
058                    String align, String valign, int colspan, String name, String href,
059                    String target, String title) {
060    
061                    super(align, valign, colspan);
062    
063                    _name = name;
064                    _href = href;
065                    _target = target;
066                    _title = title;
067            }
068    
069            public String getName() {
070                    return _name;
071            }
072    
073            public void setName(String name) {
074                    _name = name;
075            }
076    
077            public String getHref() {
078                    return _href;
079            }
080    
081            public void setHref(String href) {
082                    _href = href;
083            }
084    
085            public String getTarget() {
086                    return _target;
087            }
088    
089            public void setTarget(String target) {
090                    _target = target;
091            }
092    
093            public String getTitle() {
094                    return _title;
095            }
096    
097            public void setTitle(String title) {
098                    _title = title;
099            }
100    
101            public void print(PageContext pageContext) throws Exception {
102                    if (_href == null) {
103                            pageContext.getOut().print(_name);
104                    }
105                    else {
106                            StringBundler sb = new StringBundler();
107    
108                            sb.append("<a href=\"");
109                            sb.append(HtmlUtil.escapeAttribute(_href));
110                            sb.append("\"");
111    
112                            if (Validator.isNotNull(_target)) {
113                                    sb.append(" target=\"");
114                                    sb.append(_target);
115                                    sb.append("\"");
116                            }
117    
118                            if (Validator.isNotNull(_title)) {
119                                    sb.append(" title=\"");
120                                    sb.append(_title);
121                                    sb.append("\"");
122                            }
123    
124                            sb.append(">");
125                            sb.append(_name);
126                            sb.append("</a>");
127    
128                            pageContext.getOut().print(sb.toString());
129                    }
130            }
131    
132            public Object clone() {
133                    return new TextSearchEntry(
134                            getAlign(), getValign(), getColspan(), getName(), getHref(),
135                            getTarget(), getTitle());
136            }
137    
138            private String _name;
139            private String _href;
140            private String _target;
141            private String _title;
142    
143    }