Source Code Cross Referenced for ReportUtils.java in  » Report » pentaho-report » org » pentaho » plugin » jfreereport » helper » 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 » Report » pentaho report » org.pentaho.plugin.jfreereport.helper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved.
003:         * This software was developed by Pentaho Corporation and is provided under the terms
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005:         * this file except in compliance with the license. If you need a copy of the license,
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to
011:         * the license for the specific language governing your rights and limitations.
012:         */
013:        package org.pentaho.plugin.jfreereport.helper;
014:
015:        import java.io.BufferedOutputStream;
016:        import java.io.File;
017:        import java.io.FileOutputStream;
018:        import java.io.IOException;
019:        import java.io.InputStream;
020:        import java.io.OutputStream;
021:        import java.io.Serializable;
022:        import java.net.URL;
023:        import java.net.URLClassLoader;
024:        import java.util.HashMap;
025:        import java.util.Map;
026:
027:        import org.jfree.io.IOUtils;
028:        import org.pentaho.core.repository.ISolutionRepository;
029:        import org.pentaho.core.session.IPentahoSession;
030:        import org.pentaho.core.solution.IActionResource;
031:        import org.pentaho.core.system.IApplicationContext;
032:        import org.pentaho.core.system.PentahoSystem;
033:        import org.pentaho.messages.Messages;
034:
035:        /**
036:         * Creation-Date: 07.07.2006, 15:49:35
037:         * 
038:         * @author Thomas Morgner
039:         */
040:        public class ReportUtils {
041:            private static class ClassLoaderEntry implements  Serializable {
042:                private static final long serialVersionUID = 8925334939030498948L;
043:
044:                private transient ClassLoader entry;
045:
046:                public ClassLoaderEntry(final ClassLoader entry) {
047:                    this .entry = entry;
048:                }
049:
050:                public ClassLoader getEntry() {
051:                    return entry;
052:                }
053:            }
054:
055:            private ReportUtils() {
056:            }
057:
058:            public static synchronized File getTempDirectory(
059:                    IPentahoSession session) {
060:                IApplicationContext ctx = PentahoSystem.getApplicationContext();
061:                if (ctx != null) {
062:                    final String fileOutputPath = ctx
063:                            .getFileOutputPath("system/tmp/"); //$NON-NLS-1$
064:                    final File tempDir = new File(fileOutputPath);
065:                    final String id = session.getId();
066:
067:                    final File userTempDir;
068:                    if (id == null) {
069:                        // typical sloopy programming! Someone forgot to check null values.
070:                        userTempDir = tempDir;
071:                    } else {
072:                        userTempDir = new File(tempDir, id);
073:                    }
074:
075:                    // this operation silently fails if the dir already exists.
076:                    userTempDir.mkdir();
077:                    return userTempDir;
078:                }
079:                throw new IllegalStateException(
080:                        Messages
081:                                .getString("ReportUtils.ERROR_0036_PENTAHO_SYSTEM_NOT_OK")); //$NON-NLS-1$
082:            }
083:
084:            public static ClassLoader createJarLoader(IPentahoSession session,
085:                    IActionResource resource) {
086:
087:                // todo: We cant clean the temp directory ...
088:                // session.addListener (,..) is needed
089:                synchronized (session) {
090:                    try {
091:                        final URL url = getURL(session, resource, true);
092:                        if (url == null) {
093:                            return null;
094:                        }
095:
096:                        final Map cache = getClassLoaderCache(session);
097:                        ClassLoaderEntry entry = (ClassLoaderEntry) cache
098:                                .get(url);
099:                        if (entry != null) {
100:                            if (entry.getEntry() != null) {
101:                                return entry.getEntry();
102:                            }
103:                        }
104:
105:                        // now wrap the beast into a jar URL ...
106:                        final URL jarURL = new URL(
107:                                "jar:" + url.toExternalForm() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
108:                        final URLClassLoader urlClassLoader = URLClassLoader
109:                                .newInstance(new URL[] { jarURL });
110:                        cache.put(url, new ClassLoaderEntry(urlClassLoader));
111:                        return urlClassLoader;
112:                    } catch (IOException e) {
113:                        // something went wrong ..
114:                        return null;
115:                    }
116:                }
117:            }
118:
119:            private static Map getClassLoaderCache(IPentahoSession session) {
120:                synchronized (session) {
121:                    Object maybeMap = session
122:                            .getAttribute("-x-pentaho-classloaders"); //$NON-NLS-1$
123:                    if (maybeMap instanceof  Map) {
124:                        return (Map) maybeMap;
125:                    }
126:                    Map map = new HashMap();
127:                    session.setAttribute("-x-pentaho-classloaders", map); //$NON-NLS-1$
128:                    return map;
129:                }
130:            }
131:
132:            private static URL getURL(IPentahoSession session,
133:                    IActionResource resource, boolean create)
134:                    throws IOException {
135:                if (resource.getSourceType() == IActionResource.URL_RESOURCE) {
136:                    return new URL(resource.getAddress());
137:                }
138:                if (resource.getSourceType() == IActionResource.FILE_RESOURCE) {
139:                    File file = new File(resource.getAddress());
140:                    if (file.exists() && file.canRead()) {
141:                        return file.toURL();
142:                    }
143:                }
144:                if (resource.getSourceType() == IActionResource.SOLUTION_FILE_RESOURCE) {
145:                    String reportJarPath = PentahoSystem
146:                            .getApplicationContext().getSolutionPath(
147:                                    resource.getAddress());
148:                    File file = new File(reportJarPath);
149:                    if (file.exists() && file.canRead()) {
150:                        return file.toURL();
151:                    }
152:                }
153:
154:                if (create) {
155:                    // ok, fall back to copy the file into the temp dir and to load it from
156:                    // there...
157:                    File temp = getTempDirectory(session);
158:                    File tempFile = File.createTempFile(
159:                            "loaded-jar-", ".jar", temp); //$NON-NLS-1$ //$NON-NLS-2$
160:                    // if that fails, we dont have to waste our time on copying the stuff ..
161:                    final URL url = tempFile.toURL();
162:
163:                    final ISolutionRepository solutionRepository = PentahoSystem
164:                            .getSolutionRepository(session);
165:                    final InputStream in = solutionRepository
166:                            .getResourceInputStream(resource, true);
167:                    final OutputStream out = new BufferedOutputStream(
168:                            new FileOutputStream(tempFile));
169:                    IOUtils.getInstance().copyStreams(in, out);
170:                    in.close();
171:                    out.close();
172:                    return url;
173:                } else {
174:                    return null;
175:                }
176:            }
177:
178:            public static URL getURL(IPentahoSession session,
179:                    IActionResource resource) throws IOException {
180:                return getURL(session, resource, false);
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.