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


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