Source Code Cross Referenced for PrintableServlet.java in  » Wiki-Engine » VeryQuickWiki » vqwiki » servlets » 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 » Wiki Engine » VeryQuickWiki » vqwiki.servlets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package vqwiki.servlets;
002:
003:        import java.io.IOException;
004:        import java.util.ArrayList;
005:        import java.util.Collection;
006:        import java.util.Iterator;
007:        import java.util.ResourceBundle;
008:        import java.util.Vector;
009:
010:        import javax.servlet.ServletException;
011:        import javax.servlet.http.HttpServletRequest;
012:        import javax.servlet.http.HttpServletResponse;
013:
014:        import vqwiki.Environment;
015:        import vqwiki.PrintableEntry;
016:        import vqwiki.WikiBase;
017:        import vqwiki.PseudoTopicHandler;
018:        import vqwiki.utils.Utilities;
019:        import vqwiki.utils.JSPUtils;
020:
021:        /**
022:         * Create a printable view of one servlet.
023:         *
024:         * @author garethc, Tobias Schulz-Hess (sourcefoge@schulz-hess.de)
025:         * Date: Jan 8, 2003
026:         */
027:        public class PrintableServlet extends VQWikiServlet {
028:
029:            /**
030:             * Handle get request
031:             *
032:             * @param request The servlet request
033:             * @param response The servlet response
034:             *
035:             * @throws ServletException If something went wrong with the servlet
036:             * @throws IOException If the servlet cannot print
037:             */
038:            protected void doGet(HttpServletRequest request,
039:                    HttpServletResponse response) throws ServletException,
040:                    IOException {
041:                String topic = request.getParameter("topic");
042:                String virtualWiki = (String) request
043:                        .getAttribute("virtualWiki");
044:                request.setAttribute("topic", topic);
045:                request.setAttribute("title", topic);
046:                String strDepth = request.getParameter("depth");
047:                if (request.getParameter("hideform") != null) {
048:                    request.setAttribute("hideform", "true");
049:                }
050:                int depth = 0;
051:                try {
052:                    depth = Integer.parseInt(strDepth);
053:                } catch (NumberFormatException e1) {
054:                    depth = 0;
055:                }
056:                request.setAttribute("depth", String.valueOf(depth));
057:                Environment en = Environment.getInstance();
058:                String contextPath = request.getContextPath();
059:                en.setBaseContext(contextPath);
060:                ArrayList result = new ArrayList();
061:                Vector alreadyVisited = new Vector();
062:                try {
063:                    result.addAll(parsePage(ResourceBundle.getBundle(
064:                            "ApplicationResources", request.getLocale()), en,
065:                            virtualWiki, topic, depth, alreadyVisited));
066:                } catch (Exception e) {
067:                    error(request, response, e);
068:                    return;
069:                }
070:                // now go through all pages and replace
071:                // all href=Wiki? with href=# for the
072:                // pages in the alreadyVisited vector
073:                for (Iterator iter = result.iterator(); iter.hasNext();) {
074:                    PrintableEntry element = (PrintableEntry) iter.next();
075:                    for (Iterator visitedIterator = alreadyVisited.iterator(); visitedIterator
076:                            .hasNext();) {
077:                        String visitedTopic = (String) visitedIterator.next();
078:                        element.setContent(Utilities.replaceString(element
079:                                .getContent(), "href=\"Wiki?" + visitedTopic,
080:                                "href=\"#" + visitedTopic));
081:                    }
082:                }
083:                // put the result in the request
084:                request.setAttribute("contentList", result);
085:                dispatch("/jsp/printable.jsp", request, response);
086:            }
087:
088:            /**
089:             * Parse page and supages
090:             * @param virtualWiki The virutal wiki to use
091:             * @param topic The topic to start with
092:             * @param depth The depth to go into
093:             * @return Collection of pages
094:             */
095:            private Collection parsePage(ResourceBundle messages,
096:                    Environment en, String virtualWiki, String topic,
097:                    int depth, Vector alreadyVisited) throws Exception {
098:                WikiBase base = WikiBase.getInstance();
099:                String onepage = base.readCooked(virtualWiki, topic);
100:                Collection result = new ArrayList();
101:                if (onepage != null) {
102:                    PrintableEntry entry = new PrintableEntry();
103:                    entry.setTopic(topic);
104:                    entry.setContent(onepage);
105:                    result.add(entry);
106:                    alreadyVisited.add(topic);
107:                    if (depth > 0) {
108:                        String searchfor = "href=\"Wiki?";
109:                        int iPos = onepage.indexOf(searchfor);
110:                        int iEndPos = onepage.indexOf(messages
111:                                .getString("topic.ismentionedon"));
112:                        if (iEndPos == -1)
113:                            iEndPos = Integer.MAX_VALUE;
114:                        while (iPos > -1 && iPos < iEndPos) {
115:                            String link = onepage.substring(iPos
116:                                    + searchfor.length(), onepage.indexOf('"',
117:                                    iPos + searchfor.length()));
118:                            if (link.indexOf('&') > -1) {
119:                                link = link.substring(0, link.indexOf('&'));
120:                            }
121:                            link = JSPUtils.decodeURL(link);
122:                            if (link.length() > 3
123:                                    && !link.startsWith("topic=")
124:                                    && !link.startsWith("action=")
125:                                    && !alreadyVisited.contains(link)
126:                                    && !PseudoTopicHandler.getInstance()
127:                                            .isPseudoTopic(link)) {
128:                                result.addAll(parsePage(messages, en,
129:                                        virtualWiki, link, (depth - 1),
130:                                        alreadyVisited));
131:                            }
132:                            iPos = onepage.indexOf(searchfor, iPos + 10);
133:                        }
134:                    }
135:                }
136:                return result;
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.