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


001:        package org.enhydra.util.formfaces;
002:
003:        import java.io.StringReader;
004:
005:        import javax.xml.parsers.DocumentBuilderFactory;
006:
007:        import org.enhydra.util.ResponsePostProcessor;
008:        import org.enhydra.xml.io.OutputOptions;
009:        import org.w3c.dom.Node;
010:        import org.w3c.dom.NodeList;
011:        import org.xml.sax.InputSource;
012:
013:        import com.lutris.logging.LogChannel;
014:        import com.lutris.logging.Logger;
015:        import com.lutris.util.Config;
016:
017:        public class FormFacesResponsePostProcessor implements 
018:                ResponsePostProcessor {
019:
020:            /*
021:             * Name of the post processor
022:             */
023:            private String name = null;
024:
025:            /**
026:             * LogChannel used by ResponsePostProcessor
027:             */
028:            private LogChannel logChannel;
029:
030:            /*
031:             * Name of the post processor supported mime type
032:             */
033:            public static final String mimeType = "text/xhtml+xforms";
034:
035:            /*
036:             * Name of the post processor generated mime type
037:             */
038:            public static final String outMimeType = "text/html";
039:
040:            /*
041:             * FormFaces Response Post Processor specific parameters
042:             */
043:            private static final String SCRIPT_PATH_PARAM_NAME = "ScriptPath";
044:
045:            private static final String DEFAULT_SCRIPT_PATH_PARAM_VALUE = "formfaces.js";
046:
047:            private static final String CSS_PATH_PARAM_NAME = "CssPath";
048:
049:            private static final String DEFAULT_CSS_PATH_PARAM_VALUE = null;
050:
051:            private String scriptPath = null;
052:
053:            private String cssPath = null;
054:
055:            public FormFacesResponsePostProcessor() {
056:                super ();
057:            }
058:
059:            public FormFacesResponsePostProcessor(LogChannel logChannel) {
060:                super ();
061:                this .logChannel = logChannel;
062:            }
063:
064:            public void configure(Config config) {
065:                try {
066:                    scriptPath = config.getString(SCRIPT_PATH_PARAM_NAME,
067:                            DEFAULT_SCRIPT_PATH_PARAM_VALUE);
068:
069:                    cssPath = config.getString(CSS_PATH_PARAM_NAME,
070:                            DEFAULT_CSS_PATH_PARAM_VALUE);
071:
072:                    if (logChannel != null) {
073:                        logChannel.write(Logger.DEBUG, "FormFaces Processor ("
074:                                + name + ") - Initialized successfully!");
075:                    }
076:                } catch (Exception fe) {
077:                    if (logChannel != null) {
078:                        logChannel
079:                                .write(
080:                                        Logger.WARNING,
081:                                        "FormFaces Processor ("
082:                                                + name
083:                                                + ") - Initialized with default configuration settings!",
084:                                        fe);
085:                    }
086:
087:                    // Applying default values
088:                    scriptPath = DEFAULT_SCRIPT_PATH_PARAM_VALUE;
089:                    cssPath = DEFAULT_CSS_PATH_PARAM_VALUE;
090:                }
091:            }
092:
093:            public Node process(OutputOptions oo, Node document) {
094:                try {
095:                    if (logChannel != null) {
096:                        logChannel
097:                                .write(
098:                                        Logger.DEBUG,
099:                                        "FormFaces Post Processor ("
100:                                                + name
101:                                                + ") - Processing parameters (if any)!");
102:                    }
103:
104:                    if (oo.getFreeformOption(SCRIPT_PATH_PARAM_NAME) != null)
105:                        scriptPath = (String) oo
106:                                .getFreeformOption(SCRIPT_PATH_PARAM_NAME);
107:
108:                    if (logChannel != null) {
109:                        logChannel.write(Logger.DEBUG,
110:                                "FormFaces Post Processor (" + name
111:                                        + ") - Generating output!");
112:                    }
113:
114:                    Node head = findHeadNode(document);
115:
116:                    if (head != null) {
117:                        DocumentBuilderFactory dbf = DocumentBuilderFactory
118:                                .newInstance();
119:                        dbf.setNamespaceAware(true);
120:
121:                        Node script = dbf.newDocumentBuilder()
122:                                .parse(
123:                                        new InputSource(new StringReader(
124:                                                "<script type=\"text/javascript\" src=\""
125:                                                        + scriptPath
126:                                                        + "\"></script>")));
127:                        head.appendChild(head.getOwnerDocument().importNode(
128:                                script.getFirstChild(), true));
129:                        if (cssPath != null) {
130:                            Node css = dbf.newDocumentBuilder().parse(
131:                                    new InputSource(new StringReader(
132:                                            "<link rel=\"stylesheet\" type=\"text/css\" href=\""
133:                                                    + cssPath + "\" />")));
134:                            head.appendChild(head.getOwnerDocument()
135:                                    .importNode(css.getFirstChild(), true));
136:                        }
137:                    }
138:
139:                    oo.setEnableXHTMLCompatibility(true);
140:                    oo.setUseAposEntity(false);
141:
142:                    oo.setMIMEType("text/html");
143:
144:                    return document;
145:                } catch (Exception xfce) {
146:                    xfce.printStackTrace();
147:                }
148:
149:                // Failed to additionally process this document.
150:                // Therefore, we chose to return original one!
151:                return document;
152:            }
153:
154:            public byte[] process(byte[] buteArray, String mimeEncoding,
155:                    String mimeType) {
156:                return buteArray;
157:            }
158:
159:            public void setName(String name) {
160:                this .name = name;
161:            }
162:
163:            public String getName() {
164:                return name;
165:            }
166:
167:            public boolean shouldProcess(String mimeType) {
168:                if (mimeType != null
169:                        && mimeType
170:                                .startsWith(FormFacesResponsePostProcessor.mimeType))
171:                    return true;
172:                return false;
173:            }
174:
175:            public void setLogChannel(LogChannel logChannel) {
176:                this .logChannel = logChannel;
177:            }
178:
179:            public LogChannel getLogChannel() {
180:                return logChannel;
181:            }
182:
183:            public String getOutputMimeType() {
184:                return this .outMimeType;
185:            }
186:
187:            /**
188:             * Method returns HEAD node if it is found in source node subtree
189:             * 
190:             * @param document
191:             *            To search for HEAD node in
192:             * @return HEAD node
193:             */
194:            private Node findHeadNode(Node sourceNode) {
195:                if (sourceNode != null) {
196:                    NodeList nl = sourceNode.getChildNodes();
197:                    if (nl != null) {
198:                        for (int i = 0; i < nl.getLength(); i++) {
199:                            if ("HEAD".equalsIgnoreCase(nl.item(i)
200:                                    .getNodeName())) {
201:                                return nl.item(i);
202:                            } else {
203:                                Node temp = findHeadNode(nl.item(i));
204:                                if (temp != null) {
205:                                    return temp;
206:                                }
207:                            }
208:                        }
209:                    }
210:                }
211:                return null;
212:            }
213:
214:            public Object clone() {
215:                FormFacesResponsePostProcessor ffrpp = new FormFacesResponsePostProcessor(
216:                        this.getLogChannel());
217:                ffrpp.scriptPath = this.scriptPath;
218:                ffrpp.cssPath = this.cssPath;
219:                return ffrpp;
220:            }
221:
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.