Source Code Cross Referenced for Fo2HtmlResponsePostProcessor.java in  » J2EE » Enhydra-Application-Framework » org » enhydra » util » fo » 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 » J2EE » Enhydra Application Framework » org.enhydra.util.fo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package org.enhydra.util.fo;
004:
005:        import java.io.File;
006:
007:        import javax.xml.transform.Source;
008:        import javax.xml.transform.Transformer;
009:        import javax.xml.transform.TransformerFactory;
010:        import javax.xml.transform.dom.DOMResult;
011:        import javax.xml.transform.dom.DOMSource;
012:        import javax.xml.transform.stream.StreamSource;
013:
014:        import org.enhydra.util.ResponsePostProcessor;
015:        import org.enhydra.xml.io.OutputOptions;
016:        import org.w3c.dom.Node;
017:
018:        import com.lutris.logging.LogChannel;
019:        import com.lutris.logging.Logger;
020:        import com.lutris.util.Config;
021:        import com.lutris.util.ConfigException;
022:
023:        /**
024:         * @author Slobodan Vujasinovic
025:         * 
026:         */
027:        public class Fo2HtmlResponsePostProcessor implements 
028:                ResponsePostProcessor {
029:
030:            /*
031:             * Name of the post processor
032:             */
033:            private String name = null;
034:
035:            /**
036:             * LogChannel used by ResponsePostProcessor
037:             */
038:            private LogChannel logChannel;
039:
040:            /*
041:             * Name of the post processor supported mime type
042:             */
043:            public static final String mimeType = "text/fo+html";
044:
045:            /*
046:             * Name of the post processor generated mime type
047:             */
048:            public static final String outMimeType = "text/html";
049:
050:            // Chiba Adaptor attributes
051:            private static final String TEMPLATE_PARAM_NAME = "Fo2HtmlTemplatePath";
052:
053:            private static final String DEFAULT_TEMPLATE_PARAM_VALUE = "fo2html.xsl";
054:
055:            private String templatePath = null;
056:
057:            public Fo2HtmlResponsePostProcessor() {
058:                super ();
059:            }
060:
061:            public Fo2HtmlResponsePostProcessor(LogChannel logChannel) {
062:                super ();
063:                this .logChannel = logChannel;
064:            }
065:
066:            /*
067:             * (non-Javadoc)
068:             * 
069:             * @see org.enhydra.util.ResponsePostProcessor#configure(com.lutris.util.Config)
070:             */
071:            public void configure(Config config) {
072:                // do some property initialization
073:                // action is triggered on application startup
074:
075:                // templatePath = config.getString(TEMPLATE_PARAM_NAME,
076:                // DEFAULT_TEMPLATE_PARAM_VALUE);
077:                templatePath = getAbsolutePath(TEMPLATE_PARAM_NAME, config,
078:                        DEFAULT_TEMPLATE_PARAM_VALUE, false);
079:
080:                if (logChannel != null) {
081:                    logChannel.write(Logger.DEBUG, "Fo2Html Post Processor ("
082:                            + name + ") - Initialized successfully!");
083:                }
084:            }
085:
086:            /*
087:             * (non-Javadoc)
088:             * 
089:             * @see org.enhydra.util.ResponsePostProcessor#process(java.util.Map,
090:             *      org.w3c.dom.Node)
091:             */
092:            public Node process(OutputOptions oo, Node document) {
093:                try {
094:
095:                    if (logChannel != null) {
096:                        logChannel
097:                                .write(Logger.DEBUG, "Fo2Html Post Processor ("
098:                                        + name
099:                                        + ") - Processing parameters (if any)!");
100:                    }
101:
102:                    if (oo.getFreeformOption(TEMPLATE_PARAM_NAME) != null)
103:                        templatePath = (String) oo
104:                                .getFreeformOption(TEMPLATE_PARAM_NAME);
105:
106:                    if (logChannel != null) {
107:                        logChannel
108:                                .write(
109:                                        Logger.DEBUG,
110:                                        "Fo2Html Post Processor ("
111:                                                + name
112:                                                + ") - Processing response according to template - "
113:                                                + templatePath);
114:                    }
115:
116:                    File xslFile = new File(templatePath);
117:
118:                    // Setup XSLT
119:                    TransformerFactory factory = TransformerFactory
120:                            .newInstance();
121:                    Transformer transformer = factory
122:                            .newTransformer(new StreamSource(xslFile));
123:
124:                    Source src = new DOMSource(document);
125:
126:                    DOMResult res = new DOMResult();
127:
128:                    // Start XSLT transformation and FOP processing
129:                    transformer.transform(src, res);
130:
131:                    oo.setMIMEType("text/html");
132:
133:                    return res.getNode();
134:                } catch (Exception xfe) {
135:                    if (logChannel != null) {
136:                        logChannel
137:                                .write(
138:                                        Logger.WARNING,
139:                                        "Fo2Html Post Processor ("
140:                                                + name
141:                                                + ") - Problem occured during Html generation!",
142:                                        xfe);
143:                    }
144:                }
145:                // Failed to additionally process this document.
146:                // Therefore, we chose to return original one!
147:                return document;
148:
149:            }
150:
151:            /*
152:             * (non-Javadoc)
153:             * 
154:             * @see org.enhydra.util.ResponsePostProcessor#process(byte [],
155:             *      java.lang.String, java.lang.String)
156:             */
157:            public byte[] process(byte[] buteArray, String mimeEncoding,
158:                    String mimeType) {
159:                return buteArray;
160:            }
161:
162:            /*
163:             * (non-Javadoc)
164:             * 
165:             * @see org.enhydra.util.ResponsePostProcessor#setName(java.lang.String)
166:             */
167:            public void setName(String name) {
168:                this .name = name;
169:            }
170:
171:            /*
172:             * (non-Javadoc)
173:             * 
174:             * @see org.enhydra.util.ResponsePostProcessor#getName()
175:             */
176:            public String getName() {
177:                return name;
178:            }
179:
180:            /*
181:             * (non-Javadoc)
182:             * 
183:             * @see org.enhydra.util.RequestPreProcessor#setLogChannel()
184:             */
185:            public void setLogChannel(LogChannel logChannel) {
186:                this .logChannel = logChannel;
187:            }
188:
189:            /*
190:             * (non-Javadoc)
191:             * 
192:             * @see org.enhydra.util.RequestPreProcessor#getLogChannel()
193:             */
194:            public LogChannel getLogChannel() {
195:                return logChannel;
196:            }
197:
198:            /*
199:             * (non-Javadoc)
200:             * 
201:             * @see org.enhydra.util.ResponsePostProcessor#shouldProcess(java.lang.String)
202:             */
203:            public boolean shouldProcess(String mimeType) {
204:                if (mimeType != null
205:                        && mimeType
206:                                .startsWith(Fo2HtmlResponsePostProcessor.mimeType))
207:                    return true;
208:                return false;
209:            }
210:
211:            /*
212:             * (non-Javadoc)
213:             * 
214:             * @see org.enhydra.util.ResponsePostProcessor#getOutputMimeType()
215:             */
216:            public String getOutputMimeType() {
217:                return this .outMimeType;
218:            }
219:
220:            /**
221:             * Method returns absolute path to file (directory)!
222:             * 
223:             * @param Property
224:             *            Name
225:             * @param Configuration
226:             *            Object
227:             * @param Default
228:             *            Property Value
229:             * @param If
230:             *            This Is Directory
231:             * @return Absolute File Path
232:             */
233:            private String getAbsolutePath(String propName, Config config,
234:                    String defaultValue, boolean isDirectory) {
235:                String absoultePath = null;
236:                try {
237:                    absoultePath = config.getString(propName, defaultValue);
238:
239:                    if (absoultePath != null) {
240:                        File temp = new File(absoultePath);
241:
242:                        if ((!temp.isDirectory() && isDirectory)
243:                                || !temp.exists()) {
244:                            temp = new File(config.getConfigFile().getFile()
245:                                    .getParentFile().getAbsolutePath()
246:                                    + File.separator + absoultePath);
247:
248:                            if ((!temp.isDirectory() && isDirectory)
249:                                    || !temp.exists()) {
250:                                if (logChannel != null)
251:                                    logChannel
252:                                            .write(
253:                                                    Logger.WARNING,
254:                                                    propName
255:                                                            + " application parameter isn't properly initialized!");
256:
257:                            } else {
258:                                try {
259:                                    absoultePath = temp.getCanonicalPath();
260:                                } catch (Exception e) {
261:                                }
262:                            }
263:                        } else {
264:                            try {
265:                                absoultePath = temp.getCanonicalPath();
266:                            } catch (Exception e) {
267:                            }
268:                        }
269:                    }
270:                } catch (ConfigException e) {
271:                    if (logChannel != null) {
272:                        logChannel
273:                                .write(
274:                                        Logger.WARNING,
275:                                        propName
276:                                                + " application parameter isn't properly initialized!");
277:
278:                    }
279:                }
280:
281:                return absoultePath;
282:            }
283:
284:            public Object clone() {
285:                Fo2HtmlResponsePostProcessor f2hrpp = new Fo2HtmlResponsePostProcessor(
286:                        this.getLogChannel());
287:                f2hrpp.templatePath = this.templatePath;
288:                return f2hrpp;
289:            }
290:
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.