libloader-1.1.6/0000755000175000017500000000000011635764623012135 5ustar renerenelibloader-1.1.6/common_build.xml0000644000175000017500000020225611365605644015332 0ustar renerene ------------------------------------------------------------------------------- Common Build file provides tasks needed to perform a project build. It is typically not used directly but imported by each project's build.xml file. The build.xml file can override tasks when customization is required. MAIN TARGETS ============ * clean / clean-all : remove all artifacts of the build, clean-all adds the removal of any library or jar dependencies downloaded as part of the build * resolve : download/refresh library or jar dependencies needed for the build (uses Apache IVY) * compile : run javac on the project's source * jar : creates a jar file * dist : creates all project distributables * test : runs JUnit tests from your project's test source SPECIAL TARGETS ============ * publish-local : builds a jar for your project and registers it with the local artifact repository isolated to your machine at $HOME/.ivy2/local. Further executions of the the resolve target by this or other projects will find your published jar. * ivy-clean* : this family of targets helps reset your IVY environment in the event that you are having difficulty resolving dependencies TYPICAL TARGET SEQUENCE ============ * clean-all resolve dist : a good start to build all project distributables from scratch. Note that jar dependencies will not be downloaded unless you explicitly run the resolve target. We made the resolution and retrieval completely discretionary since there are many situations in which you will not want to get or refresh dependencies, e.g. if you are offline with no Internet access. In such case, you could just run "dist" if the set of jars you already have are sufficient. libloader-1.1.6/.project0000644000175000017500000000060111365605644013576 0ustar renerene libloader org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature libloader-1.1.6/ChangeLog.txt0000644000175000017500000001171411365605644014526 0ustar renerene--------------- 1. WHAT's NEW --------------- A list of changes in recent versions: 0.4.0: (30-May-2008) * Code-Hardening: Added more checks for NullPointers. * SVG rendering errors no longer corrupt the Graphics2D context. * DrawableWrapper now holds a cache of all class-names that have been checked so that we can avoid reflection for many non-drawables. * Switched from JCommon to LibBase. All version information is now contained in the manifest. The Project-Info implementation reads the version numbers from the Jar's Manifest or the compiler-output-directory. * Added a SVG-Loader module using Batik * Added a ImageIO loader module for JDK 1.4+ * Added a properties file loader module * Added Cache-Shutdown methods to the resource-manager. * Changed to EHCache as default cache implementation, as it can be used more efficiently and runs out of the box without forcing the user to provide a configuration. * [BUG] A NullPointerException was raised if a relative filename tried to query the parent filename. To prevent this, the file must be made absolute before trying to access the parent directory. * Added support for resource-bundles. Resource-Bundles are ZIP files or directories containing a loadable resource that may consist of multiple entries within the bundle. * LibLoader now uses the module system to manage dependencies. If either Batik is not on the classpath or LibLoader runs on JDK 1.2/1.3 the modules depending on the missing functionality will automatically be disabled. 0.3.7: (02-Nov-2007) * Upgraded to jcommon-1.0.12 0.3.6: (16-Oct-2007) * The build-system now uses the modular build again. By default the compile operation returns a automatic-monolithic build that automatically strips all classes that have unresolved dependencies. * Automatic fixes as reported by IntelliJ-IDEA's inspections * Updated the copyright header on all java-files 0.3.5: (24-Sep-2007) * All releases are now built with JDK 1.4. However, we are still compatible with JDK 1.2.2 and all releases run and compile under that release. * [BUG] NullPointerException encountered when compiling with JDK 1.4 and ehcache * [BUG] The code that opened InputStreams did not always close the streams reliably. This could lead to strange errors as soon as the number of open files exceeds the maximum number of file handles. 0.3.4: (21-May-2007) * A byte[] resource-key now compares its key-data correctly. This way keys from byte-array resources can be cached. 0.3.3: (27-Apr-2007) * [BUG] The ResourceManager's search for usable factories also included factories which were no longer assignable to the requested target type. 0.3.2: (01-Apr-2007) * Added stronger logging and cleaned up the error messages returned from the loader framework. * Derived resource-keys now preserve the parent's context. The system first tries to create the derived key before it falls back to create an absolute key from the given path. This mimics the default URL behavior now. 0.3.1: (07-Mar-2007) * [BUG] Creating and deriving File and/or URL keys from Strings failed under certain conditions. 0.3.0: (01-Mar-2007) * The internal resource-key creation and resource-loader architecture has been simplified. Instead of having complex resource-keys for each loader, we now have one generic key that consists of a single object to locate the resource and a map of factory keys to configure the resource creation process. This also fixes the various ugly misconfiguration that made working with files and file-URLs so confusing. 0.2.2: (22-Dec-2006) * [BUG] Caching raw-keys was invalid and consumed enormous amounts of memory. * The EHCache-Module has been upgraded to work with EHCache 1.2.4. 0.2.1: (11-Dec-2006) * [BUG] File-URLs failed with LibLoader if the URL's file part was URL-Encoded. We now use a special handler for these cases. 0.2.0: (03-Dec-2006) * This is the first real release version of LibLoader. At this point this library has some primitive caching and does a good job at loading resources. 0.1.5: (26-Sep-2006) * Limited the size of resources that are held in memory to 512kb. 0.1.4: (31-Aug-2006) 0.1.3: (30-Jul-2006) 0.1.2: (30-May-2006) 0.1.1: (30-Apr-2006) * New factory implementation for loading properties. * [BUG] Fixes in the resource and zip-loader implementations for dealing with derived keys. 0.1.0: (17-Apr-2006) * Initial public version. libloader-1.1.6/architecture.txt0000644000175000017500000000443011365605644015356 0ustar renereneThe resource loading framework is a caching and more general replacement for Java's own URL implementation. The framework decouples the process of identifying dependent resources from the ugly task of having to map these identifiers to their respective loader implementations. A user of the framework only has to know, what he wants to load and how the location of the resource is identified (vulgo: from where to load the content). If multiple alternatives for the raw-data format exist, as it is common for loading images (or for parsing abstract structures like report definitions), the it is the framework's responsiblity to find the correct loader and to load the content. As the framework is the central resource loading point, caching should be applied transparently in this layer. -------------------------------------------------------------------------------- General architecture: Each resource is identified by an unique resource key. A resource loader is responsible for loading the specified raw-data from the location given inside the key. The raw data is now interpreted by a suitable resource factory implementation (ie. parsed) and passed over to the client. If the resource factory produces an immutable object (or is able to create a separated copy of the generated content afterwards), the resource is stored in the cache. +--------+ +--------+ +--------+ +--------+ |Resource| --> |Resource| --> |Resource| --> |Resource| | Key | | loader | |Factory | | | +--------+ +--------+ +--------+ +--------+ The lookup, caching and overall management of the loaders and factories available is handled by the ResourceManager. -------------------------------------------------------------------------------- Usage: Loading an image from an resource located on the classpath: // if caching should have any effect, the manager must be reused. // Now: Create a manager and load all known factories ... ResourceManager manager = new ResourceManager(); manager.registerDefaults(); String resource = "res://org/pentaho/reporting/engine/classic/core/images/lion.jpg"; ResourceKey key = manager.createKey (resource); Resource res = manager.create (key, java.awt.Image.class); java.awt.Image image = (java.awt.Image) res.getResource(); libloader-1.1.6/devresource/0000755000175000017500000000000011365605644014460 5ustar renerenelibloader-1.1.6/devresource/META-INF/0000755000175000017500000000000011365605644015620 5ustar renerenelibloader-1.1.6/devresource/META-INF/MANIFEST.MF0000644000175000017500000000033011365605644017246 0ustar renereneImplementation-Title: LibLoader Implementation-Vendor: Pentaho Corporation Implementation-ProductID: libloader Release-Major-Number: 1 Release-Minor-Number: 0 Release-Milestone-Number: 0 Release-Candidate-Token: dev libloader-1.1.6/ivysettings.xml0000644000175000017500000000174311365605644015251 0ustar renerene libloader-1.1.6/build.properties0000644000175000017500000000040411365605644015345 0ustar renereneproject.revision=1.1-SNAPSHOT ivy.artifact.group=pentaho-library ivy.artifact.id=libloader impl.title=LibLoader impl.productID=libloader src.dir=${basedir}/source dependency.libbase.revision=1.1.6 dependency.libpixie.revision=1.1.6 testsrc.dir=${basedir}/test libloader-1.1.6/ant/0000755000175000017500000000000011365605644012714 5ustar renerenelibloader-1.1.6/ant/build-lib.xml0000644000175000017500000006224211365605644015307 0ustar renerene libloader-1.1.6/dev-lib/0000755000175000017500000000000011365605650013451 5ustar renerenelibloader-1.1.6/licence-LGPL.txt0000644000175000017500000006347611365605644015051 0ustar renerene GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! libloader-1.1.6/resources/0000755000175000017500000000000011365605644014144 5ustar renerenelibloader-1.1.6/resources/ehcache.xml0000644000175000017500000003451011365605644016251 0ustar renerene libloader-1.1.6/resources/oscache.properties0000644000175000017500000001224611365605644017674 0ustar renerene# CACHE IN MEMORY # # If you want to disable memory caching, just uncomment this line. # # cache.memory=false # CACHE KEY # # This is the key that will be used to store the cache in the application # and session scope. # # If you want to set the cache key to anything other than the default # uncomment this line and change the cache.key # # cache.key=__oscache_cache # USE HOST DOMAIN NAME IN KEY # # Servers for multiple host domains may wish to add host name info to # the generation of the key. If this is true, then uncomment the # following line. # # cache.use.host.domain.in.key=true # CACHE LISTENERS # # These hook OSCache events and perform various actions such as logging # cache hits and misses, or broadcasting to other cache instances across a cluster. # See the documentation for further information. # # cache.event.listeners=com.opensymphony.oscache.plugins.clustersupport.JMSBroadcastingListener, \ # com.opensymphony.oscache.extra.CacheEntryEventListenerImpl, \ # com.opensymphony.oscache.extra.CacheMapAccessEventListenerImpl, \ # com.opensymphony.oscache.extra.ScopeEventListenerImpl # CACHE PERSISTENCE CLASS # # Specify the class to use for persistence. If you use the supplied DiskPersistenceListener, # don't forget to supply the cache.path property to specify the location of the cache # directory. # # If a persistence class is not specified, OSCache will use memory caching only. # # cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener # CACHE OVERFLOW PERSISTENCE # Use persistent cache in overflow or not. The default value is false, which means # the persistent cache will be used at all times for every entry. true is the recommended setting. # # cache.persistence.overflow.only=true # CACHE DIRECTORY # # This is the directory on disk where caches will be stored by the DiskPersistenceListener. # it will be created if it doesn't already exist. Remember that OSCache must have # write permission to this directory. # # Note: for Windows machines, this needs \ to be escaped # ie Windows: # cache.path=c:\\myapp\\cache # or *ix: # cache.path=/opt/myapp/cache # # cache.path=c:\\app\\cache # CACHE ALGORITHM # # Default cache algorithm to use. Note that in order to use an algorithm # the cache size must also be specified. If the cache size is not specified, # the cache algorithm will be Unlimited cache. # cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache # cache.algorithm=com.opensymphony.oscache.base.algorithm.FIFOCache # cache.algorithm=com.opensymphony.oscache.base.algorithm.UnlimitedCache # THREAD BLOCKING BEHAVIOR # # When a request is made for a stale cache entry, it is possible that another thread is already # in the process of rebuilding that entry. This setting specifies how OSCache handles the # subsequent 'non-building' threads. The default behaviour (cache.blocking=false) is to serve # the old content to subsequent threads until the cache entry has been updated. This provides # the best performance (at the cost of serving slightly stale data). When blocking is enabled, # threads will instead block until the new cache entry is ready to be served. Once the new entry # is put in the cache the blocked threads will be restarted and given the new entry. # Note that even if blocking is disabled, when there is no stale data available to be served # threads will block until the data is added to the cache by the thread that is responsible # for building the data. # # cache.blocking=false # CACHE SIZE # # Default cache size in number of items. If a size is specified but not # an algorithm, the cache algorithm used will be LRUCache. # cache.capacity=10000 # CACHE UNLIMITED DISK # Use unlimited disk cache or not. The default value is false, which means # the disk cache will be limited in size to the value specified by cache.capacity. # # cache.unlimited.disk=false # JMS CLUSTER PROPERTIES # # Configuration properties for JMS clustering. See the clustering documentation # for more information on these settings. # #cache.cluster.jms.topic.factory=java:comp/env/jms/TopicConnectionFactory #cache.cluster.jms.topic.name=java:comp/env/jms/OSCacheTopic #cache.cluster.jms.node.name=node1 # JAVAGROUPS CLUSTER PROPERTIES # # Configuration properites for the JavaGroups clustering. Only one of these # should be specified. Default values (as shown below) will be used if niether # property is set. See the clustering documentation and the JavaGroups project # (www.javagroups.com) for more information on these settings. # #cache.cluster.properties=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;\ #mcast_send_buf_size=150000;mcast_recv_buf_size=80000):\ #PING(timeout=2000;num_initial_members=3):\ #MERGE2(min_interval=5000;max_interval=10000):\ #FD_SOCK:VERIFY_SUSPECT(timeout=1500):\ #pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800;max_xmit_size=8192):\ #UNICAST(timeout=300,600,1200,2400):\ #pbcast.STABLE(desired_avg_gossip=20000):\ #FRAG(frag_size=8096;down_thread=false;up_thread=false):\ #pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true) #cache.cluster.multicast.ip=231.12.21.132 libloader-1.1.6/maven-project.xml0000644000175000017500000000456011365605644015433 0ustar renerene 3 libloader libloader jfree @VERSION@ JFree.org http://www.jfree.org/ 2005 LibLoader is a resource loading framework. Although it is mainly used for JFreeReport and LibLayout, its generic architecture makes it a valuable addition for all projects that have to deal with large ammounts of resources. LibLoader is a resource loading framework. http://www.jfree.org/libloader/ http://sourceforge.net/tracker/?group_id=51669 scm:cvs:pserver:anonymous@cvs.sourceforge.net:/cvsroot/jfreereport:libloader http://cvs.sourceforge.net/viewcvs.py/jfreereport/libloader JFreeReport Developer List jfreereport-developers-request@lists.sourceforge.net?subject=subscribe jfreereport-developers-request@lists.sourceforge.net?subject=unsubscribe http://sourceforge.net/mailarchive/forum.php?forum=jfreereport-developers GNU Lesser General Public Licence http://www.gnu.org/licenses/lgpl.txt repo jfree jcommon 1.0.0 http://www.jfree.org/jcommon/ libloader-1.1.6/source/0000755000175000017500000000000011365605644013432 5ustar renerenelibloader-1.1.6/source/org/0000755000175000017500000000000011365605644014221 5ustar renerenelibloader-1.1.6/source/org/pentaho/0000755000175000017500000000000011365605644015657 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/0000755000175000017500000000000011365605644017670 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/0000755000175000017500000000000011365605644021644 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/0000755000175000017500000000000011365605644024662 5ustar renerene././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/DefaultResourceManagerBackend.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/DefaultResourceManagerBackend.0000644000175000017500000004166411365605644032535 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * Todo: Document Me * * @author Thomas Morgner */ public class DefaultResourceManagerBackend implements ResourceManagerBackend { private static final Log logger = LogFactory.getLog(DefaultResourceManagerBackend.class); private ArrayList resourceLoaders; private ArrayList resourceBundleLoaders; private ArrayList resourceFactories; public DefaultResourceManagerBackend() { resourceLoaders = new ArrayList(); resourceBundleLoaders = new ArrayList(); resourceFactories = new ArrayList(); } public synchronized ResourceKey createKey(final Object data, final Map parameters) throws ResourceKeyCreationException { if (data == null) { throw new NullPointerException("Key data must not be null."); } final Iterator values = resourceLoaders.iterator(); while (values.hasNext()) { final ResourceLoader loader = (ResourceLoader) values.next(); try { final ResourceKey key = loader.createKey(data, parameters); if (key != null) { return key; } } catch (ResourceKeyCreationException rkce) { // ignore it. } } throw new ResourceKeyCreationException("Unable to create key: No loader was able to handle the given key data: " + data); } /** * Derives a new key from the given resource-key. Only keys for a hierarchical storage system (like file-systems or * URLs) can have derived keys. Since LibLoader 0.3.0 only hierarchical keys can be derived. For that, the deriving * path must be given as String. *

* The optional parameter-map will be applied to the derived key after the parent's parameters have been copied to * the new key. *

* Before trying to derive the key, the system tries to interpret the path as absolute key-value. * * @param parent the parent key, or null to interpret the path as absolute key. * @param path the relative path, that is used to derive the key. * @param parameters a optional map containing resource-key parameters. * @return the derived key. * @throws ResourceKeyCreationException if deriving the key failed. */ public synchronized ResourceKey deriveKey(final ResourceKey parent, final String path, final Map parameters) throws ResourceKeyCreationException { if (parent == null) { if (path == null) { throw new NullPointerException(); } return createKey(path, parameters); } ResourceKeyCreationException rce = null; for (int i = 0; i < resourceBundleLoaders.size(); i++) { final ResourceBundleLoader bundleLoader = (ResourceBundleLoader) resourceBundleLoaders.get(i); if (bundleLoader.isSupportedKey(parent) == false) { continue; } try { final ResourceKey key = bundleLoader.deriveKey(parent, path, parameters); if (key != null) { return key; } } catch (ResourceKeyCreationException rcke) { rce = rcke; } } // First, try to derive the resource directly. This makes sure, that we preserve the parent's context. // If a file is derived, we assume that the result will be a file; and only if that fails we'll try to // query the other contexts. If the parent is an URL-context, the result is assumed to be an URL as well. for (int i = 0; i < resourceLoaders.size(); i++) { final ResourceLoader loader = (ResourceLoader) resourceLoaders.get(i); if (loader.isSupportedKey(parent) == false) { continue; } try { final ResourceKey key = loader.deriveKey(parent, path, parameters); if (key != null) { return key; } } catch (ResourceKeyCreationException rcke) { rce = rcke; } } if (path != null) { // Second, try to load the key as absolute value. // This assumes, that we have no catch-all implementation. for (int i = 0; i < resourceLoaders.size(); i++) { final ResourceLoader loader = (ResourceLoader) resourceLoaders.get(i); final ResourceKey key = loader.createKey(path, parameters); if (key != null) { return key; } } } final ResourceKey secondParent = parent.getParent(); if (secondParent != null) { // Desperate measures: Maybe the key is relative to the bundle. for (int i = 0; i < resourceLoaders.size(); i++) { final ResourceLoader loader = (ResourceLoader) resourceLoaders.get(i); if (loader.isSupportedKey(secondParent) == false) { continue; } try { final ResourceKey key = loader.deriveKey(secondParent, path, parameters); if (key != null) { return key; } } catch (ResourceKeyCreationException rcke) { rce = rcke; } } } if (rce != null) { throw rce; } throw new ResourceKeyCreationException("Unable to create key: No such schema or the key was not recognized."); } /** * Tries to find the first resource-loader that would be able to process the key. * * @param key the resource-key. * @return the resourceloader for that key, or null, if no resource-loader is able to process the key. */ private ResourceLoader findBySchema(final ResourceKey key) { for (int i = 0; i < resourceLoaders.size(); i++) { final ResourceLoader loader = (ResourceLoader) resourceLoaders.get(i); if (loader.isSupportedKey(key)) { return loader; } } return null; } public synchronized URL toURL(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } final ResourceLoader loader = findBySchema(key); if (loader == null) { return null; } return loader.toURL(key); } public synchronized Resource create(final ResourceManager frontEnd, final ResourceData data, final ResourceKey context, final Class[] target) throws ResourceLoadingException, ResourceCreationException { if (frontEnd == null) { throw new NullPointerException(); } if (data == null) { throw new NullPointerException("Data must not be null."); } // AutoMode .. if (target == null) { return autoCreateResource(frontEnd, data, context); } ResourceCreationException exception = null; final int factoryCount = resourceFactories.size(); final ResourceFactory[] factories = (ResourceFactory[]) resourceFactories .toArray(new ResourceFactory[factoryCount]); for (int targetIdx = 0; targetIdx < target.length; targetIdx++) { final Class targetClass = target[targetIdx]; for (int i = 0; i < factoryCount; i++) { final ResourceFactory fact = factories[i]; if (isSupportedTarget(targetClass, fact) == false) { // Unsupported keys: Try the next factory .. continue; } try { return fact.create(frontEnd, data, context); } catch (ContentNotRecognizedException ce) { // Ignore it, unless it is the last one. } catch (ResourceCreationException rex) { // ignore it, try the next factory ... exception = rex; if (logger.isDebugEnabled()) { logger.debug("Failed at " + fact.getClass() + ": ", rex); } } } } if (exception != null) { throw exception; } throw new ContentNotRecognizedException("None of the selected factories was able to handle the given data: " + data.getKey()); } private boolean isSupportedTarget(final Class target, final ResourceFactory fact) { final Class factoryType = fact.getFactoryType(); if (target != null && target.isAssignableFrom(factoryType)) { return true; } return false; } private Resource autoCreateResource(final ResourceManager frontEnd, final ResourceData data, final ResourceKey context) throws ResourceLoadingException, ResourceCreationException { final Iterator it = resourceFactories.iterator(); while (it.hasNext()) { final ResourceFactory fact = (ResourceFactory) it.next(); try { final Resource res = fact.create(frontEnd, data, context); if (res != null) { return res; } } catch (ResourceCreationException rex) { // ignore it, try the next factory ... } } throw new ResourceCreationException("No known factory was able to handle the given data."); } public boolean isResourceUnchanged(final ResourceManager frontEnd, final Resource resource) throws ResourceLoadingException { if (frontEnd == null) { throw new NullPointerException(); } if (resource == null) { throw new NullPointerException(); } final ResourceKey[] deps = resource.getDependencies(); for (int i = 0; i < deps.length; i++) { final ResourceKey dep = deps[i]; final long version = resource.getVersion(dep); if (version == -1) { // non-versioning key, ignore it. continue; } final ResourceData data = frontEnd.load(dep); if (data.getVersion(frontEnd) != version) { // oh, my bad, an outdated or changed entry. // We have to re-read the whole thing. return false; } } // all versions have been confirmed to be valid. Nice, we can use the // cached product. return true; } /** * Tries to find the first resource-bundle-loader that would be able to process the key. * * @param key the resource-key. * @return the resourceloader for that key, or null, if no resource-loader is able to process the key. * @throws ResourceLoadingException if an error occured. */ public synchronized ResourceBundleData loadResourceBundle(final ResourceManager frontEnd, final ResourceKey key) throws ResourceLoadingException { if (frontEnd == null) { throw new NullPointerException(); } if (key == null) { throw new NullPointerException(); } for (int i = 0; i < resourceBundleLoaders.size(); i++) { final ResourceBundleLoader loader = (ResourceBundleLoader) resourceBundleLoaders.get(i); final ResourceBundleData resourceBundle = loader.loadBundle(frontEnd, key); if (resourceBundle != null) { return resourceBundle; } } return null; } public ResourceData loadRawData(final ResourceManager frontEnd, final ResourceKey key) throws UnrecognizedLoaderException, ResourceLoadingException { if (frontEnd == null) { throw new NullPointerException(); } if (key == null) { throw new NullPointerException(); } final ResourceLoader loader = findBySchema(key); if (loader == null) { throw new UnrecognizedLoaderException("Invalid key: No resource-loader registered for schema: " + key.getSchema()); } logger.debug("Loaded " + key); return loader.load(key); } public void registerDefaultFactories() { final Configuration config = LibLoaderBoot.getInstance().getGlobalConfig(); final Iterator itType = config.findPropertyKeys(ResourceManager.FACTORY_TYPE_PREFIX); while (itType.hasNext()) { final String key = (String) itType.next(); final String factoryClass = config.getConfigProperty(key); final Object maybeFactory = ObjectUtilities.loadAndInstantiate(factoryClass, ResourceManager.class, ResourceFactory.class); if (maybeFactory instanceof ResourceFactory == false) { continue; } final ResourceFactory factory = (ResourceFactory) maybeFactory; factory.initializeDefaults(); registerFactory(factory); } } public void registerDefaultLoaders() { final Configuration config = LibLoaderBoot.getInstance().getGlobalConfig(); final Iterator it = config.findPropertyKeys(ResourceManager.LOADER_PREFIX); while (it.hasNext()) { final String key = (String) it.next(); final String value = config.getConfigProperty(key); final ResourceLoader loader = (ResourceLoader) ObjectUtilities.loadAndInstantiate(value, ResourceManager.class, ResourceLoader.class); if (loader != null) { //Log.debug("Registering loader for " + loader.getSchema()); registerLoader(loader); } } final Iterator bit = config.findPropertyKeys(ResourceManager.BUNDLE_LOADER_PREFIX); while (bit.hasNext()) { final String key = (String) bit.next(); final String value = config.getConfigProperty(key); final ResourceBundleLoader loader = (ResourceBundleLoader) ObjectUtilities.loadAndInstantiate(value, ResourceManager.class, ResourceBundleLoader.class); if (loader != null) { //Log.debug("Registering loader for " + loader.getSchema()); registerBundleLoader(loader); } } } public void registerBundleLoader(final ResourceBundleLoader loader) { if (loader == null) { throw new NullPointerException("ResourceLoader must not be null."); } resourceBundleLoaders.add(loader); } public void registerLoader(final ResourceLoader loader) { if (loader == null) { throw new NullPointerException("ResourceLoader must not be null."); } resourceLoaders.add(loader); } public void registerFactory(final ResourceFactory factory) { if (factory == null) { throw new NullPointerException("ResourceFactory must not be null."); } resourceFactories.add(factory); } /** * Converts a serialized version of a ResourceKey into an actual ResourceKey * by locating the proper ResourceLoader that can perform the deserialization. * * @param bundleKey *@param serializedKey the String serialized key to be deserialized @returns the ResourceKey that has been deserialized * @throw ResourceKeyCreationException indicates an error trying to create the ResourceKey * from the deserialized version */ public ResourceKey deserialize(final ResourceKey bundleKey, String serializedKey) throws ResourceKeyCreationException { if (serializedKey == null) { throw new NullPointerException("Key data must not be null."); } final Iterator values = resourceLoaders.iterator(); while (values.hasNext()) { final ResourceLoader loader = (ResourceLoader) values.next(); if (loader.isSupportedDeserializer(serializedKey)) { final ResourceKey key = loader.deserialize(bundleKey, serializedKey); return key; } } throw new ResourceKeyCreationException ("Unable to create key: No loader was able to handle the deserialization of the given key data: " + serializedKey); } /** * Creates a String version of the ResourceKey that can be deserialized with the * deserialize() method. * @param bundleKey *@param key @throw ResourceException indicates an error trying to serialize the key * @throw NullPointerException indicates the supplied key is null */ public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException { if (key == null) { throw new NullPointerException("Key data must not be null."); } final Iterator values = resourceLoaders.iterator(); while (values.hasNext()) { final ResourceLoader loader = (ResourceLoader) values.next(); if (loader.isSupportedKey(key)) { return loader.serialize(bundleKey, key); } } throw new ResourceException("Unable to find resource loader for specified key: " + key); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceBundleLoader.java0000644000175000017500000000763111365605644031604 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.util.Map; /** * A resource bundle is a compound archive that holds several resources. * * @author Thomas Morgner */ public interface ResourceBundleLoader { /** * Tries to load the bundle. If the key does not point to a usable resource-bundle, this method returns * null. The Exception is only thrown if the bundle is not readable because of IO-Errors. *

* A resource-bundle loader should only load the bundle for the key itself, never for any of the derived subkeys. * It is the ResourceManager's responsibility to search the key's hierachy for the correct key. * * @param key the resource key pointing to the bundle. * @return the loaded bundle or null, if the resource was not understood. * @throws ResourceLoadingException if something goes wrong. */ public ResourceBundleData loadBundle (final ResourceManager resourceManager, final ResourceKey key) throws ResourceLoadingException; /** * Checks, whether this resource loader implementation was responsible for * creating this key. * * @param key the key that should be tested. * @return true, if the key is supported. */ public boolean isSupportedKey (ResourceKey key); /** * Derives a new resource key from the given key. If neither a path nor new * factory-keys are given, the parent key is returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws ResourceKeyCreationException if the key cannot be derived for any * reason. */ public ResourceKey deriveKey (ResourceKey parent, String path, Map factoryKeys) throws ResourceKeyCreationException; /** * Serializes the resource key to a String representation which can be recreated * using the deserialize(ResourceKey) method. * @return a String which is a serialized version of the ResourceKey * @throws ResourceException indicates an error serializing the resource key * @param bundleKey * @param key */ public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException; /** * Creates a ResourceKey based off the String representation * of the key. The String should have been created using the serialize * method. * * @param bundleKey *@param stringKey the String representation of the ResourceKey @return a ResourceKey which matches the String representation * @throws ResourceKeyCreationException indicates an error occurred in the creation or * deserialization of the ResourceKey */ public ResourceKey deserialize(final ResourceKey bundleKey, final String stringKey) throws ResourceKeyCreationException; public boolean isSupportedDeserializer(final String data) throws ResourceKeyCreationException; } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceKey.java0000644000175000017500000001370611365605644027774 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.io.File; import java.io.Serializable; import java.net.URL; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * The key is an unique identifier for the resource. Most of the time, this may be an URL, but other (especially * database based) schemas are possible. *

