Source Code Cross Referenced for HTMLExporter.java in  » XML-UI » xui32 » com » xoetrope » export » html » 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 » XML UI » xui32 » com.xoetrope.export.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.export.html;
002:
003:        import com.xoetrope.export.*;
004:        import com.xoetrope.export.TagExporter;
005:        import com.xoetrope.export.util.FileCopy;
006:        import java.awt.Color;
007:        import java.io.File;
008:        import java.io.FileOutputStream;
009:        import java.util.Enumeration;
010:        import java.util.Hashtable;
011:        import java.util.Vector;
012:        import net.xoetrope.xui.XProject;
013:        import net.xoetrope.xui.XProjectManager;
014:        import net.xoetrope.xui.style.XStyle;
015:        import net.xoetrope.xui.style.XStyleManager;
016:
017:        /**
018:         * Exporter for exporting to HTML files.
019:         *
020:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
021:         * the GNU Public License (GPL), please see license.txt for more details. If
022:         * you make commercial use of this software you must purchase a commercial
023:         * license from Xoetrope.</p>
024:         * <p> $Revision: 1.7 $</p>
025:         */
026:        public class HTMLExporter extends Exporter {
027:
028:            /**
029:             * Hashtable of styles which are referenced by the export. Used to form the 
030:             * styles tag of the document
031:             */
032:            protected Hashtable styles;
033:
034:            /**
035:             * The name of the file which will be generated.
036:             */
037:            protected String exportFileName;
038:
039:            /**
040:             * Constructor creates the hashtable for the styles
041:             * @param instance the current page or object that provides the methods or fields used in the evaluation
042:             */
043:            public HTMLExporter(XProject project, Object instance) {
044:                super (project, instance);
045:                styles = new Hashtable();
046:            }
047:
048:            /**
049:             * Get the content type supported by this exporter
050:             * @return "HTML"
051:             */
052:            public String getContentType() {
053:                return "HTML";
054:            }
055:
056:            /**
057:             * Overloaded from the base abstract function. Retrieve a new 
058:             * HTMLTableBlock from this exporter.
059:             * @return a new TableBlock Object
060:             */
061:            public TableBlock getTableBlock() {
062:                return new HTMLTableBlock();
063:            }
064:
065:            /**
066:             * Overloaded from the base abstract function. Retrieve a new 
067:             * HTMLTableModelBlock from this exporter.
068:             * @return a new TableModelBlock Object
069:             */
070:            public TableModelBlock getTableModelBlock() {
071:                return new HTMLTableModelBlock();
072:            }
073:
074:            /**
075:             * Overloaded from the base abstract function. Retrieve a new 
076:             * HTMLArrayArrayBlock from this exporter.
077:             * @return a new ArrayArrayBlock Object
078:             */
079:            public ArrayArrayBlock getArrayArrayBlock() {
080:                return new HTMLArrayArrayBlock(this );
081:            }
082:
083:            /**
084:             * Overloaded from the base abstract function. Retrieve a new 
085:             * HTMLFragmentBlock from this exporter.
086:             * @return a new FragmentBlock Object
087:             */
088:            public FragmentBlock getFragmentBlock() {
089:                return new HTMLFragmentBlock();
090:            }
091:
092:            /**
093:             * Overloaded from the base abstract function. Retrieve a new 
094:             * HTMLFreeFormBlock from this exporter.
095:             * @return a new FreeFormBlock Object
096:             */
097:            public Block getFreeFormBlock() {
098:                return new HTMLFreeFormItem();
099:            }
100:
101:            /**
102:             * Export to the named file.
103:             * @param fileName the name of the file to be exported to.
104:             */
105:            public void export(String fileName) {
106:                exportFileName = fileName;
107:                StringBuffer blockContents = new StringBuffer();
108:                int numItems = blocks.size();
109:                for (int i = 0; i < numItems; i++) {
110:                    Block Block = (Block) blocks.get(i);
111:                    exportBlock(Block, blockContents);
112:                    if (Block instanceof  HTMLTableModelBlock) {
113:                        String style = ((HTMLTableModelBlock) Block)
114:                                .getTableStyle();
115:                        styles.put(style, style);
116:                        String headerStyle = ((HTMLTableModelBlock) Block)
117:                                .getHeaderStyle();
118:                        if (headerStyle != null)
119:                            styles.put(headerStyle, headerStyle);
120:                    }
121:                }
122:                content.append("<HTML>");
123:                content.append("<HEAD>");
124:                content.append(generateStyleInfo());
125:                content.append("</HEAD>");
126:                content.append("<BODY>");
127:                content.append(blockContents.toString());
128:                content.append("</BODY>");
129:                content.append("</HTML>");
130:                writeToFile(fileName, content);
131:            }
132:
133:            private void exportBlock(Block Block, StringBuffer content) {
134:                content.append(((TagExporter) Block).getStartTag());
135:                Vector blockItems = Block.getBlocks();
136:                int numItems = blockItems.size();
137:                for (int item = 0; item < numItems; item++) {
138:                    HTMLBlockItem blockItem = (HTMLBlockItem) blockItems
139:                            .get(item);
140:                    exportItem(blockItem, content);
141:                }
142:                content.append(((TagExporter) Block).getEndTag());
143:            }
144:
145:            private void exportItem(HTMLBlockItem blockItem,
146:                    StringBuffer content) {
147:                content.append(blockItem.getStartText());
148:                if (blockItem.getStyle() != null)
149:                    styles.put(blockItem.getStyle(), blockItem.getStyle());
150:
151:                Vector subBlockItems = blockItem.getBlocks();
152:                int numSubItems = subBlockItems.size();
153:                for (int i = 0; i < numSubItems; i++) {
154:                    HTMLBlockItem subBlockItem = (HTMLBlockItem) subBlockItems
155:                            .get(i);
156:                    exportItem(subBlockItem, content);
157:                }
158:                if ((blockItem.getTag() != null)
159:                        && (blockItem.getTag().compareTo(
160:                                HTMLFreeFormBlock.TAG_IMG) == 0)) {
161:                    String src = blockItem.getAttrib(Block.ATTRIB_SRC);
162:                    File file = new File(exportFileName);
163:                    String path = file.getParent();
164:                    FileCopy.copyFile(currentProject, src, path
165:                            + File.separatorChar + src);
166:                }
167:                content.append(blockItem.getEndTag());
168:            }
169:
170:            /**
171:             * Overloaded from the base abstract function. Retrieve the file extension 
172:             * '.html'
173:             */
174:            public String getFileExtension() {
175:                return ".html";
176:            }
177:
178:            public void writeToFile(String fileName, StringBuffer content) {
179:                try {
180:                    FileOutputStream fos = new FileOutputStream(fileName);
181:                    fos.write(content.toString().getBytes());
182:                    fos.flush();
183:                    fos.close();
184:                } catch (Exception e) {
185:                    e.printStackTrace();
186:                }
187:            }
188:
189:            private String generateStyleInfo() {
190:                StringBuffer styleInfo = new StringBuffer("<STYLE>");
191:                XStyleManager styleMgr = XProjectManager.getStyleManager();
192:                if (styleMgr != null) {
193:                    Enumeration keys = styles.keys();
194:                    while (keys.hasMoreElements()) {
195:                        String style = (String) keys.nextElement();
196:                        XStyle xStyle = styleMgr.getStyle(style);
197:                        String fontFace = xStyle
198:                                .getStyleAsString(XStyle.FONT_FACE);
199:                        String fontSize = xStyle
200:                                .getStyleAsString(XStyle.FONT_SIZE);
201:                        String fontWeight = xStyle
202:                                .getStyleAsString(XStyle.FONT_WEIGHT);
203:                        String fontItalic = xStyle
204:                                .getStyleAsString(XStyle.FONT_ITALIC);
205:                        Color colourFore = xStyle
206:                                .getStyleAsColor(XStyle.COLOR_FORE);
207:                        Color colourBack = xStyle
208:                                .getStyleAsColor(XStyle.COLOR_BACK);
209:                        styleInfo
210:                                .append("." + style.replaceAll("/", "_") + "{");
211:                        if (fontFace != null)
212:                            styleInfo.append("FONT-FAMILY: " + fontFace + ";");
213:                        if (fontSize != null)
214:                            styleInfo.append("FONT-SIZE: " + fontSize + ";");
215:                        if (fontWeight != null)
216:                            styleInfo
217:                                    .append("FONT-WEIGHT: "
218:                                            + ((fontWeight.compareTo("1") == 0) ? "bold"
219:                                                    : "normal") + ";");
220:                        if (fontItalic != null)
221:                            styleInfo
222:                                    .append("FONT-STYLE: "
223:                                            + ((fontItalic.compareTo("1") == 0) ? "italic"
224:                                                    : "normal") + ";");
225:                        if (colourFore != null)
226:                            styleInfo.append("COLOR: #"
227:                                    + getHexColour(colourFore) + ";");
228:                        if (colourBack != null)
229:                            styleInfo.append("BACKGROUND: #"
230:                                    + getHexColour(colourBack) + ";");
231:                        styleInfo.append("}");
232:                    }
233:
234:                    styleInfo.append("</STYLE>");
235:                    return styleInfo.toString();
236:                } else {
237:                    return "";
238:                }
239:            }
240:
241:            private String getHexColour(Color colour) {
242:                String r = getColour(colour.getRed());
243:                String g = getColour(colour.getGreen());
244:                String b = getColour(colour.getBlue());
245:                return r + g + b;
246:            }
247:
248:            private String getColour(int value) {
249:                String ret = Integer.toHexString(value);
250:                if (ret.length() == 1)
251:                    ret = "0" + ret;
252:                return ret;
253:            }
254:
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.