Source Code Cross Referenced for AddResource.java in  » J2EE » ICEfaces-1.6.1 » com » icesoft » faces » utils » 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 » ICEfaces 1.6.1 » com.icesoft.faces.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003:         *
004:         * "The contents of this file are subject to the Mozilla Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License at
007:         * http://www.mozilla.org/MPL/
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011:         * License for the specific language governing rights and limitations under
012:         * the License.
013:         *
014:         * The Original Code is ICEfaces 1.5 open source software code, released
015:         * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016:         * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017:         * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018:         *
019:         * Contributor(s): _____________________.
020:         *
021:         * Alternatively, the contents of this file may be used under the terms of
022:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023:         * License), in which case the provisions of the LGPL License are
024:         * applicable instead of those above. If you wish to allow use of your
025:         * version of this file only under the terms of the LGPL License and not to
026:         * allow others to use your version of this file under the MPL, indicate
027:         * your decision by deleting the provisions above and replace them with
028:         * the notice and other provisions required by the LGPL License. If you do
029:         * not delete the provisions above, a recipient may use your version of
030:         * this file under either the MPL or the LGPL License."
031:         *
032:         */
033:
034:        package com.icesoft.faces.utils;
035:
036:        import com.icesoft.faces.context.DOMContext;
037:        import com.icesoft.faces.renderkit.dom_html_basic.HTML;
038:        import org.w3c.dom.Document;
039:        import org.w3c.dom.Element;
040:        import org.w3c.dom.Node;
041:        import org.w3c.dom.NodeList;
042:        import org.w3c.dom.Text;
043:
044:        import java.util.Iterator;
045:        import java.util.List;
046:
047:        /**
048:         * This utility class uses DOM methods to render javascript and css resources to
049:         * the page.
050:         *
051:         * @author gmccleary
052:         */
053:        public final class AddResource {
054:
055:            private static final int TEXT_NODE_TYPE = 3;
056:            private static final String LINK_ELM = "link";
057:
058:            private AddResource() {
059:
060:            }
061:
062:            // Methods to Add Javascript and CSS resources
063:
064:            /**
065:             * Adds the given javascript to the given node
066:             *
067:             * @param parentNode
068:             * @param resourceDirectory
069:             * @param scriptFileName
070:             * @param domContext
071:             */
072:            public static void addJavaScriptToNode(Node parentNode,
073:                    String resourceDirectory, String scriptFileName,
074:                    DOMContext domContext) {
075:                // scan the given node for script elements
076:                Element jsElement = null;
077:                List scripts = DOMContext.findChildrenWithNodeName(
078:                        (Element) parentNode, HTML.SCRIPT_ELEM);
079:                Iterator scriptIterator = scripts.iterator();
080:
081:                while (scriptIterator.hasNext()) {
082:                    Element next = (Element) scriptIterator.next();
083:                    if (next.getAttribute("src").equalsIgnoreCase(
084:                            resourceDirectory + scriptFileName)) {
085:                        jsElement = next;
086:                    }
087:                }
088:                // if js script already exists, then don't add it
089:                if (jsElement == null) {
090:                    jsElement = domContext.getDocument().createElement(
091:                            HTML.SCRIPT_ELEM);
092:                    jsElement.setAttribute(HTML.SRC_ATTR, resourceDirectory
093:                            + scriptFileName);
094:                    jsElement.setAttribute("language", "javascript");
095:
096:                    parentNode.appendChild(jsElement);
097:                }
098:            }
099:
100:            /**
101:             * Adds the given javascript resource to the head node
102:             *
103:             * @param resourceDirectory
104:             * @param scriptFileName
105:             * @param domContext
106:             */
107:            public static void addJavaScriptToHead(String resourceDirectory,
108:                    String scriptFileName, DOMContext domContext) {
109:                // extract the head node from the document
110:                Document test = domContext.getDocument();
111:                NodeList heads = test.getElementsByTagName("head");
112:                Node headNode = null;
113:                if (heads.getLength() > 0) {
114:                    headNode = heads.item(0);
115:                } else { // no head exists , create one
116:                    Element head = domContext.createElement("head");
117:                    test.appendChild(head);
118:                    headNode = (Node) head;
119:                }
120:                addJavaScriptToNode(headNode, resourceDirectory,
121:                        scriptFileName, domContext);
122:            }
123:
124:            /**
125:             * Adds the given stylesheet resource to the head
126:             *
127:             * @param resourceDirectory
128:             * @param cssFileName
129:             * @param domContext
130:             */
131:            public static void addStyleSheetToHead(String resourceDirectory,
132:                    String cssFileName, DOMContext domContext) {
133:
134:                Document test = domContext.getDocument();
135:
136:                NodeList heads = test.getElementsByTagName("head");
137:
138:                Node headNode = heads.item(0);
139:
140:                // if stylesheet link already exists, then don't add it
141:                Element styleElement = null;
142:                List links = DOMContext.findChildrenWithNodeName(
143:                        (Element) headNode, LINK_ELM);
144:                Iterator linkIterator = links.iterator();
145:
146:                while (linkIterator.hasNext()) {
147:                    Element next = (Element) linkIterator.next();
148:                    if (next.getAttribute("href").equalsIgnoreCase(
149:                            resourceDirectory + cssFileName)) {
150:                        styleElement = next;
151:                    }
152:                }
153:
154:                if (styleElement == null) {
155:                    styleElement = domContext.getDocument().createElement(
156:                            LINK_ELM);
157:                    styleElement.setAttribute(HTML.HREF_ATTR, resourceDirectory
158:                            + cssFileName);
159:                    styleElement.setAttribute("type", "text/css");
160:                    styleElement.setAttribute("rel", "stylesheet");
161:
162:                    headNode.appendChild(styleElement);
163:                }
164:            }
165:
166:            /**
167:             * Adds the given inline style to the head
168:             *
169:             * @param inlineStyle
170:             * @param domContext
171:             */
172:            public static void addInlineStyleToHead(String inlineStyle,
173:                    DOMContext domContext) {
174:                // extract the head from the document element
175:                Document test = domContext.getDocument();
176:                NodeList heads = test.getElementsByTagName("head");
177:                Node headNode = heads.item(0);
178:
179:                // extract style elements from head
180:                Element styleElement = null;
181:                List styles = DOMContext.findChildrenWithNodeName(
182:                        (Element) headNode, HTML.STYLE_ELEM);
183:                Iterator styleIterator = styles.iterator();
184:
185:                while (styleIterator.hasNext()) {
186:                    Element next = (Element) styleIterator.next();
187:                    if (next.hasChildNodes()) {
188:                        if (next.getFirstChild().getNodeType() == TEXT_NODE_TYPE) {
189:                            Text styleText = (Text) next.getFirstChild();
190:                            if (styleText.getNodeValue().equalsIgnoreCase(
191:                                    inlineStyle)) {
192:                                styleElement = next;
193:                            }
194:                        }
195:                    }
196:                }
197:                // if inline style already exists, then don't add it
198:                if (styleElement == null) {
199:                    styleElement = domContext.getDocument().createElement(
200:                            HTML.STYLE_ELEM);
201:                    styleElement.setAttribute("type", "text/css");
202:                    styleElement.setAttribute("rel", "stylesheet");
203:                    Text inlineText = domContext.createTextNode(inlineStyle);
204:                    styleElement.appendChild(inlineText);
205:                    headNode.appendChild(styleElement);
206:                }
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.