* A resource key must provide an 'equals' implementation. ResourceKeys should be implemented as immutable classes, so * that they can be safely stored in collections or on external storages (like caches). * * @author Thomas Morgner */ public final class ResourceKey implements Serializable { /** * @noinspection StaticCollection */ private static final Map EMPTY_MAP = Collections.unmodifiableMap(new HashMap()); private Map factoryParameters; private Integer hashCode; private Object schema; private Object identifier; private ResourceKey parent; private static final long serialVersionUID = -7764107570068726772L; public ResourceKey(final Object schema, final Object identifier, final Map factoryParameters) { if (schema == null) { throw new NullPointerException(); } if (identifier == null) { throw new NullPointerException(); } this.schema = schema; this.identifier = identifier; if (factoryParameters != null) { this.factoryParameters = Collections.unmodifiableMap(new HashMap(factoryParameters)); } else { this.factoryParameters = EMPTY_MAP; } } public ResourceKey(final ResourceKey parent, final Object schema, final Object identifier, final Map factoryParameters) { this(schema, identifier, factoryParameters); this.parent = parent; } public ResourceKey getParent() { return parent; } public Map getFactoryParameters() { return Collections.unmodifiableMap(factoryParameters); } public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final ResourceKey that = (ResourceKey) o; if (parent != that.parent && ObjectUtilities.equal(parent, that.parent) == false) { return false; } if (!schema.equals(that.schema)) { return false; } if (!factoryParameters.equals(that.factoryParameters)) { return false; } if (identifier instanceof URL) { if (String.valueOf(identifier).equals(String.valueOf(that.identifier)) == false) { return false; } } else if (identifier instanceof File && that.identifier instanceof File) { // File.equals() does not check to see if two File objects refer to the same file ... // it checks to make sure they refer to the same file IN THE SAME way (which is deeper than we need) if (ObjectUtilities.equals((File) identifier, (File) that.identifier) == false) { return false; } } else if (!identifier.equals(that.identifier)) { if (identifier instanceof byte[] && that.identifier instanceof byte[]) { final byte[] me = (byte[]) identifier; final byte[] he = (byte[]) that.identifier; if (Arrays.equals(me, he) == false) { return false; } } else { return false; } } return true; } public int hashCode() { if (hashCode == null) { int result = factoryParameters.hashCode(); result = 29 * result + schema.hashCode(); result = 29 * result + identifier.hashCode(); if (parent != null) { result = 29 * result + parent.hashCode(); } hashCode = new Integer(result); } return hashCode.intValue(); } public Object getIdentifier() { return identifier; } /** * Returns a String version of the identifier. * * @return the identifier as string or null, if the identifier could not be converted easily. */ public String getIdentifierAsString() { if (identifier instanceof File) { final File file = (File) identifier; return file.getPath(); } if (identifier instanceof URL) { final URL url = (URL) identifier; return url.toExternalForm(); } if (identifier instanceof String) { return identifier.toString(); } return null; } /** * Returns the schema of this resource key. The schema is an internal identifier to locate the resource-loader * implementation that was responsible for creating the key in the first place. *

* The schema has no meaning outside the resource loading framework. * * @return */ public Object getSchema() { return schema; } public String toString() { return "ResourceKey{" + "schema=" + schema + ", identifier=" + identifier + ", factoryParameters=" + factoryParameters + ", parent=" + parent + '}'; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/Resource.java0000644000175000017500000000407211365605644027317 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.io.Serializable; /** * A resource is a wrapper around the final product. It shall not hold any * references to the ResourceData object used to create the resource (to allow * efficient 2-stage caching). * * Although this interfaces declares to be serializable, this might not be the * case for some of the content contained in the resource object. Cache * implementors should be aware of that issue and should act accordingly * (for instance by not caching that object). * * @author Thomas Morgner */ public interface Resource extends Serializable { public Object getResource () throws ResourceException; public Class getTargetType(); public boolean isTemporaryResult(); public long getVersion(ResourceKey key); /** * The primary source is also included in this set. The dependencies are * given as ResourceKey objects. The keys itself do not hold any state * information. * * The dependencies do not track deep dependencies. So if Resource A depends * on Resource B which depends on Resource C, then A only knows about B, not * C. * * @return */ public ResourceKey[] getDependencies(); public ResourceKey getSource(); } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/LoaderParameterKey.java0000644000175000017500000000350011365605644031243 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.io.Serializable; /** * Creation-Date: 16.05.2006, 15:24:21 * * @author Thomas Morgner */ public final class LoaderParameterKey implements Serializable { private String name; private transient int hashKey; private static final long serialVersionUID = 248656222959755320L; public LoaderParameterKey(final String name) { if (name == null) { throw new NullPointerException(); } this.name = name; } public String getName() { return name; } public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final LoaderParameterKey that = (LoaderParameterKey) o; if (!name.equals(that.name)) { return false; } return true; } public int hashCode() { if (hashKey == 0) { hashKey = name.hashCode(); } return hashKey; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader.properties0000644000175000017500000001052311365605644030247 0ustar renerene# # The list of known storage handlers. These classes are responsible to get # the binary data into the system. They do not interpret that data in any # way. org.pentaho.reporting.libraries.resourceloader.loader.url=org.pentaho.reporting.libraries.resourceloader.loader.URLResourceLoader org.pentaho.reporting.libraries.resourceloader.loader.file=org.pentaho.reporting.libraries.resourceloader.loader.file.FileResourceLoader org.pentaho.reporting.libraries.resourceloader.loader.raw=org.pentaho.reporting.libraries.resourceloader.loader.raw.RawResourceLoader org.pentaho.reporting.libraries.resourceloader.loader.res=org.pentaho.reporting.libraries.resourceloader.loader.resource.ClassloaderResourceLoader org.pentaho.reporting.libraries.resourceloader.loader.zip=org.pentaho.reporting.libraries.resourceloader.loader.zip.ZipResourceLoader # # The cache stuff. For now, this only defines *that* there are caches. # The implementation and initialization is part of the module's reponsibility # # Using no real caching .. #org.pentaho.reporting.libraries.resourceloader.cache.FactoryCacheProvider=org.pentaho.reporting.libraries.resourceloader.cache.NullCacheProvider #org.pentaho.reporting.libraries.resourceloader.cache.DataCacheProvider=org.pentaho.reporting.libraries.resourceloader.cache.NullCacheProvider #org.pentaho.reporting.libraries.resourceloader.cache.BundleDataCacheProvider=org.pentaho.reporting.libraries.resourceloader.cache.NullCacheProvider # # Using OSCache ... (if this is not available, it falls back to the 'NoCacheProvider' org.pentaho.reporting.libraries.resourceloader.cache.FactoryCacheProvider=org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache.EHCacheProvider org.pentaho.reporting.libraries.resourceloader.cache.DataCacheProvider=org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache.EHCacheProvider org.pentaho.reporting.libraries.resourceloader.cache.BundleDataCacheProvider=org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache.EHCacheProvider # # The heart of the system are the value factories. They translate binary # content into usable java objects. # # The key format is: # org.pentaho.reporting.libraries.resourceloader.factory.type.= org.pentaho.reporting.libraries.resourceloader.factory.type.java.awt.Image=org.pentaho.reporting.libraries.resourceloader.factory.image.ImageResourceFactory org.pentaho.reporting.libraries.resourceloader.factory.type.java.util.Properties=org.pentaho.reporting.libraries.resourceloader.factory.property.PropertiesResourceFactory org.pentaho.reporting.libraries.resourceloader.factory.type.org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper=org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableResourceFactory # # The factory modules are responsible for loading a certain sub-format. The # factory implementation tries to find the most suitable module for the given # content. # # The key format is: # org.pentaho.reporting.libraries.resourceloader.factory.modules..= org.pentaho.reporting.libraries.resourceloader.factory.modules.java.awt.Image.gif=org.pentaho.reporting.libraries.resourceloader.factory.image.GIFImageFactoryModule org.pentaho.reporting.libraries.resourceloader.factory.modules.java.awt.Image.png=org.pentaho.reporting.libraries.resourceloader.factory.image.PNGImageFactoryModule org.pentaho.reporting.libraries.resourceloader.factory.modules.java.awt.Image.jpeg=org.pentaho.reporting.libraries.resourceloader.factory.image.JPEGImageFactoryModule # # The known system-modules. org.pentaho.reporting.libraries.resourceloader.modules.core.Module=org.pentaho.reporting.libraries.resourceloader.LibLoaderCoreModule org.pentaho.reporting.libraries.resourceloader.modules.factory.imageio.Module=org.pentaho.reporting.libraries.resourceloader.modules.factory.imageio.ImageIOModule org.pentaho.reporting.libraries.resourceloader.modules.factory.svg.Module=org.pentaho.reporting.libraries.resourceloader.modules.factory.svg.SVGModule org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf.Module=org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf.WMFModule org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache.Module=org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache.EHCacheModule libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/SimpleResource.java0000644000175000017500000000511311365605644030466 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * A simple resource with only a single dependency. * * @author Thomas Morgner */ public class SimpleResource implements Resource { private Object value; private ResourceKey key; private long version; private static final long serialVersionUID = -6007941678785921339L; private Class targetType; public SimpleResource(final ResourceKey key, final Object value, final Class targetType, final long version) { if (key == null) { throw new NullPointerException(); } if (value == null) { throw new NullPointerException(); } if (targetType == null) { throw new NullPointerException(); } this.targetType = targetType; this.value = value; this.key = key; this.version = version; } public Object getResource() { return value; } public long getVersion(final ResourceKey key) { if (key.equals(this.key)) { return version; } // -1 is the placeholder for: not known. return -1; } /** * The primary source is also included in this set. The dependencies are given * as ResourceKey objects. The keys itself do not hold any state information. *

* The dependencies do not track deep dependencies. So if Resource A depends * on Resource B which depends on Resource C, then A only knows about B, not * C. * * @return */ public ResourceKey[] getDependencies() { return new ResourceKey[]{getSource()}; } public ResourceKey getSource() { return key; } public Class getTargetType() { return targetType; } public boolean isTemporaryResult() { return false; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/LibLoaderCoreModule.java0000644000175000017500000000351311365605644031343 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import org.pentaho.reporting.libraries.base.boot.AbstractModule; import org.pentaho.reporting.libraries.base.boot.ModuleInitializeException; import org.pentaho.reporting.libraries.base.boot.SubSystem; /** * Todo: Document Me * * @author Thomas Morgner */ public class LibLoaderCoreModule extends AbstractModule { public LibLoaderCoreModule() throws ModuleInitializeException { loadModuleInfo(); } /** * Initializes the module. Use this method to perform all initial setup operations. * This method is called only once in a modules lifetime. If the initializing cannot * be completed, throw a ModuleInitializeException to indicate the error,. The module * will not be available to the system. * * @param subSystem the subSystem. * @throws ModuleInitializeException if an error ocurred while initializing the module. */ public void initialize(final SubSystem subSystem) throws ModuleInitializeException { } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceBundleData.java0000644000175000017500000000236011365605644031241 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * Todo: Document Me * * @author Thomas Morgner */ public interface ResourceBundleData extends ResourceData { public ResourceKey getBundleKey(); public ResourceBundleData deriveData(final ResourceKey key) throws ResourceLoadingException; public ResourceManager deriveManager(final ResourceManager parent) throws ResourceLoadingException; } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/0000755000175000017500000000000011365605644026332 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/0000755000175000017500000000000011365605644027375 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/0000755000175000017500000000000011365605644030755 5ustar renerene././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHCacheProvider.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHCacheP0000644000175000017500000000643511365605644032250 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache; import net.sf.ehcache.CacheException; import net.sf.ehcache.CacheManager; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceDataCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceDataCacheProvider; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceFactoryCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceFactoryCacheProvider; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceBundleDataCacheProvider; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceBundleDataCache; /** * Creation-Date: 13.04.2006, 16:32:20 * * @author Thomas Morgner */ public class EHCacheProvider implements ResourceDataCacheProvider, ResourceFactoryCacheProvider, ResourceBundleDataCacheProvider { private static CacheManager cacheManager; public static CacheManager getCacheManager() throws CacheException { if (cacheManager == null) { cacheManager = CacheManager.create(); } return cacheManager; } public EHCacheProvider() { } public ResourceDataCache createDataCache() { try { final CacheManager manager = getCacheManager(); synchronized(manager) { if (manager.cacheExists("libloader-data") == false) { manager.addCache("libloader-data"); } return new EHResourceDataCache(manager.getCache("libloader-data")); } } catch (CacheException e) { return null; } } public ResourceBundleDataCache createBundleDataCache() { try { final CacheManager manager = getCacheManager(); synchronized(manager) { if (manager.cacheExists("libloader-bundles") == false) { manager.addCache("libloader-bundles"); } return new EHResourceBundleDataCache(manager.getCache("libloader-bundles")); } } catch (CacheException e) { return null; } } public ResourceFactoryCache createFactoryCache() { try { final CacheManager manager = getCacheManager(); synchronized(manager) { if (manager.cacheExists("libloader-factory") == false) { manager.addCache("libloader-factory"); } return new EHResourceFactoryCache(manager.getCache("libloader-factory")); } } catch (CacheException e) { return null; } } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHResourceBundleDataCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHResour0000644000175000017500000001031711365605644032376 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheException; import net.sf.ehcache.Element; import org.pentaho.reporting.libraries.resourceloader.ResourceBundleData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.cache.CachingResourceBundleData; import org.pentaho.reporting.libraries.resourceloader.cache.DefaultResourceBundleDataCacheEntry; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceBundleDataCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceBundleDataCacheEntry; /** * Creation-Date: 13.04.2006, 16:30:34 * * @author Thomas Morgner */ public class EHResourceBundleDataCache implements ResourceBundleDataCache { private Cache dataCache; public EHResourceBundleDataCache(final Cache dataCache) { if (dataCache == null) { throw new NullPointerException(); } this.dataCache = dataCache; } /** * Retrieves the given data from the cache. * * @param key the resource key for the data. */ public ResourceBundleDataCacheEntry get(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } try { final Element element = dataCache.get((Object) key); if (element != null) { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Bund Cache Hit " + key); } return (ResourceBundleDataCacheEntry) element.getObjectValue(); } else { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Bund Cache Miss " + key); } return null; } } catch (CacheException e) { return null; } } public ResourceBundleData put(final ResourceManager caller, final ResourceBundleData data) throws ResourceLoadingException { if (caller == null) { throw new NullPointerException(); } if (data == null) { throw new NullPointerException(); } final ResourceBundleData cdata = CachingResourceBundleData.createCached(data); final Object keyObject = data.getBundleKey(); final Object valueObject = new DefaultResourceBundleDataCacheEntry(cdata, caller); final Element element = new Element(keyObject, valueObject); if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Storing Bundle " + keyObject); } dataCache.put(element); return cdata; } public void remove(final ResourceBundleData data) { if (data == null) { throw new NullPointerException(); } dataCache.remove((Object) data.getBundleKey()); } /** * Remove all cached entries. This should be called after the cache has become * invalid or after it has been removed from a resource manager. */ public void clear() { try { dataCache.removeAll(); } catch (Exception e) { // ignore it .. } } public void shutdown() { try { dataCache.getCacheManager().shutdown(); } catch (Exception e) { // ignore it .. } } }././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHResourceFactoryCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHResour0000644000175000017500000001254611365605644032404 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheException; import net.sf.ehcache.Element; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceFactoryCache; /** * Creation-Date: 13.04.2006, 16:30:34 * * @author Thomas Morgner */ public class EHResourceFactoryCache implements ResourceFactoryCache { private static class CompoundCacheKey { private ResourceKey key; private Class target; public CompoundCacheKey(final ResourceKey key, final Class target) { if (key == null) { throw new NullPointerException(); } if (target == null) { throw new NullPointerException(); } this.key = key; this.target = target; } public ResourceKey getKey() { return key; } public Class getTarget() { return target; } public void setTarget(final Class target) { this.target = target; } public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final CompoundCacheKey that = (CompoundCacheKey) o; if (!target.equals(that.target)) { return false; } if (!key.equals(that.key)) { return false; } return true; } public int hashCode() { int result = key.hashCode(); result = 31 * result + target.hashCode(); return result; } public String toString() { final StringBuffer sb = new StringBuffer(); sb.append("CompoundCacheKey"); sb.append("{key=").append(key); sb.append(", target=").append(target); sb.append('}'); return sb.toString(); } } private static final Log logger = LogFactory.getLog(EHResourceFactoryCache.class); private Cache factoryCache; public EHResourceFactoryCache(final Cache factoryCache) { if (factoryCache == null) { throw new NullPointerException(); } this.factoryCache = factoryCache; } public Resource get(final ResourceKey key, final Class[] target) { for (int i = 0; i < target.length; i++) { final Resource res = getInternal(key, target[i]); if (res != null) { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Res Cache Hit " + key); } return res; } } if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Res Cache Miss " + key); } return null; } private Resource getInternal(final ResourceKey key, final Class target) { try { final Element element = factoryCache.get(new CompoundCacheKey(key, target)); if (element != null) { final Resource resource = (Resource) element.getObjectValue(); if (resource != null) { return resource; } final Resource resource1 = (Resource) element.getValue(); if (resource1 != null) { return resource1; } return null; } else { return null; } } catch (CacheException e) { if (logger.isDebugEnabled()) { logger.debug("Failed to retrieve resource for key " + key, e); } return null; } } public void put(final Resource resource) { final Object source = new CompoundCacheKey(resource.getSource(), resource.getTargetType()); try { factoryCache.put(new Element(source, (Object) resource)); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Failed to store resource for key " + source, e); } // ignore ... the object is not serializable .. } } public void remove(final Resource resource) { final Object source = new CompoundCacheKey(resource.getSource(), resource.getTargetType()); factoryCache.remove(source); } public void clear() { try { factoryCache.removeAll(); } catch (Exception e) { // ignore .. } } public void shutdown() { try { factoryCache.getCacheManager().shutdown(); } catch (Exception e) { // ignore it .. } } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHResourceDataCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHResour0000644000175000017500000001031711365605644032376 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheException; import net.sf.ehcache.Element; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.cache.CachingResourceData; import org.pentaho.reporting.libraries.resourceloader.cache.DefaultResourceDataCacheEntry; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceDataCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceDataCacheEntry; /** * Creation-Date: 13.04.2006, 16:30:34 * * @author Thomas Morgner */ public class EHResourceDataCache implements ResourceDataCache { private Cache dataCache; public EHResourceDataCache(final Cache dataCache) { if (dataCache == null) { throw new NullPointerException(); } this.dataCache = dataCache; } /** * Retrieves the given data from the cache. * * @param key the resource key for the data. */ public ResourceDataCacheEntry get(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } try { final Element element = dataCache.get((Object) key); if (element != null) { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Data Cache Hit " + key); } return (ResourceDataCacheEntry) element.getObjectValue(); } if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Data Cache Miss " + key); } return null; } catch (CacheException e) { return null; } } /** * Stores the given data on the cache. The data is registered by its primary * key. The cache has to store the current version of the data. * * @param data the data to be stored in the cache * @return the resource data object, possibly wrapped by a cache-specific * implementation. */ public ResourceData put(final ResourceManager caller, final ResourceData data) throws ResourceLoadingException { if (data == null) { throw new NullPointerException(); } if (caller == null) { throw new NullPointerException(); } final ResourceData cdata = CachingResourceData.createCached(data); final Object keyObject = data.getKey(); final Object dataCacheEntry = new DefaultResourceDataCacheEntry(cdata, caller); dataCache.put(new Element(keyObject, dataCacheEntry)); return cdata; } public void remove(final ResourceData data) { if (data == null) { throw new NullPointerException(); } dataCache.remove((Object) data.getKey()); } /** * Remove all cached entries. This should be called after the cache has become * invalid or after it has been removed from a resource manager. */ public void clear() { try { dataCache.removeAll(); } catch (Exception e) { // ignore it .. } } public void shutdown() { try { dataCache.getCacheManager().shutdown(); } catch (Exception e) { // ignore it .. } } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/module.propertieslibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/module.p0000644000175000017500000000071011365605644032421 0ustar renerenemodule.name: cache-ehcache module.producer: The Pentaho Reporting Project module.description: A cache module for 'libLoader', that uses EHCache. module.version.major: 1 module.version.minor: 0 module.version.patchlevel: 0 dependency.core.dependency-type: required dependency.core.module=org.pentaho.reporting.libraries.resourceloader.LibLoaderCoreModule dependency.core.version.major=1 dependency.core.version.minor=0 dependency.core.version.patchlevel=0 ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHCacheModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/cache/ehcache/EHCacheM0000644000175000017500000000411711365605644032240 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache; import org.pentaho.reporting.libraries.base.boot.AbstractModule; import org.pentaho.reporting.libraries.base.boot.ModuleInitializeException; import org.pentaho.reporting.libraries.base.boot.SubSystem; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Creation-Date: 13.04.2006, 16:29:07 * * @author Thomas Morgner */ public class EHCacheModule extends AbstractModule { public static final Log CACHE_MONITOR = LogFactory.getLog(EHCacheModule.class.getName() + "#CacheLog"); public EHCacheModule() throws ModuleInitializeException { loadModuleInfo(); } /** * Initializes the module. Use this method to perform all initial setup * operations. This method is called only once in a modules lifetime. If the * initializing cannot be completed, throw a ModuleInitializeException to * indicate the error,. The module will not be available to the system. * * @param subSystem the subSystem. * @throws ModuleInitializeException if an error ocurred while initializing * the module. */ public void initialize(final SubSystem subSystem) throws ModuleInitializeException { } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/0000755000175000017500000000000011365605644030001 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/0000755000175000017500000000000011365605644030600 5ustar renerene././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/AbstractSVGFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/AbstractSV0000644000175000017500000000336411365605644032545 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractFactoryModule; /** * Creation-Date: 05.04.2006, 17:52:57 * * @author Thomas Morgner */ public abstract class AbstractSVGFactoryModule extends AbstractFactoryModule { private static final int[] FINGERPRINT = new int[0]; private static final String[] MIMETYPES = { "image/svg-xml", "image/svg+xml" }; private static final String[] FILEEXTENSIONS = { ".svg" }; protected AbstractSVGFactoryModule() { } protected int[] getFingerPrint() { return FINGERPRINT; } protected String[] getMimeTypes() { return MIMETYPES; } protected String[] getFileExtensions() { return FILEEXTENSIONS; } public int getHeaderFingerprintSize() { return FINGERPRINT.length; } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/WrapperSVGDrawableFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/WrapperSVG0000644000175000017500000000530011365605644032521 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import org.pentaho.reporting.libraries.resourceloader.factory.FactoryModule; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * Todo: Document Me * * @author Thomas Morgner */ public class WrapperSVGDrawableFactoryModule implements FactoryModule { private FactoryModule parent; public WrapperSVGDrawableFactoryModule() { parent = (FactoryModule) ObjectUtilities.loadAndInstantiate ("org.pentaho.reporting.libraries.resourceloader.modules.factory.svg.SVGDrawableFactoryModule", WrapperSVGDrawableFactoryModule.class, FactoryModule.class); } public int canHandleResource(final ResourceManager caller, final ResourceData data) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { return FactoryModule.REJECTED; } return parent.canHandleResource(caller, data); } public int getHeaderFingerprintSize() { if (parent == null) { return 0; } return parent.getHeaderFingerprintSize(); } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { throw new ResourceCreationException("Cannot create resource: Batik libraries are not available."); } return parent.create(caller, data, context); } }././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGDrawableFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGDrawabl0000644000175000017500000000545411365605644032467 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import java.io.IOException; import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.DocumentLoader; import org.apache.batik.bridge.GVTBuilder; import org.apache.batik.gvt.GraphicsNode; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; import org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper; import org.w3c.dom.svg.SVGDocument; /** * Creation-Date: 05.04.2006, 17:58:42 * * @author Thomas Morgner */ public class SVGDrawableFactoryModule extends AbstractSVGFactoryModule { public SVGDrawableFactoryModule() { } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceLoadingException { try { final long version = data.getVersion(caller); final HeadlessSVGUserAgent userAgent = new HeadlessSVGUserAgent(); final DocumentLoader loader = new DocumentLoader(userAgent); final SVGDocument document = (SVGDocument) loader.loadDocument (String.valueOf(data.getKey().getIdentifier()), data.getResourceAsStream(caller)); final BridgeContext ctx = new BridgeContext(userAgent, loader); final GVTBuilder builder = new GVTBuilder(); final GraphicsNode node = builder.build(ctx, document); return new SimpleResource(data.getKey(), new SVGDrawable(node), DrawableWrapper.class, version); } catch (IOException e) { throw new ResourceLoadingException("Failed to process WMF file", e); } } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGModule.0000644000175000017500000000365611365605644032420 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import org.pentaho.reporting.libraries.base.boot.AbstractModule; import org.pentaho.reporting.libraries.base.boot.ModuleInitializeException; import org.pentaho.reporting.libraries.base.boot.SubSystem; /** * Creation-Date: 06.04.2006, 10:56:37 * * @author Thomas Morgner */ public class SVGModule extends AbstractModule { public SVGModule() throws ModuleInitializeException { loadModuleInfo(); } /** * Initializes the module. Use this method to perform all initial setup * operations. This method is called only once in a modules lifetime. If the * initializing cannot be completed, throw a ModuleInitializeException to * indicate the error,. The module will not be available to the system. * * @param subSystem the subSystem. * @throws org.pentaho.reporting.libraries.base.boot.ModuleInitializeException if an error ocurred while initializing * the module. */ public void initialize(final SubSystem subSystem) throws ModuleInitializeException { } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/HeadlessSVGUserAgent.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/HeadlessSV0000644000175000017500000000311611365605644032525 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import org.apache.batik.bridge.ScriptSecurity; import org.apache.batik.bridge.UserAgentAdapter; import org.apache.batik.util.ParsedURL; /** * Creation-Date: 11.12.2007, 15:01:44 * * @author Thomas Morgner */ public class HeadlessSVGUserAgent extends UserAgentAdapter { public HeadlessSVGUserAgent() { } /** * Should we prevent users from running scripts? If yes, then add it here. * * @param string * @param parsedURL * @param parsedURL1 * @return */ public ScriptSecurity getScriptSecurity(final String string, final ParsedURL parsedURL, final ParsedURL parsedURL1) { return super.getScriptSecurity(string, parsedURL, parsedURL1); } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/WrapperSVGImageFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/WrapperSVG0000644000175000017500000000526511365605644032533 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import org.pentaho.reporting.libraries.resourceloader.factory.FactoryModule; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * Todo: Document Me * * @author Thomas Morgner */ public class WrapperSVGImageFactoryModule implements FactoryModule { private FactoryModule parent; public WrapperSVGImageFactoryModule() { parent = (FactoryModule) ObjectUtilities.loadAndInstantiate ("org.pentaho.reporting.libraries.resourceloader.modules.factory.svg.SVGImageFactoryModule", WrapperSVGImageFactoryModule.class, FactoryModule.class); } public int canHandleResource(final ResourceManager caller, final ResourceData data) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { return FactoryModule.REJECTED; } return parent.canHandleResource(caller, data); } public int getHeaderFingerprintSize() { if (parent == null) { return 0; } return parent.getHeaderFingerprintSize(); } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { throw new ResourceCreationException("Cannot create resource: Batik libraries are not available."); } return parent.create(caller, data, context); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/configuration.propertieslibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/configurat0000644000175000017500000000065011365605644032665 0ustar renereneorg.pentaho.reporting.libraries.resourceloader.factory.modules.org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper.svg=org.pentaho.reporting.libraries.resourceloader.modules.factory.svg.WrapperSVGDrawableFactoryModule org.pentaho.reporting.libraries.resourceloader.factory.modules.java.awt.Image.svg=org.pentaho.reporting.libraries.resourceloader.modules.factory.svg.WrapperSVGImageFactoryModule ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGImageFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGImageFa0000644000175000017500000000612711365605644032402 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import java.io.IOException; import java.awt.geom.Rectangle2D; import java.awt.Image; import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.DocumentLoader; import org.apache.batik.bridge.GVTBuilder; import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.renderer.StaticRenderer; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; import org.w3c.dom.svg.SVGDocument; /** * Creation-Date: 05.04.2006, 17:58:42 * * @author Thomas Morgner */ public class SVGImageFactoryModule extends AbstractSVGFactoryModule { public SVGImageFactoryModule() { } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceLoadingException { try { final long version = data.getVersion(caller); final HeadlessSVGUserAgent userAgent = new HeadlessSVGUserAgent(); final DocumentLoader loader = new DocumentLoader(userAgent); final SVGDocument document = (SVGDocument) loader.loadDocument (String.valueOf(data.getKey().getIdentifier()), data.getResourceAsStream(caller)); final BridgeContext ctx = new BridgeContext(userAgent, loader); final GVTBuilder builder = new GVTBuilder(); final GraphicsNode node = builder.build(ctx, document); final Rectangle2D bounds = node.getBounds(); final StaticRenderer staticRenderer = new StaticRenderer(); staticRenderer.setDoubleBuffered(true); staticRenderer.setTree(node); staticRenderer.updateOffScreen((int) bounds.getWidth(), (int) bounds.getHeight()); return new SimpleResource(data.getKey(), staticRenderer.getOffScreen(), Image.class, version); } catch (IOException e) { throw new ResourceLoadingException("Failed to process SVG file", e); } } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGDrawable.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/SVGDrawabl0000644000175000017500000000520111365605644032455 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.svg; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import org.apache.batik.gvt.GraphicsNode; /** * Creation-Date: 21.12.2005, 20:25:29 * * @author Thomas Morgner */ public class SVGDrawable { private GraphicsNode rootNode; private int width; private int height; public SVGDrawable(final GraphicsNode rootNode) { if (rootNode == null) { throw new NullPointerException(); } this.rootNode = rootNode; final Rectangle2D bounds = rootNode.getBounds(); this.width = (int) bounds.getWidth(); this.height = (int) bounds.getHeight(); } /** * Returns the preferred size of the drawable. If the drawable is aspect ratio * aware, these bounds should be used to compute the preferred aspect ratio * for this drawable. * * @return the preferred size. */ public Dimension getPreferredSize() { return new Dimension(width, height); } /** * Returns true, if this drawable will preserve an aspect ratio during the * drawing. * * @return true, if an aspect ratio is preserved, false otherwise. */ public boolean isPreserveAspectRatio() { return true; } /** * Draws the object. * * @param g the graphics device. * @param area the area inside which the object should be drawn. */ public void draw(final Graphics2D g, final Rectangle2D area) { final Graphics2D g2 = (Graphics2D) g.create(); try { g2.translate(-area.getX(), -area.getY()); final double sx = area.getWidth() / width; final double sy = area.getHeight() / height; final double sm = Math.min (sx, sy); g2.scale(sm, sm); rootNode.paint(g2); } finally { g2.dispose(); } } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/module.propertieslibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/svg/module.pro0000644000175000017500000000076411365605644032616 0ustar renerenemodule.name: factory-svg module.producer: The Pentaho Reporting Project module.description: A input module for 'libLoader', which supports the SVG file format using the Apache-Batik library module.version.major: 1 module.version.minor: 0 module.version.patchlevel: 0 dependency.core.dependency-type=required dependency.core.module=org.pentaho.reporting.libraries.resourceloader.LibLoaderCoreModule dependency.core.version.major=1 dependency.core.version.minor=0 dependency.core.version.patchlevel=0 libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/0000755000175000017500000000000011365605644031413 5ustar renerene././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/ImageIOFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/ImageI0000644000175000017500000000653111365605644032476 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.imageio; import java.awt.Image; import java.io.ByteArrayInputStream; import java.io.IOException; import javax.imageio.ImageIO; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractFactoryModule; public class ImageIOFactoryModule extends AbstractFactoryModule { private static final int[] EMPTY_FINGERPRINT = new int[0]; private static final String[] EMPTY_FILETYPE = new String[0]; public ImageIOFactoryModule() { } private Image createImage(final byte[] imageData) throws IOException { return ImageIO.read(new ByteArrayInputStream(imageData)); } public int canHandleResource(final ResourceManager caller, final ResourceData data) throws ResourceCreationException, ResourceLoadingException { try { final byte[] resource = data.getResource(caller); if (createImage(resource) != null) { return RECOGNIZED_CONTENTTYPE; } } catch (IOException e) { // ignore me .. } return REJECTED; } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { final long version = data.getVersion(caller); final byte[] resource = data.getResource(caller); final Image image; try { image = createImage(resource); } catch (IOException e) { throw new ResourceCreationException("Failed to load the image.", e); } if (image == null) { throw new ResourceCreationException("Failed to load the image. ImageIO#read returned null"); } return new SimpleResource(data.getKey(), image, Image.class, version); } protected String[] getMimeTypes() { return EMPTY_FILETYPE; } protected String[] getFileExtensions() { return EMPTY_FILETYPE; } protected int[] getFingerPrint() { return EMPTY_FINGERPRINT; } public int getHeaderFingerprintSize() { return 0; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/ImageIOModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/ImageI0000644000175000017500000000265311365605644032477 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.imageio; import org.pentaho.reporting.libraries.base.boot.AbstractModule; import org.pentaho.reporting.libraries.base.boot.ModuleInitializeException; import org.pentaho.reporting.libraries.base.boot.SubSystem; /** * Creation-Date: 11.12.2007, 15:53:49 * * @author Thomas Morgner */ public class ImageIOModule extends AbstractModule { public ImageIOModule() throws ModuleInitializeException { loadModuleInfo(); } public void initialize(final SubSystem subSystem) throws ModuleInitializeException { } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/configuration.propertieslibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/config0000644000175000017500000000026311365605644032604 0ustar renereneorg.pentaho.reporting.libraries.resourceloader.factory.modules.java.awt.Image.image-io=org.pentaho.reporting.libraries.resourceloader.modules.factory.imageio.ImageIOFactoryModule ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/module.propertieslibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/imageio/module0000644000175000017500000000077011365605644032627 0ustar renerenemodule.name: factory-imageio module.producer: The Pentaho Reporting Project module.description: A input module for 'libLoader', which supports raster-images loaded through JDK 1.4+ ImageIO code module.version.major: 1 module.version.minor: 0 module.version.patchlevel: 0 dependency.core.dependency-type=required dependency.core.module=org.pentaho.reporting.libraries.resourceloader.LibLoaderCoreModule dependency.core.version.major=1 dependency.core.version.minor=0 dependency.core.version.patchlevel=0 libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/0000755000175000017500000000000011365605644030572 5ustar renerene././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/AbstractWMFFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/AbstractWM0000644000175000017500000000364311365605644032532 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractFactoryModule; /** * Creation-Date: 05.04.2006, 17:52:57 * * @author Thomas Morgner */ public abstract class AbstractWMFFactoryModule extends AbstractFactoryModule { private static final int[] FINGERPRINT = {0xD7, 0xCD}; private static final String[] MIMETYPES = { "application/x-msmetafile", "application/wmf", "application/x-wmf", "image/wmf", "image/x-wmf", "image/x-win-metafile", "zz-application/zz-winassoc-wmf" }; private static final String[] FILEEXTENSIONS = { ".wmf" }; protected AbstractWMFFactoryModule() { } protected int[] getFingerPrint() { return FINGERPRINT; } protected String[] getMimeTypes() { return MIMETYPES; } protected String[] getFileExtensions() { return FILEEXTENSIONS; } public int getHeaderFingerprintSize() { return 2; } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WMFImageFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WMFImageFa0000644000175000017500000000454211365605644032365 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf; import java.awt.Image; import java.io.IOException; import java.io.InputStream; import org.pentaho.reporting.libraries.pixie.wmf.WmfFile; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; /** * Creation-Date: 05.04.2006, 17:58:42 * * @author Thomas Morgner */ public class WMFImageFactoryModule extends AbstractWMFFactoryModule { public WMFImageFactoryModule() { } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceLoadingException { try { final long version = data.getVersion(caller); final InputStream stream = data.getResourceAsStream(caller); try { final WmfFile wmfFile = new WmfFile(stream, -1, -1); final Image image = wmfFile.replay(); return new SimpleResource(data.getKey(), image, Image.class, version); } finally { stream.close(); } } catch (IOException e) { throw new ResourceLoadingException("Failed to process WMF file", e); } } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WrapperWMFDrawableFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WrapperWMF0000644000175000017500000000526711365605644032521 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.factory.FactoryModule; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * Todo: Document Me * * @author Thomas Morgner */ public class WrapperWMFDrawableFactoryModule implements FactoryModule { private FactoryModule parent; public WrapperWMFDrawableFactoryModule() { parent = (FactoryModule) ObjectUtilities.loadAndInstantiate ("org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf.WMFImageFactoryModule", WrapperWMFImageFactoryModule.class, FactoryModule.class); } public int canHandleResource(final ResourceManager caller, final ResourceData data) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { return FactoryModule.REJECTED; } return parent.canHandleResource(caller, data); } public int getHeaderFingerprintSize() { if (parent == null) { return 0; } return parent.getHeaderFingerprintSize(); } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { throw new ResourceCreationException("Cannot create resource: Pixie library is not available."); } return parent.create(caller, data, context); } }././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/configuration.propertieslibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/configurat0000644000175000017500000000065111365605644032660 0ustar renereneorg.pentaho.reporting.libraries.resourceloader.factory.modules.org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper.wmf=org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf.WrapperWMFDrawableFactoryModule org.pentaho.reporting.libraries.resourceloader.factory.modules.java.awt.Image.wmf=org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf.WrapperWMFImageFactoryModule ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WMFDrawableFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WMFDrawabl0000644000175000017500000000461411365605644032450 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf; import java.io.IOException; import java.io.InputStream; import org.pentaho.reporting.libraries.pixie.wmf.WmfFile; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper; /** * Creation-Date: 05.04.2006, 17:58:42 * * @author Thomas Morgner */ public class WMFDrawableFactoryModule extends AbstractWMFFactoryModule { public WMFDrawableFactoryModule() { } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceLoadingException { try { final long version = data.getVersion(caller); final InputStream stream = data.getResourceAsStream(caller); try { final WmfFile wmfFile = new WmfFile(stream, -1, -1); return new SimpleResource (data.getKey(), wmfFile, DrawableWrapper.class, version); } finally { stream.close(); } } catch (IOException e) { throw new ResourceLoadingException("Failed to process WMF file", e); } } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WMFModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WMFModule.0000644000175000017500000000360411365605644032375 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf; import org.pentaho.reporting.libraries.base.boot.ModuleInitializeException; import org.pentaho.reporting.libraries.base.boot.SubSystem; import org.pentaho.reporting.libraries.base.boot.AbstractModule; /** * Creation-Date: 06.04.2006, 10:56:37 * * @author Thomas Morgner */ public class WMFModule extends AbstractModule { public WMFModule() throws ModuleInitializeException { loadModuleInfo(); } /** * Initializes the module. Use this method to perform all initial setup * operations. This method is called only once in a modules lifetime. If the * initializing cannot be completed, throw a ModuleInitializeException to * indicate the error,. The module will not be available to the system. * * @param subSystem the subSystem. * @throws ModuleInitializeException if an error ocurred while initializing * the module. */ public void initialize(final SubSystem subSystem) throws ModuleInitializeException { } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/module.propertieslibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/module.pro0000644000175000017500000000075611365605644032611 0ustar renerenemodule.name: factory-wmf module.producer: The Pentaho Reporting Project module.description: A input module for 'libLoader', which supports the WMF file format using the Pixie library module.version.major: 1 module.version.minor: 0 module.version.patchlevel: 0 dependency.core.dependency-type=required dependency.core.module=org.pentaho.reporting.libraries.resourceloader.LibLoaderCoreModule dependency.core.version.major=1 dependency.core.version.minor=0 dependency.core.version.patchlevel=0 ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WrapperWMFImageFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/modules/factory/wmf/WrapperWMF0000644000175000017500000000526111365605644032513 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.factory.FactoryModule; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * Todo: Document Me * * @author Thomas Morgner */ public class WrapperWMFImageFactoryModule implements FactoryModule { private FactoryModule parent; public WrapperWMFImageFactoryModule() { parent = (FactoryModule) ObjectUtilities.loadAndInstantiate ("org.pentaho.reporting.libraries.resourceloader.modules.factory.wmf.WMFImageFactoryModule", WrapperWMFImageFactoryModule.class, FactoryModule.class); } public int canHandleResource(final ResourceManager caller, final ResourceData data) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { return FactoryModule.REJECTED; } return parent.canHandleResource(caller, data); } public int getHeaderFingerprintSize() { if (parent == null) { return 0; } return parent.getHeaderFingerprintSize(); } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { if (parent == null) { throw new ResourceCreationException("Cannot create resource: Pixie library is not available."); } return parent.create(caller, data, context); } }libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceLoadingException.java0000644000175000017500000000316711365605644032500 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * Creation-Date: 05.04.2006, 13:03:37 * * @author Thomas Morgner */ public class ResourceLoadingException extends ResourceException { private static final long serialVersionUID = -940152083042961377L; /** Creates a StackableRuntimeException with no message and no parent. */ public ResourceLoadingException() { } /** * Creates an exception. * * @param message the exception message. * @param ex the parent exception. */ public ResourceLoadingException(final String message, final Exception ex) { super(message, ex); } /** * Creates an exception. * * @param message the exception message. */ public ResourceLoadingException(final String message) { super(message); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/FactoryParameterKey.java0000644000175000017500000000364711365605644031460 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.io.Serializable; /** * Creation-Date: 16.05.2006, 15:24:21 * * @author Thomas Morgner */ public final class FactoryParameterKey implements Serializable { private String name; private transient int hashKey; private static final long serialVersionUID = 4574332935778105499L; public FactoryParameterKey(final String name) { if (name == null) { throw new NullPointerException(); } this.name = name; } public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final FactoryParameterKey that = (FactoryParameterKey) o; if (!name.equals(that.name)) { return false; } return true; } public int hashCode() { if (hashKey == 0) { hashKey = name.hashCode(); } return hashKey; } public String getName() { return name; } public String toString() { return getClass().getName() + "{name=" + getName() + "}"; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/0000755000175000017500000000000011365605644026130 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/URLResourceLoader.java0000644000175000017500000001644711365605644032310 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyData; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyUtils; import org.pentaho.reporting.libraries.resourceloader.ResourceLoader; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; /** * Creation-Date: 05.04.2006, 15:32:36 * * @author Thomas Morgner */ public class URLResourceLoader implements ResourceLoader { public static final String SCHEMA_NAME = URLResourceLoader.class.getName(); private static final Log logger = LogFactory.getLog(URLResourceLoader.class); public URLResourceLoader() { } /** * Checks, whether this resource loader implementation was responsible for * creating this key. * * @param key * @return */ public boolean isSupportedKey(final ResourceKey key) { if (SCHEMA_NAME.equals(key.getSchema())) { return true; } return false; } /** * Creates a new resource key from the given object and the factory keys. * * @param value * @param factoryKeys * @return the created key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if creating the key failed. */ public ResourceKey createKey(final Object value, final Map factoryKeys) throws ResourceKeyCreationException { if (value instanceof URL) { return new ResourceKey(SCHEMA_NAME, value, factoryKeys); } if (value instanceof String) { final String valueString = (String) value; // the 'file' schema is defined to have double-slashes, but the JDK // ignores RFC 1738 in that case. So we have to check for these beasts // directly .. if (valueString.indexOf("://") >= 0 || valueString.startsWith("file:/")) { try { return new ResourceKey(SCHEMA_NAME, new URL(valueString), factoryKeys); } catch (MalformedURLException mfue) { // we dont take this easy! throw new ResourceKeyCreationException("Malformed value: " + value); } } } return null; } /** * Derives a new resource key from the given key. If neither a path nor new * factory-keys are given, the parent key is returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if the key cannot be derived for any reason. */ public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map factoryKeys) throws ResourceKeyCreationException { if (isSupportedKey(parent) == false) { throw new ResourceKeyCreationException("Assertation: Unsupported parent key type"); } try { final URL url; if (path != null) { url = new URL((URL) parent.getIdentifier(), path); } else { url = (URL) parent.getIdentifier(); } final Map map; if (factoryKeys != null) { map = new HashMap(); map.putAll(parent.getFactoryParameters()); map.putAll(factoryKeys); } else { map = parent.getFactoryParameters(); } return new ResourceKey(parent.getSchema(), url, map); } catch (MalformedURLException e) { throw new ResourceKeyCreationException("Malformed value: " + path); } } public URL toURL(final ResourceKey key) { return (URL) key.getIdentifier(); } public ResourceData load(final ResourceKey key) throws ResourceLoadingException { if (isSupportedKey(key) == false) { throw new ResourceLoadingException("Key format is not recognized."); } return new URLResourceData(key); } /** * Creates a String version of the resource key that can be used to generate a new ResourceKey * object via deserialization * @param bundleKey * @param key */ public String serialize(ResourceKey bundleKey, final ResourceKey key) { // Validate the parameter if (key == null) { throw new NullPointerException("The ResourceKey can not be null"); } if (isSupportedKey(key) == false) { throw new IllegalArgumentException("Key format is not recognized."); } if (!(key.getIdentifier() instanceof URL)) { throw new IllegalArgumentException("ResourceKey is invalid - identifier is not a URL object"); } // Log information logger.debug("Serializing a Classloader Resource Key..."); if (key.getParent() != null) { logger.warn("Serializing a Classloader Resource Key which contains a parent: key=[" + bundleKey + "] parent=[" + key.getParent() + "]"); } // Serialize the key final URL url = (URL) key.getIdentifier(); final String result = ResourceKeyUtils.createStringResourceKey (key.getSchema().toString(), url.toExternalForm(), key.getFactoryParameters()); logger.debug("Serialized Classloader Resource Key: [" + result + "]"); return result; } /** * Parses the input string and returns a newly created ResourceKey based on the string data */ public ResourceKey deserialize(final ResourceKey bundleKey, String stringKey) throws ResourceKeyCreationException { // Parse the data ResourceKeyData keyData = ResourceKeyUtils.parse(stringKey); // Validate the data if (SCHEMA_NAME.equals(keyData.getSchema()) == false) { throw new ResourceKeyCreationException("Serialized version of key does not contain correct schema"); } // Create and return a new key try { return createKey(new URL(keyData.getIdentifier()), keyData.getFactoryParameters()); } catch (MalformedURLException mfue) { throw new ResourceKeyCreationException("Malformed value: " + keyData.getIdentifier()); } } public boolean isSupportedDeserializer(String data) { return SCHEMA_NAME.equals(ResourceKeyUtils.readSchemaFromString(data)); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/resource/0000755000175000017500000000000011365605644027757 5ustar renerene././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/resource/ClassloaderResourceData.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/resource/ClassloaderRes0000644000175000017500000000547411365605644032622 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.resource; import java.io.InputStream; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.loader.AbstractResourceData; import org.pentaho.reporting.libraries.resourceloader.loader.LoaderUtils; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * Creation-Date: 05.04.2006, 15:15:36 * * @author Thomas Morgner */ public class ClassloaderResourceData extends AbstractResourceData { private ResourceKey key; private String resourcePath; private static final long serialVersionUID = 980009972320937886L; public ClassloaderResourceData(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } this.key = key; final String rawPath = (String) key.getIdentifier(); this.resourcePath = rawPath.substring(6); } public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException { final InputStream stream = ObjectUtilities.getResourceAsStream (resourcePath, ClassloaderResourceData.class); if (stream == null) { throw new ResourceLoadingException("Resource is not available: " + resourcePath); } return stream; } public Object getAttribute(final String key) { // we do not support attributes ... if (key.equals(ResourceData.FILENAME)) { return LoaderUtils.getFileName(this.resourcePath); } return null; } public long getVersion(final ResourceManager caller) throws ResourceLoadingException { // We assume, that the data does never change // This way, we get the benefit of the cache. return 0; } public ResourceKey getKey() { return key; } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/resource/ClassloaderResourceLoader.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/resource/ClassloaderRes0000644000175000017500000001655211365605644032621 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.resource; import java.util.HashMap; import java.util.Map; import java.net.URL; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyData; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyUtils; import org.pentaho.reporting.libraries.resourceloader.ResourceLoader; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceException; import org.pentaho.reporting.libraries.resourceloader.loader.LoaderUtils; /** * Creation-Date: 05.04.2006, 14:40:59 * * @author Thomas Morgner */ public class ClassloaderResourceLoader implements ResourceLoader { public static final String SCHEMA_NAME = ClassloaderResourceLoader.class.getName(); private static final Log logger = LogFactory.getLog(ClassloaderResourceLoader.class); public ClassloaderResourceLoader() { } /** * Checks, whether this resource loader implementation was responsible for * creating this key. * * @param key * @return */ public boolean isSupportedKey(final ResourceKey key) { if (SCHEMA_NAME.equals(key.getSchema())) { return true; } return false; } /** * Creates a new resource key from the given object and the factory keys. * * @param value * @param factoryKeys * @return the created key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if creating the key failed. */ public ResourceKey createKey(final Object value, final Map factoryKeys) throws ResourceKeyCreationException { if (value instanceof String) { final String valueString = (String) value; if (valueString.startsWith("res://")) { return new ResourceKey(SCHEMA_NAME, value, factoryKeys); } } return null; } /** * Derives a new resource key from the given key. If neither a path nor new * factory-keys are given, the parent key is returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if the key cannot be derived for any reason. */ public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map factoryKeys) throws ResourceKeyCreationException { if (isSupportedKey(parent) == false) { throw new ResourceKeyCreationException("Assertation: Unsupported parent key type"); } final String resource; if (path.startsWith("res://")) { resource = path; } else if (path.length() > 0 && path.charAt(0) == '/') { resource = "res:/" + path; } else { resource = LoaderUtils.mergePaths((String) parent.getIdentifier(), path); } final Map map; if (factoryKeys != null) { map = new HashMap(); map.putAll(parent.getFactoryParameters()); map.putAll(factoryKeys); } else { map = parent.getFactoryParameters(); } return new ResourceKey(parent.getSchema(), resource, map); } public URL toURL(final ResourceKey key) { return null; } public ResourceData load(final ResourceKey key) throws ResourceLoadingException { if (isSupportedKey(key) == false) { throw new ResourceLoadingException("Key format is not recognized."); } return new ClassloaderResourceData(key); } /** * A helper method to make it easier to create resource descriptions. * * @param c * @param resource * @return */ public static String createResourceKey(final Class c, final String resource) { if (c == null) { // the resource given should already be absolute .. return "res://" + resource; } final String className = c.getName(); final int lastDot = className.lastIndexOf('.'); if (lastDot < 0) { return "res://" + resource; } else { final String packageName = className.substring(0, lastDot); final String packagePath = packageName.replace('.', '/'); return "res://" + packageName + '/' + packagePath; } } /** * Creates a String version of the resource key that can be used to generate a new ResourceKey * object via deserialization * @param bundleKey * @param key */ public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException { // Validate the parameter if (key == null) { throw new NullPointerException("The ResourceKey can not be null"); } if (isSupportedKey(key) == false) { throw new IllegalArgumentException("Key format is not recognized."); } if (!(key.getIdentifier() instanceof String)) { throw new IllegalArgumentException("ResourceKey is invalid - identifier is not a String object"); } // Log information logger.debug("Serializing a Classloader Resource Key..."); if (key.getParent() != null) { throw new ResourceException ("Cannot serialize this key, it contains a parent, but should not contain one at all."); } // Serialize the key final String result = ResourceKeyUtils.createStringResourceKey(key.getSchema().toString(), (String) key.getIdentifier(), key.getFactoryParameters()); logger.debug("Serialized Classloader Resource Key: [" + result + "]"); return result; } /** * Parses the input string and returns a newly created ResourceKey based on the string data */ public ResourceKey deserialize(final ResourceKey bundleKey, String stringKey) throws ResourceKeyCreationException { // Parse the data final ResourceKeyData keyData = ResourceKeyUtils.parse(stringKey); // Validate the data if (SCHEMA_NAME.equals(keyData.getSchema()) == false) { throw new ResourceKeyCreationException("Serialized version of key does not contain correct schema"); } // Create and return a new key return createKey(keyData.getIdentifier(), keyData.getFactoryParameters()); } public boolean isSupportedDeserializer(String data) { return SCHEMA_NAME.equals(ResourceKeyUtils.readSchemaFromString(data)); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/AbstractResourceData.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/AbstractResourceData.ja0000644000175000017500000001063411365605644032515 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * Creation-Date: 05.04.2006, 15:24:47 * * @author Thomas Morgner */ public abstract class AbstractResourceData implements ResourceData, Serializable { private static final long serialVersionUID = -2578855461270413802L; protected AbstractResourceData() { } public byte[] getResource(final ResourceManager caller) throws ResourceLoadingException { try { final InputStream in = getResourceAsStream(caller); if (in == null) { throw new ResourceLoadingException("Unable to read Stream: No input stream: " + getKey()); } try { final ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtils.getInstance().copyStreams(in, bout); return bout.toByteArray(); } finally { in.close(); } } catch (ResourceLoadingException rle) { throw rle; } catch (IOException e) { throw new ResourceLoadingException("Unable to read Stream: ", e); } } public long getLength() { final Object attribute = getAttribute(CONTENT_LENGTH); if (attribute instanceof Number) { final Number length = (Number) attribute; return length.longValue(); } return -1; } public int getResource(final ResourceManager caller, final byte[] target, final long offset, final int length) throws ResourceLoadingException { try { if (target == null) { throw new NullPointerException(); } if (target.length < length) { throw new IndexOutOfBoundsException("Requested end-position is greater than "); } final InputStream in = getResourceAsStream(caller); if (in == null) { throw new ResourceLoadingException("Unable to read Stream: No input stream: " + getKey()); } try { if (offset > 0) { long toBeSkipped = offset; long skipResult = in.skip(toBeSkipped); toBeSkipped -= skipResult; while (skipResult > 0 && toBeSkipped > 0) { skipResult = in.skip(offset); toBeSkipped -= skipResult; } if (toBeSkipped > 0) { // failed to read up to the offset .. throw new ResourceLoadingException ("Unable to read Stream: Skipping content failed: " + getKey()); } } int bytesToRead = length; // the input stream does not supply accurate available() data // the zip entry does not know the size of the data int bytesRead = in.read(target, length - bytesToRead, bytesToRead); while (bytesRead > -1 && bytesToRead > 0) { bytesToRead -= bytesRead; bytesRead = in.read(target, length - bytesToRead, bytesToRead); } return length - bytesRead; } finally { in.close(); } } catch (ResourceLoadingException rle) { throw rle; } catch (IOException e) { throw new ResourceLoadingException("Unable to read Stream: ", e); } } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/file/0000755000175000017500000000000011365605644027047 5ustar renerene././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/file/FileResourceLoader.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/file/FileResourceLoader0000644000175000017500000001771111365605644032517 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.file; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyData; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyUtils; import org.pentaho.reporting.libraries.resourceloader.ResourceLoader; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceException; /** * Creation-Date: 05.04.2006, 14:17:56 * * @author Thomas Morgner */ public class FileResourceLoader implements ResourceLoader { public static final String SCHEMA_NAME = FileResourceLoader.class.getName(); private static final Log logger = LogFactory.getLog(FileResourceLoader.class); public FileResourceLoader() { } /** * Checks, whether this resource loader implementation was responsible for * creating this key. * * @param key * @return */ public boolean isSupportedKey(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } if (SCHEMA_NAME.equals(key.getSchema())) { return true; } return false; } /** * Creates a new resource key from the given object and the factory keys. * * @param value * @param factoryKeys * @return the created key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if creating the key failed. */ public ResourceKey createKey(final Object value, final Map factoryKeys) throws ResourceKeyCreationException { if (value instanceof File) { final File f = (File) value; if (f.exists() && f.isFile()) { return new ResourceKey(SCHEMA_NAME, f, factoryKeys); } } else if (value instanceof String) { final File f = new File(String.valueOf(value)); if (f.exists() && f.isFile()) { return new ResourceKey(SCHEMA_NAME, f, factoryKeys); } } return null; } /** * Derives a new resource key from the given key. If neither a path nor new * factory-keys are given, the parent key is returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if the key cannot be derived for any reason. */ public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map factoryKeys) throws ResourceKeyCreationException { if (isSupportedKey(parent) == false) { throw new ResourceKeyCreationException("Assertation: Unsupported parent key type"); } try { final File target; if (path != null) { final File parentResource = (File) parent.getIdentifier(); target = new File(parentResource.getCanonicalFile().getParentFile(), path); if (target.exists() == false || target.isFile() == false) { throw new ResourceKeyCreationException("Malformed value: " + path + " (" + target + ')'); } } else { target = (File) parent.getIdentifier(); } final Map map; if (factoryKeys != null) { map = new HashMap(); map.putAll(parent.getFactoryParameters()); map.putAll(factoryKeys); } else { map = parent.getFactoryParameters(); } return new ResourceKey(parent.getSchema(), target, map); } catch (IOException ioe) { throw new ResourceKeyCreationException("Failed to create key", ioe); } } public URL toURL(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } if (isSupportedKey(key) == false) { throw new IllegalArgumentException("Key format is not recognized."); } final File file = (File) key.getIdentifier(); try { return file.toURL(); } catch (MalformedURLException e) { return null; } } public ResourceData load(final ResourceKey key) throws ResourceLoadingException { if (isSupportedKey(key) == false) { throw new ResourceLoadingException("Key format is not recognized."); } return new FileResourceData(key); } /** * Generates a String representation of the ResourceKey specified. * TODO: implement * @param bundleKey * @param key */ public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException { // Validate the parameter if (key == null) { throw new NullPointerException("The ResourceKey can not be null"); } if (isSupportedKey(key) == false) { throw new IllegalArgumentException("Key format is not recognized."); } if (!(key.getIdentifier() instanceof File)) { throw new IllegalArgumentException("ResourceKey is invalid - identifier is not a File object"); } // Log information logger.debug("Serializing a File Resource Key..."); if (key.getParent() != null) { throw new ResourceException ("Unable to serialize a File-ResourceKey with a parent. This type is not expected to have a parent."); } // Create a string version of the identifier try { final File file = (File) key.getIdentifier(); final String strIdentifier = file.getCanonicalPath(); final String result = ResourceKeyUtils.createStringResourceKey (key.getSchema().toString(), strIdentifier, key.getFactoryParameters()); logger.debug("Serialized File Resource Key: [" + result + "]"); return result; } catch (IOException ioe) { throw new IllegalArgumentException("Could not determine cononical path to file specified in ResourceKey: " + ioe.getMessage()); } } /** * Generates a String representation of the ResourceKey specified. * TODO: implement */ public ResourceKey deserialize(final ResourceKey bundleKey, String stringKey) throws ResourceKeyCreationException { // Parse the data ResourceKeyData keyData = ResourceKeyUtils.parse(stringKey); // Validate the data if (SCHEMA_NAME.equals(keyData.getSchema()) == false) { throw new ResourceKeyCreationException("Serialized version of key does not contain correct schema"); } // Create a new file based on the path provided final File file = new File(keyData.getIdentifier()); // Return a newly created key based on the parameters we loaded return createKey(file, keyData.getFactoryParameters()); } public boolean isSupportedDeserializer(String data) { return SCHEMA_NAME.equals(ResourceKeyUtils.readSchemaFromString(data)); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/file/FileResourceData.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/file/FileResourceData.j0000644000175000017500000000650611365605644032412 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.file; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.loader.AbstractResourceData; /** * A simple file reader. This class, as all core implementation, does not hold * any references to the data read from the file. Caching is left to the cache * provider. * * @author Thomas Morgner */ public class FileResourceData extends AbstractResourceData { private ResourceKey key; private File file; private static final long serialVersionUID = -5719048997437795736L; public FileResourceData(final ResourceKey key) throws ResourceLoadingException { if (key == null) { throw new NullPointerException(); } final File file = (File) key.getIdentifier(); if (file.isFile() == false) { throw new ResourceLoadingException ("File-handle given does not point to a regular file."); } if (file.canRead() == false) { throw new ResourceLoadingException ("File '" + file + "' is not readable."); } this.key = key; this.file = file; } public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException { if (caller == null) { throw new NullPointerException(); } try { return new BufferedInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { throw new ResourceLoadingException("Unable to open Stream: ", e); } } public Object getAttribute(final String attrkey) { if (attrkey == null) { throw new NullPointerException(); } if (attrkey.equals(ResourceData.FILENAME)) { return file.getName(); } if (attrkey.equals(ResourceData.CONTENT_LENGTH)) { return new Long(file.length()); } return null; } public long getVersion(final ResourceManager caller) throws ResourceLoadingException { if (caller == null) { throw new NullPointerException(); } return file.lastModified(); } public ResourceKey getKey() { return key; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/LoaderUtils.java0000644000175000017500000001141211365605644031221 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; /** * Creation-Date: 05.04.2006, 16:02:53 * * @author Thomas Morgner */ public class LoaderUtils { private LoaderUtils() { } public static String stripLeadingSlashes(String s) { int leadingSlashes = 0; while (s.length() > leadingSlashes && s.charAt(leadingSlashes) == '/') { leadingSlashes += 1; } if (leadingSlashes == 0) { return s; } return s.substring(leadingSlashes); } /** * Merges two paths. A path is recognized as an absolute path, if * it has an URL-schema definition attached. A parent is recognized as * container path (a directory, in the common language), if it ends with * a slash. * * Todo: Introduce escaping using "\" as escape char. * * @param parent * @param child * @return * @throws ResourceKeyCreationException */ public static String mergePaths(final String parent, final String child) throws ResourceKeyCreationException { final int childPrefix = child.indexOf("://"); if (childPrefix > 0) { return child; } final String parentResource; final String parentPrefix; final int parentPrefixPos = parent.indexOf("://"); if (parentPrefixPos > 0) { parentResource = parent.substring(parentPrefixPos + 3); parentPrefix = parent.substring(0, parentPrefixPos + 3); } else { parentResource = parent; parentPrefix = ""; } final List parentList; if (parentResource.length() > 0 && parentResource.charAt(parentResource.length() - 1) == '/') { parentList = parseName(parentResource, false); } else { parentList = parseName(parentResource, true); } // construct the full name ... parentList.addAll(parseName(child, false)); // and normalize it by removing all '.' and '..' elements. final ArrayList normalizedList = new ArrayList(); for (int i = 0; i < parentList.size(); i++) { final String o = (String) parentList.get(i); if (".".equals(o)) { continue; } if ("..".equals(o)) { if (normalizedList.isEmpty() == false) { // remove last element normalizedList.remove(normalizedList.size() - 1); } } else { normalizedList.add(o); } } if (normalizedList.isEmpty()) { throw new ResourceKeyCreationException("Unable to build a valid key."); } final StringBuffer buffer = new StringBuffer(); buffer.append(parentPrefix); for (int i = 0; i < normalizedList.size(); i++) { final String s = (String) normalizedList.get(i); if (i > 0) { buffer.append('/'); } buffer.append(s); } return buffer.toString(); } /** * Parses the given name and returns the name elements as List of Strings. * * @param name the name, that should be parsed. * @return the parsed name. */ private static List parseName(final String name, final boolean skipLast) { final ArrayList list = new ArrayList(); final StringTokenizer strTok = new StringTokenizer(name, "/"); while (strTok.hasMoreElements()) { final String s = (String) strTok.nextElement(); if (s.length() != 0) { list.add(s); } } if (skipLast && list.isEmpty() == false) { list.remove(list.size() - 1); } return list; } /** * Extracts the file name from a path name. * * @param file the path name. * @return the extracted filename. */ public static String getFileName(final String file) { final int last = file.lastIndexOf('/'); if (last < 0) { return file; } return file.substring(last + 1); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/URLResourceData.java0000644000175000017500000001142211365605644031737 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import org.pentaho.reporting.libraries.base.util.IOUtils; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * A generic read handler for URL resources. * * @author Thomas Morgner */ public class URLResourceData extends AbstractResourceData { private long lastDateMetaDataRead; private long modificationDate; private String filename; private Long contentLength; private String contentType; private boolean metaDataOK; private URL url; private ResourceKey key; private static final long serialVersionUID = -7183025686032509509L; public URLResourceData(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } this.modificationDate = -1; this.key = key; this.url = (URL) key.getIdentifier(); // for the ease of implementation, we take the file name from the URL. // Feel free to add a 'Content-Disposition' parser with all details :) this.filename = IOUtils.getInstance().getFileName(url); } protected URLResourceData() { } protected void setUrl(final URL url) { this.url = url; } protected void setKey(final ResourceKey key) { this.key = key; } protected void setFilename(final String filename) { this.filename = filename; } protected URL getUrl() { return url; } protected String getFilename() { return filename; } private void readMetaData() throws IOException { if (metaDataOK && (System.currentTimeMillis() - lastDateMetaDataRead) < 5000) { return; } final URLConnection c = url.openConnection(); c.setDoOutput(false); c.setAllowUserInteraction(false); if (c instanceof HttpURLConnection) { final HttpURLConnection httpURLConnection = (HttpURLConnection) c; httpURLConnection.setRequestMethod("HEAD"); } c.connect(); modificationDate = c.getDate(); contentLength = new Long(c.getContentLength()); contentType = c.getHeaderField("content-type"); c.getInputStream().close(); metaDataOK = true; lastDateMetaDataRead = System.currentTimeMillis(); } public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException { try { final URLConnection c = url.openConnection(); c.setDoOutput(false); c.setAllowUserInteraction(false); return c.getInputStream(); } catch (IOException e) { throw new ResourceLoadingException("Failed to open URL connection", e); } } public Object getAttribute(final String key) { if (key.equals(ResourceData.FILENAME)) { return filename; } if (key.equals(ResourceData.CONTENT_LENGTH)) { try { if (metaDataOK == false) { readMetaData(); } return contentLength; } catch (IOException e) { return null; } } if (key.equals(ResourceData.CONTENT_TYPE)) { try { if (metaDataOK == false) { readMetaData(); } return contentType; } catch (IOException e) { return null; } } return null; } public long getVersion(final ResourceManager caller) throws ResourceLoadingException { try { // always read the new date .. sorry, this is expensive, but needed here // else the cache would not be in sync ... readMetaData(); return modificationDate; } catch (IOException e) { return -1; } } public ResourceKey getKey() { return key; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/zip/0000755000175000017500000000000011365605644026732 5ustar renerene././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/zip/ZipResourceLoader.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/zip/ZipResourceLoader.j0000644000175000017500000001262311365605644032512 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.zip; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceException; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyUtils; import org.pentaho.reporting.libraries.resourceloader.ResourceLoader; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.loader.LoaderUtils; /** * Creation-Date: 05.04.2006, 15:53:21 * * @author Thomas Morgner */ public class ZipResourceLoader implements ResourceLoader { public static final String SCHEMA_NAME = ZipResourceLoader.class.getName(); private static final Log logger = LogFactory.getLog(ZipResourceLoader.class); public ZipResourceLoader() { } /** * Checks, whether this resource loader implementation was responsible for * creating this key. * * @param key * @return */ public boolean isSupportedKey(final ResourceKey key) { return SCHEMA_NAME.equals(key.getSchema()); } /** * Creates a new resource key from the given object and the factory keys. * * @param value * @param factoryKeys * @return the created key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if creating the key failed. */ public ResourceKey createKey(final Object value, final Map factoryKeys) throws ResourceKeyCreationException { if (value instanceof ZipEntryKey == false) { return null; } final ZipEntryKey entryKey = (ZipEntryKey) value; final ResourceKey parentKey = entryKey.getZipFile().getKey(); return new ResourceKey(parentKey, SCHEMA_NAME, entryKey.getEntryName(), factoryKeys); } /** * Derives a new resource key from the given key. If neither a path nor new * factory-keys are given, the parent key is returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if the key cannot be derived for any reason. */ public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map factoryKeys) throws ResourceKeyCreationException { if (isSupportedKey(parent) == false) { throw new ResourceKeyCreationException("Assertation: Unsupported parent key type"); } final String entry; if (path != null) { entry = LoaderUtils.mergePaths((String) parent.getIdentifier(), path); } else { entry = (String) parent.getIdentifier(); } final Map map; if (factoryKeys != null) { map = new HashMap(); map.putAll(parent.getFactoryParameters()); map.putAll(factoryKeys); } else { map = parent.getFactoryParameters(); } return new ResourceKey(parent.getParent(), parent.getSchema(), entry, map); } public URL toURL(final ResourceKey key) { return null; } public ResourceData load(final ResourceKey key) throws ResourceLoadingException { if (isSupportedKey(key) == false) { throw new ResourceLoadingException("Key format is not recognized."); } return new ZipResourceData(key); } public ResourceKey deserialize(final ResourceKey bundleKey, String stringKey) throws ResourceKeyCreationException { // For now, we are just going to have to pass on this one throw new ResourceKeyCreationException("Can not deserialize a ZipResourceKey"); } public String serialize(ResourceKey bundleKey, final ResourceKey key) throws ResourceException { if (isSupportedKey(key) == false) { throw new IllegalArgumentException("Not supported"); } final ZipEntryKey entryKey = (ZipEntryKey) key.getIdentifier(); final String name = entryKey.getEntryName(); final ResourceKey zipKey = entryKey.getZipFile().getKey(); // For now, we are just going to have to pass on this one throw new ResourceException("Can not serialize a ZipResourceKey"); } public boolean isSupportedDeserializer(String data) { return SCHEMA_NAME.equals(ResourceKeyUtils.readSchemaFromString(data)); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/zip/ZipEntryKey.java0000644000175000017500000000745011365605644032040 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.zip; import java.io.File; import java.io.Serializable; import java.net.URL; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * An external zip key. * * @author Thomas Morgner */ public class ZipEntryKey implements Serializable { private ResourceData zipFile; private String entryName; public ZipEntryKey(final ResourceData zipFile, final String entryName) { if (zipFile == null) { throw new NullPointerException(); } if (entryName == null) { throw new NullPointerException(); } this.zipFile = zipFile; this.entryName = entryName; } public ZipEntryKey(final ResourceManager manager, final String zipFile, final String entryName) throws ResourceKeyCreationException, ResourceLoadingException { if (zipFile == null) { throw new NullPointerException(); } if (entryName == null) { throw new NullPointerException(); } this.zipFile = manager.load(manager.createKey(zipFile)); this.entryName = entryName; } public ZipEntryKey(final ResourceManager manager, final URL zipFile, final String entryName) throws ResourceKeyCreationException, ResourceLoadingException { if (zipFile == null) { throw new NullPointerException(); } if (entryName == null) { throw new NullPointerException(); } this.zipFile = manager.load(manager.createKey(zipFile)); this.entryName = entryName; } public ZipEntryKey(final ResourceManager manager, final File zipFile, final String entryName) throws ResourceKeyCreationException, ResourceLoadingException { if (zipFile == null) { throw new NullPointerException(); } if (entryName == null) { throw new NullPointerException(); } this.zipFile = manager.load(manager.createKey(zipFile)); this.entryName = entryName; } public ResourceData getZipFile() { return zipFile; } public String getEntryName() { return entryName; } public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final ZipEntryKey that = (ZipEntryKey) o; if (!entryName.equals(that.entryName)) { return false; } if (!zipFile.getKey().equals(that.zipFile.getKey())) { return false; } return true; } public int hashCode() { int result = zipFile.getKey().hashCode(); result = 29 * result + entryName.hashCode(); return result; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/zip/ZipResourceData.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/zip/ZipResourceData.jav0000644000175000017500000000646511365605644032513 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.zip; import java.io.InputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.loader.AbstractResourceData; import org.pentaho.reporting.libraries.resourceloader.loader.LoaderUtils; /** * Creation-Date: 05.04.2006, 15:44:07 * * @author Thomas Morgner */ public class ZipResourceData extends AbstractResourceData { private ResourceKey key; private static final long serialVersionUID = -7432641415119820243L; public ZipResourceData(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } this.key = key; } public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException { // again, this is going to hurt the performance. final ResourceKey parentKey = key.getParent(); final ResourceData data = caller.load(parentKey); final ZipInputStream zin = new ZipInputStream(data.getResourceAsStream(caller)); try { try { ZipEntry zipEntry = zin.getNextEntry(); while (zipEntry != null) { if (zipEntry.getName().equals(key.getIdentifier()) == false) { zipEntry = zin.getNextEntry(); continue; } // read from here .. return zin; } } finally { zin.close(); } } catch (IOException e) { throw new ResourceLoadingException ("Reading the zip-file failed.", e); } throw new ResourceLoadingException ("The zip-file did not contain the specified entry"); } public Object getAttribute(final String key) { if (key.equals(ResourceData.FILENAME)) { return LoaderUtils.getFileName((String) this.key.getIdentifier()); } return null; } public ResourceKey getKey() { return key; } public long getVersion(final ResourceManager caller) throws ResourceLoadingException { final ResourceKey parentKey = key.getParent(); final ResourceData data = caller.load(parentKey); return data.getVersion(caller); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/raw/0000755000175000017500000000000011365605644026721 5ustar renerene././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/raw/RawResourceData.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/raw/RawResourceData.jav0000644000175000017500000000623311365605644032462 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.raw; import java.io.ByteArrayInputStream; import java.io.InputStream; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Creation-Date: 12.04.2006, 15:06:48 * * @author Thomas Morgner */ public class RawResourceData implements ResourceData { private ResourceKey rawKey; private byte[] data; public RawResourceData(final ResourceKey rawKey) { if (rawKey == null) { throw new NullPointerException(); } this.rawKey = rawKey; this.data = (byte[]) rawKey.getIdentifier(); } public byte[] getResource(final ResourceManager caller) throws ResourceLoadingException { return (byte[]) data.clone(); } public long getLength() { return data.length; } public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException { return new ByteArrayInputStream(data); } /** * Tries to read data into the given byte-array. * * @param caller * @param target * @param offset * @param length * @return the number of bytes read or -1 if no more data can be read. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException * */ public int getResource(final ResourceManager caller, final byte[] target, final long offset, final int length) throws ResourceLoadingException { if (offset > data.length) { return -1; } final int iOffset = (int) (0x7FFFFFFF & offset); final int remaining = data.length - iOffset; final int maxReadable = Math.min(target.length, Math.min (remaining, length)); System.arraycopy(data, iOffset, target, 0, maxReadable); return maxReadable; } /** * We do not support attributes. * * @param key * @return */ public Object getAttribute(final String key) { return null; } public ResourceKey getKey() { return rawKey; } public long getVersion(final ResourceManager caller) throws ResourceLoadingException { return -1; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/raw/RawResourceLoader.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/loader/raw/RawResourceLoader.j0000644000175000017500000001423211365605644032466 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.raw; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceException; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyData; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyUtils; import org.pentaho.reporting.libraries.resourceloader.ResourceLoader; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; /** * Creation-Date: 12.04.2006, 15:19:03 * * @author Thomas Morgner */ public class RawResourceLoader implements ResourceLoader { public static final String SCHEMA_NAME = RawResourceLoader.class.getName(); public RawResourceLoader() { } /** * Checks, whether this resource loader implementation was responsible for * creating this key. * * @param key * @return */ public boolean isSupportedKey(final ResourceKey key) { if (SCHEMA_NAME.equals(key.getSchema())) { return true; } return false; } /** * Creates a new resource key from the given object and the factory keys. * * @param value * @param factoryKeys * @return the created key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if creating the key failed. */ public ResourceKey createKey(final Object value, final Map factoryKeys) throws ResourceKeyCreationException { if (value instanceof byte[] == false) { return null; } return new ResourceKey(SCHEMA_NAME, value, factoryKeys); } /** * Derives a new resource key from the given key. If neither a path nor new * factory-keys are given, the parent key is returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException * if the key cannot be derived for any reason. */ public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map factoryKeys) throws ResourceKeyCreationException { if (path != null) { throw new ResourceKeyCreationException("Unable to derive key for new path."); } if (isSupportedKey(parent) == false) { throw new ResourceKeyCreationException("Assertation: Unsupported parent key type"); } if (factoryKeys == null) { return parent; } final HashMap map = new HashMap(); map.putAll(parent.getFactoryParameters()); map.putAll(factoryKeys); return new ResourceKey(parent.getSchema(), parent.getIdentifier(), map); } public URL toURL(final ResourceKey key) { // not supported .. return null; } public ResourceData load(final ResourceKey key) throws ResourceLoadingException { if (isSupportedKey(key) == false) { throw new ResourceLoadingException("The key type is not supported."); } return new RawResourceData(key); } /** * Creates a String version of the resource key that can be used to generate a new ResourceKey * object via deserialization * @param bundleKey * @param key */ public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException { // Validate the parameter if (key == null) { throw new NullPointerException("The ResourceKey can not be null"); } if (isSupportedKey(key) == false) { throw new IllegalArgumentException("Key format is not recognized."); } if (!(key.getIdentifier() instanceof byte[])) { throw new IllegalArgumentException("ResourceKey is invalid - identifier is not a byte[] object"); } final byte[] data = (byte[]) key.getIdentifier(); final char[] cdata = new char[data.length]; for (int i = 0; i < data.length; i++) { cdata[i] = (char) (data[i] & 0xFF); } return ResourceKeyUtils.createStringResourceKey (String.valueOf(key.getSchema()), new String(cdata), key.getFactoryParameters()); } /** * Parses the input string and returns a newly created ResourceKey based on the string data */ public ResourceKey deserialize(final ResourceKey bundleKey, String stringKey) throws ResourceKeyCreationException { // Parse the data final ResourceKeyData keyData = ResourceKeyUtils.parse(stringKey); // Validate the data if (SCHEMA_NAME.equals(keyData.getSchema()) == false) { throw new ResourceKeyCreationException("Serialized version of key does not contain correct schema"); } final String identifier = keyData.getIdentifier(); final char[] chars = identifier.toCharArray(); final byte[] data = new byte[chars.length]; for (int i = 0; i < chars.length; i++) { data[i] = (byte) chars[i]; } return createKey(data, keyData.getFactoryParameters()); } public boolean isSupportedDeserializer(String data) { return SCHEMA_NAME.equals(ResourceKeyUtils.readSchemaFromString(data)); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/UnrecognizedLoaderException.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/UnrecognizedLoaderException.ja0000644000175000017500000000331411365605644032641 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * This exception is thrown whenever a resource-manager tries to load data using an invalid key. * * @author Thomas Morgner */ public class UnrecognizedLoaderException extends ResourceLoadingException { private static final long serialVersionUID = 6319955849184970434L; /** * Creates a StackableRuntimeException with no message and no parent. */ public UnrecognizedLoaderException() { } /** * Creates an exception. * * @param message the exception message. * @param ex the parent exception. */ public UnrecognizedLoaderException(final String message, final Exception ex) { super(message, ex); } /** * Creates an exception. * * @param message the exception message. */ public UnrecognizedLoaderException(final String message) { super(message); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceKeyData.java0000644000175000017500000000330411365605644030557 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.util.Collections; import java.util.HashMap; import java.util.Map; /** * Data class which holds the pieces of the String version of the Resource Key. * * @author David M. Kincade */ public class ResourceKeyData { private String schema; private String identifier; private Map factoryParameters; public ResourceKeyData(final String schema, final String identifier, final Map factoryParameters) { this.schema = schema; this.identifier = identifier; this.factoryParameters = (factoryParameters == null ? null : Collections.unmodifiableMap(new HashMap( factoryParameters))); } public String getSchema() { return schema; } public String getIdentifier() { return identifier; } public Map getFactoryParameters() { return factoryParameters; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceException.java0000644000175000017500000000324311365605644031175 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import org.pentaho.reporting.libraries.base.util.StackableException; /** * Creation-Date: 05.04.2006, 13:03:53 * * @author Thomas Morgner */ public class ResourceException extends StackableException { private static final long serialVersionUID = 9017929290846143507L; /** Creates a StackableRuntimeException with no message and no parent. */ public ResourceException() { } /** * Creates an exception. * * @param message the exception message. * @param ex the parent exception. */ public ResourceException(final String message, final Exception ex) { super(message, ex); } /** * Creates an exception. * * @param message the exception message. */ public ResourceException(final String message) { super(message); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/LibLoaderBoot.java0000644000175000017500000000427311365605644030214 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import org.pentaho.reporting.libraries.base.boot.AbstractBoot; import org.pentaho.reporting.libraries.base.boot.PackageManager; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.versioning.ProjectInformation; public class LibLoaderBoot extends AbstractBoot { private static LibLoaderBoot singleton; public static LibLoaderBoot getInstance() { if (singleton == null) { singleton = new LibLoaderBoot(); } return singleton; } private LibLoaderBoot () { } /** * Returns the project info. * * @return The project info. */ protected ProjectInformation getProjectInfo () { return LibLoaderInfo.getInstance(); } /** * Loads the configuration. * * @return The configuration. */ protected Configuration loadConfiguration () { return createDefaultHierarchicalConfiguration ("/org/pentaho/reporting/libraries/resourceloader/loader.properties", "/loader.properties", true, LibLoaderBoot.class); } /** * Performs the boot. */ protected void performBoot () { final PackageManager packageManager = getPackageManager(); packageManager.load("org.pentaho.reporting.libraries.resourceloader.modules."); packageManager.initializeModules(); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceManager.java0000644000175000017500000005564111365605644030622 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.net.URL; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; import org.pentaho.reporting.libraries.resourceloader.cache.BundleCacheResourceWrapper; import org.pentaho.reporting.libraries.resourceloader.cache.NullResourceBundleDataCache; import org.pentaho.reporting.libraries.resourceloader.cache.NullResourceDataCache; import org.pentaho.reporting.libraries.resourceloader.cache.NullResourceFactoryCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceBundleDataCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceBundleDataCacheEntry; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceBundleDataCacheProvider; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceDataCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceDataCacheEntry; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceDataCacheProvider; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceFactoryCache; import org.pentaho.reporting.libraries.resourceloader.cache.ResourceFactoryCacheProvider; import org.pentaho.reporting.libraries.resourceloader.modules.cache.ehcache.EHCacheModule; /** * The resource manager takes care about the loaded resources, performs caching, if needed and is the central instance * when dealing with resources. Resource loading is a two-step process. In the first step, the {@link ResourceLoader} * accesses the physical storage or network connection to read in the binary data. The loaded {@link ResourceData} * carries versioning information with it an can be cached indendently from the produced result. Once the loading is * complete, a {@link ResourceFactory} interprets the binary data and produces a Java-Object from it. *

* Resources are identified by an Resource-Key and some optional loader parameters (which can be used to parametrize the * resource-factories). * * @author Thomas Morgner * @see ResourceData * @see ResourceLoader * @see ResourceFactory */ public final class ResourceManager { private static final Log logger = LogFactory.getLog(ResourceManager.class); private ResourceManagerBackend backend; public static final String BUNDLE_LOADER_PREFIX = "org.pentaho.reporting.libraries.resourceloader.bundle.loader."; public static final String LOADER_PREFIX = "org.pentaho.reporting.libraries.resourceloader.loader."; public static final String FACTORY_TYPE_PREFIX = "org.pentaho.reporting.libraries.resourceloader.factory.type."; public static final String BUNDLE_CACHE_PROVIDER_KEY = "org.pentaho.reporting.libraries.resourceloader.cache.BundleDataCacheProvider"; public static final String DATA_CACHE_PROVIDER_KEY = "org.pentaho.reporting.libraries.resourceloader.cache.DataCacheProvider"; public static final String FACTORY_CACHE_PROVIDER_KEY = "org.pentaho.reporting.libraries.resourceloader.cache.FactoryCacheProvider"; private ResourceDataCache dataCache; private ResourceBundleDataCache bundleCache; private ResourceFactoryCache factoryCache; /** * A set that contains the class-names of all cache-modules, which could not be instantiated correctly. * This set is used to limit the number of warnings in the log to exactly one per class. */ private static final Set failedModules = new HashSet(); /** * Default Constructor. */ public ResourceManager() { this(new DefaultResourceManagerBackend()); } public ResourceManager(final ResourceManagerBackend resourceManagerBackend) { if (resourceManagerBackend == null) { throw new NullPointerException(); } this.backend = resourceManagerBackend; this.bundleCache = new NullResourceBundleDataCache(); this.dataCache = new NullResourceDataCache(); this.factoryCache = new NullResourceFactoryCache(); } public ResourceManager(final ResourceManager parent, final ResourceManagerBackend backend) { if (backend == null) { throw new NullPointerException(); } if (parent == null) { throw new NullPointerException(); } this.backend = backend; this.bundleCache = parent.getBundleCache(); this.dataCache = parent.getDataCache(); this.factoryCache = parent.getFactoryCache(); } public ResourceManagerBackend getBackend() { return backend; } /** * Creates a ResourceKey that carries no Loader-Parameters from the given object. * * @param data the key-data * @return the generated resource-key, never null. * @throws ResourceKeyCreationException if the key-creation failed. */ public ResourceKey createKey(final Object data) throws ResourceKeyCreationException { return createKey(data, null); } /** * Creates a ResourceKey that carries the given Loader-Parameters contained in the optional map. * * @param data the key-data * @param parameters an optional map of parameters. * @return the generated resource-key, never null. * @throws ResourceKeyCreationException if the key-creation failed. */ public ResourceKey createKey(final Object data, final Map parameters) throws ResourceKeyCreationException { return backend.createKey(data, parameters); } /** * Derives a new key from the given resource-key. Only keys for a hierarchical storage system (like file-systems or * URLs) can have derived keys. Since LibLoader 0.3.0 only hierarchical keys can be derived. For that, the deriving * path must be given as String. *

* Before trying to derive the key, the system tries to interpret the path as absolute key-value. * * @param parent the parent key, must never be null * @param path the relative path, that is used to derive the key. * @return the derived key. * @throws ResourceKeyCreationException if deriving the key failed. */ public ResourceKey deriveKey(final ResourceKey parent, final String path) throws ResourceKeyCreationException { return deriveKey(parent, path, null); } /** * Derives a new key from the given resource-key. Only keys for a hierarchical storage system (like file-systems or * URLs) can have derived keys. Since LibLoader 0.3.0 only hierarchical keys can be derived. For that, the deriving * path must be given as String. *

* The optional parameter-map will be applied to the derived key after the parent's parameters have been copied to * the new key. *

* Before trying to derive the key, the system tries to interpret the path as absolute key-value. * * @param parent the parent key, or null to interpret the path as absolute key. * @param path the relative path, that is used to derive the key. * @param parameters a optional map containing resource-key parameters. * @return the derived key. * @throws ResourceKeyCreationException if deriving the key failed. */ public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map parameters) throws ResourceKeyCreationException { return backend.deriveKey(parent, path, parameters); } /** * Tries to convert the resource-key into an URL. Not all resource-keys have an URL representation. This method * exists to make it easier to connect LibLoader to other resource-loading frameworks. * * @param key the resource-key * @return the URL for the key, or null if there is no such key. */ public URL toURL(final ResourceKey key) { return backend.toURL(key); } public Resource createDirectly(final Object keyValue, final Class target) throws ResourceLoadingException, ResourceCreationException, ResourceKeyCreationException { final ResourceKey key = createKey(keyValue); return create(key, null, target); } /** * Tries to find the first resource-bundle-loader that would be able to process the key. * * @param key the resource-key. * @return the resourceloader for that key, or null, if no resource-loader is able to process the key. * @throws ResourceLoadingException if an error occured. */ public synchronized ResourceBundleData loadResourceBundle(final ResourceKey key) throws ResourceLoadingException { final ResourceBundleDataCache bundleCache = getBundleCache(); final ResourceBundleDataCacheEntry cached = bundleCache.get(key); if (cached != null) { final ResourceBundleData data = cached.getData(); // check, whether it is valid. final long version = data.getVersion(this); if ((cached.getStoredVersion() < 0) || (version >= 0 && cached.getStoredVersion() == version)) { // now also make sure that the underlying data has not changed. // This may look a bit superfluous, but the repository may not provide // sensible cacheable information. final ResourceDataCacheEntry bundleRawDataCacheEntry = getDataCache().get(data.getBundleKey()); if (bundleRawDataCacheEntry != null) { final ResourceData bundleRawData = bundleRawDataCacheEntry.getData(); if (bundleRawData != null) { if (isValidData(bundleRawDataCacheEntry, bundleRawData)) { return data; } getDataCache().remove(bundleRawData); } } } bundleCache.remove(data); } final ResourceBundleData data = backend.loadResourceBundle(this, key); if (data != null && isResourceDataCacheable(data)) { bundleCache.put(this, data); } return data; } private boolean isResourceDataCacheable(final ResourceData data) { try { return data.getVersion(this) != -1; } catch (ResourceLoadingException e) { return false; } } public ResourceData load(final ResourceKey key) throws ResourceLoadingException { final ResourceBundleData bundle = loadResourceBundle(key); if (bundle != null) { logger.debug("Loaded bundle for key " + key); return bundle; } final ResourceKey parent = key.getParent(); if (parent != null) { // try to load the bundle data of the parent final ResourceBundleData parentData = loadResourceBundle(parent); if (parentData != null) { logger.debug("Loaded bundle for key (derivate) " + key); return parentData.deriveData(key); } } return loadRawData(key); } private boolean isValidData(final ResourceDataCacheEntry cached, final ResourceData data) throws ResourceLoadingException { // check, whether it is valid. if (cached.getStoredVersion() < 0) { // a non versioned entry is always valid. (Maybe this is from a Jar-URL?) return true; } final long version = data.getVersion(this); if (version < 0) { // the system is no longer able to retrieve the version information? // (but versioning information must have been available in the past) // oh, that's bad. Assume the worst and re-read the data. return false; } if (cached.getStoredVersion() == version) { return true; } else { return false; } } public synchronized ResourceData loadRawData(final ResourceKey key) throws UnrecognizedLoaderException, ResourceLoadingException { final ResourceDataCache dataCache = getDataCache(); // Alternative 3: This is a plain resource and not contained in a bundle. Load as binary data final ResourceDataCacheEntry cached = dataCache.get(key); if (cached != null) { final ResourceData data = cached.getData(); if (data != null) { if (isValidData(cached, data)) { return data; } dataCache.remove(data); } } final ResourceData data = backend.loadRawData(this, key); if (data != null && isResourceDataCacheable(data)) { dataCache.put(this, data); } return data; } public Resource create(final ResourceKey key, final ResourceKey context, final Class target) throws ResourceLoadingException, ResourceCreationException { if (target == null) { throw new NullPointerException("Target must not be null"); } if (key == null) { throw new NullPointerException("Key must not be null."); } return create(key, context, new Class[]{target}); } public Resource create(final ResourceKey key, final ResourceKey context) throws ResourceLoadingException, ResourceCreationException { return create(key, context, (Class[]) null); } public Resource create(final ResourceKey key, final ResourceKey context, final Class[] target) throws ResourceLoadingException, ResourceCreationException { if (key == null) { throw new NullPointerException(); } final ResourceFactoryCache factoryCache = getFactoryCache(); // ok, we have a handle to the data, and the data is current. // Lets check whether we also have a cached result. final Resource resource = factoryCache.get(key, target); if (resource != null) { if (backend.isResourceUnchanged(this, resource)) { // mama, look i am a good cache manager ... return resource; } else { // someone evil changed one of the dependent resources ... factoryCache.remove(resource); } } final ResourceData loadedData = load(key); final Resource newResource; if (loadedData instanceof ResourceBundleData) { final ResourceBundleData resourceBundleData = (ResourceBundleData) loadedData; final ResourceManager derivedManager = resourceBundleData.deriveManager(this); newResource = backend.create(derivedManager, resourceBundleData, context, target); if (isResourceCacheable(newResource)) { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Storing created bundle-resource for key: " + key); } factoryCache.put(newResource); if (key != newResource.getSource()) { factoryCache.put(new BundleCacheResourceWrapper(newResource, key)); } } else { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Created bundle-resource is not cacheable for " + key); } } } else { newResource = backend.create(this, loadedData, context, target); if (isResourceCacheable(newResource)) { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Storing created resource for key: " + key); } factoryCache.put(newResource); } else { if (EHCacheModule.CACHE_MONITOR.isDebugEnabled()) { EHCacheModule.CACHE_MONITOR.debug("Created resource is not cacheable for " + key); } } } return newResource; } private boolean isResourceCacheable(final Resource newResource) { final ResourceKey source = newResource.getSource(); if (newResource.isTemporaryResult()) { return false; } if (newResource.getVersion(source) == -1) { return false; } final ResourceKey[] keys = newResource.getDependencies(); for (int i = 0; i < keys.length; i++) { if (newResource.getVersion(keys[i]) == -1) { return false; } } return true; } public ResourceDataCache getDataCache() { return dataCache; } public void setDataCache(final ResourceDataCache dataCache) { if (dataCache == null) { throw new NullPointerException(); } this.dataCache = dataCache; } public ResourceFactoryCache getFactoryCache() { return factoryCache; } public void setFactoryCache(final ResourceFactoryCache factoryCache) { if (factoryCache == null) { throw new NullPointerException(); } this.factoryCache = factoryCache; } public ResourceBundleDataCache getBundleCache() { return bundleCache; } public void setBundleCache(final ResourceBundleDataCache bundleCache) { if (bundleCache == null) { throw new NullPointerException(); } this.bundleCache = bundleCache; } public void registerDefaults() { // Create all known resource loaders ... registerDefaultLoaders(); // Register all known factories ... registerDefaultFactories(); // add the caches .. registerDataCache(); registerBundleDataCache(); registerFactoryCache(); } public void registerDefaultFactories() { backend.registerDefaultFactories(); } public void registerBundleDataCache() { final Configuration config = LibLoaderBoot.getInstance().getGlobalConfig(); final String dataCacheProviderClass = config.getConfigProperty(BUNDLE_CACHE_PROVIDER_KEY); if (dataCacheProviderClass == null) { return; } final Object maybeDataCacheProvider = ObjectUtilities.loadAndInstantiate (dataCacheProviderClass, ResourceManager.class, ResourceBundleDataCacheProvider.class); if (maybeDataCacheProvider == null) { return; } final ResourceBundleDataCacheProvider provider = (ResourceBundleDataCacheProvider) maybeDataCacheProvider; try { final ResourceBundleDataCache cache = provider.createBundleDataCache(); if (cache != null) { setBundleCache(cache); } } catch (Throwable e) { // ok, did not work ... synchronized (failedModules) { if (failedModules.contains(dataCacheProviderClass) == false) { logger.warn("Failed to create data cache: " + e.getLocalizedMessage()); failedModules.add(dataCacheProviderClass); } } } } public void registerDataCache() { final Configuration config = LibLoaderBoot.getInstance().getGlobalConfig(); final String dataCacheProviderClass = config.getConfigProperty(DATA_CACHE_PROVIDER_KEY); if (dataCacheProviderClass == null) { return; } final Object maybeDataCacheProvider = ObjectUtilities.loadAndInstantiate (dataCacheProviderClass, ResourceManager.class, ResourceDataCacheProvider.class); if (maybeDataCacheProvider instanceof ResourceDataCacheProvider) { final ResourceDataCacheProvider provider = (ResourceDataCacheProvider) maybeDataCacheProvider; try { final ResourceDataCache cache = provider.createDataCache(); if (cache != null) { setDataCache(cache); } } catch (Throwable e) { // ok, did not work ... synchronized (failedModules) { if (failedModules.contains(dataCacheProviderClass) == false) { logger.warn("Failed to create data cache: " + e.getLocalizedMessage()); failedModules.add(dataCacheProviderClass); } } } } } public void registerFactoryCache() { final Configuration config = LibLoaderBoot.getInstance().getGlobalConfig(); final String cacheProviderClass = config.getConfigProperty (FACTORY_CACHE_PROVIDER_KEY); if (cacheProviderClass == null) { return; } final Object maybeCacheProvider = ObjectUtilities.loadAndInstantiate (cacheProviderClass, ResourceManager.class, ResourceFactoryCacheProvider.class); if (maybeCacheProvider != null) { final ResourceFactoryCacheProvider provider = (ResourceFactoryCacheProvider) maybeCacheProvider; try { final ResourceFactoryCache cache = provider.createFactoryCache(); if (cache != null) { setFactoryCache(cache); } } catch (Throwable e) { synchronized (failedModules) { if (failedModules.contains(cacheProviderClass) == false) { logger.warn("Failed to create factory cache: " + e.getLocalizedMessage()); failedModules.add(cacheProviderClass); } } } } } public void registerDefaultLoaders() { backend.registerDefaultLoaders(); } public void registerBundleLoader(final ResourceBundleLoader loader) { if (loader == null) { throw new NullPointerException(); } backend.registerBundleLoader(loader); } public void registerLoader(final ResourceLoader loader) { if (loader == null) { throw new NullPointerException(); } backend.registerLoader(loader); } public void registerFactory(final ResourceFactory factory) { if (factory == null) { throw new NullPointerException(); } backend.registerFactory(factory); } public void shutDown() { factoryCache.shutdown(); dataCache.shutdown(); } /** * Creates a String version of the ResourceKey that can be deserialized with the * deserialize() method. * * @param bundleKey the key to the bundle containing the resource, or null if no bundle exists. * @param key the key to be serialized * @throws ResourceException indicates an error trying to serialize the key * @throws NullPointerException indicates the supplied key is null */ public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException { return backend.serialize(bundleKey, key); } /** * Converts a serialized version of a ResourceKey into an actual ResourceKey * by locating the proper ResourceLoader that can perform the deserialization. * * @param serializedKey the String serialized key to be deserialized * @return the ResourceKey that has been deserialized * @throws ResourceKeyCreationException indicates an error trying to create the ResourceKey * from the deserialized version */ public ResourceKey deserialize(final ResourceKey bundleKey, final String serializedKey) throws ResourceKeyCreationException { return backend.deserialize(bundleKey, serializedKey); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceManagerBackend.java0000644000175000017500000000470311365605644032063 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.net.URL; import java.util.Map; /** * Todo: Document Me * * @author Thomas Morgner */ public interface ResourceManagerBackend { public ResourceKey createKey(final Object data, final Map parameters) throws ResourceKeyCreationException; public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map parameters) throws ResourceKeyCreationException; public URL toURL(final ResourceKey key); public Resource create(final ResourceManager frontEnd, final ResourceData key, final ResourceKey context, final Class[] target) throws ResourceLoadingException, ResourceCreationException; public ResourceBundleData loadResourceBundle(final ResourceManager frontEnd, final ResourceKey key) throws ResourceLoadingException; public void registerDefaultFactories(); public void registerDefaultLoaders(); public void registerBundleLoader(final ResourceBundleLoader loader); public void registerLoader(final ResourceLoader loader); public void registerFactory(final ResourceFactory factory); public ResourceData loadRawData(final ResourceManager frontEnd, final ResourceKey key) throws ResourceLoadingException, UnrecognizedLoaderException; public boolean isResourceUnchanged(final ResourceManager resourceManager, final Resource resource) throws ResourceLoadingException; public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException; public ResourceKey deserialize(final ResourceKey bundleKey, final String serializedKey) throws ResourceKeyCreationException; } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ContentNotRecognizedException.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ContentNotRecognizedException.0000644000175000017500000000343511365605644032654 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * The ContentNotRecognizedException signals that none of the selected resource * factories was able to handle the request. * * @author Thomas Morgner */ public class ContentNotRecognizedException extends ResourceCreationException { private static final long serialVersionUID = 816828118909665976L; /** * Creates a ContentNotRecognizedException with no message and no parent. */ public ContentNotRecognizedException() { } /** * Creates an ContentNotRecognizedException. * * @param message the exception message. * @param ex the parent exception. */ public ContentNotRecognizedException(final String message, final Exception ex) { super(message, ex); } /** * Creates an ContentNotRecognizedException. * * @param message the exception message. */ public ContentNotRecognizedException(final String message) { super(message); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/DependencyCollector.java0000644000175000017500000000527011365605644031456 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.util.HashMap; import java.io.Serializable; /** * Creation-Date: 08.04.2006, 14:12:14 * * @author Thomas Morgner */ public class DependencyCollector implements Serializable, Cloneable { private HashMap dependencies; private static final long serialVersionUID = -3568774359923270189L; public DependencyCollector(final ResourceKey source, final long version) { if (source == null) { throw new NullPointerException(); } dependencies = new HashMap(); dependencies.put(source, new Long(version)); } public ResourceKey[] getDependencies() { return (ResourceKey[]) dependencies.keySet().toArray (new ResourceKey[dependencies.size()]); } public void add(final Resource dependentResource) { if (dependentResource == null) { throw new NullPointerException(); } final ResourceKey[] depKeys = dependentResource.getDependencies(); for (int i = 0; i < depKeys.length; i++) { final ResourceKey depKey = depKeys[i]; final long version = dependentResource.getVersion(depKey); add(depKey, version); } } public void add(final ResourceKey resourceKey, final long version) { if (resourceKey == null) { throw new NullPointerException(); } dependencies.put(resourceKey, new Long(version)); } public long getVersion(final ResourceKey key) { if (key == null) { throw new NullPointerException(); } final Long l = (Long) dependencies.get(key); if (l == null) { return -1; } return l.longValue(); } public Object clone () throws CloneNotSupportedException { final DependencyCollector dc = (DependencyCollector) super.clone(); dc.dependencies = (HashMap) dependencies.clone(); return dc; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/0000755000175000017500000000000011365605644025725 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/CachingResourceData.java0000644000175000017500000001102511365605644032425 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.Serializable; import java.util.HashMap; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * A very simple implementation which is suitable for smaller objects. The complete data is read into memory. * * @author Thomas Morgner */ public class CachingResourceData implements ResourceData, Serializable { private static final int CACHE_THRESHOLD = 512 * 1024; private ResourceData data; private HashMap attributes; // The cached raw data. This is stored on the serialized stream as well // so that we can cache that stuff. private transient byte[] rawData; private static final long serialVersionUID = -1749415356208356705L; public CachingResourceData(final ResourceData data) { if (data == null) { throw new NullPointerException(); } this.data = data; } public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException { final byte[] data = getResource(caller); return new ByteArrayInputStream(data); } public long getLength() { if (rawData != null) { return rawData.length; } return data.getLength(); } public synchronized byte[] getResource(final ResourceManager caller) throws ResourceLoadingException { if (rawData == null) { rawData = data.getResource(caller); } return (byte[]) rawData.clone(); } public synchronized int getResource (final ResourceManager caller, final byte[] target, final long offset, final int length) throws ResourceLoadingException { if (target == null) { throw new NullPointerException(); } if (target.length < (offset + length)) { throw new IndexOutOfBoundsException(); } if (rawData == null) { rawData = data.getResource(caller); } final int iOffset = (int) (0x7FFFFFFF & offset); final int maxLength = Math.min(rawData.length - iOffset, length); if (maxLength <= 0) { return -1; } System.arraycopy(rawData, iOffset, target, 0, maxLength); return maxLength; } public synchronized Object getAttribute(final String key) { if (attributes == null) { attributes = new HashMap(); } else { final Object cached = attributes.get(key); if (cached != null) { return cached; } } final Object value = data.getAttribute(key); if (value != null) { attributes.put(key, value); } return value; } public ResourceKey getKey() { return data.getKey(); } public long getVersion(final ResourceManager caller) throws ResourceLoadingException { return data.getVersion(caller); } public static ResourceData createCached(final ResourceData data) { // this relieves the pain of having to re-open the same stream more than // once. This is no real long term caching, but at least a caching during // the current request. final Object rawCl = data.getAttribute(ResourceData.CONTENT_LENGTH); if (rawCl instanceof Number) { final Number contentLength = (Number) rawCl; if (contentLength.intValue() < CACHE_THRESHOLD) { // only buffer all data if the content is less than 512kb. // Else, we may run into trouble if we try to load a huge item into memory .. return new CachingResourceData(data); } } return data; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceDataCache.java0000644000175000017500000000420311365605644032074 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Creation-Date: 06.04.2006, 09:30:28 * * @author Thomas Morgner */ public interface ResourceDataCache { /** * Retrieves the given data from the cache. * * @param key the resource key for the data. */ public ResourceDataCacheEntry get (ResourceKey key); /** * Stores the given data on the cache. The data is registered by its * primary key. The cache has to store the current version of the data. * * @param data the data to be stored in the cache * @return the resource data object, possibly wrapped by a cache-specific * implementation. */ public ResourceData put (ResourceManager caller, ResourceData data) throws ResourceLoadingException; public void remove (ResourceData data); /** * Remove all cached entries. This should be called after the cache has * become invalid or after it has been removed from a resource manager. */ public void clear(); public void shutdown(); } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/DefaultResourceBundleDataCacheEntry.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/DefaultResourceBundleDat0000644000175000017500000000355611365605644032540 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceBundleData; /** * Creation-Date: 06.04.2006, 09:53:37 * * @author Thomas Morgner */ public class DefaultResourceBundleDataCacheEntry implements ResourceBundleDataCacheEntry { private ResourceBundleData data; private long version; private static final long serialVersionUID = 980125445121523950L; public DefaultResourceBundleDataCacheEntry(final ResourceBundleData data, final ResourceManager manager) throws ResourceLoadingException { if (data == null) { throw new NullPointerException(); } this.version = data.getVersion(manager); this.data = data; } public ResourceBundleData getData() { return data; } public long getStoredVersion() { return version; } }././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/NullResourceDataCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/NullResourceDataCache.ja0000644000175000017500000000460311365605644032404 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import java.lang.ref.Reference; import java.lang.ref.WeakReference; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Disables caching. It simply returns null on every request and ignores * the put requests. You certainly want to use one of the other cache * providers in real world applications. * * @author Thomas Morgner */ public class NullResourceDataCache implements ResourceDataCache { private Reference lastEntry; public NullResourceDataCache() { } public ResourceData put(final ResourceManager caller, final ResourceData data) throws ResourceLoadingException { final ResourceData retval = CachingResourceData.createCached(data); lastEntry = new WeakReference(new DefaultResourceDataCacheEntry(retval, caller)); return retval; } public ResourceDataCacheEntry get(final ResourceKey key) { if (lastEntry != null) { final ResourceDataCacheEntry entry = (ResourceDataCacheEntry) lastEntry.get(); if (entry != null && key.equals(entry.getData().getKey())) { return entry; } lastEntry = null; } return null; } public void remove(final ResourceData data) { } public void clear() { lastEntry = null; } public void shutdown() { lastEntry = null; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/CachingResourceBundleData.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/CachingResourceBundleDat0000644000175000017500000001221511365605644032500 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.Serializable; import java.util.HashMap; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ResourceBundleData; import org.pentaho.reporting.libraries.resourceloader.ResourceException; /** * A very simple implementation which is suitable for smaller objects. The * complete data is read into memory. * * @author Thomas Morgner */ public class CachingResourceBundleData implements ResourceBundleData, Serializable { private static final int CACHE_THRESHOLD = 512*1024; private ResourceBundleData data; private HashMap attributes; // The cached raw data. This is stored on the serialized stream as well // so that we can cache that stuff. private transient byte[] rawData; private static final long serialVersionUID = -7272527822440412818L; public CachingResourceBundleData(final ResourceBundleData data) { if (data == null) { throw new NullPointerException(); } this.data = data; } public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException { final byte[] data = getResource(caller); return new ByteArrayInputStream(data); } public long getLength() { if (rawData != null) { return rawData.length; } return data.getLength(); } public synchronized byte[] getResource(final ResourceManager caller) throws ResourceLoadingException { if (rawData == null) { rawData = data.getResource(caller); } return (byte[]) rawData.clone(); } public synchronized int getResource (final ResourceManager caller, final byte[] target, final long offset, final int length) throws ResourceLoadingException { if (target == null) { throw new NullPointerException(); } if (target.length < (offset + length)) { throw new IndexOutOfBoundsException(); } if (rawData == null) { rawData = data.getResource(caller); } final int iOffset = (int) (0x7FFFFFFF & offset); final int maxLength = Math.min (rawData.length - iOffset, length); if (maxLength <= 0) { return -1; } System.arraycopy(rawData, iOffset, target, 0, maxLength); return maxLength; } public synchronized Object getAttribute(final String key) { if (attributes == null) { attributes = new HashMap(); } else { final Object cached = attributes.get(key); if (cached != null) { return cached; } } final Object value = data.getAttribute(key); if (value != null) { attributes.put(key, value); } return value; } public ResourceKey getKey() { return data.getKey(); } public long getVersion(final ResourceManager caller) throws ResourceLoadingException { return data.getVersion(caller); } public ResourceKey getBundleKey() { return data.getBundleKey(); } public ResourceBundleData deriveData(final ResourceKey key) throws ResourceLoadingException { return data.deriveData(key); } public ResourceManager deriveManager(final ResourceManager parent) throws ResourceLoadingException { return data.deriveManager(parent); } public ResourceBundleData getBackend() { return data; } public static ResourceBundleData createCached(final ResourceBundleData data) { // this relieves the pain of having to re-open the same stream more than // once. This is no real long term caching, but at least a caching during // the current request. final Object rawCl = data.getAttribute(ResourceData.CONTENT_LENGTH); if (rawCl instanceof Number) { final Number contentLength = (Number) rawCl; if (contentLength.intValue() < CACHE_THRESHOLD) { // only buffer all data if the content is less than 512kb. // Else, we may run into trouble if we try to load a huge item into memory .. return new CachingResourceBundleData(data); } } return data; } }././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceDataCacheProvider.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceDataCacheProvide0000644000175000017500000000207611365605644032513 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; /** * Creation-Date: 06.04.2006, 10:38:36 * * @author Thomas Morgner */ public interface ResourceDataCacheProvider { public ResourceDataCache createDataCache(); } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceBundleDataCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceBundleDataCache.0000644000175000017500000000460311365605644032370 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.resourceloader.ResourceBundleData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Creation-Date: 06.04.2006, 09:30:28 * * @author Thomas Morgner */ public interface ResourceBundleDataCache { /** * Retrieves the given data from the cache. * * @param key the resource key for the data. * @return the cached entry or null, if the entry is no longer in the cache. */ public ResourceBundleDataCacheEntry get (ResourceKey key); /** * Stores the given data on the cache. The data is registered by its * primary key. The cache has to store the current version of the data. * * @param caller the calling resource manager. * @param data the data to be stored in the cache * @return the resource data object, possibly wrapped by a cache-specific * implementation. * @throws ResourceLoadingException if an error prevents the data from being cached. */ public ResourceBundleData put (ResourceManager caller, ResourceBundleData data) throws ResourceLoadingException; public void remove (ResourceBundleData data); /** * Remove all cached entries. This should be called after the cache has * become invalid or after it has been removed from a resource manager. */ public void clear(); public void shutdown(); }././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceFactoryCacheProvider.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceFactoryCacheProv0000644000175000017500000000210711365605644032562 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; /** * Creation-Date: 06.04.2006, 10:38:36 * * @author Thomas Morgner */ public interface ResourceFactoryCacheProvider { public ResourceFactoryCache createFactoryCache(); } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/NullResourceBundleDataCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/NullResourceBundleDataCa0000644000175000017500000000454111365605644032466 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.resourceloader.ResourceBundleData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Disables caching. It simply returns null on every request and ignores * the put requests. You certainly want to use one of the other cache * providers in real world applications. * @author Thomas Morgner */ public class NullResourceBundleDataCache implements ResourceBundleDataCache { private Object lastEntry; public NullResourceBundleDataCache() { } public ResourceBundleData put(final ResourceManager caller, final ResourceBundleData data) throws ResourceLoadingException { final ResourceBundleData retval = CachingResourceBundleData.createCached(data); lastEntry = new DefaultResourceBundleDataCacheEntry(retval, caller); return retval; } public ResourceBundleDataCacheEntry get(final ResourceKey key) { if (lastEntry != null) { final ResourceBundleDataCacheEntry entry = (ResourceBundleDataCacheEntry) lastEntry; if (key.equals(entry.getData().getBundleKey())) { return entry; } lastEntry = null; } return null; } public void remove(final ResourceBundleData data) { } public void clear() { lastEntry = null; } public void shutdown() { lastEntry = null; } }././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceFactoryCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceFactoryCache.jav0000644000175000017500000000253011365605644032472 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; /** * Creation-Date: 06.04.2006, 10:10:18 * * @author Thomas Morgner */ public interface ResourceFactoryCache { public Resource get (ResourceKey key, Class[] target); public void put(final Resource resource); public void remove (final Resource resource); public void clear (); public void shutdown(); } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/NullCacheProvider.java0000644000175000017500000000271411365605644032145 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; /** * Creation-Date: 06.04.2006, 10:39:10 * * @author Thomas Morgner */ public class NullCacheProvider implements ResourceDataCacheProvider, ResourceFactoryCacheProvider, ResourceBundleDataCacheProvider { public NullCacheProvider() { } public ResourceDataCache createDataCache() { return new NullResourceDataCache(); } public ResourceFactoryCache createFactoryCache() { return new NullResourceFactoryCache(); } public ResourceBundleDataCache createBundleDataCache() { return new NullResourceBundleDataCache(); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceBundleDataCacheEntry.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceBundleDataCacheE0000644000175000017500000000233111365605644032413 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import java.io.Serializable; import org.pentaho.reporting.libraries.resourceloader.ResourceBundleData; /** * Creation-Date: 06.04.2006, 09:44:05 * * @author Thomas Morgner */ public interface ResourceBundleDataCacheEntry extends Serializable { public ResourceBundleData getData(); public long getStoredVersion(); }././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/BundleCacheResourceWrapper.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/BundleCacheResourceWrapp0000644000175000017500000000310711365605644032530 0ustar renerenepackage org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceException; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; /** * Todo: Document me! *

* Date: 07.10.2009 * Time: 18:31:11 * * @author Thomas Morgner. */ public class BundleCacheResourceWrapper implements Resource { private Resource parent; private ResourceKey outsideKey; public BundleCacheResourceWrapper(final Resource parent, final ResourceKey outsideKey) { this.parent = parent; this.outsideKey = outsideKey; } public Object getResource() throws ResourceException { return parent.getResource(); } public Class getTargetType() { return parent.getTargetType(); } public long getVersion(final ResourceKey key) { if (ObjectUtilities.equal(key, outsideKey)) { return parent.getVersion(parent.getSource()); } return parent.getVersion(key); } public ResourceKey[] getDependencies() { final ResourceKey[] resourceKeys = parent.getDependencies(); final ResourceKey[] target = new ResourceKey[resourceKeys.length + 1]; target[0] = parent.getSource(); System.arraycopy(resourceKeys, 0, target, 1, resourceKeys.length); return target; } public ResourceKey getSource() { return outsideKey; } public boolean isTemporaryResult() { return parent.isTemporaryResult(); } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/DefaultResourceDataCacheEntry.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/DefaultResourceDataCache0000644000175000017500000000350711365605644032467 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; /** * Creation-Date: 06.04.2006, 09:53:37 * * @author Thomas Morgner */ public class DefaultResourceDataCacheEntry implements ResourceDataCacheEntry { private ResourceData data; private long version; private static final long serialVersionUID = -8308023147327221724L; public DefaultResourceDataCacheEntry(final ResourceData data, final ResourceManager manager) throws ResourceLoadingException { if (data == null) { throw new NullPointerException(); } this.version = data.getVersion(manager); this.data = data; } public ResourceData getData() { return data; } public long getStoredVersion() { return version; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceBundleDataCacheProvider.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceBundleDataCacheP0000644000175000017500000000211711365605644032430 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; /** * Creation-Date: 06.04.2006, 10:38:36 * * @author Thomas Morgner */ public interface ResourceBundleDataCacheProvider { public ResourceBundleDataCache createBundleDataCache(); }././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceDataCacheEntry.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/ResourceDataCacheEntry.j0000644000175000017500000000231011365605644032423 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import java.io.Serializable; import org.pentaho.reporting.libraries.resourceloader.ResourceData; /** * Creation-Date: 06.04.2006, 09:44:05 * * @author Thomas Morgner */ public interface ResourceDataCacheEntry extends Serializable { public ResourceData getData(); public long getStoredVersion(); } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/NullResourceFactoryCache.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/NullResourceFactoryCache0000644000175000017500000000275011365605644032552 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; /** * Creation-Date: 06.04.2006, 10:26:21 * * @author Thomas Morgner */ public class NullResourceFactoryCache implements ResourceFactoryCache { public NullResourceFactoryCache() { } public Resource get(final ResourceKey key, final Class[] target) { return null; } public void put(final Resource resource) { } public void remove(final Resource resource) { } public void clear() { } public void shutdown() { } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/cache/CacheUtility.java0000644000175000017500000000445711365605644031171 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.cache; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; /** * Creation-Date: Feb 22, 2007, 7:36:19 PM * * @author Thomas Morgner */ public class CacheUtility { public static String externalizeKey(final ResourceKey key) { try { final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final ObjectOutputStream oout = new ObjectOutputStream(bout); oout.writeObject(key); oout.close(); final byte[] serializedKeyData = bout.toByteArray(); return convertToString(serializedKeyData); } catch (IOException ioe) { return null; } } private static String convertToString(final byte[] serializedKeyData) { final int capacity = (serializedKeyData.length / 2) + 2; final StringBuffer buffer = new StringBuffer(capacity); char data = 0; if ((serializedKeyData.length & 1) == 1) { buffer.append('*'); } else { buffer.append('#'); } for (int i = 0; i < serializedKeyData.length; i += 1) { data <<= 8; data |= serializedKeyData[i]; if ((i & 1) == 1) { buffer.append(data); } } if ((serializedKeyData.length & 1) == 1) { data <<= 8; buffer.append(data); } return buffer.toString(); } private CacheUtility() { } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceFactory.java0000644000175000017500000000455111365605644030651 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * Creation-Date: 05.04.2006, 12:52:32 * * @author Thomas Morgner */ public interface ResourceFactory { public static final String CONFIG_PREFIX = "org.pentaho.reporting.libraries.resourceloader.factory.modules."; /** * Creates a resource by interpreting the data given in the resource-data object. If additional datastreams need to * be parsed, the provided resource manager should be used. * * @param manager the resource manager used for all resource loading. * @param data the resource-data from where the binary data is read. * @param context the resource context used to resolve relative resource paths. * @return the parsed result, never null. * @throws ResourceCreationException if the resource could not be parsed due to syntaxctial or logical errors in the data. * @throws ResourceLoadingException if the resource could not be accessed from the physical storage. */ public Resource create(final ResourceManager manager, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException; /** * Returns the expected result type. * * @return the result type. */ public Class getFactoryType(); /** * Initializes the resource factory. This usually loads all system resources from the environment and maybe sets up * and initializes any factories needed during the parsing. */ public void initializeDefaults(); } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceKeyUtils.java0000644000175000017500000003156111365605644031014 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.base.util.CSVQuoter; import org.pentaho.reporting.libraries.base.util.CSVTokenizer; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * Provides a setup of utility methods for operating on a ResourceKey class. * * @author David Kincade */ public class ResourceKeyUtils { private static final String DELIMITER = ";"; private static final String SERIALIZATION_PREFIX = "resourcekey:"; private static final Log logger = LogFactory.getLog(ResourceManager.class); /** * Returns a string representation of the ResourceKey based on the pieces that are passed as parameters * * @param schema the string representation of the schema * @param identifier the string representation of the identifier * @param factoryParameters the set of factory parameters (null allowed) * @return the string version with the pieces delimited and concatenated */ public static String createStringResourceKey(final String schema, final String identifier, final Map factoryParameters) { final String factoryParamString = convertFactoryParametersToString(factoryParameters); final CSVQuoter quoter = new CSVQuoter(';'); return quoter.doQuoting(SERIALIZATION_PREFIX + schema) + DELIMITER + quoter.doQuoting(identifier) + (factoryParamString == null ? "" : DELIMITER + quoter.doQuoting(factoryParamString)); } /** * Parses the string version of the Resource Key into the components * * @return */ public static ResourceKeyData parse(final String resourceKeyString) throws ResourceKeyCreationException { if (resourceKeyString == null) { throw new IllegalArgumentException("Source string can not be null"); } if (!resourceKeyString.startsWith(SERIALIZATION_PREFIX)) { throw new ResourceKeyCreationException("The source string does not start with the string [" + SERIALIZATION_PREFIX + "]"); } final CSVTokenizer tokenizer = new CSVTokenizer(resourceKeyString, DELIMITER, CSVTokenizer.DOUBLE_QUATE, false); if (tokenizer.hasMoreElements() == false) { throw new ResourceKeyCreationException("Schema is missing"); } final String rawSchema = tokenizer.nextToken(); if (rawSchema.startsWith(SERIALIZATION_PREFIX) == false) { throw new ResourceKeyCreationException("Prefix is wrong"); } final String schema = rawSchema.substring(SERIALIZATION_PREFIX.length()); if (tokenizer.hasMoreElements() == false) { throw new ResourceKeyCreationException("Identifier is missing"); } final String id = tokenizer.nextToken(); final Map parameters; if (tokenizer.hasMoreElements()) { parameters = parseFactoryParametersFromString(tokenizer.nextToken()); } else { parameters = null; } // The 1st component is the schema... the 2nd is the identifier... the 3rd is the factory parameters (optional) return new ResourceKeyData(schema, id, parameters); } /** * Returns the list of factory parameters for the specified ResourceKey as a String * representation in the format: *

   *   key=value:key=value:...:key=value
   * 
* The colon (:) is the separator between parameters and the equal sign (=) is the separator * between the key and the value. *

* If the factory parameters is empty, null will be returned * * @param factoryParameters the parameter map. * @return a String representation of the factory parameters for the ResourceKey */ public static String convertFactoryParametersToString(final Map factoryParameters) { if (factoryParameters == null || factoryParameters.size() <= 0) { return null; } final CSVQuoter innerQuoter = new CSVQuoter('='); final CSVQuoter quoter = new CSVQuoter(':'); final StringBuffer sb = new StringBuffer(); for (Iterator iterator = factoryParameters.keySet().iterator(); iterator.hasNext();) { if (sb.length() > 0) { sb.append(':'); } final StringBuffer entrySb = new StringBuffer(); Object key = iterator.next(); if (key instanceof FactoryParameterKey) { FactoryParameterKey fkey = (FactoryParameterKey) key; entrySb.append(innerQuoter.doQuoting("f:" + fkey.getName())); } else if (key instanceof LoaderParameterKey) { LoaderParameterKey fkey = (LoaderParameterKey) key; entrySb.append(innerQuoter.doQuoting("l:" + fkey.getName())); } else { throw new IllegalArgumentException(); } Object value = factoryParameters.get(key); entrySb.append('='); if (value != null) { // todo: This String.valueOf is probably and very likely wrong entrySb.append(innerQuoter.doQuoting(String.valueOf(value))); } sb.append(quoter.doQuoting(entrySb.toString())); } logger.debug("Converted ResourceKey's Factory Parameters to String: [" + sb.toString() + "]"); return sb.toString(); } /** * Returns a Map of parameters based on the input string. The string will be parsed using the * same format as defined in the getFactoryParametersAsString() method. * * @param factoryParameters the String representation of factory parameters * @return a Map of factory parameters parsed from the string, or null * if the source string was null or contained no data */ public static Map parseFactoryParametersFromString(final String factoryParameters) { if (factoryParameters == null) { return null; } final Map params = new HashMap(); final CSVTokenizer tokenizer = new CSVTokenizer(factoryParameters, ":", CSVTokenizer.DOUBLE_QUATE, false); while (tokenizer.hasMoreTokens()) { final String entry = tokenizer.nextToken(); final CSVTokenizer innerTokenizer = new CSVTokenizer(entry, "=", CSVTokenizer.DOUBLE_QUATE, false); final Object key; if (innerTokenizer.hasMoreElements()) { final String keyString = innerTokenizer.nextToken(); if (keyString.startsWith("f:")) { key = new FactoryParameterKey(keyString.substring(2)); } else if (keyString.startsWith("l:")) { key = new LoaderParameterKey(keyString.substring(2)); } else { throw new IllegalStateException(); } } else { throw new IllegalStateException(); } final Object value; if (innerTokenizer.hasMoreElements()) { value = innerTokenizer.nextToken(); } else { value = null; } params.put(key, value); } if (logger.isDebugEnabled()) { logger.debug("Converted ResourceKey's Factory Parameter String to a Map: [" + factoryParameters + "] -> map of size " + params.size()); } return params; } /** * Returns the schema portion of the serialized ResourceKey string. If the string is invalid, * null will be returned. * * @param data the String serialized version of a ResourceKey * @return the schema object. */ public static Object readSchemaFromString(final String data) { if (data == null) { return null; } final CSVTokenizer tokenizer = new CSVTokenizer(data, DELIMITER, CSVTokenizer.DOUBLE_QUATE, false); if (tokenizer.hasMoreElements() == false) { return null; } final String tempData = tokenizer.nextToken(); if (tempData.startsWith(SERIALIZATION_PREFIX)) { return tempData.substring(SERIALIZATION_PREFIX.length()); } return null; } /** * Performs a simple attempt at a "smart" conversion to a ResourceKey. *

    *
  1. If the value is null, this method will return null
  2. *
  3. If the value is a ResourceKey, the value will be returned
  4. *
  5. If the value is a String and is syntactically valid as a URL, * it will be converted to a URL and then used to create a ResourceKey
  6. *
  7. If the value is a String and is NOT syntactically valid as a URL, * it will be converted ot a File and then used to create a ResourceKey
  8. *
  9. All other types will be passed along to attempt a key creation as is *
* * @param value the object to convert to a ResourceKey * @param resourceManager the resource manager used in key creation * @param parameters the parameters that should be passed to generate a resource key * @return the resource key created * @throws ResourceKeyCreationException indicates the value can not be used to create a Resource Key */ public static ResourceKey toResourceKey(final Object value, final ResourceManager resourceManager, final ResourceKey contextKey, final Map parameters) throws ResourceKeyCreationException { if (value == null) { return null; } if (value instanceof ResourceKey) { return (ResourceKey) value; } if (resourceManager == null) { throw new NullPointerException("ResourceManager is null"); } // If the value is a String, try a URL or a File Object tempObject = value; if (tempObject instanceof String) { final String spec = (String) value; if (contextKey != null) { try { return resourceManager.deriveKey(contextKey, spec, parameters); } catch (ResourceKeyCreationException e) { // ignored .. } } try { tempObject = new URL(spec); } catch (MalformedURLException e) { tempObject = new File(spec); } } return resourceManager.createKey(tempObject, parameters); } /** * Returns a new ResourceKey with the specified source resource embedded inside as a byte [] * * @param source the ResourceKey to the source which will be embedded - NOTE: the pattern can specify an exact name * or a pattern for creating a temporary name. If the name exists, it will be replaced. * @param factoryParameters any factory parameters which should be added to the ResourceKey being created * @return the ResourceKey for the newly created embedded entry */ public static ResourceKey embedResourceInKey(final ResourceManager manager, final ResourceKey source, final Map factoryParameters) throws IOException, ResourceKeyCreationException, ResourceLoadingException { if (manager == null) { throw new IllegalArgumentException(); } if (source == null) { throw new IllegalArgumentException(); } final ResourceData resourceData = manager.load(source); // Load the resource into a byte array final InputStream in = resourceData.getResourceAsStream(manager); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { IOUtils.getInstance().copyStreams(in, out); // Create a resource key with the byte array return manager.createKey(out.toByteArray(), factoryParameters); } finally { try { in.close(); } catch (IOException e) { logger.error("Error closing input stream", e); } } } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/0000755000175000017500000000000011365605644026331 5ustar renerenelibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/0000755000175000017500000000000011365605644027413 5ustar renerene././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/GIFImageFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/GIFImageFactoryM0000644000175000017500000000537311365605644032363 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory.image; import java.awt.Image; import java.awt.Toolkit; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractFactoryModule; /** * Creation-Date: 05.04.2006, 17:35:12 * * @author Thomas Morgner */ public class GIFImageFactoryModule extends AbstractFactoryModule { private static final int[] FINGERPRINT = {'G', 'I', 'F', '8'}; private static final String[] MIMETYPES = { "image/gif", "image/x-xbitmap", "image/gi_" }; private static final String[] FILEEXTENSIONS = { ".gif" }; public GIFImageFactoryModule() { } public int getHeaderFingerprintSize () { return GIFImageFactoryModule.FINGERPRINT.length; } protected int[] getFingerPrint() { return GIFImageFactoryModule.FINGERPRINT; } protected String[] getMimeTypes() { return GIFImageFactoryModule.MIMETYPES; } protected String[] getFileExtensions() { return GIFImageFactoryModule.FILEEXTENSIONS; } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceLoadingException { final long version = data.getVersion(caller); final Image image = Toolkit.getDefaultToolkit().createImage(data.getResource(caller)); return new SimpleResource (data.getKey(), image, Image.class, version); } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/JPEGImageFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/JPEGImageFactory0000644000175000017500000000731711365605644032366 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory.image; import java.awt.Image; import java.awt.Toolkit; import java.io.InputStream; import java.io.IOException; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractFactoryModule; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Creation-Date: 05.04.2006, 17:35:12 * * @author Thomas Morgner */ public class JPEGImageFactoryModule extends AbstractFactoryModule { private static final int[] FINGERPRINT_1 = {0xFF, 0xD8}; private static final String[] MIMETYPES = { "image/jpeg", "image/jpg", "image/jp_", "application/jpg", "application/x-jpg", "image/pjpeg", "image/pipeg", "image/vnd.swiftview-jpeg", "image/x-xbitmap" }; private static final String[] FILEEXTENSIONS = { ".jpg", ".jpeg" }; private static final int[] EMPTY_ARRAY = new int[0]; public JPEGImageFactoryModule() { } public int getHeaderFingerprintSize () { // indicate that we cannot allow the generic fingerprinting. We need to test it by ourselfs. return -1; } protected boolean canHandleResourceByContent(final InputStream data) throws IOException { final int[] fingerprint = FINGERPRINT_1; for (int i = 0; i < fingerprint.length; i++) { if (fingerprint[i] != data.read()) { return false; } } if (data.read() == -1) { return false; } if (data.read() == -1) { return false; } // fingerprint = FINGERPRINT_2; // for (int i = 0; i < fingerprint.length; i++) // { // if (fingerprint[i] != data.read()) // { // return false; // } // } return true; } protected int[] getFingerPrint() { return EMPTY_ARRAY; } protected String[] getMimeTypes() { return (String[]) JPEGImageFactoryModule.MIMETYPES.clone(); } protected String[] getFileExtensions() { return (String[]) JPEGImageFactoryModule.FILEEXTENSIONS.clone(); } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceLoadingException { final long version = data.getVersion(caller); final Image image = Toolkit.getDefaultToolkit().createImage(data.getResource(caller)); return new SimpleResource (data.getKey(), image, Image.class, version); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/ImageResourceFactory.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/ImageResourceFac0000644000175000017500000000270111365605644032502 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory.image; import java.awt.Image; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractResourceFactory; /** * Creation-Date: 05.04.2006, 17:59:50 * * @author Thomas Morgner */ public class ImageResourceFactory extends AbstractResourceFactory { private static ImageResourceFactory instance; public ImageResourceFactory() { super(Image.class); } public static synchronized ImageResourceFactory getInstance() { if (instance == null) { instance = new ImageResourceFactory(); } return instance; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/PNGImageFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/image/PNGImageFactoryM0000644000175000017500000000525011365605644032374 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory.image; import java.awt.Toolkit; import java.awt.Image; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractFactoryModule; /** * Creation-Date: 05.04.2006, 17:35:12 * * @author Thomas Morgner */ public class PNGImageFactoryModule extends AbstractFactoryModule { private static final int[] FINGERPRINT = {137, 80, 78, 71, 13, 10, 26, 10}; private static final String[] MIMETYPES = { "image/png", "application/png", "application/x-png" }; private static final String[] FILEEXTENSIONS = { ".png", }; public PNGImageFactoryModule() { } public int getHeaderFingerprintSize () { return FINGERPRINT.length; } protected int[] getFingerPrint() { return FINGERPRINT; } protected String[] getMimeTypes() { return MIMETYPES; } protected String[] getFileExtensions() { return FILEEXTENSIONS; } public Resource create(final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceLoadingException { final long version = data.getVersion(caller); final Image image = Toolkit.getDefaultToolkit().createImage(data.getResource(caller)); return new SimpleResource (data.getKey(), image, Image.class, version); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/drawable/0000755000175000017500000000000011365605644030112 5ustar renerene././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/drawable/DrawableWrapper.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/drawable/DrawableWrapp0000644000175000017500000001523211365605644032573 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory.drawable; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Collections; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Creation-Date: 05.12.2007, 19:15:56 * * @author Thomas Morgner */ public class DrawableWrapper { private static final Log logger = LogFactory.getLog(DrawableWrapper.class); private static final Map drawables = Collections.synchronizedMap(new HashMap()); private Object backend; private Method drawMethod; private Method getPreferredSizeMethod; private Method isKeepAspectRatioMethod; private static final Object[] EMPTY_ARGS = new Object[0]; private static final Class[] EMPTY_PARAMS = new Class[0]; private static final Class[] PARAMETER_TYPES = new Class[]{Graphics2D.class, Rectangle2D.class}; public DrawableWrapper(final Object maybeDrawable) { if (maybeDrawable == null) { throw new NullPointerException("Drawable must not be null"); } if (maybeDrawable instanceof DrawableWrapper) { throw new IllegalArgumentException("Cannot wrap around a drawable-wrapper"); } final Class aClass = maybeDrawable.getClass(); try { drawMethod = aClass.getMethod("draw", PARAMETER_TYPES); final int modifiers = drawMethod.getModifiers(); if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers)) { if (logger.isWarnEnabled()) { logger.warn("DrawMethod is not valid: " + aClass + '#' + drawMethod); } drawMethod = null; } } catch (NoSuchMethodException e) { // ignore exception if (logger.isWarnEnabled()) { logger.warn("The object is not a drawable: " + aClass); } drawMethod = null; } if (drawMethod != null) { try { isKeepAspectRatioMethod = aClass.getMethod("isPreserveAspectRatio", EMPTY_PARAMS); final int modifiers = isKeepAspectRatioMethod.getModifiers(); if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers) || Boolean.TYPE.equals(isKeepAspectRatioMethod.getReturnType()) == false) { isKeepAspectRatioMethod = null; } } catch (NoSuchMethodException e) { // ignored .. } try { getPreferredSizeMethod = aClass.getMethod("getPreferredSize", EMPTY_PARAMS); final int modifiers = getPreferredSizeMethod.getModifiers(); if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers) || Dimension2D.class.equals(getPreferredSizeMethod.getReturnType()) == false) { isKeepAspectRatioMethod = null; } } catch (NoSuchMethodException e) { // ignored .. } } backend = maybeDrawable; } public Object getBackend() { return backend; } public void draw(final Graphics2D g2, final Rectangle2D bounds) { if (drawMethod == null) { return; } try { drawMethod.invoke(backend, new Object[]{g2, bounds}); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.warn("Invoking draw failed:", e); } } } /** * Returns the preferred size of the drawable. If the drawable is aspect ratio aware, these bounds should be used to * compute the preferred aspect ratio for this drawable. * * @return the preferred size. */ public Dimension getPreferredSize() { if (getPreferredSizeMethod == null) { return null; } try { return (Dimension) getPreferredSizeMethod.invoke(backend, EMPTY_ARGS); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Invoking getPreferredSize failed:", e); } return null; } } /** * Returns true, if this drawable will preserve an aspect ratio during the drawing. * * @return true, if an aspect ratio is preserved, false otherwise. */ public boolean isPreserveAspectRatio() { if (isKeepAspectRatioMethod == null) { return false; } try { return Boolean.TRUE.equals(isKeepAspectRatioMethod.invoke(backend, EMPTY_ARGS)); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Invoking isKeepAspectRatio failed:", e); } return false; } } public static boolean isDrawable(final Object maybeDrawable) { if (maybeDrawable == null) { throw new NullPointerException("A value can never be a drawable."); } final String key = maybeDrawable.getClass().getName(); final Boolean result = (Boolean) drawables.get(key); if (result != null) { return result.booleanValue(); } final boolean b = computeIsDrawable(maybeDrawable); if (b == true) { drawables.put(key, Boolean.TRUE); } else { drawables.put(key, Boolean.FALSE); } return b; } private static boolean computeIsDrawable(final Object maybeDrawable) { final Class aClass = maybeDrawable.getClass(); try { final Method drawMethod = aClass.getMethod("draw", PARAMETER_TYPES); final int modifiers = drawMethod.getModifiers(); return (Modifier.isPublic(modifiers) && Modifier.isAbstract(modifiers) == false && Modifier.isStatic(modifiers) == false); } catch (NoSuchMethodException e) { // ignore exception return false; } } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/drawable/DrawableResourceFactory.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/drawable/DrawableResou0000644000175000017500000000270511365605644032600 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory.drawable; import org.pentaho.reporting.libraries.resourceloader.factory.AbstractResourceFactory; /** * Creation-Date: 05.04.2006, 17:59:50 * * @author Thomas Morgner */ public class DrawableResourceFactory extends AbstractResourceFactory { private static DrawableResourceFactory instance; public DrawableResourceFactory() { super(DrawableWrapper.class); } public static synchronized DrawableResourceFactory getInstance() { if (instance == null) { instance = new DrawableResourceFactory(); } return instance; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/FactoryModule.java0000644000175000017500000000427011365605644031754 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Creation-Date: 05.04.2006, 17:00:33 * * @author Thomas Morgner */ public interface FactoryModule { public static final int RECOGNIZED_FINGERPRINT = 4000; public static final int RECOGNIZED_CONTENTTYPE = 2000; public static final int RECOGNIZED_FILE = 1000; /** A default handler does not reject the content. */ public static final int FEELING_LUCKY = 0; public static final int REJECTED = -1; public int canHandleResource (final ResourceManager caller, final ResourceData data) throws ResourceCreationException, ResourceLoadingException; public int getHeaderFingerprintSize (); public Resource create (final ResourceManager caller, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException; } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/property/0000755000175000017500000000000011365605644030215 5ustar renerene././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/property/PropertiesResourceFactory.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/property/PropertiesRes0000644000175000017500000000500611365605644032747 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory.property; import java.util.Properties; import java.io.IOException; import java.io.InputStream; import org.pentaho.reporting.libraries.resourceloader.ResourceFactory; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.SimpleResource; public class PropertiesResourceFactory implements ResourceFactory { public PropertiesResourceFactory () { } public Resource create (final ResourceManager manager, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { try { final Properties properties = new Properties(); final InputStream stream = data.getResourceAsStream(manager); try { properties.load(stream); } finally { stream.close(); } return new SimpleResource (data.getKey(), properties, Properties.class, data.getVersion(manager)); } catch (IOException e) { throw new ResourceLoadingException("Failed to load the properties file.",e); } } public Class getFactoryType () { return Properties.class; } public void initializeDefaults () { // none required ... } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/AbstractFactoryModule.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/AbstractFactoryModule.0000644000175000017500000000741011365605644032575 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory; import java.io.IOException; import java.io.InputStream; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Creation-Date: 05.04.2006, 17:44:42 * * @author Thomas Morgner */ public abstract class AbstractFactoryModule implements FactoryModule { protected AbstractFactoryModule() { } protected abstract int[] getFingerPrint(); protected abstract String[] getMimeTypes(); protected abstract String[] getFileExtensions(); public int getHeaderFingerprintSize() { final int[] fingerPrint = getFingerPrint(); if (fingerPrint == null) { return 0; } return fingerPrint.length; } public int canHandleResource(final ResourceManager caller, final ResourceData data) throws ResourceCreationException, ResourceLoadingException { try { final InputStream asStream = data.getResourceAsStream(caller); try { if (canHandleResourceByContent(asStream)) { return RECOGNIZED_FINGERPRINT; } final String mimeType = (String) data.getAttribute(ResourceData.CONTENT_TYPE); if (mimeType != null && canHandleResourceByMimeType(mimeType)) { return RECOGNIZED_CONTENTTYPE; } final String fileName = (String) data.getAttribute(ResourceData.FILENAME); if (fileName != null && canHandleResourceByName(fileName)) { return RECOGNIZED_CONTENTTYPE; } return REJECTED; } finally { asStream.close(); } } catch (ResourceLoadingException e) { throw e; } catch (Exception e) { throw new ResourceCreationException("Failed to load or check content", e); } } protected boolean canHandleResourceByContent(final InputStream data) throws IOException { final int[] fingerprint = getFingerPrint(); if (fingerprint.length == 0) { return false; } for (int i = 0; i < fingerprint.length; i++) { if (fingerprint[i] != data.read()) { return false; } } return true; } protected boolean canHandleResourceByMimeType(final String name) { final String[] mimes = getMimeTypes(); for (int i = 0; i < mimes.length; i++) { if (name.equals(mimes[i])) { return true; } } return false; } protected boolean canHandleResourceByName(final String name) { final String[] fexts = getFileExtensions(); for (int i = 0; i < fexts.length; i++) { if (name.equalsIgnoreCase(fexts[i])) { return true; } } return false; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/AbstractResourceFactory.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/factory/AbstractResourceFactor0000644000175000017500000001562711365605644032701 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.factory; import java.util.HashSet; import java.util.Iterator; import java.util.TreeSet; import org.pentaho.reporting.libraries.resourceloader.LibLoaderBoot; import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.ResourceCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceData; import org.pentaho.reporting.libraries.resourceloader.ResourceFactory; import org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ContentNotRecognizedException; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; import org.pentaho.reporting.libraries.base.config.Configuration; /** * Creation-Date: 05.04.2006, 16:58:57 * * @author Thomas Morgner */ public abstract class AbstractResourceFactory implements ResourceFactory { private static class ResourceFactoryEntry implements Comparable { private FactoryModule module; private int weight; private ResourceFactoryEntry(final FactoryModule module, final int weight) { this.module = module; this.weight = weight; } public FactoryModule getModule() { return module; } public int getWeight() { return weight; } public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final ResourceFactoryEntry that = (ResourceFactoryEntry) o; if (weight != that.weight) { return false; } if (module != null ? !module.equals(that.module) : that.module != null) { return false; } return true; } public int hashCode() { int result; result = (module != null ? module.hashCode() : 0); result = 31 * result + weight; return result; } /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less than, * equal to, or greater than the specified object.

* * "Note: this class has a natural ordering that is inconsistent with * equals." * * @param o the Object to be compared. * @return a negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. * @throws ClassCastException if the specified object's type prevents it from * being compared to this Object. */ public int compareTo(final Object o) { final ResourceFactoryEntry entry = (ResourceFactoryEntry) o; // the order is intentionally reveresed, so that a sorted set has the best // fit as first entry. if (weight == entry.weight) { return 0; } if (weight < entry.weight) { return -1; } return 1; } } /** The available factory methods. */ private HashSet factoryModules; /** Which type of objects do we create here? */ private Class factoryType; protected AbstractResourceFactory(final Class factoryType) { if (factoryType == null) { throw new NullPointerException(); } this.factoryType = factoryType; this.factoryModules = new HashSet(); } public Class getFactoryType() { return factoryType; } public void initializeDefaults () { final String type = getFactoryType().getName(); final String prefix = CONFIG_PREFIX + type; final Configuration config = LibLoaderBoot.getInstance().getGlobalConfig(); final Iterator itType = config.findPropertyKeys(prefix); while (itType.hasNext()) { final String key = (String) itType.next(); final String modClass = config.getConfigProperty(key); final Object maybeFactory = ObjectUtilities.loadAndInstantiate (modClass, AbstractResourceFactory.class, FactoryModule.class); if (maybeFactory instanceof FactoryModule == false) { continue; } registerModule((FactoryModule) maybeFactory); } } public synchronized boolean registerModule(final String className) { try { final ClassLoader loader = ObjectUtilities.getClassLoader(getClass()); final Class c = Class.forName(className, false, loader); registerModule((FactoryModule) c.newInstance()); return true; } catch (Exception e) { return false; } } public synchronized void registerModule(final FactoryModule module) { if (factoryModules.contains(module)) { return; } factoryModules.add(module); } /** * * @param data * @param context * @return * @throws ResourceCreationException * @throws ResourceLoadingException */ public synchronized Resource create(final ResourceManager manager, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { final TreeSet sortedEntries = new TreeSet(); final Iterator factoryModulesIt = factoryModules.iterator(); while (factoryModulesIt.hasNext()) { final FactoryModule mod = (FactoryModule) factoryModulesIt.next(); final int weight = mod.canHandleResource(manager, data); if (weight >= 0) { sortedEntries.add(new ResourceFactoryEntry(mod, weight)); } } final Iterator it = sortedEntries.iterator(); while (it.hasNext()) { final ResourceFactoryEntry entry = (ResourceFactoryEntry) it.next(); try { return entry.getModule().create(manager, data, context); } catch(Exception ex) { // ok, that one failed, try the next one ... } } throw new ContentNotRecognizedException ("No valid handler for the given content."); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/CompoundResource.java0000644000175000017500000000575511365605644031035 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * Creation-Date: 08.04.2006, 14:08:13 * * @author Thomas Morgner */ public class CompoundResource implements Resource { private static final long serialVersionUID = -5828242419391352185L; private ResourceKey source; private DependencyCollector dependencies; private Object product; private Class targetType; public CompoundResource(final ResourceKey source, final DependencyCollector dependencies, final Object product, final Class targetType) { if (source == null) { throw new NullPointerException("Source must not be null"); } if (dependencies == null) { throw new NullPointerException("Dependecies must be given."); } if (targetType == null) { throw new NullPointerException("TargetType must not be null"); } if (product == null) { throw new NullPointerException("Product must not be null"); } this.targetType = targetType; this.source = source; try { this.dependencies = (DependencyCollector) dependencies.clone(); } catch (CloneNotSupportedException e) { throw new IllegalStateException ("Clone not supported? This should not happen."); } this.product = product; } public Object getResource() throws ResourceException { return product; } public long getVersion(final ResourceKey key) { return dependencies.getVersion(key); } /** * The primary source is also included in this set. The dependencies are given * as ResourceKey objects. The keys itself do not hold any state information. *

* The dependencies do not track deep dependencies. So if Resource A depends * on Resource B which depends on Resource C, then A only knows about B, not * C. * * @return */ public ResourceKey[] getDependencies() { return dependencies.getDependencies(); } public ResourceKey getSource() { return source; } public Class getTargetType() { return targetType; } public boolean isTemporaryResult() { return false; } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceCreationException.java0000644000175000017500000000317311365605644032664 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * Creation-Date: 05.04.2006, 17:33:09 * * @author Thomas Morgner */ public class ResourceCreationException extends ResourceException { private static final long serialVersionUID = 3808811250190779639L; /** Creates a StackableRuntimeException with no message and no parent. */ public ResourceCreationException() { } /** * Creates an exception. * * @param message the exception message. * @param ex the parent exception. */ public ResourceCreationException(final String message, final Exception ex) { super(message, ex); } /** * Creates an exception. * * @param message the exception message. */ public ResourceCreationException(final String message) { super(message); } } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/module.properties0000644000175000017500000000030311365605644030261 0ustar renerenemodule.name: libloader module.producer: The Pentaho Reporting Project module.description: The 'libLoader' main module module.version.major: 1 module.version.minor: 0 module.version.patchlevel: 0 libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceLoader.java0000644000175000017500000001142011365605644030441 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.util.Map; import java.net.URL; /** * A resource loader knows how to get binary rawdata from a location specified * by an resource key. A resource key is a wrapper around any kind of data that * is suitable to identify a resource location. The resource key can also hold * configuration data for the factory. * * If the storage system is hierarchical, a new resource key can be derived from * a given path-string. * * @author Thomas Morgner */ public interface ResourceLoader { /** * Checks, whether this resource loader implementation was responsible for * creating this key. * * @param key the key that should be tested. * @return true, if the key is supported. */ public boolean isSupportedKey (ResourceKey key); /** * Creates a new resource key from the given object and the factory keys. * * @param value the key value. * @param factoryKeys optional parameter map (can be null). * @return the created key or null, if the format was not recognized. * @throws ResourceKeyCreationException if creating the key failed. */ public ResourceKey createKey (Object value, Map factoryKeys) throws ResourceKeyCreationException; /** * Derives a new resource key from the given key. If neither a path nor new * factory-keys are given, the parent key is returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws ResourceKeyCreationException if the key cannot be derived for any * reason. */ public ResourceKey deriveKey (ResourceKey parent, String path, Map factoryKeys) throws ResourceKeyCreationException; /** * Loads the binary data represented by this key. * * @param key * @return * @throws ResourceLoadingException */ public ResourceData load (final ResourceKey key) throws ResourceLoadingException; /** * Generates a URL version of the supplied ResourceKey. * * @param key the ResourceKey from which a URL will be created * @return the URL representation of the ResourceKey */ public URL toURL (ResourceKey key); /** * Determines if the resource loader is capable of deserializing the * serialized version of the ResourceKey. * @param data the serialized version of the resource key * @return true if this ResourceLoader is capable of deserializing the * serialized version of this resource key, false otherwise. */ public boolean isSupportedDeserializer(final String data); /** * Serializes the resource key to a String representation which can be recreated * using the deserialize(ResourceKey) method. * @return a String which is a serialized version of the ResourceKey * @throws ResourceException indicates an error serializing the resource key * @param bundleKey * @param key */ public String serialize(final ResourceKey bundleKey, final ResourceKey key) throws ResourceException; /** * Creates a ResourceKey based off the String representation * of the key. The String should have been created using the serialize * method. * * @param bundleKey *@param stringKey the String representation of the ResourceKey @return a ResourceKey which matches the String representation * @throws ResourceKeyCreationException indicates an error occurred in the creation or * deserialization of the ResourceKey */ public ResourceKey deserialize(final ResourceKey bundleKey, final String stringKey) throws ResourceKeyCreationException; } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceData.java0000644000175000017500000000510011365605644030102 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.io.InputStream; /** * A resource data object encapsulates the raw data of an resource at a given * point in the past. * * Any change to the resource increases the version number. Version numbers * are not needed to be checked regulary, but must be checked on each call to * 'getVersion()'. * * This definitly does *not* solve the problem of concurrent modifications; if * you need to be sure that the resource has not been altered between the last * call to 'getVersion' and 'getResource..' external locking mechanism have to * be implemented. * * @author Thomas Morgner */ public interface ResourceData { public static final String CONTENT_LENGTH = "content-length"; public static final String CONTENT_TYPE = "content-type"; public static final String FILENAME = "filename"; public InputStream getResourceAsStream(ResourceManager caller) throws ResourceLoadingException; /** * This is dangerous, especially if the resource is large. * * @param caller * @return * @throws ResourceLoadingException */ public byte[] getResource(ResourceManager caller) throws ResourceLoadingException; /** * Tries to read data into the given byte-array. * * @param caller * @param target * @param offset * @param length * @return the number of bytes read or -1 if no more data can be read. * @throws ResourceLoadingException */ public int getResource(ResourceManager caller, byte[] target, long offset, int length) throws ResourceLoadingException; public long getLength(); public Object getAttribute (String key); public ResourceKey getKey(); public long getVersion(ResourceManager caller) throws ResourceLoadingException; } libloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/LibLoaderInfo.java0000644000175000017500000000417611365605644030206 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import org.pentaho.reporting.libraries.base.LibBaseInfo; import org.pentaho.reporting.libraries.base.versioning.DependencyInformation; import org.pentaho.reporting.libraries.base.versioning.ProjectInformation; public class LibLoaderInfo extends ProjectInformation { private static LibLoaderInfo instance; public static LibLoaderInfo getInstance() { if (instance == null) { instance = new LibLoaderInfo(); instance.initialize(); } return instance; } /** * Constructs an empty project info object. */ public LibLoaderInfo() { super("libloader", "LibLoader"); } private void initialize() { setLicenseName("LGPL"); setInfo("http://reporting.pentaho.org/libloader/"); setCopyright("(C)opyright 2006-2010, by Pentaho Corporation and Contributors"); setBootClass(LibLoaderBoot.class.getName()); addLibrary(LibBaseInfo.getInstance()); addOptionalLibrary("org.pentaho.reporting.libraries.pixie.PixieInfo"); addOptionalLibrary(new DependencyInformation("EHCache", "1.2rc1", "Apache Licence 2.0", "http://ehcache.sourceforge.net/")); addOptionalLibrary(new DependencyInformation("Batik", "1.6", "Apache Software License", "http://xml.apache.org/batik")); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceKeyCreationException.javalibloader-1.1.6/source/org/pentaho/reporting/libraries/resourceloader/ResourceKeyCreationException.j0000644000175000017500000000321011365605644032635 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; /** * Creation-Date: 05.04.2006, 13:02:23 * * @author Thomas Morgner */ public class ResourceKeyCreationException extends ResourceException { private static final long serialVersionUID = -8411385657974722306L; /** Creates a StackableRuntimeException with no message and no parent. */ public ResourceKeyCreationException() { } /** * Creates an exception. * * @param message the exception message. * @param ex the parent exception. */ public ResourceKeyCreationException(final String message, final Exception ex) { super(message, ex); } /** * Creates an exception. * * @param message the exception message. */ public ResourceKeyCreationException(final String message) { super(message); } } libloader-1.1.6/libloader.iml0000644000175000017500000002623311365605644014600 0ustar renerene libloader-1.1.6/README.txt0000644000175000017500000000425211365605644013633 0ustar renerene************************ * LIBLOADER 0.4.0 * ************************ 30 May 2008 1. INTRODUCTION --------------- LibLoader is a general purpose resource loading framework. It has been designed to allow to load resources from any physical location and to allow the processing of that content data in a generic way, totally transparent to the user of that library. For the latest news and information about LibLoader, please refer to: http://reporting.pentaho.org/libloader/ 2. REQUIREMENTS --------------- LibLoader needs at least JDK 1.2.2 for its core functionality. The EHCache support requires at least JDK 1.4. This module is therefore not included by default. It can be built manually using the supplied ANT-script. 3. SUPPORT ---------- Free support is available via the Pentaho forum, follow the link from the home page. Please note that questions are answered by volunteers, so there is no guaranteed response time or level of service. Please avoid e-mailing the developers directly for support questions. If you post a message in the forum, then everyone can see the question, and everyone can see the answer. The forums can be found at http://forums.pentaho.org/ 4. REPORTING BUGS ----------------- If you find bugs in LibLoader, we'd like to hear about it so that we can improve future releases of LibLoader. Please post a bug report to the JIRA bug-tracker at Pentaho.org: http://jira.pentaho.org/ Please be sure to provide as much information as you can. We need to know the version of LibLoader that you are using, the JDK version, and the steps required to replicate the bug. Include any other information that you think is relevant. 5. ANT ------ We use an open source build tool called Ant to build LibLoader. An Ant script (tested using Ant 1.7.0) is included in the distribution: /build.xml You can find out more about Ant at: http://ant.apache.org/ Ant is licensed under the terms of the Apache Software License (a popular open source software license). 6. OTHER FEEDBACK ----------------- For other feedback and comments, please post a message on the Pentaho forums. The Forum is available at http://forums.pentaho.org/ libloader-1.1.6/ivy.xml0000644000175000017500000000520011365605644013460 0ustar renerene libloader-1.1.6/test-lib/0000755000175000017500000000000011640450023013636 5ustar renerenelibloader-1.1.6/lib/0000755000175000017500000000000011635764421012677 5ustar renerenelibloader-1.1.6/test/0000755000175000017500000000000011365605642013107 5ustar renerenelibloader-1.1.6/test/org/0000755000175000017500000000000011365605642013676 5ustar renerenelibloader-1.1.6/test/org/pentaho/0000755000175000017500000000000011365605642015334 5ustar renerenelibloader-1.1.6/test/org/pentaho/reporting/0000755000175000017500000000000011365605642017345 5ustar renerenelibloader-1.1.6/test/org/pentaho/reporting/libraries/0000755000175000017500000000000011365605642021321 5ustar renerenelibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/0000755000175000017500000000000011365605644024341 5ustar renerenelibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/test1.properties0000644000175000017500000000002311365605644027512 0ustar renerene# Just a test file.libloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/TestResourceKeyUtils.java0000644000175000017500000001637311365605642031335 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; /** * Test cases for the ResourceKeyUtils class * * @author David Kincade */ public class TestResourceKeyUtils extends TestCase { public TestResourceKeyUtils() { } public TestResourceKeyUtils(final String string) { super(string); } protected void setUp() throws Exception { LibLoaderBoot.getInstance().start(); } public void testGetFactoryParametersAsString() throws ResourceKeyCreationException { final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); ResourceKey key = null; String stringParameters = null; Map factoryParameters = new HashMap(); // Test with no factory parameters specified key = manager.createKey("res://org/pentaho/reporting/libraries/resourceloader/test1.properties"); assertNotNull(key); stringParameters = ResourceKeyUtils.convertFactoryParametersToString(key.getFactoryParameters()); assertNull("Null parameter set should result null", stringParameters); // Test with empty parameter set key = manager.createKey("res://org/pentaho/reporting/libraries/resourceloader/test1.properties", factoryParameters); assertNotNull(key); stringParameters = ResourceKeyUtils.convertFactoryParametersToString(key.getFactoryParameters()); assertNull("Empty parameter set should result in null", stringParameters); // Test with one parameter factoryParameters.put("this", "that"); key = manager.createKey("res://org/pentaho/reporting/libraries/resourceloader/test1.properties", factoryParameters); assertNotNull(key); stringParameters = ResourceKeyUtils.convertFactoryParametersToString(key.getFactoryParameters()); assertEquals("Unexpected results with one parameter", "this=that", stringParameters); // Test with one parameter that has a null value factoryParameters.clear(); factoryParameters.put("null", null); key = manager.createKey("res://org/pentaho/reporting/libraries/resourceloader/test1.properties", factoryParameters); assertNotNull(key); stringParameters = ResourceKeyUtils.convertFactoryParametersToString(key.getFactoryParameters()); assertEquals("Could not handle parameter with a null value", "null=", stringParameters); // Test with multiple parameters (and one has a null value) factoryParameters.clear(); factoryParameters.put("this", "that"); factoryParameters.put("test with spaces", " spaces should be preserved "); factoryParameters.put("this-one_null", null); factoryParameters.put(manager.getClass(), manager); key = manager.createKey("res://org/pentaho/reporting/libraries/resourceloader/test1.properties", factoryParameters); assertNotNull(key); stringParameters = ResourceKeyUtils.convertFactoryParametersToString(key.getFactoryParameters()); // Count the number of separators (:) in the string int count = 0; String temp = stringParameters; while (temp.indexOf(':') > -1) { ++count; temp = temp.substring(temp.indexOf(':') + 1); } assertEquals("There should be 3 separators in the string", 3, count); // Make sure the parameters exist assertTrue("Could not find parameter 'this=that'", stringParameters.indexOf("this=that") > -1); assertTrue("Could not find parameter 'test with spaces'", stringParameters .indexOf("test with spaces= spaces should be preserved ") > -1); assertTrue("Could not find parameter that isn't a String", stringParameters.indexOf(manager.getClass() + "=" + manager.toString()) > -1); assertTrue("Could not find parameter with null value", stringParameters.indexOf("this-one_null=:") > -1 || stringParameters.endsWith("this-one_null=")); } /** * Tests the parsing of a String into a set of parameters */ public void testGetFactoryParametersFromString() { Map map = null; // Test null string map = ResourceKeyUtils.parseFactoryParametersFromString(null); assertNull("The map should be null if the source string is null", map); // Test empty string map = ResourceKeyUtils.parseFactoryParametersFromString(""); assertNull("The map should be null if the source string is blank", map); // Test invalid string with no equals signs map = ResourceKeyUtils.parseFactoryParametersFromString("this is a test of the string : a colon : and another:one more"); assertNull("The map should be null if the source string is invalid", map); // Test a valid string including a null value in the middle map = ResourceKeyUtils.parseFactoryParametersFromString("this=that:null=:one=1: with spaces = more spaces :space= :junk:one=won:nullagain="); assertNotNull("The map should not be null if the source string is valid", map); assertEquals("The map should have 6 entries - skipping the junk and not containing a duplicate", 6, map.size()); assertEquals("Invalid value for 'this'", "that", map.get("this")); assertEquals("Invalid value for ' with spaces '", " more spaces ", map.get(" with spaces ")); assertEquals("Invalid value for 'space'", " ", map.get("space")); assertTrue("Could not find entry for 'null'", map.containsKey("null")); assertNull("Invalid value for 'null'", map.get("null")); assertTrue("Could not find entry for 'nullagain'", map.containsKey("nullagain")); assertNull("Invalid value for 'nullagain'", map.get("nullagain")); assertTrue("Invalid value for 'one'", "1".equals(map.get("one")) || "won".equals(map.get("one"))); assertTrue("The map should not contain a value for 'junk'", !map.containsKey("junk")); } public void testGetSchemaFromString() { assertNull(ResourceKeyUtils.readSchemaFromString(null)); assertNull(ResourceKeyUtils.readSchemaFromString("")); assertNull(ResourceKeyUtils.readSchemaFromString("invalid string")); assertEquals("sample", ResourceKeyUtils.readSchemaFromString("sample;")); assertEquals("sample2", ResourceKeyUtils.readSchemaFromString("sample2;junk")); assertEquals("sample", ResourceKeyUtils.readSchemaFromString("resourcekey:sample;")); assertEquals("sample2", ResourceKeyUtils.readSchemaFromString("resourcekey:sample2;junk")); assertEquals("resourcekey2:sample", ResourceKeyUtils.readSchemaFromString("resourcekey2:sample;")); assertEquals("resourcekey2:sample2", ResourceKeyUtils.readSchemaFromString("resourcekey2:sample2;junk")); } } libloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/0000755000175000017500000000000011365605644025607 5ustar renerenelibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/resource/0000755000175000017500000000000011365605644027436 5ustar renerene././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/resource/TestClassloaderResourceLoader.javalibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/resource/TestClassloaderR0000644000175000017500000001411411365605644032600 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.resource; import java.io.File; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceLoader; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; public class TestClassloaderResourceLoader extends TestCase { private static final String STRING_SERIALIZATION_PREFIX = "resourcekey:"; //$NON-NLS-1$ private static final String DESERIALIZE_PREFIX = STRING_SERIALIZATION_PREFIX + ClassloaderResourceLoader.class.getName() + ';'; public TestClassloaderResourceLoader() { super(); } public TestClassloaderResourceLoader(String name) { super(name); } protected void setUp() throws Exception { super.setUp(); } public void testSerialize() throws Exception { final ResourceLoader resourceLoader = new ClassloaderResourceLoader(); final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); // Test failure - null key try { resourceLoader.serialize(null, null); fail("Serialization of a null key should throw an exception"); } catch (NullPointerException npe) { // success } // Test failure - not a Classloader resource key try { final File tempFile = File.createTempFile("junit-test", ".tmp"); final ResourceKey tempKey = manager.createKey(tempFile); resourceLoader.serialize(null, tempKey); fail("The Classloader Resource Loader should fail when handling a non-classloader resource key"); } catch(IllegalArgumentException iae) { // success } // Create key final String key1source = "res://org/pentaho/reporting/libraries/resourceloader/test1.properties"; final ResourceKey key1 = manager.createKey(key1source); assertNotNull(key1); // Serialize the key final String serKey1 = resourceLoader.serialize(null, key1); assertNotNull("The returned key should not be null", serKey1); //$NON-NLS-1$ assertTrue("Serialized verison does not start with the correct header", serKey1.startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serKey1.startsWith(DESERIALIZE_PREFIX)); assertTrue("Serialized version should contain the identifier intact", serKey1.endsWith(key1.getIdentifier().toString())); // Serialize a key created from a derived key final String key2source = "test2.properties"; final ResourceKey key2 = manager.deriveKey(key1, key2source); assertNotNull(key2); final String serKey2 = resourceLoader.serialize(null, key2); assertNotNull("The returned key should not be null", serKey2); //$NON-NLS-1$ assertTrue("Serialized verison does not start with the correct header", serKey2.startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serKey2.startsWith(DESERIALIZE_PREFIX)); assertTrue("Serialized version should contain the identifier intact", serKey2.endsWith(";res://org/pentaho/reporting/libraries/resourceloader/test2.properties")); // Serialize a key with factory parameters final Map factoryParams = new HashMap(); factoryParams.put("this", "that"); factoryParams.put("null", null); final ResourceKey key3 = manager.createKey(key1source, factoryParams); assertNotNull(key3); final String serKey3 = resourceLoader.serialize(null, key3); assertNotNull("The returned key should not be null", serKey3); //$NON-NLS-1$ assertTrue("Serialized verison does not start with the correct header", serKey3.startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serKey3.startsWith(DESERIALIZE_PREFIX)); assertTrue("Serialized version should contain the identifier intact", serKey3.indexOf(";"+key1source+";") != -1); assertTrue("Serialized version should contain 'this' parameter", serKey3.indexOf("this=that") != -1); assertTrue("Serialized version should contain 'null' parameter", serKey3.indexOf("null=:") != -1 || serKey3.endsWith("null=")); } public void testDeserializer() throws Exception { final ResourceLoader resourceLoader = new ClassloaderResourceLoader(); // Test failure - null input try { resourceLoader.deserialize(null, null); fail("Deserialize should throw an exception on null parameter"); } catch (IllegalArgumentException iae) { // success } // Test failure - invalid input try { resourceLoader.deserialize(null, "junk"); fail("Deserialize should throw an exception on bad parameter"); } catch (ResourceKeyCreationException rkce) { // success } // Test failure - wrong schema try { resourceLoader.deserialize(null, "resourcekey:org.pentaho.reporting.libraries.resourceloader.loader.resource.Junk;stuff"); fail("Deserialize should throw an exception on bad parameter"); } catch (ResourceKeyCreationException rkce) { // success } // Test successful case w/o factory parameters } } libloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/file/0000755000175000017500000000000011365605644026526 5ustar renerene././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/file/TestFileResourceLoader.javalibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/file/TestFileResourceLoad0000644000175000017500000002311211365605644032477 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader.file; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import org.pentaho.reporting.libraries.resourceloader.LibLoaderBoot; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; /** * Test cases for the FileResourceLoader class. * * @author David M. Kincade */ public class TestFileResourceLoader extends TestCase { private static final String STRING_SERIALIZATION_PREFIX = "resourcekey:"; //$NON-NLS-1$ private static final String DESERIALIZE_PREFIX = STRING_SERIALIZATION_PREFIX + FileResourceLoader.class.getName(); private static final String TEMP_FILENAME = "tmp"; //$NON-NLS-1$ private File tempFile = null; private File tempSubFile = null; private File tempSubDir = null; private String tempRelativePath = null; private String tempRelativeFilename = null; public TestFileResourceLoader() { } public TestFileResourceLoader(final String string) { super(string); } protected void setUp() throws Exception { LibLoaderBoot.getInstance().start(); setupTempFiles(); } private void setupTempFiles() { try { // Create a temporary file tempFile = File.createTempFile(TEMP_FILENAME, ".tmp"); //$NON-NLS-1$ tempFile.deleteOnExit(); // Create a temporary directory in the same directory as the temp file tempRelativePath = "." + File.separatorChar + TEMP_FILENAME; tempSubDir = new File(tempFile.getParent(), tempRelativePath); if (!tempSubDir.exists()) { tempSubDir.mkdir(); } tempSubDir.deleteOnExit(); // Create a temp file in the new subdirectory tempSubFile = File.createTempFile(TEMP_FILENAME, ".tmp", tempSubDir); //$NON-NLS-1$ tempSubFile.deleteOnExit(); tempRelativeFilename = tempRelativePath + File.separatorChar + tempSubFile.getName(); } catch (IOException ioe) { throw new RuntimeException("Could not create temp files", ioe); //$NON-NLS-1$ } } /** * Tests the serialization of File based resource keys */ public void testSerialize() throws Exception { final FileResourceLoader fileResourceLoader = new FileResourceLoader(); final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); ResourceKey key = null; Map factoryParameters = new HashMap(); String serializedVersion = null; // Test with null parameter try { serializedVersion = fileResourceLoader.serialize(null, key); fail("Serialization with a null paramter should throw a NullPointerException"); //$NON-NLS-1$ } catch (NullPointerException npe) { // success } // Test with a resource key instead of a file key try { key = manager.createKey("res://org/pentaho/reporting/libraries/resourceloader/test1.properties"); //$NON-NLS-1$ serializedVersion = fileResourceLoader.serialize(key, key); fail("The resource key should not handles by the file resource loader"); //$NON-NLS-1$ } catch (IllegalArgumentException iae) { // success } // Create a key from the temp file key = manager.createKey(tempFile); serializedVersion = fileResourceLoader.serialize(key, key); assertNotNull("The returned key should not be null", key); //$NON-NLS-1$ assertTrue("Serialized verison does not start with the correct header", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX + fileResourceLoader.getClass().getName() + ';')); assertTrue("Serialized version should contain the filename", serializedVersion.endsWith(tempFile.getName())); //$NON-NLS-1$ // Create a key as a relative path from the above key key = manager.deriveKey(key, tempRelativeFilename); assertNotNull(key); serializedVersion = fileResourceLoader.serialize(key, key); assertNotNull(serializedVersion); assertTrue("Serialized verison does not start with the correct header", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX + fileResourceLoader.getClass().getName() + ';')); assertTrue( "Serialized version should contain the filename", serializedVersion.endsWith(tempSubFile.getCanonicalPath())); //$NON-NLS-1$ // Create a key with factory parameters factoryParameters.put("this", "that"); factoryParameters.put("null", null); key = manager.createKey(tempFile, factoryParameters); serializedVersion = fileResourceLoader.serialize(key, key); assertNotNull("The returned key should not be null", key); //$NON-NLS-1$ assertTrue("Serialized verison does not start with the correct header", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX + fileResourceLoader.getClass().getName() + ';')); assertTrue( "Serialized version should contain the filename", serializedVersion.indexOf(";" + tempFile.getCanonicalPath() + ";") > -1); //$NON-NLS-1$ assertTrue("Serialized version should contain factory parameters", serializedVersion.indexOf("this=that") > -1); assertTrue("Serialized version should contain factory parameters", serializedVersion.indexOf(':') > -1); assertTrue("Serialized version should contain factory parameters", serializedVersion.endsWith("null=") || serializedVersion.contains("null=:")); } /** * Tests the deserialization of File based resource keys */ public void testDeserializer() throws Exception { final FileResourceLoader fileResourceLoader = new FileResourceLoader(); // Test deserializing invalid strings try { fileResourceLoader.deserialize(null, null); fail("deserialize of a null string should throw an exception"); } catch (IllegalArgumentException iae) { // success } try { fileResourceLoader.deserialize(null, ""); fail("deserialize of an empty string should throw an exception"); } catch (ResourceKeyCreationException rkce) { // success } try { fileResourceLoader.deserialize(null, STRING_SERIALIZATION_PREFIX + this.getClass().getName() + ';' + tempFile.getCanonicalPath()); fail("deserialize with an invalid resource class name should throw an exception"); } catch (ResourceKeyCreationException rkce) { // success } try { fileResourceLoader.deserialize(null, DESERIALIZE_PREFIX + ":/tmp"); fail("deserialize with an invalid file should thrown an exception"); } catch (ResourceKeyCreationException rkce) { // success } final ResourceKey key1 = fileResourceLoader.deserialize(null, DESERIALIZE_PREFIX + ';' + tempFile.getCanonicalPath() + ";this=that:invalid:null="); assertNotNull(key1); assertTrue(key1.getIdentifier() instanceof File); assertEquals(FileResourceLoader.class.getName(), key1.getSchema()); assertEquals(tempFile.getCanonicalPath(), ((File)key1.getIdentifier()).getCanonicalPath()); assertEquals(2, key1.getFactoryParameters().size()); assertTrue(!key1.getFactoryParameters().containsKey("invalid")); assertTrue(key1.getFactoryParameters().containsKey("null")); assertNull(key1.getFactoryParameters().get("null")); assertEquals("that", key1.getFactoryParameters().get("this")); } /** * This is a happy path "round-trip" test which should demonstrate the serializing and deserializing * a resource key should produce the same key */ public void testSerializeDeserializeRoundtrip() throws Exception { final FileResourceLoader fileResourceLoader = new FileResourceLoader(); final Map factoryParams = new HashMap(); final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); factoryParams.put("this", "that"); factoryParams.put("null", null); final ResourceKey originalKey = manager.createKey(tempFile, factoryParams); final String serializedVersion = fileResourceLoader.serialize(null, originalKey); final ResourceKey duplicateKey = fileResourceLoader.deserialize(null, serializedVersion); assertNotNull(duplicateKey); assertTrue(originalKey.equals(duplicateKey)); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/TestURLResourceLoader.javalibloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/loader/TestURLResourceLoader.jav0000644000175000017500000002031211365605644032450 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader.loader; import java.io.File; import java.net.URL; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import org.pentaho.reporting.libraries.resourceloader.LibLoaderBoot; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; import org.pentaho.reporting.libraries.resourceloader.ResourceManager; public class TestURLResourceLoader extends TestCase { private static final String STRING_SERIALIZATION_PREFIX = "resourcekey:"; //$NON-NLS-1$ private static final String DESERIALIZE_PREFIX = STRING_SERIALIZATION_PREFIX + URLResourceLoader.class.getName(); private static final String URL1 = "http://www.pentaho.com/index.html"; private static final String URL2 = "http://www.pentaho.com/images/pentaho_logo.png"; public TestURLResourceLoader() { } public TestURLResourceLoader(final String string) { super(string); } protected void setUp() throws Exception { LibLoaderBoot.getInstance().start(); } /** * Tests the serialization of File based resource keys */ public void testSerialize() throws Exception { final URLResourceLoader resourceLoader = new URLResourceLoader(); final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); ResourceKey key = null; Map factoryParameters = new HashMap(); String serializedVersion = null; // Test with null parameter try { serializedVersion = resourceLoader.serialize(null, key); fail("Serialization with a null paramter should throw a NullPointerException"); //$NON-NLS-1$ } catch (NullPointerException npe) { // success } // Test with a file instead of a URL try { final File tempFile = File.createTempFile("unittest", "test"); tempFile.deleteOnExit(); key = manager.createKey(tempFile); serializedVersion = resourceLoader.serialize(key, key); fail("The resource key should not handled by the URL resource loader"); //$NON-NLS-1$ } catch (IllegalArgumentException iae) { // success } // Create a key from the temp file key = manager.createKey(new URL(URL1)); serializedVersion = resourceLoader.serialize(key, key); assertNotNull("The returned key should not be null", key); //$NON-NLS-1$ assertTrue("Serialized verison does not start with the correct header", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX + resourceLoader.getClass().getName() + ';')); assertTrue("Serialized version should contain the filename", serializedVersion.endsWith(URL1)); //$NON-NLS-1$ // Create a key as a relative path from the above key key = manager.deriveKey(key, "images/pentaho_logo.png"); assertNotNull(key); serializedVersion = resourceLoader.serialize(key, key); assertNotNull(serializedVersion); assertTrue("Serialized verison does not start with the correct header", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX + resourceLoader.getClass().getName() + ';')); assertTrue("Serialized version should contain the filename", serializedVersion.endsWith(URL2)); //$NON-NLS-1$ // Create a key with factory parameters factoryParameters.put("this", "that"); factoryParameters.put("null", null); key = manager.createKey(new URL(URL1), factoryParameters); serializedVersion = resourceLoader.serialize(key, key); assertNotNull("The returned key should not be null", key); //$NON-NLS-1$ assertTrue("Serialized verison does not start with the correct header", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX)); assertTrue("Serialized version does not contain the correct schema information", serializedVersion //$NON-NLS-1$ .startsWith(STRING_SERIALIZATION_PREFIX + resourceLoader.getClass().getName() + ';')); assertTrue("Serialized version should contain the filename", serializedVersion.indexOf(";" + URL1 + ";") > -1); //$NON-NLS-1$ assertTrue("Serialized version should contain factory parameters", serializedVersion.indexOf("this=that") > -1); assertTrue("Serialized version should contain factory parameters", serializedVersion.indexOf(':') > -1); assertTrue("Serialized version should contain factory parameters", serializedVersion.endsWith("null=") || serializedVersion.contains("null=:")); } /** * Tests the deserialization of File based resource keys */ public void testDeserializer() throws Exception { final URLResourceLoader resourceLoader = new URLResourceLoader(); // Test deserializing invalid strings try { resourceLoader.deserialize(null, null); fail("deserialize of a null string should throw an exception"); } catch (IllegalArgumentException iae) { // success } try { resourceLoader.deserialize(null, ""); fail("deserialize of an empty string should throw an exception"); } catch (ResourceKeyCreationException rkce) { // success } try { resourceLoader.deserialize(null, STRING_SERIALIZATION_PREFIX + this.getClass().getName() + ';' + URL1); fail("deserialize with an invalid resource class name should throw an exception"); } catch (ResourceKeyCreationException rkce) { // success } try { resourceLoader.deserialize(null, DESERIALIZE_PREFIX + ":/tmp"); fail("deserialize with an invalid file should thrown an exception"); } catch (ResourceKeyCreationException rkce) { // success } final ResourceKey key1 = resourceLoader.deserialize(null, DESERIALIZE_PREFIX + ';' + URL1 + ";this=that:invalid:null="); assertNotNull(key1); assertTrue(key1.getIdentifier() instanceof URL); assertEquals(URLResourceLoader.class.getName(), key1.getSchema()); assertEquals(new URL(URL1), key1.getIdentifier()); assertEquals(2, key1.getFactoryParameters().size()); assertTrue(!key1.getFactoryParameters().containsKey("invalid")); assertTrue(key1.getFactoryParameters().containsKey("null")); assertNull(key1.getFactoryParameters().get("null")); assertEquals("that", key1.getFactoryParameters().get("this")); } /** * This is a happy path "round-trip" test which should demonstrate the serializing and deserializing * a resource key should produce the same key */ public void testSerializeDeserializeRoundtrip() throws Exception { final URLResourceLoader resourceLoader = new URLResourceLoader(); final Map factoryParams = new HashMap(); final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); factoryParams.put("this", "that"); factoryParams.put("null", null); final ResourceKey originalKey = manager.createKey(URL1, factoryParams); final String serializedVersion = resourceLoader.serialize(null, originalKey); final ResourceKey duplicateKey = resourceLoader.deserialize(null, serializedVersion); assertNotNull(duplicateKey); assertTrue(originalKey.equals(duplicateKey)); } } libloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/test2.properties0000644000175000017500000000002311365605644027513 0ustar renerene# Just a test file.libloader-1.1.6/test/org/pentaho/reporting/libraries/resourceloader/TestResourceKey.java0000644000175000017500000000712311365605644030307 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.resourceloader; import java.net.URL; import java.io.File; import java.io.IOException; import junit.framework.TestCase; /** * Todo: Document me! * * @author Thomas Morgner * @since 08.03.2007 */ public class TestResourceKey extends TestCase { public TestResourceKey() { } public TestResourceKey(final String string) { super(string); } protected void setUp() throws Exception { LibLoaderBoot.getInstance().start(); } public void testResourceKeyCreation () throws ResourceKeyCreationException { final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); final ResourceKey key = manager.createKey ("res://org/pentaho/reporting/libraries/resourceloader/test1.properties"); assertNotNull(key); final ResourceKey key1 = manager.deriveKey(key, "test2.properties"); assertNotNull(key1); } public void testURLKeyCreation () throws ResourceKeyCreationException { final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); final URL url = TestResourceKey.class.getResource ("/org/pentaho/reporting/libraries/resourceloader/test1.properties"); assertNotNull(url); final ResourceKey key = manager.createKey(url); assertNotNull(key); final ResourceKey key1 = manager.deriveKey(key, "test2.properties"); assertNotNull(key1); } public void testFileKeyCreation () throws ResourceKeyCreationException, IOException { final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); final File f1 = File.createTempFile("junit-test", ".tmp"); f1.deleteOnExit(); final File f2 = File.createTempFile("junit-test", ".tmp"); f2.deleteOnExit(); assertNotNull(f1); final ResourceKey key = manager.createKey(f1); assertNotNull(key); final ResourceKey key1 = manager.deriveKey(key, f2.getName()); assertNotNull(key1); } public void testMixedKeyDerivation () throws ResourceKeyCreationException, IOException { final File f1 = File.createTempFile("junit-test", ".tmp"); f1.deleteOnExit(); assertNotNull(f1); final URL url = TestResourceKey.class.getResource ("/org/pentaho/reporting/libraries/resourceloader/test1.properties"); assertNotNull(url); final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); final ResourceKey key = manager.createKey(f1); assertNotNull(key); final ResourceKey key2 = manager.deriveKey(key, url.toString()); assertNotNull(key2); final ResourceKey key3 = manager.createKey(url); assertNotNull(key3); final ResourceKey key4 = manager.deriveKey(key3, f1.getAbsolutePath()); assertNotNull(key4); } } libloader-1.1.6/.classpath0000644000175000017500000000146611365605644014124 0ustar renerene libloader-1.1.6/build.xml0000644000175000017500000000322011365605644013750 0ustar renerene This build file is used to create the API project and works with the common_build.xml file.