Source Code Cross Referenced for TestNekoRewriter.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » rewriter » 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 » Portal » jetspeed 2.1.3 » org.apache.jetspeed.rewriter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.rewriter;
018:
019:        import java.io.File;
020:        import java.io.FileReader;
021:        import java.io.FileWriter;
022:        import java.io.IOException;
023:        import java.util.Arrays;
024:
025:        import org.apache.jetspeed.rewriter.html.neko.NekoParserAdaptor;
026:        import org.apache.jetspeed.rewriter.rules.Ruleset;
027:        import org.apache.jetspeed.rewriter.xml.SaxParserAdaptor;
028:
029:        import junit.framework.Test;
030:        import junit.framework.TestCase;
031:        import junit.framework.TestSuite;
032:
033:        /**
034:         * TestNekoRewriter
035:         * 
036:         * @author <a href="mailto:dyoung@phase2systems.com">David L Young</a>
037:         * @version $Id:$
038:         */
039:        public class TestNekoRewriter extends TestCase {
040:
041:            /**
042:             * Defines the testcase name for JUnit.
043:             * 
044:             * @param name
045:             *            the testcase's name.
046:             */
047:            public TestNekoRewriter(String name) {
048:                super (name);
049:            }
050:
051:            public String getBaseProject() {
052:                return "components/jetspeed";
053:            }
054:
055:            /**
056:             * Start the tests.
057:             * 
058:             * @param args
059:             *            the arguments. Not used
060:             */
061:            public static void main(String args[]) {
062:                junit.awtui.TestRunner
063:                        .main(new String[] { TestNekoRewriter.class.getName() });
064:            }
065:
066:            public static Test suite() {
067:                // All methods starting with "test" will be executed in the test suite.
068:                return new TestSuite(TestNekoRewriter.class);
069:            }
070:
071:            // DOMParser example
072:
073:            /* BOZO
074:
075:            public void testDOM() throws Exception
076:            {
077:                System.out.println( "testing...DOM" ) ;
078:
079:                // parse something and echo the DOM tree
080:                String target = "http://www.google.com" ;
081:                System.out.println( "Parsing: " + target ) ;
082:                
083:                DOMParser parser = new DOMParser() ;
084:                parser.parse( target ) ;
085:                System.out.println( "parse() result..." ) ;
086:                print( parser.getDocument(), "" ) ;
087:            }
088:
089:            void print( Node node, String indent )
090:            {
091:                System.out.println(indent+node.getClass().getName());
092:                Node child = node.getFirstChild();
093:                while (child != null) {
094:                    print(child, indent+" ");
095:                    child = child.getNextSibling();
096:                }
097:            }
098:             */
099:
100:            // SAXParser example
101:            /* BOZO
102:
103:            public void testSAX() throws Exception
104:            {
105:                System.out.println( "testing...SAX" ) ;
106:
107:                // parse something to stdout
108:                String target = "http://www.google.com" ;
109:                System.out.println( "Parsing: " + target ) ;
110:                
111:                SAXParser parser = new SAXParser() ;
112:
113:                // create pipeline filters
114:                org.cyberneko.html.filters.Writer writer = new org.cyberneko.html.filters.Writer();
115:                Purifier purifier = new Purifier() ;
116:
117:                // setup filter chain
118:                XMLDocumentFilter[] filters = {
119:                    purifier,
120:                    writer,
121:                };
122:
123:                parser.setProperty("http://cyberneko.org/html/properties/filters", filters);
124:
125:                // parse documents
126:                XMLInputSource source = new XMLInputSource(null, target, null);
127:                parser.parse(source);
128:            }
129:             */
130:
131:            // NekoParserAdapter test
132:            public void testNekoParserAdaptor() throws Exception {
133:                RewriterController controller = getController();
134:                FileReader rulesReader = getTestReader("test-remove-rules.xml");
135:                Ruleset ruleset = controller.loadRuleset(rulesReader);
136:                rulesReader.close();
137:                assertNotNull("ruleset is null", ruleset);
138:                RulesetRewriter rewriter = controller.createRewriter(ruleset);
139:                assertNotNull("ruleset rewriter is null", rewriter);
140:
141:                FileReader htmlReader = getTestReader("test-001.html");
142:                FileWriter htmlWriter = getTestWriter("test-002-output.html");
143:
144:                ParserAdaptor adaptor = controller
145:                        .createParserAdaptor("text/html");
146:                rewriter.setBaseUrl("http://www.rewriter.com");
147:                rewriter.rewrite(adaptor, htmlReader, htmlWriter);
148:                htmlReader.close();
149:            }
150:
151:            private RewriterController getController() throws Exception {
152:                Class[] rewriterClasses = new Class[] {
153:                        RulesetRewriterImpl.class, RulesetRewriterImpl.class };
154:
155:                Class[] adaptorClasses = new Class[] { NekoParserAdaptor.class,
156:                        SaxParserAdaptor.class };
157:                return new JetspeedRewriterController(
158:                        "test/WEB-INF/conf/rewriter-rules-mapping.xml", Arrays
159:                                .asList(rewriterClasses), Arrays
160:                                .asList(adaptorClasses));
161:            }
162:
163:            /*
164:            private Reader getRemoteReader(String uri) throws IOException
165:            {
166:                HttpClient client = new HttpClient();
167:                GetMethod get = new GetMethod(uri);
168:                client.executeMethod(get);
169:                BufferedInputStream bis = new BufferedInputStream(get.getResponseBodyAsStream());
170:                String encoding = get.getResponseCharSet();
171:                return new InputStreamReader(bis, encoding);
172:            }
173:             */
174:
175:            /**
176:             * Gets a reader for a given filename in the test directory.
177:             * 
178:             * @return A file reader to the test rules file
179:             * @throws IOException
180:             */
181:            private FileReader getTestReader(String filename)
182:                    throws IOException {
183:                return new FileReader("test/rewriter/" + filename);
184:            }
185:
186:            /**
187:             * Gets a writer for a given filename in the test directory.
188:             * 
189:             * @return A file reader to the test rules file
190:             * @throws IOException
191:             */
192:            private FileWriter getTestWriter(String filename)
193:                    throws IOException {
194:                new File("target/test/rewriter").mkdirs();
195:                return new FileWriter("target/test/rewriter/" + filename);
196:            }
197:
198:            /* BOZO
199:            public void testNekoWebTarget() throws Exception
200:            {        
201:                // parse something with the NekoParserAdaptor
202:                String target = "http://www.google.com";
203:                        
204:                RewriterController controller = getController();
205:                FileReader rulesReader = getTestReader("test-remove-rules.xml");
206:                Ruleset ruleset = controller.loadRuleset(rulesReader);
207:                rulesReader.close();
208:                assertNotNull("ruleset is null", ruleset);
209:                RulesetRewriter rewriter = controller.createRewriter(ruleset);
210:                assertNotNull("ruleset rewriter is null", rewriter);
211:
212:                java.io.Reader htmlReader = getRemoteReader(target);
213:                java.io.Writer htmlWriter = new OutputStreamWriter(System.out);
214:
215:                ParserAdaptor adaptor = controller.createParserAdaptor("text/html");
216:                rewriter.setBaseUrl("http://www.rewriter.com");
217:                rewriter.rewrite(adaptor, htmlReader, htmlWriter);
218:                htmlReader.close();
219:            }
220:             */
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.