Source Code Cross Referenced for Txt2Html.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » tomcat » buildutil » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.tomcat.buildutil 
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:
018:        package org.apache.tomcat.buildutil;
019:
020:        import java.io.BufferedReader;
021:        import java.io.File;
022:        import java.io.FileReader;
023:        import java.io.FileWriter;
024:        import java.io.IOException;
025:        import java.io.PrintWriter;
026:        import java.util.Iterator;
027:        import java.util.LinkedList;
028:        import java.util.List;
029:        import org.apache.tools.ant.BuildException;
030:        import org.apache.tools.ant.DirectoryScanner;
031:        import org.apache.tools.ant.Project;
032:        import org.apache.tools.ant.Task;
033:        import org.apache.tools.ant.types.FileSet;
034:
035:        /**
036:         * Ant task to convert a given set of files from Text to HTML.
037:         * Inserts an HTML header including pre tags and replaces special characters
038:         * with their HTML escaped equivalents.
039:         *
040:         * <p>This task is currently used by the ant script to build our examples</p>
041:         *
042:         * @author Mark Roth
043:         */
044:        public class Txt2Html extends Task {
045:
046:            /** The directory to contain the resulting files */
047:            private File todir;
048:
049:            /** The file to be converted into HTML */
050:            private List<FileSet> filesets = new LinkedList<FileSet>();
051:
052:            /**
053:             * Sets the directory to contain the resulting files
054:             *
055:             * @param todir The directory
056:             */
057:            public void setTodir(File todir) {
058:                this .todir = todir;
059:            }
060:
061:            /**
062:             * Sets the files to be converted into HTML
063:             *
064:             * @param fileset The fileset to be converted.
065:             */
066:            public void addFileset(FileSet fs) {
067:                filesets.add(fs);
068:            }
069:
070:            /**
071:             * Perform the conversion
072:             *
073:             * @param BuildException Thrown if an error occurs during execution of
074:             *    this task.
075:             */
076:            public void execute() throws BuildException {
077:                int count = 0;
078:
079:                // Step through each file and convert.
080:                Iterator iter = filesets.iterator();
081:                while (iter.hasNext()) {
082:                    FileSet fs = (FileSet) iter.next();
083:                    DirectoryScanner ds = fs.getDirectoryScanner(project);
084:                    File basedir = ds.getBasedir();
085:                    String[] files = ds.getIncludedFiles();
086:                    for (int i = 0; i < files.length; i++) {
087:                        File from = new File(basedir, files[i]);
088:                        File to = new File(todir, files[i] + ".html");
089:                        if (!to.exists()
090:                                || (from.lastModified() > to.lastModified())) {
091:                            log("Converting file '" + from.getAbsolutePath()
092:                                    + "' to '" + to.getAbsolutePath(),
093:                                    Project.MSG_VERBOSE);
094:                            try {
095:                                convert(from, to);
096:                            } catch (IOException e) {
097:                                throw new BuildException("Could not convert '"
098:                                        + from.getAbsolutePath() + "' to '"
099:                                        + to.getAbsolutePath() + "'", e);
100:                            }
101:                            count++;
102:                        }
103:                    }
104:                    if (count > 0) {
105:                        log("Converted " + count + " file"
106:                                + (count > 1 ? "s" : "") + " to "
107:                                + todir.getAbsolutePath());
108:                    }
109:                }
110:            }
111:
112:            /**
113:             * Perform the actual copy and conversion
114:             *
115:             * @param from The input file
116:             * @param to The output file
117:             * @throws IOException Thrown if an error occurs during the conversion
118:             */
119:            private void convert(File from, File to) throws IOException {
120:                // Open files:
121:                BufferedReader in = new BufferedReader(new FileReader(from));
122:                PrintWriter out = new PrintWriter(new FileWriter(to));
123:
124:                // Output header:
125:                out.println("<html><body><pre>");
126:
127:                // Convert, line-by-line:
128:                String line;
129:                while ((line = in.readLine()) != null) {
130:                    StringBuffer result = new StringBuffer();
131:                    int len = line.length();
132:                    for (int i = 0; i < len; i++) {
133:                        char c = line.charAt(i);
134:                        switch (c) {
135:                        case '&':
136:                            result.append("&amp;");
137:                            break;
138:                        case '<':
139:                            result.append("&lt;");
140:                            break;
141:                        default:
142:                            result.append(c);
143:                        }
144:                    }
145:                    out.println(result.toString());
146:                }
147:
148:                // Output footer:
149:                out.println("</pre></body></html>");
150:
151:                // Close streams:
152:                out.close();
153:                in.close();
154:            }
155:
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.