001    /**
002     * Copyright (c) 2000-2012 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.portal.kernel.dao.search;
016    
017    import com.liferay.portal.kernel.bean.BeanPropertiesUtil;
018    import com.liferay.portal.kernel.util.HtmlUtil;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import java.util.Map;
023    
024    import javax.servlet.jsp.JspWriter;
025    import javax.servlet.jsp.PageContext;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class TextSearchEntry extends SearchEntry {
031    
032            @Override
033            public Object clone() {
034                    TextSearchEntry textSearchEntry = new TextSearchEntry();
035    
036                    BeanPropertiesUtil.copyProperties(this, textSearchEntry);
037    
038                    return textSearchEntry;
039            }
040    
041            public Map<String, Object> getData() {
042                    return _data;
043            }
044    
045            public String getHref() {
046                    return _href;
047            }
048    
049            public String getName() {
050                    return _name;
051            }
052    
053            public String getTarget() {
054                    return _target;
055            }
056    
057            public String getTitle() {
058                    return _title;
059            }
060    
061            @Override
062            public void print(PageContext pageContext) throws Exception {
063                    if (_href == null) {
064                            pageContext.getOut().print(_name);
065                    }
066                    else {
067                            StringBundler sb = new StringBundler();
068    
069                            sb.append("<a");
070    
071                            if (_data != null) {
072                                    for (Map.Entry<String, Object> entry : _data.entrySet()) {
073                                            String key = entry.getKey();
074                                            String value = String.valueOf(entry.getValue());
075    
076                                            sb.append(" data-");
077                                            sb.append(key);
078                                            sb.append("=\"");
079                                            sb.append(value);
080                                            sb.append("\"");
081                                    }
082                            }
083    
084                            sb.append(" href=\"");
085                            sb.append(HtmlUtil.escape(_href));
086                            sb.append("\"");
087    
088                            if (Validator.isNotNull(_target)) {
089                                    sb.append(" target=\"");
090                                    sb.append(_target);
091                                    sb.append("\"");
092                            }
093    
094                            if (Validator.isNotNull(_title)) {
095                                    sb.append(" title=\"");
096                                    sb.append(_title);
097                                    sb.append("\"");
098                            }
099    
100                            sb.append(">");
101                            sb.append(_name);
102                            sb.append("</a>");
103    
104                            JspWriter jspWriter = pageContext.getOut();
105    
106                            jspWriter.print(sb.toString());
107                    }
108            }
109    
110            public void setData(Map<String, Object> data) {
111                    _data = data;
112            }
113    
114            public void setHref(String href) {
115                    _href = href;
116            }
117    
118            public void setName(String name) {
119                    _name = name;
120            }
121    
122            public void setTarget(String target) {
123                    _target = target;
124            }
125    
126            public void setTitle(String title) {
127                    _title = title;
128            }
129    
130            private Map<String, Object> _data;
131            private String _href;
132            private String _name;
133            private String _target;
134            private String _title;
135    
136    }