Source Code Cross Referenced for ThemeResourceLoader.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » ui » rendering » velocity » 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 » Blogger System » apache roller 3.1 » org.apache.roller.ui.rendering.velocity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  The ASF licenses this file to You
004:         * under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.  For additional information regarding
015:         * copyright in this work, please see the NOTICE file in the top level
016:         * directory of this distribution.
017:         */
018:        /*
019:         * ThemeResourceLoader.java
020:         *
021:         * Created on June 28, 2005, 12:25 PM
022:         */
023:
024:        package org.apache.roller.ui.rendering.velocity;
025:
026:        import java.io.ByteArrayInputStream;
027:        import java.io.InputStream;
028:        import java.io.UnsupportedEncodingException;
029:        import org.apache.commons.collections.ExtendedProperties;
030:        import org.apache.commons.logging.Log;
031:        import org.apache.commons.logging.LogFactory;
032:        import org.apache.velocity.exception.ResourceNotFoundException;
033:        import org.apache.velocity.runtime.resource.Resource;
034:        import org.apache.velocity.runtime.resource.loader.ResourceLoader;
035:        import org.apache.roller.RollerException;
036:        import org.apache.roller.business.ThemeNotFoundException;
037:        import org.apache.roller.business.RollerFactory;
038:        import org.apache.roller.business.ThemeManager;
039:        import org.apache.roller.pojos.Theme;
040:        import org.apache.roller.pojos.ThemeTemplate;
041:
042:        /**
043:         * The ThemeResourceLoader is a Velocity template loader which loads
044:         * templates from shared themes.
045:         *
046:         * @author Allen Gilliland
047:         */
048:        public class ThemeResourceLoader extends ResourceLoader {
049:
050:            private static Log mLogger = LogFactory.getFactory().getInstance(
051:                    ThemeResourceLoader.class);
052:
053:            public void init(ExtendedProperties configuration) {
054:                mLogger.debug(configuration);
055:            }
056:
057:            public InputStream getResourceStream(String name)
058:                    throws ResourceNotFoundException {
059:
060:                mLogger.debug("Looking up resource named ... " + name);
061:
062:                if (name == null || name.length() < 1) {
063:                    throw new ResourceNotFoundException(
064:                            "Need to specify a template name!");
065:                }
066:
067:                try {
068:                    // parse the name ... theme templates name are <theme>:<template>
069:                    String[] split = name.split(":", 2);
070:                    if (split.length < 2)
071:                        throw new ResourceNotFoundException(
072:                                "Invalid ThemeRL key " + name);
073:
074:                    // lookup the template from the proper theme
075:                    ThemeManager themeMgr = RollerFactory.getRoller()
076:                            .getThemeManager();
077:                    Theme theme = themeMgr.getTheme(split[0]);
078:                    ThemeTemplate template = theme.getTemplate(split[1]);
079:
080:                    if (template == null)
081:                        throw new ResourceNotFoundException("Template ["
082:                                + split[1]
083:                                + "] doesn't seem to be part of theme ["
084:                                + split[0] + "]");
085:
086:                    mLogger.debug("Resource found!");
087:
088:                    // return the input stream
089:                    return new ByteArrayInputStream(template.getContents()
090:                            .getBytes("UTF-8"));
091:
092:                } catch (UnsupportedEncodingException uex) {
093:                    // We expect UTF-8 in all JRE installation.
094:                    // This rethrows as a Runtime exception after logging.
095:                    mLogger.error(uex);
096:                    throw new RuntimeException(uex);
097:
098:                } catch (ThemeNotFoundException tnfe) {
099:                    String msg = "ThemeResourceLoader Error: "
100:                            + tnfe.getMessage();
101:                    mLogger.error(msg, tnfe);
102:                    throw new ResourceNotFoundException(msg);
103:
104:                } catch (RollerException re) {
105:                    String msg = "RollerResourceLoader Error: "
106:                            + re.getMessage();
107:                    mLogger.error(msg, re);
108:                    throw new ResourceNotFoundException(msg);
109:                }
110:            }
111:
112:            public boolean isSourceModified(Resource resource) {
113:                return (resource.getLastModified() != this 
114:                        .getLastModified(resource));
115:            }
116:
117:            public long getLastModified(Resource resource) {
118:                long last_mod = 0;
119:                String name = resource.getName();
120:
121:                mLogger
122:                        .debug("Checking last modified time for resource named ... "
123:                                + name);
124:
125:                if (name == null || name.length() < 1)
126:                    return last_mod;
127:
128:                try {
129:                    // parse the name ... theme templates name are <theme>:<template>
130:                    String[] split = name.split(":", 2);
131:                    if (split.length < 2)
132:                        return last_mod;
133:
134:                    // lookup the template from the proper theme
135:                    ThemeManager themeMgr = RollerFactory.getRoller()
136:                            .getThemeManager();
137:                    Theme theme = themeMgr.getTheme(split[0]);
138:                    ThemeTemplate template = theme.getTemplate(split[1]);
139:
140:                    if (template == null)
141:                        return last_mod;
142:
143:                    last_mod = template.getLastModified().getTime();
144:
145:                } catch (ThemeNotFoundException tnfe) {
146:                    // ignore
147:                } catch (RollerException re) {
148:                    // we don't like to see this happen, but oh well
149:                }
150:
151:                return last_mod;
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.