001    /**
002     * Copyright (c) 2000-2013 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    
086                            if (_href.startsWith("javascript:")) {
087                                    sb.append(_href);
088                            }
089                            else {
090                                    sb.append(HtmlUtil.escape(_href));
091                            }
092    
093                            sb.append("\"");
094    
095                            if (Validator.isNotNull(_target)) {
096                                    sb.append(" target=\"");
097                                    sb.append(_target);
098                                    sb.append("\"");
099                            }
100    
101                            if (Validator.isNotNull(_title)) {
102                                    sb.append(" title=\"");
103                                    sb.append(_title);
104                                    sb.append("\"");
105                            }
106    
107                            sb.append(">");
108                            sb.append(_name);
109                            sb.append("</a>");
110    
111                            JspWriter jspWriter = pageContext.getOut();
112    
113                            jspWriter.print(sb.toString());
114                    }
115            }
116    
117            public void setData(Map<String, Object> data) {
118                    _data = data;
119            }
120    
121            public void setHref(String href) {
122                    _href = href;
123            }
124    
125            public void setName(String name) {
126                    _name = name;
127            }
128    
129            public void setTarget(String target) {
130                    _target = target;
131            }
132    
133            public void setTitle(String title) {
134                    _title = title;
135            }
136    
137            private Map<String, Object> _data;
138            private String _href;
139            private String _name;
140            private String _target;
141            private String _title;
142    
143    }