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 getName(PageContext pageContext) {
054                    return getName();
055            }
056    
057            public String getTarget() {
058                    return _target;
059            }
060    
061            public String getTitle() {
062                    return _title;
063            }
064    
065            @Override
066            public void print(PageContext pageContext) throws Exception {
067                    if (_href == null) {
068                            pageContext.getOut().print(getName(pageContext));
069                    }
070                    else {
071                            StringBundler sb = new StringBundler();
072    
073                            sb.append("<a");
074    
075                            if (_data != null) {
076                                    for (Map.Entry<String, Object> entry : _data.entrySet()) {
077                                            String key = entry.getKey();
078                                            String value = String.valueOf(entry.getValue());
079    
080                                            sb.append(" data-");
081                                            sb.append(key);
082                                            sb.append("=\"");
083                                            sb.append(value);
084                                            sb.append("\"");
085                                    }
086                            }
087    
088                            sb.append(" href=\"");
089    
090                            if (_href.startsWith("javascript:")) {
091                                    sb.append(_href);
092                            }
093                            else {
094                                    sb.append(HtmlUtil.escape(_href));
095                            }
096    
097                            sb.append("\"");
098    
099                            if (Validator.isNotNull(_target)) {
100                                    sb.append(" target=\"");
101                                    sb.append(_target);
102                                    sb.append("\"");
103                            }
104    
105                            if (Validator.isNotNull(_title)) {
106                                    sb.append(" title=\"");
107                                    sb.append(_title);
108                                    sb.append("\"");
109                            }
110    
111                            sb.append(">");
112                            sb.append(getName(pageContext));
113                            sb.append("</a>");
114    
115                            JspWriter jspWriter = pageContext.getOut();
116    
117                            jspWriter.print(sb.toString());
118                    }
119            }
120    
121            public void setData(Map<String, Object> data) {
122                    _data = data;
123            }
124    
125            public void setHref(String href) {
126                    _href = href;
127            }
128    
129            public void setName(String name) {
130                    _name = name;
131            }
132    
133            public void setTarget(String target) {
134                    _target = target;
135            }
136    
137            public void setTitle(String title) {
138                    _title = title;
139            }
140    
141            private Map<String, Object> _data;
142            private String _href;
143            private String _name;
144            private String _target;
145            private String _title;
146    
147    }