Source Code Cross Referenced for SInclude.java in  » Swing-Library » Swinglets » com » javelin » swinglets » 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 » Swing Library » Swinglets » com.javelin.swinglets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Javelin Software, All rights reserved.
003:         */
004:
005:        package com.javelin.swinglets;
006:
007:        import java.awt.*;
008:        import java.util.*;
009:        import java.io.*;
010:        import java.net.*;
011:        import javax.servlet.*;
012:
013:        /**
014:         * SInclude lets you do server side includes easily
015:         * 
016:         * @author Robin Sharp
017:         */
018:
019:        public class SInclude extends SComponent {
020:            /**
021:             * Construct an unqualified include. 
022:             * <p>
023:             * The url or URL or File or Class, Path mut be set.
024:             */
025:            public SInclude() {
026:            }
027:
028:            /**
029:             * Construct a fully qualified include from a url.
030:             */
031:            public SInclude(String url) {
032:                this .url = getSwingletManager().getRealPath() + url;
033:            }
034:
035:            /**
036:             * Construct a fully qualified include from a file.
037:             */
038:            public SInclude(File file) {
039:                this .file = file;
040:            }
041:
042:            /**
043:             * Construct a fully qualified include from a url.
044:             */
045:            public SInclude(URL url) {
046:                this .url = url.toExternalForm();
047:            }
048:
049:            /**
050:             * Construct a fully qualified include from a class and path.
051:             */
052:            public SInclude(Class relativeClass, String path) {
053:                this .relativeClass = relativeClass;
054:                this .path = path;
055:            }
056:
057:            /**
058:             * Is this a file
059:             */
060:            public boolean isFile() {
061:                return file != null;
062:            }
063:
064:            /**
065:             * Is this a URL
066:             */
067:            public boolean isURL() {
068:                return url != null;
069:            }
070:
071:            /**
072:             * Is this a relative file
073:             */
074:            public boolean isRelative() {
075:                return relativeClass != null && path != null;
076:            }
077:
078:            /**
079:             * Get the URL
080:             */
081:            public String getUrl() {
082:                return url;
083:            }
084:
085:            /**
086:             * Set the URL
087:             */
088:            public SInclude setUrl(URL url) {
089:                return setUrl(url.toExternalForm());
090:            }
091:
092:            /**
093:             * Set the URL
094:             */
095:            public SInclude setUrl(String url) {
096:                this .url = url;
097:
098:                this .file = null;
099:                this .relativeClass = null;
100:                this .path = null;
101:
102:                return this ;
103:            }
104:
105:            /**
106:             * Get the File
107:             */
108:            public File getFile() {
109:                return file;
110:            }
111:
112:            /**
113:             * Set the File.
114:             */
115:            public SInclude setFile(File file) {
116:                this .file = file;
117:
118:                this .url = null;
119:                this .relativeClass = null;
120:                this .path = null;
121:
122:                return this ;
123:            }
124:
125:            /**
126:             * Get the Relative Class
127:             */
128:            public Class getRelativeClass() {
129:                return relativeClass;
130:            }
131:
132:            /**
133:             * Set the Relative Class.
134:             */
135:            public SInclude setRelativeClass(Class relativeClass) {
136:                this .relativeClass = relativeClass;
137:
138:                this .url = null;
139:                this .file = null;
140:
141:                return this ;
142:            }
143:
144:            /**
145:             * Get the Path.
146:             */
147:            public String getRelativePath() {
148:                return path;
149:            }
150:
151:            /**
152:             * Set the Path.
153:             */
154:            public SInclude setPath(String path) {
155:                this .path = path;
156:
157:                this .url = null;
158:                this .file = null;
159:
160:                return this ;
161:            }
162:
163:            /**
164:             * By default the output is included as is, exact copy, char by char.
165:             * But if verbatim is set to false then the text is readin/writeout line by line
166:             */
167:            public SInclude setVerbatim(boolean verbatim) {
168:                this .verbatim = verbatim;
169:                return this ;
170:            }
171:
172:            /**
173:             * Is the output readin/writeout char by char.
174:             */
175:            public boolean isVerbatim() {
176:                return verbatim;
177:            }
178:
179:            /**
180:             * By default the output is included as is, and the look and feel
181:             * interprets the text. If preformatted is true the look and feel
182:             * does not intrepret the text. (e.g. <PRE> in html).
183:             */
184:            public SInclude setPreformatted(boolean preformatted) {
185:                this .preformatted = preformatted;
186:                return this ;
187:            }
188:
189:            /**
190:             * Is the include prefromatted.
191:             */
192:            public boolean isPreformatted() {
193:                return preformatted;
194:            }
195:
196:            /**
197:             * Returns the name of the L&F class that renders this component.
198:             */
199:            public Class getUIClass() {
200:                return SInclude.class;
201:            }
202:
203:            public String toString() {
204:                BufferedReader in = null;
205:                StringBuffer srcBuf;
206:
207:                try {
208:                    if (file != null) {
209:                        in = new BufferedReader(new FileReader(file));
210:                    } else if (url != null) {
211:                        java.net.URL realUrl = new URL(url);
212:                        in = new BufferedReader(new InputStreamReader(realUrl
213:                                .openStream()));
214:                    } else if (relativeClass != null && path != null) {
215:                        in = new BufferedReader(new InputStreamReader(
216:                                relativeClass.getResourceAsStream(path)));
217:                    } else {
218:                        return "";
219:                    }
220:
221:                    srcBuf = new StringBuffer(1024);
222:                    if (verbatim) {
223:                        int val;
224:                        while ((val = in.read()) != -1) {
225:                            srcBuf.append((char) val);
226:                        }
227:                    } else {
228:                        String s;
229:                        while ((s = in.readLine()) != null) {
230:                            srcBuf.append(s).append((char) '\n');
231:                        }
232:                    }
233:                    return srcBuf.toString();
234:                } catch (Exception ex) {
235:                    //ex.printStackTrace();
236:                } finally {
237:                    if (in != null) {
238:                        try {
239:                            in.close();
240:                        } catch (Exception ex2) {
241:
242:                        }
243:                    }
244:                }
245:
246:                return "";
247:            }
248:
249:            // PROTECTED ////////////////////////////////////////////////////
250:
251:            protected String url;
252:            protected File file;
253:            protected Class relativeClass;
254:            protected String path;
255:
256:            boolean verbatim = true;
257:            boolean preformatted = false;
258:
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.