Source Code Cross Referenced for ClassPathStylesheetResource.java in  » Swing-Library » wings3 » org » wings » resource » 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 » wings3 » org.wings.resource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2005 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:        package org.wings.resource;
014:
015:        import org.apache.commons.logging.Log;
016:        import org.apache.commons.logging.LogFactory;
017:        import org.wings.Resource;
018:        import org.wings.externalizer.ExternalizeManager;
019:        import org.wings.session.SessionManager;
020:
021:        import java.io.IOException;
022:        import java.io.InputStream;
023:
024:        /**
025:         * A ClassPathStylesheetResource is a static resource whose content is
026:         * read from a classloader. It is special for its handling of occurences
027:         * of "url([classPath])" strings. These are read from classPath and 
028:         * externalized.
029:         *
030:         * @author ole
031:         * @version $$
032:         */
033:        public class ClassPathStylesheetResource extends ClassPathResource {
034:            private final transient static Log log = LogFactory
035:                    .getLog(ClassPathStylesheetResource.class);
036:            /**
037:             * The default max size for the buffer. since we do some replacement every time we
038:             * read the input stream, we want this to be high, so we can cache the
039:             * interpreted style sheet.
040:             */
041:            private static final int MAX_BUFFER_SIZE = 24 * 1024; // 24kb
042:
043:            private transient ExternalizeManager extManager;
044:
045:            /**
046:             * A static css resource that is obtained from the default classpath.
047:             */
048:            public ClassPathStylesheetResource(String resourceFileName) {
049:                this (Thread.currentThread().getContextClassLoader(),
050:                        resourceFileName, "unkonwn");
051:            }
052:
053:            /**
054:             * A static css resource that is obtained from the default classpath.
055:             */
056:            public ClassPathStylesheetResource(String resourceFileName,
057:                    String mimeType) {
058:                this (Thread.currentThread().getContextClassLoader(),
059:                        resourceFileName, mimeType);
060:            }
061:
062:            /**
063:             * A static css resource that is obtained from the specified class loader
064:             *
065:             * @param classLoader      the classLoader from which the resource is obtained
066:             * @param resourceFileName the css resource relative to the baseClass
067:             */
068:            public ClassPathStylesheetResource(ClassLoader classLoader,
069:                    String resourceFileName) {
070:                this (classLoader, resourceFileName, "unknown");
071:            }
072:
073:            /**
074:             * A static css resource that is obtained from the specified class loader
075:             *
076:             * @param classLoader      the classLoader from which the resource is obtained
077:             * @param resourceFileName the css resource relative to the baseClass
078:             * @param mimeType         the mimetype of the resource
079:             */
080:            public ClassPathStylesheetResource(ClassLoader classLoader,
081:                    String resourceFileName, String mimeType) {
082:                this (classLoader, resourceFileName, mimeType, MAX_BUFFER_SIZE);
083:            }
084:
085:            /**
086:             * A static css resource that is obtained from the specified class loader
087:             *
088:             * @param classLoader      the classLoader from which the resource is obtained
089:             * @param resourceFileName the css resource relative to the baseClass
090:             * @param mimeType         the mimetype of the resource
091:             * @param maxBufferSize    the maximum buffer size for the style sheet. If
092:             *                         big enough, stylesheet is cached, else parsed again. 
093:             */
094:            public ClassPathStylesheetResource(ClassLoader classLoader,
095:                    String resourceFileName, String mimeType, int maxBufferSize) {
096:                super (classLoader, resourceFileName, mimeType);
097:                // need to set it here, because at this moment there is a session in the sessionManager
098:                extManager = SessionManager.getSession()
099:                        .getExternalizeManager();
100:                // we need a bigger buffer, so that the parsing only happens once
101:                setMaxBufferSize(maxBufferSize);
102:            }
103:
104:            /* (non-Javadoc)
105:             * @see org.wings.StaticResource#getResourceStream()
106:             */
107:            @Override
108:            protected final InputStream getResourceStream()
109:                    throws ResourceNotFoundException {
110:                InputStream in = getClassLoader().getResourceAsStream(
111:                        resourceFileName);
112:                if (in != null) {
113:                    return new CssUrlFilterInputStream(in, getExtManager());
114:                } else {
115:                    throw new ResourceNotFoundException(
116:                            "Unable to find classpath resource "
117:                                    + resourceFileName);
118:                }
119:            }
120:
121:            /*
122:             * the equal() and hashCode() method make sure, that the same resources
123:             * get the same name in the SystemExternalizer.
124:             */
125:
126:            /**
127:             * Two ClassPathStylesheetResource are equal if both of them are instances
128:             * of ClassPathStylesheetResource and the equals method of ClassPathResource
129:             * is true.
130:             *
131:             * @return true if the two instances are equal.
132:             */
133:            public boolean equals(Object o) {
134:                if (o instanceof  ClassPathStylesheetResource) {
135:                    if (super .equals(o)) {
136:                        return true;
137:                    }
138:                }
139:                return false;
140:            }
141:
142:            /**
143:             * Simple hascode implementation
144:             */
145:            public int hashCode() {
146:                return super .hashCode();
147:            }
148:
149:            /* (non-Javadoc)
150:             * @see org.wings.StaticResource#bufferResource()
151:             */
152:            @Override
153:            protected LimitedBuffer bufferResource() throws IOException,
154:                    ResourceNotFoundException {
155:                try {
156:                    return super .bufferResource();
157:                } catch (IOException e) {
158:                    log.error("Unable to retrieve css file from classpath: '"
159:                            + resourceFileName);
160:                    throw e;
161:                }
162:            }
163:
164:            private ExternalizeManager getExtManager() {
165:                if (extManager == null)
166:                    // need to set it here, because at this moment there is a session in the sessionManager
167:                    extManager = SessionManager.getSession()
168:                            .getExternalizeManager();
169:                return extManager;
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.