Source Code Cross Referenced for AbstractJava2HtmlConversion.java in  » Code-Analyzer » Java2Html » de » java2html » commandline » 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 » Code Analyzer » Java2Html » de.java2html.commandline 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.java2html.commandline;
002:
003:        import java.io.File;
004:        import java.io.FileInputStream;
005:        import java.io.FileOutputStream;
006:        import java.io.IOException;
007:        import java.io.InputStream;
008:        import java.io.StringWriter;
009:
010:        import de.java2html.converter.IJavaSourceConverter;
011:        import de.java2html.javasource.JavaSource;
012:        import de.java2html.javasource.JavaSourceParser;
013:        import de.java2html.options.JavaSourceConversionOptions;
014:        import de.java2html.util.Ensure;
015:        import de.java2html.util.IoUtilities;
016:
017:        /**
018:         * @author Markus Gebhard
019:         */
020:        public abstract class AbstractJava2HtmlConversion implements 
021:                IJava2HtmlConversion {
022:            private IJavaSourceConverter converter;
023:            private final JavaSourceConversionOptions options;
024:
025:            public AbstractJava2HtmlConversion(IJavaSourceConverter converter,
026:                    JavaSourceConversionOptions options) {
027:                Ensure.ensureArgumentNotNull(converter);
028:                Ensure.ensureArgumentNotNull(options);
029:                this .options = options;
030:                this .converter = converter;
031:            }
032:
033:            public final JavaSourceConversionOptions getConversionOptions() {
034:                return options;
035:            }
036:
037:            public final IJavaSourceConverter getConverter() {
038:                return converter;
039:            }
040:
041:            /**
042:             * Read the contents from the specified file name.
043:             * 
044:             * @param file
045:             * @return byte[]
046:             * @throws IOException
047:             */
048:            protected byte[] readFile(File file) throws IOException {
049:                InputStream inputStream = null;
050:                try {
051:                    inputStream = new FileInputStream(file);
052:                    return IoUtilities.readBytes(inputStream);
053:                } finally {
054:                    IoUtilities.close(inputStream);
055:                }
056:            }
057:
058:            /**
059:             * Invoke the converter on the specified file and return the converted contents.
060:             * 
061:             * @param sourceFile The file to be converted
062:             * @return a String containing the converted result
063:             * @throws IOException when there is an io error reading the file. */
064:            protected String readAndConvert(File sourceFile) throws IOException {
065:                StringWriter stringWriter = new StringWriter();
066:
067:                converter.writeDocumentHeader(stringWriter,
068:                        getConversionOptions(), ""); //$NON-NLS-1$
069:                JavaSourceParser parser = new JavaSourceParser(
070:                        getConversionOptions());
071:                JavaSource source = parser.parse(sourceFile);
072:                try {
073:                    converter.convert(source, getConversionOptions(),
074:                            stringWriter);
075:                } catch (IOException e) {
076:                    //Should never happen since we are a StringWriter
077:                    throw new RuntimeException(e);
078:                }
079:                converter.writeDocumentFooter(stringWriter,
080:                        getConversionOptions());
081:                return stringWriter.toString();
082:            }
083:
084:            /**
085:             * Converts the source file to the targetfile using the specified converter
086:             * 
087:             * @param sourceFile
088:             * @param targetFile the target file to write the output to or <code>null</code> if the converter
089:             * shall determine an appropriate name for the output file itself.
090:             */
091:            protected void convertFile(File sourceFile, File targetFile) {
092:                String text;
093:                try {
094:                    text = readAndConvert(sourceFile);
095:                } catch (IOException exception) {
096:                    //TODO Mar 11, 2004 (Markus Gebhard):
097:                    exception.printStackTrace();
098:                    return;
099:                }
100:                if (targetFile == null) {
101:                    targetFile = IoUtilities.exchangeFileExtension(sourceFile,
102:                            getConverter().getMetaData()
103:                                    .getDefaultFileExtension());
104:                }
105:
106:                IoUtilities.ensureFoldersExist(targetFile.getParentFile());
107:                try {
108:                    writeFile(targetFile, text.getBytes());
109:                } catch (IOException exception) {
110:                    //TODO Mar 11, 2004 (Markus Gebhard):
111:                    exception.printStackTrace();
112:                }
113:            }
114:
115:            /**
116:             * Write the contents to the specified file. If the file already exists it will be overwritten.
117:             * 
118:             * @param targetFile the file to write the contents to.
119:             * @param contents the bytes to be written.
120:             * @throws IOException if the is an error writing the file. */
121:            private void writeFile(File targetFile, byte[] contents)
122:                    throws IOException {
123:                FileOutputStream outputStream = null;
124:                try {
125:                    outputStream = new FileOutputStream(targetFile);
126:                    outputStream.write(contents);
127:                } finally {
128:                    IoUtilities.close(outputStream);
129:                }
130:            }
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.