Source Code Cross Referenced for NavigationTag.java in  » Search-Engine » regain » net » sf » regain » search » sharedlib » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » regain » net.sf.regain.search.sharedlib 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * regain - A file search engine providing plenty of formats
003:         * Copyright (C) 2004  Til Schneider
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         * Contact: Til Schneider, info@murfman.de
020:         *
021:         * CVS information:
022:         *  $RCSfile$
023:         *   $Source$
024:         *     $Date: 2005-11-02 22:58:52 +0100 (Mi, 02 Nov 2005) $
025:         *   $Author: til132 $
026:         * $Revision: 177 $
027:         */
028:        package net.sf.regain.search.sharedlib;
029:
030:        import net.sf.regain.RegainException;
031:        import net.sf.regain.RegainToolkit;
032:        import net.sf.regain.search.SearchConstants;
033:        import net.sf.regain.search.SearchToolkit;
034:        import net.sf.regain.search.results.SearchResults;
035:        import net.sf.regain.util.sharedtag.PageRequest;
036:        import net.sf.regain.util.sharedtag.PageResponse;
037:        import net.sf.regain.util.sharedtag.SharedTag;
038:
039:        /**
040:         * This Tag creates hyperlinks to navigate through the search result pages.
041:         * <p>
042:         * Tag Parameters:
043:         * <ul>
044:         * <li><code>msgBack</code>: The message to use for labeling the back link.</li>
045:         * <li><code>msgForward</code>: The message to use for labeling the forward link.</li>
046:         * <li><code>targetPage</code>: The URL of the page where the links should point to.</li>
047:         * <li><code>class</code>: The style sheet class to use for the link tags.</li>
048:         * </ul>
049:         *
050:         * @author Til Schneider, www.murfman.de
051:         */
052:        public class NavigationTag extends SharedTag implements  SearchConstants {
053:
054:            /** The maximum number of links to create. */
055:            private static final int MAX_BUTTONS = 15;
056:
057:            /** Die Default-Seite, auf die die Weiter-Links zeigen sollen. */
058:            private static final String DEFAULT_TARGET_PAGE = "SearchOutput.jsp";
059:
060:            /**
061:             * Called when the parser reaches the end tag.
062:             *  
063:             * @param request The page request.
064:             * @param response The page response.
065:             * @throws RegainException If there was an exception.
066:             */
067:            public void printEndTag(PageRequest request, PageResponse response)
068:                    throws RegainException {
069:                String query = SearchToolkit.getSearchQuery(request);
070:                SearchResults results = SearchToolkit.getSearchResults(request);
071:
072:                int fromResult = request
073:                        .getParameterAsInt(PARAM_FROM_RESULT, 0);
074:                int maxResults = request.getParameterAsInt(PARAM_MAX_RESULTS,
075:                        SearchConstants.DEFAULT_MAX_RESULTS);
076:                int totalResults = results.getHitCount();
077:
078:                int buttonCount = (int) Math.ceil((double) totalResults
079:                        / (double) maxResults);
080:                int currButton = fromResult / maxResults;
081:
082:                // The first and the last button to show
083:                int fromButton = 0;
084:                int toButton = buttonCount - 1;
085:
086:                if (buttonCount > MAX_BUTTONS) {
087:                    if (currButton < (MAX_BUTTONS / 2)) {
088:                        // The button range starts at the first button (---X------.....)
089:                        toButton = fromButton + MAX_BUTTONS - 1;
090:                    } else if (currButton > (buttonCount - ((MAX_BUTTONS + 1) / 2))) {
091:                        // The button range ends at the last button (.....-------X--)
092:                        fromButton = toButton - MAX_BUTTONS + 1;
093:                    } else {
094:                        // The button range is somewhere in the middle (...----X-----..)
095:                        toButton = currButton + (MAX_BUTTONS / 2);
096:                        fromButton = toButton - MAX_BUTTONS + 1;
097:                    }
098:                }
099:
100:                String[] indexNameArr = request.getParameters("index");
101:                if (currButton > 0) {
102:                    String msgBack = getParameter("msgBack", true);
103:                    msgBack = RegainToolkit.replace(msgBack, "&quot;", "\"");
104:                    printLink(response, currButton - 1, query, maxResults,
105:                            indexNameArr, msgBack);
106:                }
107:                for (int i = fromButton; i <= toButton; i++) {
108:                    if (i == currButton) {
109:                        // This is the current button
110:                        response.print("<b>" + (i + 1) + "</b> ");
111:                    } else {
112:                        String linkText = Integer.toString(i + 1);
113:                        printLink(response, i, query, maxResults, indexNameArr,
114:                                linkText);
115:                    }
116:                }
117:                if (currButton < (buttonCount - 1)) {
118:                    String msgForward = getParameter("msgForward", true);
119:                    msgForward = RegainToolkit.replace(msgForward, "'", "\"");
120:                    printLink(response, currButton + 1, query, maxResults,
121:                            indexNameArr, msgForward);
122:                }
123:            }
124:
125:            /**
126:             * Prints the HTML for a hyperlink.
127:             *
128:             * @param response The page response.
129:             * @param button The index of the button to create the HTML for.
130:             * @param query The search query.
131:             * @param maxResults The maximum results.
132:             * @param indexNameArr The names of the search indexes.
133:             * @param linkText The link text.
134:             * @throws RegainException If printing failed.
135:             */
136:            private void printLink(PageResponse response, int button,
137:                    String query, int maxResults, String[] indexNameArr,
138:                    String linkText) throws RegainException {
139:                String targetPage = getParameter("targetPage",
140:                        DEFAULT_TARGET_PAGE);
141:
142:                String encoding = response.getEncoding();
143:                String encodedQuery = RegainToolkit.urlEncode(query, encoding);
144:
145:                response.print("<a href=\"" + targetPage + "?query="
146:                        + encodedQuery);
147:                if (indexNameArr != null) {
148:                    for (int i = 0; i < indexNameArr.length; i++) {
149:                        String encodedIndexName = RegainToolkit.urlEncode(
150:                                indexNameArr[i], encoding);
151:                        response.print("&index=" + encodedIndexName);
152:                    }
153:                }
154:                if (maxResults != SearchConstants.DEFAULT_MAX_RESULTS) {
155:                    response.print("&maxresults=" + maxResults);
156:                }
157:                if (button != 0) {
158:                    response.print("&fromresult=" + (button * maxResults));
159:                }
160:                response.print("\"");
161:                String styleSheetClass = getParameter("class");
162:                if (styleSheetClass != null) {
163:                    response.print(" class=\"" + styleSheetClass + "\"");
164:                }
165:                response.print(">" + linkText + "</a> ");
166:            }
167:
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.