[Lutinweb-commits] r121 - in lutinrss/tags: . 2.3.8 2.3.8/src/main 2.3.8/src/main/assembly 2.3.8/src/main/java/org/codelutin/rss 2.3.8/src/site 2.3.8/src/site/fr/rst 2.3.8/src/test/java/org/codelutin/rss
Author: tchemit Date: 2008-10-09 15:17:48 +0000 (Thu, 09 Oct 2008) New Revision: 121 Added: lutinrss/tags/2.3.8/ lutinrss/tags/2.3.8/LICENSE.txt lutinrss/tags/2.3.8/README.txt lutinrss/tags/2.3.8/changelog lutinrss/tags/2.3.8/pom.xml lutinrss/tags/2.3.8/src/main/assembly/ lutinrss/tags/2.3.8/src/main/assembly/bin.xml lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/BaseServlet.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/ConfigInitializer.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedData.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedEntryComparator.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRenderer.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRendererConfig.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedType.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedURLResolver.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/Field.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLCleaner.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSConfig.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGenerator.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSHelper.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSIOUtil.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSServlet.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java lutinrss/tags/2.3.8/src/site/fr/rst/Todo.rst lutinrss/tags/2.3.8/src/site/fr/rst/index.rst lutinrss/tags/2.3.8/src/site/site.xml lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSTest.java Removed: lutinrss/tags/2.3.8/LICENSE.txt lutinrss/tags/2.3.8/pom.xml lutinrss/tags/2.3.8/src/main/assembly/bin.xml lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/BaseServlet.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/ConfigInitializer.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedData.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedEntryComparator.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRenderer.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRendererConfig.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedType.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedURLResolver.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/Field.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLCleaner.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSConfig.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGenerator.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSHelper.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSIOUtil.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSServlet.java lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java lutinrss/tags/2.3.8/src/site/fr/rst/index.rst lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSTest.java Log: [maven-release-plugin] copy for tag 2.3.8 Copied: lutinrss/tags/2.3.8 (from rev 111, lutinrss/trunk) Deleted: lutinrss/tags/2.3.8/LICENSE.txt =================================================================== --- lutinrss/trunk/LICENSE.txt 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/LICENSE.txt 2008-10-09 15:17:48 UTC (rev 121) @@ -1,280 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 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. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, 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 or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -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 give any other recipients of the Program a copy of this License -along with the Program. - -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 Program or any portion -of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -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 Program, 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 Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) 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; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, 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 executable. However, as a -special exception, the source code 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. - -If distribution of executable or 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 counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program 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. - - 5. 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 Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program 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 to -this License. - - 7. 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 Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program 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 Program. - -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. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program 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. - - 9. The Free Software Foundation may publish revised and/or new versions -of the 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 Program -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 Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, 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 - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. 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 PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS Copied: lutinrss/tags/2.3.8/LICENSE.txt (from rev 117, lutinrss/trunk/LICENSE.txt) =================================================================== --- lutinrss/tags/2.3.8/LICENSE.txt (rev 0) +++ lutinrss/tags/2.3.8/LICENSE.txt 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + 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 that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU 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 as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Copied: lutinrss/tags/2.3.8/README.txt (from rev 117, lutinrss/trunk/README.txt) =================================================================== --- lutinrss/tags/2.3.8/README.txt (rev 0) +++ lutinrss/tags/2.3.8/README.txt 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1 @@ +TODO \ No newline at end of file Copied: lutinrss/tags/2.3.8/changelog (from rev 117, lutinrss/trunk/changelog) =================================================================== --- lutinrss/tags/2.3.8/changelog (rev 0) +++ lutinrss/tags/2.3.8/changelog 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,5 @@ +ver-2.3.8 chemit 200810XX + * 20081008 [chemit] using license LGPL v3 + * 20081008 [chemit] Using lutinpluginproject 3.0 + * 20081008 [chemit] begin of site + * 20081008 [chemit] use now the groupId org.codelutin Deleted: lutinrss/tags/2.3.8/pom.xml =================================================================== --- lutinrss/trunk/pom.xml 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/pom.xml 2008-10-09 15:17:48 UTC (rev 121) @@ -1,160 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <!--The version of maven's project object model--> - <modelVersion>4.0.0</modelVersion> - - <distributionManagement> - <site> - <id>labs</id> - <url>scp://labs.libre-entreprise.org/home/groups/${pom.artifactId}/htdocs/</url> - </site> - <repository> - <id>labs</id> - <url>scp://labs.libre-entreprise.org/home/groups/lutinbuilder/htdocs/maven2</url> - </repository> - </distributionManagement> - - <!--A unique name for this project--> - <groupId>lutinlib</groupId> - <artifactId>lutinrss</artifactId> - <name>LutinRSS</name> - - <!--ejb, jar, war...--> - <packaging>war</packaging> - - <!--Version--> - <version>2.3.7</version> - - <!--Description--> - <description>Servlet pouvant etre appeler depuis du JS pour recuperer un - flux RSS - </description> - <inceptionYear>2008</inceptionYear> - - <!--Tracking--> - <issueManagement> - <url>http://labs.libre-entreprise.org/tracker/?group_id=41</url> - </issueManagement> - - <!--Librairies--> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.1.1</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.2.1</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>jdom</groupId> - <artifactId>jdom</artifactId> - <version>1.0</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>rome</groupId> - <artifactId>rome</artifactId> - <version>0.9</version> - <scope>compile</scope> - </dependency> - - <!--Provided--> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>${maven.compile.source}</source> - <target>${maven.compile.target}</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <phase>verify</phase> - <goals> - <goal>jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <executions> - <execution> - <phase>verify</phase> - <goals> - <goal>jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-war-plugin</artifactId> - <configuration> - <!--warName>lutinrss</warName--> - <webappDirectory>target/lutinrss</webappDirectory> - </configuration> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>project</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <properties> - <maven.compile.source>1.5</maven.compile.source> - <maven.compile.target>1.5</maven.compile.target> - </properties> - <!--pluginRepositories> - <pluginRepository> - <id>codelutin-plugins</id> - <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url> - </pluginRepository> - </pluginRepositories--> - </profile> - </profiles> -</project> Copied: lutinrss/tags/2.3.8/pom.xml (from rev 120, lutinrss/trunk/pom.xml) =================================================================== --- lutinrss/tags/2.3.8/pom.xml (rev 0) +++ lutinrss/tags/2.3.8/pom.xml 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,160 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + <parent> + <groupId>org.codelutin</groupId> + <artifactId>lutinproject</artifactId> + <version>3.0</version> + </parent> + + <artifactId>lutinrss</artifactId> + + <dependencies> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>jdom</groupId> + <artifactId>jdom</artifactId> + <version>1.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>rome</groupId> + <artifactId>rome</artifactId> + <version>0.9</version> + <scope>compile</scope> + </dependency> + + <!--Provided--> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + <name>LutinRSS</name> + <version>2.3.8</version> + <description>Servlet pouvant etre appeler depuis du JS pour recuperer un + flux RSS + </description> + <inceptionYear>2008</inceptionYear> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + <packaging>war</packaging> + + <properties> + <!-- id du projet du labs --> + <labs.id>41</labs.id> + + <!-- nom du projet sur le labs --> + <labs.project>lutinweb</labs.project> + + </properties> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <link>http://java.sun.com/javase/6/docs/api/index.html</link> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <configuration> + <outputDirectory>${project.build.directory}/lib</outputDirectory> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <classpathPrefix>lib/</classpathPrefix> + </manifest> + </archive> + </configuration> + <executions> + <execution> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <!--warName>lutinrss</warName--> + <webappDirectory>target/lutinrss</webappDirectory> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.2-beta-2</version> + <configuration> + <descriptors> + <descriptor>src/main/assembly/bin.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <phase>verify</phase> + <goals> + <goal>attached</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> + + <!-- ************************************************************* --> + <!-- *** Build Environment ************************************** --> + <!-- ************************************************************* --> + <scm> + <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinweb/lutinrss/tags/2.3.8</connection> + <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/lutinweb/lutinrss/tags/2.3.8</developerConnection> + <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinrss/tags/2.3.8?root=lutinweb</url> + </scm> + +</project> \ No newline at end of file Copied: lutinrss/tags/2.3.8/src/main/assembly (from rev 117, lutinrss/trunk/src/main/assembly) Deleted: lutinrss/tags/2.3.8/src/main/assembly/bin.xml =================================================================== --- lutinrss/trunk/src/main/assembly/bin.xml 2008-10-09 14:49:45 UTC (rev 117) +++ lutinrss/tags/2.3.8/src/main/assembly/bin.xml 2008-10-09 15:17:48 UTC (rev 121) @@ -1,60 +0,0 @@ -<assembly> - <id>bin</id> - <formats> - <format>zip</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <!--dependencySets> - <dependencySet> - <outputDirectory>lib</outputDirectory> - <includes> - <include>*:jar:*</include> - </includes> - <scope>runtime</scope> - </dependencySet> - </dependencySets--> - - <fileSets> - - <fileSet> - <directory>target/lib</directory> - <outputDirectory>lib</outputDirectory> - <includes> - <include>*.jar</include> - </includes> - </fileSet> - - <fileSet> - <directory>target</directory> - <outputDirectory>/</outputDirectory> - <includes> - <include>*.?ar</include> - </includes> - </fileSet> - <fileSet> - <includes> - <include>README.txt</include> - <include>LICENSE.txt</include> - </includes> - </fileSet> - <fileSet> - <directory>target/classes</directory> - <outputDirectory>/</outputDirectory> - <includes> - <include>THIRD-PARTY.txt</include> - </includes> - </fileSet> - - <!--fileSet> - <directory>src/main/assembly</directory> - <filtered>true</filtered> - <outputDirectory>/</outputDirectory> - <fileMode>0755</fileMode> - <includes> - <include>go.sh</include> - <include>go.bat</include> - </includes> - </fileSet--> - - </fileSets> -</assembly> \ No newline at end of file Copied: lutinrss/tags/2.3.8/src/main/assembly/bin.xml (from rev 119, lutinrss/trunk/src/main/assembly/bin.xml) =================================================================== --- lutinrss/tags/2.3.8/src/main/assembly/bin.xml (rev 0) +++ lutinrss/tags/2.3.8/src/main/assembly/bin.xml 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,39 @@ +<assembly> + <id>bin</id> + <formats> + <format>zip</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <dependencySets> + <dependencySet> + <outputDirectory>lib</outputDirectory> + <includes> + <include>*:jar:*</include> + </includes> + <scope>runtime</scope> + </dependencySet> + </dependencySets> + + <fileSets> + <fileSet> + <directory>target</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>*.?ar</include> + </includes> + </fileSet> + <fileSet> + <includes> + <include>README.txt</include> + <include>LICENSE.txt</include> + </includes> + </fileSet> + <fileSet> + <directory>target/classes</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>THIRD-PARTY.txt</include> + </includes> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/BaseServlet.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/BaseServlet.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/BaseServlet.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,112 +0,0 @@ -package org.codelutin.rss; - -import java.io.*; - -import javax.servlet.*; -import javax.servlet.http.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * <p> - * Servlet de base - * @param D la classe de l'object de delegation - * - * @author chemit - */ -public abstract class BaseServlet<D> extends HttpServlet { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - protected static final Log log = LogFactory.getLog(BaseServlet.class); - /** L'objet de delegation du metier de la servlet */ - protected transient D delegate; - private static final long serialVersionUID = 1L; - - /** - * - * @return the new delegate object to be used by servlet - * @throws java.lang.Exception if any problem while instanciation - */ - protected abstract D newDelegate() throws Exception; - - /** - * - * @return a new ConfigInitializer to be used in - * {@link #init(javax.servlet.ServletConfig, boolean)} method to prepare - * default config. - */ - protected abstract ConfigInitializer<ServletConfig,? > newConfigInitializer(); - - /** - * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. - * @param request servlet request - * @param response servlet response - * @throws java.io.IOException TODO - * @throws ServletException TODO - */ - protected abstract void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; - - @Override - public void init(ServletConfig config) throws ServletException { - init(config, true); - } - - protected void init(ServletConfig config, boolean initConfig) throws ServletException { - try { - super.init(config); - if (initConfig) { - // init de la configuration par defaut depuis la config de servlet - newConfigInitializer().init(config); - } - // instanciate delegate - delegate = newDelegate(); - } catch (Exception eee) { - log.warn("Can't configure Servlet", eee); - if (eee instanceof ServletException) { - throw (ServletException) eee; - } - throw new ServletException("Can't configure Servlet", eee); - } - } - - protected Integer convertToInt(String parameter) { - Integer result = null; - try { - result = Integer.parseInt(parameter); - } catch (Exception eee) { - log.debug("Can't convert to int: '" + parameter + "'", eee); - } - return result; - } - // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> - /** - * Handles the HTTP <code>GET</code> method. - * @param request servlet request - * @param response servlet response - */ - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - processRequest(request, response); - } - - /** - * Handles the HTTP <code>POST</code> method. - * @param request servlet request - * @param response servlet response - */ - @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - processRequest(request, response); - } - - /** - * Returns a short description of the servlet. - */ - @Override - public String getServletInfo() { - return "RSS Servlet"; - } - // </editor-fold> -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/BaseServlet.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/BaseServlet.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/BaseServlet.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/BaseServlet.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,130 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.codelutin.rss; + +import java.io.*; + +import javax.servlet.*; +import javax.servlet.http.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * <p> + * Servlet de base + * @param D la classe de l'object de delegation + * + * @author chemit + */ +public abstract class BaseServlet<D> extends HttpServlet { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + protected static final Log log = LogFactory.getLog(BaseServlet.class); + /** L'objet de delegation du metier de la servlet */ + protected transient D delegate; + private static final long serialVersionUID = 1L; + + /** + * + * @return the new delegate object to be used by servlet + * @throws java.lang.Exception if any problem while instanciation + */ + protected abstract D newDelegate() throws Exception; + + /** + * + * @return a new ConfigInitializer to be used in + * {@link #init(javax.servlet.ServletConfig, boolean)} method to prepare + * default config. + */ + protected abstract ConfigInitializer<ServletConfig,? > newConfigInitializer(); + + /** + * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. + * @param request servlet request + * @param response servlet response + * @throws java.io.IOException TODO + * @throws ServletException TODO + */ + protected abstract void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; + + @Override + public void init(ServletConfig config) throws ServletException { + init(config, true); + } + + protected void init(ServletConfig config, boolean initConfig) throws ServletException { + try { + super.init(config); + if (initConfig) { + // init de la configuration par defaut depuis la config de servlet + newConfigInitializer().init(config); + } + // instanciate delegate + delegate = newDelegate(); + } catch (Exception eee) { + log.warn("Can't configure Servlet", eee); + if (eee instanceof ServletException) { + throw (ServletException) eee; + } + throw new ServletException("Can't configure Servlet", eee); + } + } + + protected Integer convertToInt(String parameter) { + Integer result = null; + try { + result = Integer.parseInt(parameter); + } catch (Exception eee) { + log.debug("Can't convert to int: '" + parameter + "'", eee); + } + return result; + } + // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> + /** + * Handles the HTTP <code>GET</code> method. + * @param request servlet request + * @param response servlet response + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP <code>POST</code> method. + * @param request servlet request + * @param response servlet response + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + */ + @Override + public String getServletInfo() { + return "RSS Servlet"; + } + // </editor-fold> +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/ConfigInitializer.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/ConfigInitializer.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/ConfigInitializer.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,60 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.codelutin.rss; - -import org.apache.commons.beanutils.BeanUtils; - -/** - * - * @author tony - * - * @param S la classe source de la configuration - * @param T la classe destination de la configuration - */ -public abstract class ConfigInitializer<S,D> { - - - /** - * - * @param config l'object source contenant les configs - * @param fullConfigName le nom complet de la propriete recherchee - * @return la valeur de la propriete ou null si non trouve - */ - protected abstract String getConfigValue(S config, String fullConfigName); - - public abstract void init(S config) ; - - /** - * Initialise RSSConfig. - * @param klass la class de la configuration de destination - * @param config la configuration source - */ - public void init(String prefix,Class<D> klass, S config, String... keys) { - try { - String prefixConfig = getConfigValue(config, prefix); - prefixConfig = prefixConfig == null ? "" : prefixConfig.trim(); - - D instance = klass.newInstance(); - for (String key : keys) { - loadConfig(config, instance, prefixConfig, key); - } - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } - } - - protected void loadConfig(S config, D instance, String prefix, String configName) { - String value = getConfigValue(config, prefix + configName); - if (value != null && !"".equals(value)) { - try { - BeanUtils.setProperty(instance, configName, value); - } catch (Exception ex) { - throw new IllegalStateException("could not load property " + configName + " from config " + config + " for reason : " + ex.getMessage()); - } - } - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/ConfigInitializer.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/ConfigInitializer.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/ConfigInitializer.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/ConfigInitializer.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,78 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.codelutin.rss; + +import org.apache.commons.beanutils.BeanUtils; + +/** + * + * @author tony + * + * @param S la classe source de la configuration + * @param T la classe destination de la configuration + */ +public abstract class ConfigInitializer<S,D> { + + + /** + * + * @param config l'object source contenant les configs + * @param fullConfigName le nom complet de la propriete recherchee + * @return la valeur de la propriete ou null si non trouve + */ + protected abstract String getConfigValue(S config, String fullConfigName); + + public abstract void init(S config) ; + + /** + * Initialise RSSConfig. + * @param klass la class de la configuration de destination + * @param config la configuration source + */ + public void init(String prefix,Class<D> klass, S config, String... keys) { + try { + String prefixConfig = getConfigValue(config, prefix); + prefixConfig = prefixConfig == null ? "" : prefixConfig.trim(); + + D instance = klass.newInstance(); + for (String key : keys) { + loadConfig(config, instance, prefixConfig, key); + } + } catch (InstantiationException ex) { + throw new RuntimeException(ex); + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + + protected void loadConfig(S config, D instance, String prefix, String configName) { + String value = getConfigValue(config, prefix + configName); + if (value != null && !"".equals(value)) { + try { + BeanUtils.setProperty(instance, configName, value); + } catch (Exception ex) { + throw new IllegalStateException("could not load property " + configName + " from config " + config + " for reason : " + ex.getMessage()); + } + } + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedData.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/FeedData.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedData.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,95 +0,0 @@ -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndFeed; -import java.net.URL; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * <p> - * Represente une URL demandee. Cette objet est conserve durant le temps de vie - * de la JVM pour permettre de mutualiser la recuperation et la transformation en - * HTML. - * </p> - * <p> - * Lorsque l'on demande le HTML et que l'url n'a pas encore ete recuperee ou - * est trop ancienne alors on lance la recuperation. Si deux threads demandent - * la recuperation, le deuxieme est mis en attente et profitera de la recuperation - * de l'autre. - * </p> - * - * @author poussin - */ -public class FeedData { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static final Log log = LogFactory.getLog(FeedData.class); - - /** url du feed */ - protected URL url = null; - /** les champs que l'on souhaite visualiser pour le feed */ - protected FeedRendererConfig rendererConfig = null; - /** Le nombre d'item que l'on souhaite visualiser pour le feed */ - protected int nbItem = -1; - - protected SyndFeed feed = null; - protected long lastRetrived = 0; - - public FeedData(URL url, int nbItem, String representation) { - this(url); - this.nbItem = nbItem; - this.rendererConfig = new FeedRendererConfig(representation); - } - - public FeedData(URL url) { - this.url = url; - } - - public long getLastRetrived() { - return lastRetrived; - } - - public URL getUrl() { - return url; - } - - public FeedRendererConfig getRendererConfig() { - return rendererConfig; - } - - public void setRendererConfig(FeedRendererConfig rendererConfig) { - this.rendererConfig = rendererConfig; - } - - public int getNbItem() { - return nbItem; - } - - public void setNbItem(int nbItem) { - this.nbItem = nbItem; - } - - /** - * Retourne la representation HTML du RSS - * - * @return la representation HTML du RSS - */ - public SyndFeed getFeed() { - if (feed == null || lastRetrived + RSSConfig.TIME_FORCE_RETRIEVED < System.currentTimeMillis()) { - forceRetrived(); - } - - return feed; - } - - synchronized protected void forceRetrived() { - if (lastRetrived + RSSConfig.TIME_FORCE_RETRIEVED < System.currentTimeMillis()) { - try { - feed = RSSIOUtil.readFeed(url); - lastRetrived = System.currentTimeMillis(); - } catch (Exception eee) { - log.warn("Can't get feed: " + url, eee); - } - } - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedData.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/FeedData.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedData.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedData.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,113 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndFeed; +import java.net.URL; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * <p> + * Represente une URL demandee. Cette objet est conserve durant le temps de vie + * de la JVM pour permettre de mutualiser la recuperation et la transformation en + * HTML. + * </p> + * <p> + * Lorsque l'on demande le HTML et que l'url n'a pas encore ete recuperee ou + * est trop ancienne alors on lance la recuperation. Si deux threads demandent + * la recuperation, le deuxieme est mis en attente et profitera de la recuperation + * de l'autre. + * </p> + * + * @author poussin + */ +public class FeedData { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static final Log log = LogFactory.getLog(FeedData.class); + + /** url du feed */ + protected URL url = null; + /** les champs que l'on souhaite visualiser pour le feed */ + protected FeedRendererConfig rendererConfig = null; + /** Le nombre d'item que l'on souhaite visualiser pour le feed */ + protected int nbItem = -1; + + protected SyndFeed feed = null; + protected long lastRetrived = 0; + + public FeedData(URL url, int nbItem, String representation) { + this(url); + this.nbItem = nbItem; + this.rendererConfig = new FeedRendererConfig(representation); + } + + public FeedData(URL url) { + this.url = url; + } + + public long getLastRetrived() { + return lastRetrived; + } + + public URL getUrl() { + return url; + } + + public FeedRendererConfig getRendererConfig() { + return rendererConfig; + } + + public void setRendererConfig(FeedRendererConfig rendererConfig) { + this.rendererConfig = rendererConfig; + } + + public int getNbItem() { + return nbItem; + } + + public void setNbItem(int nbItem) { + this.nbItem = nbItem; + } + + /** + * Retourne la representation HTML du RSS + * + * @return la representation HTML du RSS + */ + public SyndFeed getFeed() { + if (feed == null || lastRetrived + RSSConfig.TIME_FORCE_RETRIEVED < System.currentTimeMillis()) { + forceRetrived(); + } + + return feed; + } + + synchronized protected void forceRetrived() { + if (lastRetrived + RSSConfig.TIME_FORCE_RETRIEVED < System.currentTimeMillis()) { + try { + feed = RSSIOUtil.readFeed(url); + lastRetrived = System.currentTimeMillis(); + } catch (Exception eee) { + log.warn("Can't get feed: " + url, eee); + } + } + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedEntryComparator.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/FeedEntryComparator.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedEntryComparator.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,20 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndEntry; -import java.util.Comparator; - -/** - * Comparator of entry base on his publication date - * @author tony - */ -public class FeedEntryComparator implements Comparator<SyndEntry> { - - public int compare(SyndEntry o1, SyndEntry o2) { - return o1.getPublishedDate().compareTo(o2.getPublishedDate()); - } - -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedEntryComparator.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/FeedEntryComparator.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedEntryComparator.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedEntryComparator.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,38 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndEntry; +import java.util.Comparator; + +/** + * Comparator of entry base on his publication date + * @author tony + */ +public class FeedEntryComparator implements Comparator<SyndEntry> { + + public int compare(SyndEntry o1, SyndEntry o2) { + return o1.getPublishedDate().compareTo(o2.getPublishedDate()); + } + +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,216 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; -import java.util.EnumMap; -import java.util.HashSet; -import java.util.Set; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author poussin - */ -public class FeedHTMLRenderer implements FeedRenderer { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static final Log log = LogFactory.getLog(FeedHTMLRenderer.class); - - private static final String FEED_CSS_PREFIX ="feed-"; - private static final String FEED_ITEM_CSS_PREFIX ="feedItem-"; - - /** tous les HTMLCleaner a utiliser pour nettoyer les chaines */ - protected Set<HTMLCleaner> cleaners = new HashSet<HTMLCleaner>(); - - protected EnumMap<Field, String> templates = new EnumMap<Field, String>(Field.class); - protected EnumMap<Field, String> classnames = new EnumMap<Field, String>(Field.class); - protected EnumMap<Field, String> feedProperties = new EnumMap<Field, String>(Field.class); - protected EnumMap<Field, String> itemProperties = new EnumMap<Field, String>(Field.class); - - /** - * - * @param cleaners La liste des cleaners a utiliser par defaut. Si aucun - * cleaner n'est passer en argument HTMLScriptCleaner est automatiquement - * ajoute - */ - public FeedHTMLRenderer(HTMLCleaner ... cleaners) { - if (cleaners.length == 0) { - addHTMLCleaner(new HTMLScriptCleaner()); - } - for (HTMLCleaner cleaner : cleaners) { - addHTMLCleaner(cleaner); - } - - templates.put(Field.NAME, "<span class=\"%1$s\">%2$s</span>\n"); - templates.put(Field.LINK, "<a class=\"%1$s\" href=\"%2$s\">%3$s</a>"); - templates.put(Field.IMAGE, "<span class=\"%1$s\"><img src=\"%2$s\"/></span>\n"); - templates.put(Field.DESCRIPTION, "<span class=\"%1$s\">%2$s</span>\n"); - templates.put(Field.AUTHOR, "<span class=\"%1$s\">%2$s</span>\n"); - //Probleme de conversion FIXME - templates.put(Field.TIME, "<span class=\"%1$s\">%2$s</span>\n"); - //templates.put(Field.TIME, "<span class=\"%1$s\">%2$tF</span>\n"); - - classnames.put(Field.NAME, "name"); - classnames.put(Field.LINK, "link"); - classnames.put(Field.IMAGE, "image"); - classnames.put(Field.DESCRIPTION, "description"); - classnames.put(Field.AUTHOR, "author"); - classnames.put(Field.TIME, "time"); - - feedProperties.put(Field.NAME, "title"); - feedProperties.put(Field.LINK, "link"); - // cela engendre des NPE... - feedProperties.put(Field.IMAGE, "image.url"); - feedProperties.put(Field.DESCRIPTION, "description"); - feedProperties.put(Field.AUTHOR, "author"); - feedProperties.put(Field.TIME, "publishedDate"); - - itemProperties.put(Field.NAME, "title"); - itemProperties.put(Field.LINK, "link"); - itemProperties.put(Field.IMAGE, null); - itemProperties.put(Field.DESCRIPTION, "description.value"); - itemProperties.put(Field.AUTHOR, "author"); - itemProperties.put(Field.TIME, "publishedDate"); - } - - - public FeedHTMLRenderer() { - this(new HTMLCleaner[0]); - } - - /** - * Supprime tous les cleaners de code html - */ - public void clearCleaners() { - this.cleaners.clear(); - } - - /** - * Ajoute un nouveau cleaner de code HTML - * @param cleaner cleaner to add - */ - public void addHTMLCleaner(HTMLCleaner cleaner) { - cleaners.add(cleaner); - } - - public String render(FeedRendererConfig config, SyndFeed feed, SyndEntry[] items) { - - StringBuffer sbGlobal= new StringBuffer(); - - StringBuffer sbTemp= new StringBuffer(); - for (Field f : config.getFeedFieldOrder()) { - renderField(f, FEED_CSS_PREFIX,feedProperties, feed,sbTemp); - } - - String tmp = sbTemp.toString(); - if (!"".equals(tmp)) { - sbGlobal.append("<div class='rss-feed'>\n").append(tmp).append("</div>\n"); - } - sbGlobal.append("<ul class='rss-items'>\n"); - sbTemp = new StringBuffer(); - for (SyndEntry item : items) { - sbTemp.append( "<li>\n"); - for (Field f : config.getItemFieldOrder()) { - renderField(f, FEED_ITEM_CSS_PREFIX,itemProperties,item,sbTemp); - } - sbTemp.append("</li>\n"); - } - sbGlobal.append(sbTemp.toString()).append("</ul>\n"); - - return sbGlobal.toString(); - } - - protected void renderField(Field f, String cssPrefix, EnumMap<Field, String> properties,Object src,StringBuffer buffer) { - - if (f== Field.LINK) { - // do nothing, link should not be called alone but inside name field only - return; - } - String template = templates.get(f); - String classname = cssPrefix + classnames.get(f); - String prop = properties.get(f); - - if ("".equals(prop)) { - return; - } - - String result; - Object value = null; - try { - - value = BeanUtils.getProperty(src, prop); - if (f == Field.NAME) { - //special case, we must first render link - String templateLink = templates.get(Field.LINK); - String classnameLink = "feed-" + classnames.get(Field.LINK); - String propLink = properties.get(Field.LINK); - Object value2 = BeanUtils.getProperty(src, propLink); - value = render(templateLink, classnameLink, value2, value); - } - - result = render(template, classname, value); - - if (result != null && buffer != null) { - buffer.append(result); - } - } catch (Exception eee) { - log.warn("Can't get feed property value for property " + prop + ", value:" + value); - } - - } - - /** - * Permet de rendre un element du feed - * - * @param template le template pour rendre l'element - * @param classname la class de l'element html (pour une utilisation CSS) - * @param value la valeur de l'element - * @return le code HTML - */ - protected String render(String template, String classname, Object value) { - StringBuffer sb = new StringBuffer(); - if (value != null && !"".equals(value)) { - if (value instanceof String) { - // si value est une chaine, on la nettoie avec les cleaners enregistrer - for (HTMLCleaner cleaner : cleaners) { - value = cleaner.clean((String)value); - } - } - sb.append(renderTemplate(template, classname, value)); - } - return sb.toString(); - } - - protected String render(String template, String classname, Object value,Object value2) { - StringBuffer sb = new StringBuffer(); - if (value != null && !"".equals(value)) { - if (value instanceof String) { - // si value est une chaine, on la nettoie avec les cleaners enregistrer - for (HTMLCleaner cleaner : cleaners) { - value = cleaner.clean((String)value); - } - } - sb.append(renderTemplate(template, classname, value,value2)); - } - return sb.toString(); - } - - protected String renderTemplate(String template,Object... args) { - try { - String result; - result = String.format(template, args); - return result; - } catch (Exception e) { - log.warn("could not format template "+template+" with args : "+java.util.Arrays.toString(args)); - return ""; - } - } - -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,234 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.Set; +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author poussin + */ +public class FeedHTMLRenderer implements FeedRenderer { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static final Log log = LogFactory.getLog(FeedHTMLRenderer.class); + + private static final String FEED_CSS_PREFIX ="feed-"; + private static final String FEED_ITEM_CSS_PREFIX ="feedItem-"; + + /** tous les HTMLCleaner a utiliser pour nettoyer les chaines */ + protected Set<HTMLCleaner> cleaners = new HashSet<HTMLCleaner>(); + + protected EnumMap<Field, String> templates = new EnumMap<Field, String>(Field.class); + protected EnumMap<Field, String> classnames = new EnumMap<Field, String>(Field.class); + protected EnumMap<Field, String> feedProperties = new EnumMap<Field, String>(Field.class); + protected EnumMap<Field, String> itemProperties = new EnumMap<Field, String>(Field.class); + + /** + * + * @param cleaners La liste des cleaners a utiliser par defaut. Si aucun + * cleaner n'est passer en argument HTMLScriptCleaner est automatiquement + * ajoute + */ + public FeedHTMLRenderer(HTMLCleaner ... cleaners) { + if (cleaners.length == 0) { + addHTMLCleaner(new HTMLScriptCleaner()); + } + for (HTMLCleaner cleaner : cleaners) { + addHTMLCleaner(cleaner); + } + + templates.put(Field.NAME, "<span class=\"%1$s\">%2$s</span>\n"); + templates.put(Field.LINK, "<a class=\"%1$s\" href=\"%2$s\">%3$s</a>"); + templates.put(Field.IMAGE, "<span class=\"%1$s\"><img src=\"%2$s\"/></span>\n"); + templates.put(Field.DESCRIPTION, "<span class=\"%1$s\">%2$s</span>\n"); + templates.put(Field.AUTHOR, "<span class=\"%1$s\">%2$s</span>\n"); + //Probleme de conversion FIXME + templates.put(Field.TIME, "<span class=\"%1$s\">%2$s</span>\n"); + //templates.put(Field.TIME, "<span class=\"%1$s\">%2$tF</span>\n"); + + classnames.put(Field.NAME, "name"); + classnames.put(Field.LINK, "link"); + classnames.put(Field.IMAGE, "image"); + classnames.put(Field.DESCRIPTION, "description"); + classnames.put(Field.AUTHOR, "author"); + classnames.put(Field.TIME, "time"); + + feedProperties.put(Field.NAME, "title"); + feedProperties.put(Field.LINK, "link"); + // cela engendre des NPE... + feedProperties.put(Field.IMAGE, "image.url"); + feedProperties.put(Field.DESCRIPTION, "description"); + feedProperties.put(Field.AUTHOR, "author"); + feedProperties.put(Field.TIME, "publishedDate"); + + itemProperties.put(Field.NAME, "title"); + itemProperties.put(Field.LINK, "link"); + itemProperties.put(Field.IMAGE, null); + itemProperties.put(Field.DESCRIPTION, "description.value"); + itemProperties.put(Field.AUTHOR, "author"); + itemProperties.put(Field.TIME, "publishedDate"); + } + + + public FeedHTMLRenderer() { + this(new HTMLCleaner[0]); + } + + /** + * Supprime tous les cleaners de code html + */ + public void clearCleaners() { + this.cleaners.clear(); + } + + /** + * Ajoute un nouveau cleaner de code HTML + * @param cleaner cleaner to add + */ + public void addHTMLCleaner(HTMLCleaner cleaner) { + cleaners.add(cleaner); + } + + public String render(FeedRendererConfig config, SyndFeed feed, SyndEntry[] items) { + + StringBuffer sbGlobal= new StringBuffer(); + + StringBuffer sbTemp= new StringBuffer(); + for (Field f : config.getFeedFieldOrder()) { + renderField(f, FEED_CSS_PREFIX,feedProperties, feed,sbTemp); + } + + String tmp = sbTemp.toString(); + if (!"".equals(tmp)) { + sbGlobal.append("<div class='rss-feed'>\n").append(tmp).append("</div>\n"); + } + sbGlobal.append("<ul class='rss-items'>\n"); + sbTemp = new StringBuffer(); + for (SyndEntry item : items) { + sbTemp.append( "<li>\n"); + for (Field f : config.getItemFieldOrder()) { + renderField(f, FEED_ITEM_CSS_PREFIX,itemProperties,item,sbTemp); + } + sbTemp.append("</li>\n"); + } + sbGlobal.append(sbTemp.toString()).append("</ul>\n"); + + return sbGlobal.toString(); + } + + protected void renderField(Field f, String cssPrefix, EnumMap<Field, String> properties,Object src,StringBuffer buffer) { + + if (f== Field.LINK) { + // do nothing, link should not be called alone but inside name field only + return; + } + String template = templates.get(f); + String classname = cssPrefix + classnames.get(f); + String prop = properties.get(f); + + if ("".equals(prop)) { + return; + } + + String result; + Object value = null; + try { + + value = BeanUtils.getProperty(src, prop); + if (f == Field.NAME) { + //special case, we must first render link + String templateLink = templates.get(Field.LINK); + String classnameLink = "feed-" + classnames.get(Field.LINK); + String propLink = properties.get(Field.LINK); + Object value2 = BeanUtils.getProperty(src, propLink); + value = render(templateLink, classnameLink, value2, value); + } + + result = render(template, classname, value); + + if (result != null && buffer != null) { + buffer.append(result); + } + } catch (Exception eee) { + log.warn("Can't get feed property value for property " + prop + ", value:" + value); + } + + } + + /** + * Permet de rendre un element du feed + * + * @param template le template pour rendre l'element + * @param classname la class de l'element html (pour une utilisation CSS) + * @param value la valeur de l'element + * @return le code HTML + */ + protected String render(String template, String classname, Object value) { + StringBuffer sb = new StringBuffer(); + if (value != null && !"".equals(value)) { + if (value instanceof String) { + // si value est une chaine, on la nettoie avec les cleaners enregistrer + for (HTMLCleaner cleaner : cleaners) { + value = cleaner.clean((String)value); + } + } + sb.append(renderTemplate(template, classname, value)); + } + return sb.toString(); + } + + protected String render(String template, String classname, Object value,Object value2) { + StringBuffer sb = new StringBuffer(); + if (value != null && !"".equals(value)) { + if (value instanceof String) { + // si value est une chaine, on la nettoie avec les cleaners enregistrer + for (HTMLCleaner cleaner : cleaners) { + value = cleaner.clean((String)value); + } + } + sb.append(renderTemplate(template, classname, value,value2)); + } + return sb.toString(); + } + + protected String renderTemplate(String template,Object... args) { + try { + String result; + result = String.format(template, args); + return result; + } catch (Exception e) { + log.warn("could not format template "+template+" with args : "+java.util.Arrays.toString(args)); + return ""; + } + } + +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRenderer.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/FeedRenderer.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRenderer.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,26 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; - -/** - * - * @author poussin - */ -public interface FeedRenderer { - - /** - * Retourne une chaine qui est la representation du feed et de ces items - * - * @param config la configuration a utiliser pour rendre le feed - * @param feed le feed a representer - * @param items la liste des items du feed a prendre en compte - * @return la representation souhaitee - */ - public String render(FeedRendererConfig config, SyndFeed feed, SyndEntry [] items); -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRenderer.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/FeedRenderer.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRenderer.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRenderer.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,44 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; + +/** + * + * @author poussin + */ +public interface FeedRenderer { + + /** + * Retourne une chaine qui est la representation du feed et de ces items + * + * @param config la configuration a utiliser pour rendre le feed + * @param feed le feed a representer + * @param items la liste des items du feed a prendre en compte + * @return la representation souhaitee + */ + public String render(FeedRendererConfig config, SyndFeed feed, SyndEntry [] items); +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRendererConfig.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/FeedRendererConfig.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRendererConfig.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,101 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import java.util.ArrayList; -import java.util.List; - -/** - * <p> - * Permet de spcecifier les champs a rendre, cet objet peut etre converti - * en une representation chaine pour etre facilement transportable. - * </p> - * <p> - * Exemple de representation texte: ndat-ndat. Le premier block represente le - * feed le second les items. S'il n'y a qu'un block cela veut dire qu'il ne - * faut pas reprensenter le feed mais seulement les items. L'ordre des lettres - * determine l'ordre du rendu. - * <li>n: name pour demander le nom ou titre du feed ou de l'item - * <li>i: image - * <li>d: description - * <li>a: author - * <li>t: time pour demander la date du feed ou de l'item - * </p> - * - * @author poussin - */ -public class FeedRendererConfig { - - protected String feedString = "indat"; - protected List<Field> feedList = null; - protected String itemString = "indat"; - protected List<Field> itemList = null; - - public FeedRendererConfig() { - } - - public FeedRendererConfig(String representation) { - setString(representation); - } - - protected List<Field> createList(String value) { - List<Field> result = new ArrayList<Field>(); - for (char c : value.toCharArray()) { - Field field = Field.valueOf(c); - if (field!=null) { - result.add(field); - } - } - return result; - } - - public List<Field> getFeedFieldOrder() { - if (feedList == null) { - feedList = createList(feedString); - } - return feedList; - } - - public List<Field> getItemFieldOrder() { - if (itemList == null) { - itemList = createList(itemString); - } - return itemList; - } - - /** - * Permet de modifier la representation souhaitee - * - * @param f la nouvelle representation par ex: n-na - */ - public void setString(String f) { - String [] fi = f.split("-"); - if (fi.length > 1) { - feedString = fi[0]; - itemString = fi[1]; - } else { - feedString = ""; - itemString = fi[0]; - } - feedList = null; - itemList = null; - } - - /** - * Permet de retourner la representation string - * - * @return par ex: n-nad - */ - public String getString() { - String result = ""; - if (!"".equals(feedString)) { - result = feedString + "-"; - } - result += itemString; - return result; - } - -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRendererConfig.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/FeedRendererConfig.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRendererConfig.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedRendererConfig.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,119 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import java.util.ArrayList; +import java.util.List; + +/** + * <p> + * Permet de spcecifier les champs a rendre, cet objet peut etre converti + * en une representation chaine pour etre facilement transportable. + * </p> + * <p> + * Exemple de representation texte: ndat-ndat. Le premier block represente le + * feed le second les items. S'il n'y a qu'un block cela veut dire qu'il ne + * faut pas reprensenter le feed mais seulement les items. L'ordre des lettres + * determine l'ordre du rendu. + * <li>n: name pour demander le nom ou titre du feed ou de l'item + * <li>i: image + * <li>d: description + * <li>a: author + * <li>t: time pour demander la date du feed ou de l'item + * </p> + * + * @author poussin + */ +public class FeedRendererConfig { + + protected String feedString = "indat"; + protected List<Field> feedList = null; + protected String itemString = "indat"; + protected List<Field> itemList = null; + + public FeedRendererConfig() { + } + + public FeedRendererConfig(String representation) { + setString(representation); + } + + protected List<Field> createList(String value) { + List<Field> result = new ArrayList<Field>(); + for (char c : value.toCharArray()) { + Field field = Field.valueOf(c); + if (field!=null) { + result.add(field); + } + } + return result; + } + + public List<Field> getFeedFieldOrder() { + if (feedList == null) { + feedList = createList(feedString); + } + return feedList; + } + + public List<Field> getItemFieldOrder() { + if (itemList == null) { + itemList = createList(itemString); + } + return itemList; + } + + /** + * Permet de modifier la representation souhaitee + * + * @param f la nouvelle representation par ex: n-na + */ + public void setString(String f) { + String [] fi = f.split("-"); + if (fi.length > 1) { + feedString = fi[0]; + itemString = fi[1]; + } else { + feedString = ""; + itemString = fi[0]; + } + feedList = null; + itemList = null; + } + + /** + * Permet de retourner la representation string + * + * @return par ex: n-nad + */ + public String getString() { + String result = ""; + if (!"".equals(feedString)) { + result = feedString + "-"; + } + result += itemString; + return result; + } + +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedType.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/FeedType.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedType.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,33 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.codelutin.rss; - -/** - * Enumeration of known feed's type. - * - * Used to generate some feed files. - * - * @author tony - */ -public enum FeedType { - - RSS_0_90("rss_0.90"), - RSS_0_91("rss_0.91"), - RSS_0_92("rss_0.92"), - RSS_0_93("rss_0.93"), - RSS_1_0("rss_1.0"), - RSS_2_0("rss_2.0"), - ATOM_0_3("atom_0.3"), - ATOM_1_0("atom_1.0"); - private String type; - - public String getType() { - return type; - } - - private FeedType(String type) { - this.type = type; - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedType.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/FeedType.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedType.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedType.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,51 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.codelutin.rss; + +/** + * Enumeration of known feed's type. + * + * Used to generate some feed files. + * + * @author tony + */ +public enum FeedType { + + RSS_0_90("rss_0.90"), + RSS_0_91("rss_0.91"), + RSS_0_92("rss_0.92"), + RSS_0_93("rss_0.93"), + RSS_1_0("rss_1.0"), + RSS_2_0("rss_2.0"), + ATOM_0_3("atom_0.3"), + ATOM_1_0("atom_1.0"); + private String type; + + public String getType() { + return type; + } + + private FeedType(String type) { + this.type = type; + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedURLResolver.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/FeedURLResolver.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedURLResolver.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,21 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * Permet de convertir une chaine en une URL. Le resolver le plus simple - * peut créer une URL avec la chaine, mais un autre resolver peut utiliser - * cette chaine comme cle dans une base de données pour recuperer la bonne URL. - * - * @author poussin - */ -public interface FeedURLResolver { - - public FeedData resolv(String ask) throws MalformedURLException; -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedURLResolver.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/FeedURLResolver.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedURLResolver.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/FeedURLResolver.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,39 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * Permet de convertir une chaine en une URL. Le resolver le plus simple + * peut créer une URL avec la chaine, mais un autre resolver peut utiliser + * cette chaine comme cle dans une base de données pour recuperer la bonne URL. + * + * @author poussin + */ +public interface FeedURLResolver { + + public FeedData resolv(String ask) throws MalformedURLException; +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/Field.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/Field.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/Field.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,45 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -/** - * Enumeration des champs disponibles pour le renderer - * - * @author poussin - */ -public enum Field { - - NAME('n'), IMAGE('i'), DESCRIPTION('d'), AUTHOR('a'), TIME('t'),LINK('l'),CATEGORY('c'); - - /** le caractere utilise pour la version compactee d'une configuration de renderer */ - private char c; - - Field(char c) { - this.c= c; - } - - public char getC() { - return c; - } - - public static Field valueOf(char c) { - for (Field field : values()) { - if (field.c==c){ - return field; - } - } - return null; - } - - public static Field[] getFeedFields() { - return new Field[]{NAME,IMAGE,DESCRIPTION,AUTHOR,TIME,LINK}; - } - - public static Field[] getItemFields() { - return new Field[]{NAME,DESCRIPTION,AUTHOR,TIME,LINK}; - } -} - Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/Field.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/Field.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/Field.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/Field.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,63 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +/** + * Enumeration des champs disponibles pour le renderer + * + * @author poussin + */ +public enum Field { + + NAME('n'), IMAGE('i'), DESCRIPTION('d'), AUTHOR('a'), TIME('t'),LINK('l'),CATEGORY('c'); + + /** le caractere utilise pour la version compactee d'une configuration de renderer */ + private char c; + + Field(char c) { + this.c= c; + } + + public char getC() { + return c; + } + + public static Field valueOf(char c) { + for (Field field : values()) { + if (field.c==c){ + return field; + } + } + return null; + } + + public static Field[] getFeedFields() { + return new Field[]{NAME,IMAGE,DESCRIPTION,AUTHOR,TIME,LINK}; + } + + public static Field[] getItemFields() { + return new Field[]{NAME,DESCRIPTION,AUTHOR,TIME,LINK}; + } +} + Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLCleaner.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/HTMLCleaner.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLCleaner.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,17 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -/** - * Permet de nettoyer une chaine avant incorporation dans du HTML - * - * @author poussin - */ -public interface HTMLCleaner { - - public String clean(String s); - -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLCleaner.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/HTMLCleaner.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLCleaner.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLCleaner.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,35 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +/** + * Permet de nettoyer une chaine avant incorporation dans du HTML + * + * @author poussin + */ +public interface HTMLCleaner { + + public String clean(String s); + +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,22 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import java.util.regex.Pattern; - -/** - * Supprime les balises <script.*</script> de la chaine - * - * @author poussin - */ -public class HTMLScriptCleaner implements HTMLCleaner { - - public String clean(String s) { - String result = s.replaceAll("(?i)(?s)<script.*?</script>", ""); - return result; - } - -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,40 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import java.util.regex.Pattern; + +/** + * Supprime les balises <script.*</script> de la chaine + * + * @author poussin + */ +public class HTMLScriptCleaner implements HTMLCleaner { + + public String clean(String s) { + String result = s.replaceAll("(?i)(?s)<script.*?</script>", ""); + return result; + } + +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSConfig.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/RSSConfig.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSConfig.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,63 +0,0 @@ -package org.codelutin.rss; - -/** - * Default configuration for {@link RSSHelper}. - * - * @author poussin - */ -public class RSSConfig { - - /** - * la propriete de configuration qui definit le prefix a jouter pour scruter la configuration - */ - private static final String CONFIGURATION_PREFIX_PROPERTY = RSSServlet.class.getSimpleName() + "_configuration_prefix"; - - - /** Temps a partir duquel on reforce une recuperation */ - public static long TIME_FORCE_RETRIEVED = 5 * 60 * 1000; - public static FeedRendererConfig DEFAULT_RENDERER_CONFIG = new FeedRendererConfig("n-natd"); - public static int DEFAULT_NB_ITEM = 7; - public static Class<? extends FeedRenderer> DEFAULT_RENDERER_CLASS = FeedHTMLRenderer.class; - public static Class<? extends FeedURLResolver> DEFAULT_RESOLVER_CLASS = SimpleFeedURLResolver.class; - - public void setTIME_FORCE_RETRIEVED(long TIME_FORCE_RETRIEVED) { - RSSConfig.TIME_FORCE_RETRIEVED = TIME_FORCE_RETRIEVED; - } - - public void setDEFAULT_RENDERER_CONFIG(String DEFAULT_RENDERER_CONFIG) { - RSSConfig.DEFAULT_RENDERER_CONFIG = new FeedRendererConfig(DEFAULT_RENDERER_CONFIG); - } - - public void setDEFAULT_NBITEM(int DEFAULT_NBITEM) { - RSSConfig.DEFAULT_NB_ITEM = DEFAULT_NBITEM; - } - - public void setDEFAULT_RENDERER_CLASS(Class<? extends FeedRenderer> DEFAULT_RENDERER_CLASS) { - RSSConfig.DEFAULT_RENDERER_CLASS = DEFAULT_RENDERER_CLASS; - } - - public void setDEFAULT_RESOLVER_CLASS(Class<? extends FeedURLResolver> DEFAULT_RESOLVER_CLASS) { - RSSConfig.DEFAULT_RESOLVER_CLASS = DEFAULT_RESOLVER_CLASS; - } - - /** - * - * @param S la classe source de la configuration - */ - public static abstract class RSSConfigInitializer<S> extends ConfigInitializer<S,RSSConfig > { - - /** - * Initialise RSSConfig. - * @param config la configuration source - */ - public void init(S config) { - RSSHelper.log.info("with source "+config); - super.init(CONFIGURATION_PREFIX_PROPERTY,RSSConfig.class, config, - "TIME_FORCE_RETRIEVED", - "DEFAULT_RENDERER_CONFIG", - "DEFAULT_NB_ITEM", - "DEFAULT_RENDERER_CLASS", - "DEFAULT_RESOLVER_CLASS"); - } - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSConfig.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/RSSConfig.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSConfig.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSConfig.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,81 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.codelutin.rss; + +/** + * Default configuration for {@link RSSHelper}. + * + * @author poussin + */ +public class RSSConfig { + + /** + * la propriete de configuration qui definit le prefix a jouter pour scruter la configuration + */ + private static final String CONFIGURATION_PREFIX_PROPERTY = RSSServlet.class.getSimpleName() + "_configuration_prefix"; + + + /** Temps a partir duquel on reforce une recuperation */ + public static long TIME_FORCE_RETRIEVED = 5 * 60 * 1000; + public static FeedRendererConfig DEFAULT_RENDERER_CONFIG = new FeedRendererConfig("n-natd"); + public static int DEFAULT_NB_ITEM = 7; + public static Class<? extends FeedRenderer> DEFAULT_RENDERER_CLASS = FeedHTMLRenderer.class; + public static Class<? extends FeedURLResolver> DEFAULT_RESOLVER_CLASS = SimpleFeedURLResolver.class; + + public void setTIME_FORCE_RETRIEVED(long TIME_FORCE_RETRIEVED) { + RSSConfig.TIME_FORCE_RETRIEVED = TIME_FORCE_RETRIEVED; + } + + public void setDEFAULT_RENDERER_CONFIG(String DEFAULT_RENDERER_CONFIG) { + RSSConfig.DEFAULT_RENDERER_CONFIG = new FeedRendererConfig(DEFAULT_RENDERER_CONFIG); + } + + public void setDEFAULT_NBITEM(int DEFAULT_NBITEM) { + RSSConfig.DEFAULT_NB_ITEM = DEFAULT_NBITEM; + } + + public void setDEFAULT_RENDERER_CLASS(Class<? extends FeedRenderer> DEFAULT_RENDERER_CLASS) { + RSSConfig.DEFAULT_RENDERER_CLASS = DEFAULT_RENDERER_CLASS; + } + + public void setDEFAULT_RESOLVER_CLASS(Class<? extends FeedURLResolver> DEFAULT_RESOLVER_CLASS) { + RSSConfig.DEFAULT_RESOLVER_CLASS = DEFAULT_RESOLVER_CLASS; + } + + /** + * + * @param S la classe source de la configuration + */ + public static abstract class RSSConfigInitializer<S> extends ConfigInitializer<S,RSSConfig > { + + /** + * Initialise RSSConfig. + * @param config la configuration source + */ + public void init(S config) { + RSSHelper.log.info("with source "+config); + super.init(CONFIGURATION_PREFIX_PROPERTY,RSSConfig.class, config, + "TIME_FORCE_RETRIEVED", + "DEFAULT_RENDERER_CONFIG", + "DEFAULT_NB_ITEM", + "DEFAULT_RENDERER_CLASS", + "DEFAULT_RESOLVER_CLASS"); + } + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGenerator.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/RSSGenerator.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGenerator.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,311 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.io.FeedException; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * generator of rss feeds to be stored in a file - * @author tony - */ -public class RSSGenerator { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static final Log log = LogFactory.getLog(RSSGenerator.class); - /** date formater use to save date in feed and entries */ - public static final DateFormat DATE_PARSER = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); - - /** - * - * @return une nouvelle instance de RssHelper en utilisant les implantations - * definies dans RSSGeneratorConfig. - * @throws java.lang.Exception pour tout pb lors de l'instanciation des objects - */ - public static RSSGenerator newDefaultInstance() throws Exception { - RSSGenerator helper = new RSSGenerator(); - return helper; - } - - - /** dictonnary of field <-> property for feed */ - protected final EnumMap<Field, String> feedProperties; - /** dictonnary of field <-> property for entry */ - protected final EnumMap<Field, String> itemProperties; - /** directory where feeds are stored */ - protected final File generatorDirectory; - /** feed format to use **/ - protected final FeedType format; - /** number of feed to use by default */ - protected final int nbItems; - - protected RSSGenerator() { - this(null); - } - - protected RSSGenerator(EnumMap<Field, String> feedProperties, EnumMap<Field, String> itemProperties, File generatorDirectory,FeedType format,int nbItems) { - this.feedProperties = feedProperties; - this.itemProperties = itemProperties; - this.generatorDirectory = generatorDirectory; - this.format=format; - this.nbItems=nbItems; - } - - protected RSSGenerator(File generatorDirectory) { - - feedProperties = new EnumMap<Field, String>(Field.class); - feedProperties.put(Field.NAME, "title"); - feedProperties.put(Field.LINK, "link"); - // cela engendre des NPE... - feedProperties.put(Field.IMAGE, "image.url"); - feedProperties.put(Field.DESCRIPTION, "description"); - feedProperties.put(Field.AUTHOR, "author"); - feedProperties.put(Field.TIME, "publishedDate"); - feedProperties.put(Field.CATEGORY, "categories"); - - itemProperties = new EnumMap<Field, String>(Field.class); - itemProperties.put(Field.NAME, "title"); - itemProperties.put(Field.LINK, "link"); - itemProperties.put(Field.IMAGE, null); - itemProperties.put(Field.DESCRIPTION, "description.value"); - itemProperties.put(Field.AUTHOR, "author"); - itemProperties.put(Field.TIME, "publishedDate"); - - this.generatorDirectory = generatorDirectory==null?new File(RSSGeneratorConfig.GENERATOR_DIRECTORY):generatorDirectory; - this.format=FeedType.valueOf(RSSGeneratorConfig.DEFAULT_GENERATOR_FORMAT); - this.nbItems = RSSGeneratorConfig.DEFAULT_GENERATOR_NB_ITEM; - } - - /** - * - * @param url location where to create the file - * @param type fromat of feed to create - * @param values properties of the feed - * @throws ParseException if pb while parsing date - * @throws IOException if io pb - * @throws FeedException if pb while creating feed - */ - public void createFeedFile(URL url, FeedType type, Map<Field, Object> values) throws IOException, FeedException, ParseException { - if (url == null) { - throw new NullPointerException("can not create a feed with null url"); - } - if (type == null) { - throw new NullPointerException("can not create a feed with null feedtype"); - } - if (values == null || values.isEmpty()) { - //TODO Should check mandatory values (title, link,...) - throw new NullPointerException("can not create a feed with null nor empty values dictonnary"); - } - File f = getFile(url); - - if (f.exists()) { - throw new IllegalStateException("feed already existing in " + f.getName()); - } - - // make sure parent exists - f.getParentFile().mkdirs(); - - // block until can acquire lock - FileLock lock = acquireLock(f); - - try { - - SyndFeed feed = RSSIOUtil.createFeed(feedProperties, type, values); - - RSSIOUtil.saveFeed(f, feed); - - } catch (FeedException e) { - // file must not be created - f.delete(); - throw e; - } catch (ParseException e) { - // file must not be created - f.delete(); - throw e; - } finally { - releaseLock(f, lock); - } - } - - /** - * Add a item to an existing feed file. - * - * @param url location of feed to used - * @param nbEntries number of maximum entries to be written in feed file - * @param values dictionnary of properties to write - * @throws FeedException if feed pb - * @throws IOException if io pb - * @throws ParseException if dateparser pb - */ - public void addItemToFeedFile(URL url, int nbEntries, Map<Field, Object> values) throws IOException, FeedException, ParseException { - if (url == null) { - throw new NullPointerException("can not add a feed's entry with null url"); - } - if (values == null || values.isEmpty()) { - //TODO Should check mandatory values (title, link,...) - throw new NullPointerException("can not add a feed's entry with null nor empty values dictonnary"); - } - File f = getFile(url); - - if (!f.exists()) { - throw new FileNotFoundException("file not existing " + f); - } - - // block until can acquire lock - FileLock lock = acquireLock(f); - - try { - // get feed - SyndFeed feed = RSSIOUtil.readFeed(url); - - // create item - SyndEntry item = RSSIOUtil.createFeedItem(itemProperties, values); - - // add item - feed = RSSIOUtil.addItemToFeed(feed, item, nbEntries, values); - - // save feed into a tmp file - File tmpFile = new File(f.getAbsolutePath() + "-tmp_" + System.nanoTime()); - - RSSIOUtil.saveFeed(tmpFile, feed); - - // move tmpFile to real file - tmpFile.renameTo(f); - } finally { - releaseLock(f, lock); - } - } - - public void deleteFeedFile(URL toURL) { - File f = getFile(toURL); - if (f.exists() && !f.delete()) { - throw new IllegalStateException("could not delete feed " + f.getName()); - } - } -/** - * - * @param url - * @param values - * @return the set of modified fields. - * @throws java.io.IOException - * @throws com.sun.syndication.io.FeedException - * @throws java.text.ParseException - */ - public EnumSet<Field> updateFeedFile(URL url,Map<Field,Object> values) throws IOException, FeedException, ParseException { - if (url == null) { - throw new NullPointerException("can not add a feed's entry with null url"); - } - if (values == null || values.isEmpty()) { - //TODO Should check mandatory values (title, link,...) - throw new NullPointerException("can not add a feed's entry with null nor empty values dictonnary"); - } - File f = getFile(url); - - if (!f.exists()) { - throw new FileNotFoundException("file not existing " + f); - } - - // block until can acquire lock - FileLock lock = acquireLock(f); - - try { - - SyndFeed feed =RSSIOUtil.readFeed(url); - - // update feed and keep trace of modified fields - EnumSet<Field> modifieds = RSSIOUtil.updateFeed(feed,feedProperties, values); - - // save feed into a tmp file - File tmpFile = new File(f.getAbsolutePath() + "-tmp_" + System.nanoTime()); - - RSSIOUtil.saveFeed(tmpFile, feed); - - // move tmpFile to real file - tmpFile.renameTo(f); - - // feed link has changed - return modifieds; - } finally { - releaseLock(f, lock); - } - } - - public FeedType getFormat() { - return format; - } - - public File getFeedFile(String name) { - return new File(getGeneratorDirectory(),name+".xml"); - } - - public int getNbItems() { - return nbItems; - } - - /** - * Obtain the file from his url location. - * - * @param url location of the file - * @return the file - * @throws java.lang.IllegalStateException if uri is not sytax valid - */ - protected File getFile(URL url) throws IllegalStateException { - try { - return new File(url.toURI()); - } catch (URISyntaxException e) { - throw new IllegalStateException("could not obtain file from url " + url, e); - } - } - - protected FileLock acquireLock(File f) throws IOException { - File lockFile = getWriteFileLock(f); - - /*if (!lockFile.exists()) lockFile.createNewFile(); */ - // open file for writing only - FileChannel channel = new RandomAccessFile(lockFile, "rw").getChannel(); - - // block until can acquire lock - - return channel.lock(); - } - - protected File getWriteFileLock(File f) { - return new File(f.getParentFile(), f.getName() + ".wlock"); - } - - protected void releaseLock(File f, FileLock lock) throws IOException { - // release lock - lock.release(); - // close channel - lock.channel().close(); - // delete file lock - File lockFile = getWriteFileLock(f); - // delete lock file - lockFile.delete(); - } - - public File getGeneratorDirectory() { - return generatorDirectory; - } - -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGenerator.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/RSSGenerator.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGenerator.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGenerator.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,329 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * generator of rss feeds to be stored in a file + * @author tony + */ +public class RSSGenerator { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static final Log log = LogFactory.getLog(RSSGenerator.class); + /** date formater use to save date in feed and entries */ + public static final DateFormat DATE_PARSER = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); + + /** + * + * @return une nouvelle instance de RssHelper en utilisant les implantations + * definies dans RSSGeneratorConfig. + * @throws java.lang.Exception pour tout pb lors de l'instanciation des objects + */ + public static RSSGenerator newDefaultInstance() throws Exception { + RSSGenerator helper = new RSSGenerator(); + return helper; + } + + + /** dictonnary of field <-> property for feed */ + protected final EnumMap<Field, String> feedProperties; + /** dictonnary of field <-> property for entry */ + protected final EnumMap<Field, String> itemProperties; + /** directory where feeds are stored */ + protected final File generatorDirectory; + /** feed format to use **/ + protected final FeedType format; + /** number of feed to use by default */ + protected final int nbItems; + + protected RSSGenerator() { + this(null); + } + + protected RSSGenerator(EnumMap<Field, String> feedProperties, EnumMap<Field, String> itemProperties, File generatorDirectory,FeedType format,int nbItems) { + this.feedProperties = feedProperties; + this.itemProperties = itemProperties; + this.generatorDirectory = generatorDirectory; + this.format=format; + this.nbItems=nbItems; + } + + protected RSSGenerator(File generatorDirectory) { + + feedProperties = new EnumMap<Field, String>(Field.class); + feedProperties.put(Field.NAME, "title"); + feedProperties.put(Field.LINK, "link"); + // cela engendre des NPE... + feedProperties.put(Field.IMAGE, "image.url"); + feedProperties.put(Field.DESCRIPTION, "description"); + feedProperties.put(Field.AUTHOR, "author"); + feedProperties.put(Field.TIME, "publishedDate"); + feedProperties.put(Field.CATEGORY, "categories"); + + itemProperties = new EnumMap<Field, String>(Field.class); + itemProperties.put(Field.NAME, "title"); + itemProperties.put(Field.LINK, "link"); + itemProperties.put(Field.IMAGE, null); + itemProperties.put(Field.DESCRIPTION, "description.value"); + itemProperties.put(Field.AUTHOR, "author"); + itemProperties.put(Field.TIME, "publishedDate"); + + this.generatorDirectory = generatorDirectory==null?new File(RSSGeneratorConfig.GENERATOR_DIRECTORY):generatorDirectory; + this.format=FeedType.valueOf(RSSGeneratorConfig.DEFAULT_GENERATOR_FORMAT); + this.nbItems = RSSGeneratorConfig.DEFAULT_GENERATOR_NB_ITEM; + } + + /** + * + * @param url location where to create the file + * @param type fromat of feed to create + * @param values properties of the feed + * @throws ParseException if pb while parsing date + * @throws IOException if io pb + * @throws FeedException if pb while creating feed + */ + public void createFeedFile(URL url, FeedType type, Map<Field, Object> values) throws IOException, FeedException, ParseException { + if (url == null) { + throw new NullPointerException("can not create a feed with null url"); + } + if (type == null) { + throw new NullPointerException("can not create a feed with null feedtype"); + } + if (values == null || values.isEmpty()) { + //TODO Should check mandatory values (title, link,...) + throw new NullPointerException("can not create a feed with null nor empty values dictonnary"); + } + File f = getFile(url); + + if (f.exists()) { + throw new IllegalStateException("feed already existing in " + f.getName()); + } + + // make sure parent exists + f.getParentFile().mkdirs(); + + // block until can acquire lock + FileLock lock = acquireLock(f); + + try { + + SyndFeed feed = RSSIOUtil.createFeed(feedProperties, type, values); + + RSSIOUtil.saveFeed(f, feed); + + } catch (FeedException e) { + // file must not be created + f.delete(); + throw e; + } catch (ParseException e) { + // file must not be created + f.delete(); + throw e; + } finally { + releaseLock(f, lock); + } + } + + /** + * Add a item to an existing feed file. + * + * @param url location of feed to used + * @param nbEntries number of maximum entries to be written in feed file + * @param values dictionnary of properties to write + * @throws FeedException if feed pb + * @throws IOException if io pb + * @throws ParseException if dateparser pb + */ + public void addItemToFeedFile(URL url, int nbEntries, Map<Field, Object> values) throws IOException, FeedException, ParseException { + if (url == null) { + throw new NullPointerException("can not add a feed's entry with null url"); + } + if (values == null || values.isEmpty()) { + //TODO Should check mandatory values (title, link,...) + throw new NullPointerException("can not add a feed's entry with null nor empty values dictonnary"); + } + File f = getFile(url); + + if (!f.exists()) { + throw new FileNotFoundException("file not existing " + f); + } + + // block until can acquire lock + FileLock lock = acquireLock(f); + + try { + // get feed + SyndFeed feed = RSSIOUtil.readFeed(url); + + // create item + SyndEntry item = RSSIOUtil.createFeedItem(itemProperties, values); + + // add item + feed = RSSIOUtil.addItemToFeed(feed, item, nbEntries, values); + + // save feed into a tmp file + File tmpFile = new File(f.getAbsolutePath() + "-tmp_" + System.nanoTime()); + + RSSIOUtil.saveFeed(tmpFile, feed); + + // move tmpFile to real file + tmpFile.renameTo(f); + } finally { + releaseLock(f, lock); + } + } + + public void deleteFeedFile(URL toURL) { + File f = getFile(toURL); + if (f.exists() && !f.delete()) { + throw new IllegalStateException("could not delete feed " + f.getName()); + } + } +/** + * + * @param url + * @param values + * @return the set of modified fields. + * @throws java.io.IOException + * @throws com.sun.syndication.io.FeedException + * @throws java.text.ParseException + */ + public EnumSet<Field> updateFeedFile(URL url,Map<Field,Object> values) throws IOException, FeedException, ParseException { + if (url == null) { + throw new NullPointerException("can not add a feed's entry with null url"); + } + if (values == null || values.isEmpty()) { + //TODO Should check mandatory values (title, link,...) + throw new NullPointerException("can not add a feed's entry with null nor empty values dictonnary"); + } + File f = getFile(url); + + if (!f.exists()) { + throw new FileNotFoundException("file not existing " + f); + } + + // block until can acquire lock + FileLock lock = acquireLock(f); + + try { + + SyndFeed feed =RSSIOUtil.readFeed(url); + + // update feed and keep trace of modified fields + EnumSet<Field> modifieds = RSSIOUtil.updateFeed(feed,feedProperties, values); + + // save feed into a tmp file + File tmpFile = new File(f.getAbsolutePath() + "-tmp_" + System.nanoTime()); + + RSSIOUtil.saveFeed(tmpFile, feed); + + // move tmpFile to real file + tmpFile.renameTo(f); + + // feed link has changed + return modifieds; + } finally { + releaseLock(f, lock); + } + } + + public FeedType getFormat() { + return format; + } + + public File getFeedFile(String name) { + return new File(getGeneratorDirectory(),name+".xml"); + } + + public int getNbItems() { + return nbItems; + } + + /** + * Obtain the file from his url location. + * + * @param url location of the file + * @return the file + * @throws java.lang.IllegalStateException if uri is not sytax valid + */ + protected File getFile(URL url) throws IllegalStateException { + try { + return new File(url.toURI()); + } catch (URISyntaxException e) { + throw new IllegalStateException("could not obtain file from url " + url, e); + } + } + + protected FileLock acquireLock(File f) throws IOException { + File lockFile = getWriteFileLock(f); + + /*if (!lockFile.exists()) lockFile.createNewFile(); */ + // open file for writing only + FileChannel channel = new RandomAccessFile(lockFile, "rw").getChannel(); + + // block until can acquire lock + + return channel.lock(); + } + + protected File getWriteFileLock(File f) { + return new File(f.getParentFile(), f.getName() + ".wlock"); + } + + protected void releaseLock(File f, FileLock lock) throws IOException { + // release lock + lock.release(); + // close channel + lock.channel().close(); + // delete file lock + File lockFile = getWriteFileLock(f); + // delete lock file + lockFile.delete(); + } + + public File getGeneratorDirectory() { + return generatorDirectory; + } + +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,63 +0,0 @@ -package org.codelutin.rss; - -/** - * - * Default Configuration for {@link RSSGenerator}. - * - * @author chemit - */ -public class RSSGeneratorConfig { - - /** - * la propriete de configuration qui definit le prefix a jouter pour scruter la configuration - */ - private static final String CONFIGURATION_PREFIX_PROPERTY = RSSGeneratorServlet.class.getSimpleName() + "_configuration_prefix"; - /** nombre d'items max à ecrire dans le fichier du flux */ - public static int DEFAULT_GENERATOR_NB_ITEM = 100; - /** le format par défaut duflux à générer */ - public static String DEFAULT_GENERATOR_FORMAT = "RSS_2_0"; - /** le répertoire où générer les flux */ - public static String GENERATOR_DIRECTORY = "/tmp/rssinclude"; - /** le caractère séparateur des listes de métas (categorie par exemple) */ - public static String DEFAULT_LIST_SEPARATOR = ";"; - - public void setDEFAULT_GENERATOR_NB_ITEM(int DEFAULT_GENERATOR_NB_ITEM) { - RSSGeneratorConfig.DEFAULT_GENERATOR_NB_ITEM = DEFAULT_GENERATOR_NB_ITEM; - } - - public void setDEFAULT_GENERATOR_FORMAT(String DEFAULT_GENERATOR_FORMAT) { - RSSGeneratorConfig.DEFAULT_GENERATOR_FORMAT = DEFAULT_GENERATOR_FORMAT; - } - - public void setGENERATOR_DIRECTORY(String GENERATOR_DIRECTORY) { - RSSGeneratorConfig.GENERATOR_DIRECTORY = GENERATOR_DIRECTORY; - } - - public void setDEFAULT_LIST_SEPARATOR(String DEFAULT_LIST_SEPARATOR) { - RSSGeneratorConfig.DEFAULT_LIST_SEPARATOR = DEFAULT_LIST_SEPARATOR; - } - /** - * - * @param S la classe source de la configuration - */ - public static abstract class RssGeneratorConfigInitializer<S> extends ConfigInitializer<S,RSSGeneratorConfig> { - - /** - * Initialise RSSGeneratorConfig. - * @param config la configuration source - */ - public void init(S config) { - RSSGenerator.log.info("with source "+config); - - super.init(CONFIGURATION_PREFIX_PROPERTY,RSSGeneratorConfig.class, config, - "DEFAULT_GENERATOR_NB_ITEM", - "DEFAULT_GENERATOR_FORMAT", - "DEFAULT_LIST_SEPARATOR", - "GENERATOR_DIRECTORY"); - - // create delegate directory - new java.io.File(GENERATOR_DIRECTORY).mkdirs(); - - } - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorConfig.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,81 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.codelutin.rss; + +/** + * + * Default Configuration for {@link RSSGenerator}. + * + * @author chemit + */ +public class RSSGeneratorConfig { + + /** + * la propriete de configuration qui definit le prefix a jouter pour scruter la configuration + */ + private static final String CONFIGURATION_PREFIX_PROPERTY = RSSGeneratorServlet.class.getSimpleName() + "_configuration_prefix"; + /** nombre d'items max à ecrire dans le fichier du flux */ + public static int DEFAULT_GENERATOR_NB_ITEM = 100; + /** le format par défaut duflux à générer */ + public static String DEFAULT_GENERATOR_FORMAT = "RSS_2_0"; + /** le répertoire où générer les flux */ + public static String GENERATOR_DIRECTORY = "/tmp/rssinclude"; + /** le caractère séparateur des listes de métas (categorie par exemple) */ + public static String DEFAULT_LIST_SEPARATOR = ";"; + + public void setDEFAULT_GENERATOR_NB_ITEM(int DEFAULT_GENERATOR_NB_ITEM) { + RSSGeneratorConfig.DEFAULT_GENERATOR_NB_ITEM = DEFAULT_GENERATOR_NB_ITEM; + } + + public void setDEFAULT_GENERATOR_FORMAT(String DEFAULT_GENERATOR_FORMAT) { + RSSGeneratorConfig.DEFAULT_GENERATOR_FORMAT = DEFAULT_GENERATOR_FORMAT; + } + + public void setGENERATOR_DIRECTORY(String GENERATOR_DIRECTORY) { + RSSGeneratorConfig.GENERATOR_DIRECTORY = GENERATOR_DIRECTORY; + } + + public void setDEFAULT_LIST_SEPARATOR(String DEFAULT_LIST_SEPARATOR) { + RSSGeneratorConfig.DEFAULT_LIST_SEPARATOR = DEFAULT_LIST_SEPARATOR; + } + /** + * + * @param S la classe source de la configuration + */ + public static abstract class RssGeneratorConfigInitializer<S> extends ConfigInitializer<S,RSSGeneratorConfig> { + + /** + * Initialise RSSGeneratorConfig. + * @param config la configuration source + */ + public void init(S config) { + RSSGenerator.log.info("with source "+config); + + super.init(CONFIGURATION_PREFIX_PROPERTY,RSSGeneratorConfig.class, config, + "DEFAULT_GENERATOR_NB_ITEM", + "DEFAULT_GENERATOR_FORMAT", + "DEFAULT_LIST_SEPARATOR", + "GENERATOR_DIRECTORY"); + + // create delegate directory + new java.io.File(GENERATOR_DIRECTORY).mkdirs(); + + } + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,219 +0,0 @@ -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.io.FeedException; -import java.io.*; - -import java.util.HashMap; -import java.util.Map; -import javax.servlet.*; -import javax.servlet.http.*; - -/** - * <p> - * Servlet permettant de generer des flux generes par RSSGenerator et de - * les publier. - * - * @author chemit - */ -public class RSSGeneratorServlet extends BaseServlet<RSSGenerator> { - - private static final long serialVersionUID = 1L; - - public void doCreateFeed(HttpServletRequest request, HttpServletResponse response, String feedName, File file) throws ServletException, IOException { - String type = request.getParameter("feedType"); - FeedType feedType = null; - if (type != null) { - try { - feedType = FeedType.valueOf(type); - } catch (Exception e) { - feedType = null; - } - } - if (feedType == null) { - feedType = delegate.getFormat(); - } - String description = request.getParameter("feedDescription"); - String link = request.getParameter("feedLink"); - String author = request.getParameter("feedAuthor"); - String categories = request.getParameter("feedCategories"); - Map<Field, Object> values = new HashMap<Field, Object>(); - values.put(Field.NAME, feedName); - addFieldValue(Field.DESCRIPTION, description, values); - addFieldValue(Field.LINK, link, values); - addFieldValue(Field.AUTHOR, author, values); - addFieldValue(Field.CATEGORY, categories, values); - values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); - try { - delegate.createFeedFile(file.toURI().toURL(), feedType, values); - } catch (Exception ex) { - throw new ServletException(ex); - } - - String redirect = request.getParameter("from"); - if (redirect != null) { - response.sendRedirect(redirect); - } - } - - public void doDeleteFeed(HttpServletRequest request, HttpServletResponse response, String feedName, File file) throws ServletException, IOException { - try { - delegate.deleteFeedFile(file.toURI().toURL()); - } catch (Exception ex) { - throw new ServletException(ex); - } - - String redirect = request.getParameter("from"); - if (redirect != null) { - response.sendRedirect(redirect); - } - } - - public void doAddItem(HttpServletRequest request, HttpServletResponse response, String feedName, File file) throws ServletException, IOException { - - Integer nbItems = convertToInt(request.getParameter("nbItems")); - if (nbItems == null) { - nbItems = RSSGeneratorConfig.DEFAULT_GENERATOR_NB_ITEM; - } - String description = request.getParameter("itemDescription"); - String link = request.getParameter("itemLink"); - String author = request.getParameter("itemAuthor"); - String name = request.getParameter("itemName"); - - Map<Field, Object> values = new HashMap<Field, Object>(); - addFieldValue(Field.NAME, name, values); - addFieldValue(Field.DESCRIPTION, description, values); - addFieldValue(Field.LINK, link, values); - addFieldValue(Field.AUTHOR, author, values); - values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); - try { - delegate.addItemToFeedFile(file.toURI().toURL(), nbItems, values); - } catch (Exception ex) { - throw new ServletException(ex); - } - - String redirect = request.getParameter("from"); - if (redirect != null) { - response.sendRedirect(redirect); - } - } - - public void doList(HttpServletResponse response) throws IOException { - // obtain the list of known feeds - File[] files = delegate.getGeneratorDirectory().listFiles(new FileFilter() { - - public boolean accept(File pathname) { - return pathname.isFile() && pathname.getName().endsWith(".xml"); - } - }); - response.setContentType("text/xml;charset=UTF-8"); - PrintWriter out = response.getWriter(); - - try { - if (files.length > 0) { - String format = "<option value=\"%1$s\">%1$s</option>"; - for (File f : files) { - String name = f.getName(); - out.println(String.format(format, name.substring(0, name.length() - 4))); - } - } else { - out.println("<span class='error'>no feed generated</span>"); - } - } finally { - out.close(); - } - } - - public void doShow(File file, String feedName, HttpServletResponse response) throws ServletException, IOException { - // no action, just publication - if (!file.exists()) { - throw new ServletException("could not find feed " + feedName); - } - response.setContentType("text/xml;charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - SyndFeed feed = RSSIOUtil.readFeed(file.toURI().toURL()); - RSSIOUtil.saveFeed(out, feed); - } catch (IllegalArgumentException ex) { - throw new ServletException(ex); - } catch (FeedException ex) { - throw new ServletException(ex); - } finally { - out.close(); - } - } - - @Override - protected ConfigInitializer<ServletConfig, ?> newConfigInitializer() { - return new RSSGeneratorConfig.RssGeneratorConfigInitializer<ServletConfig>() { - - protected String getConfigValue(ServletConfig config, String fullConfigName) { - return config.getInitParameter(fullConfigName); - } - }; - } - - @Override - protected RSSGenerator newDelegate() throws Exception { - return RSSGenerator.newDefaultInstance(); - } - - /** - * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. - * @param request servlet request - * @param response servlet response - * @throws java.io.IOException TODO - * @throws ServletException TODO - */ - @Override - protected void processRequest(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - - String action = request.getParameter("action"); - if (action == null) { - action = ""; - } - action = action.trim().toLowerCase(); - if ("list".equals(action)) { - doList(response); - return; - } - - String feedName = request.getParameter("feedName"); - - if (feedName == null || "".equals(feedName)) { - throw new ServletException("could not find feedName parameter"); - } - //feedName =new String(feedName.getBytes(),0,feedName.length(),Charset.forName("utf-8")); - File file = new File(delegate.getGeneratorDirectory(), feedName + ".xml"); - - if ("show".equals(action)) { - doShow(file, feedName, response); - return; - } - - if ("create".equals(action)) { - doCreateFeed(request, response, feedName, file); - return; - } - - if ("delete".equals(action)) { - doDeleteFeed(request, response, feedName, file); - return; - } - - if ("additem".equals(action)) { - doAddItem(request, response, feedName, file); - return; - } - - throw new ServletException("action '" + action + "' is unknown "); - - } - - protected void addFieldValue(Field field, String value, Map<Field, Object> values) { - if (value != null && !"".equals(value.trim())) { - values.put(field, value); - } - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSGeneratorServlet.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,237 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import java.io.*; + +import java.util.HashMap; +import java.util.Map; +import javax.servlet.*; +import javax.servlet.http.*; + +/** + * <p> + * Servlet permettant de generer des flux generes par RSSGenerator et de + * les publier. + * + * @author chemit + */ +public class RSSGeneratorServlet extends BaseServlet<RSSGenerator> { + + private static final long serialVersionUID = 1L; + + public void doCreateFeed(HttpServletRequest request, HttpServletResponse response, String feedName, File file) throws ServletException, IOException { + String type = request.getParameter("feedType"); + FeedType feedType = null; + if (type != null) { + try { + feedType = FeedType.valueOf(type); + } catch (Exception e) { + feedType = null; + } + } + if (feedType == null) { + feedType = delegate.getFormat(); + } + String description = request.getParameter("feedDescription"); + String link = request.getParameter("feedLink"); + String author = request.getParameter("feedAuthor"); + String categories = request.getParameter("feedCategories"); + Map<Field, Object> values = new HashMap<Field, Object>(); + values.put(Field.NAME, feedName); + addFieldValue(Field.DESCRIPTION, description, values); + addFieldValue(Field.LINK, link, values); + addFieldValue(Field.AUTHOR, author, values); + addFieldValue(Field.CATEGORY, categories, values); + values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); + try { + delegate.createFeedFile(file.toURI().toURL(), feedType, values); + } catch (Exception ex) { + throw new ServletException(ex); + } + + String redirect = request.getParameter("from"); + if (redirect != null) { + response.sendRedirect(redirect); + } + } + + public void doDeleteFeed(HttpServletRequest request, HttpServletResponse response, String feedName, File file) throws ServletException, IOException { + try { + delegate.deleteFeedFile(file.toURI().toURL()); + } catch (Exception ex) { + throw new ServletException(ex); + } + + String redirect = request.getParameter("from"); + if (redirect != null) { + response.sendRedirect(redirect); + } + } + + public void doAddItem(HttpServletRequest request, HttpServletResponse response, String feedName, File file) throws ServletException, IOException { + + Integer nbItems = convertToInt(request.getParameter("nbItems")); + if (nbItems == null) { + nbItems = RSSGeneratorConfig.DEFAULT_GENERATOR_NB_ITEM; + } + String description = request.getParameter("itemDescription"); + String link = request.getParameter("itemLink"); + String author = request.getParameter("itemAuthor"); + String name = request.getParameter("itemName"); + + Map<Field, Object> values = new HashMap<Field, Object>(); + addFieldValue(Field.NAME, name, values); + addFieldValue(Field.DESCRIPTION, description, values); + addFieldValue(Field.LINK, link, values); + addFieldValue(Field.AUTHOR, author, values); + values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); + try { + delegate.addItemToFeedFile(file.toURI().toURL(), nbItems, values); + } catch (Exception ex) { + throw new ServletException(ex); + } + + String redirect = request.getParameter("from"); + if (redirect != null) { + response.sendRedirect(redirect); + } + } + + public void doList(HttpServletResponse response) throws IOException { + // obtain the list of known feeds + File[] files = delegate.getGeneratorDirectory().listFiles(new FileFilter() { + + public boolean accept(File pathname) { + return pathname.isFile() && pathname.getName().endsWith(".xml"); + } + }); + response.setContentType("text/xml;charset=UTF-8"); + PrintWriter out = response.getWriter(); + + try { + if (files.length > 0) { + String format = "<option value=\"%1$s\">%1$s</option>"; + for (File f : files) { + String name = f.getName(); + out.println(String.format(format, name.substring(0, name.length() - 4))); + } + } else { + out.println("<span class='error'>no feed generated</span>"); + } + } finally { + out.close(); + } + } + + public void doShow(File file, String feedName, HttpServletResponse response) throws ServletException, IOException { + // no action, just publication + if (!file.exists()) { + throw new ServletException("could not find feed " + feedName); + } + response.setContentType("text/xml;charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + SyndFeed feed = RSSIOUtil.readFeed(file.toURI().toURL()); + RSSIOUtil.saveFeed(out, feed); + } catch (IllegalArgumentException ex) { + throw new ServletException(ex); + } catch (FeedException ex) { + throw new ServletException(ex); + } finally { + out.close(); + } + } + + @Override + protected ConfigInitializer<ServletConfig, ?> newConfigInitializer() { + return new RSSGeneratorConfig.RssGeneratorConfigInitializer<ServletConfig>() { + + protected String getConfigValue(ServletConfig config, String fullConfigName) { + return config.getInitParameter(fullConfigName); + } + }; + } + + @Override + protected RSSGenerator newDelegate() throws Exception { + return RSSGenerator.newDefaultInstance(); + } + + /** + * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. + * @param request servlet request + * @param response servlet response + * @throws java.io.IOException TODO + * @throws ServletException TODO + */ + @Override + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String action = request.getParameter("action"); + if (action == null) { + action = ""; + } + action = action.trim().toLowerCase(); + if ("list".equals(action)) { + doList(response); + return; + } + + String feedName = request.getParameter("feedName"); + + if (feedName == null || "".equals(feedName)) { + throw new ServletException("could not find feedName parameter"); + } + //feedName =new String(feedName.getBytes(),0,feedName.length(),Charset.forName("utf-8")); + File file = new File(delegate.getGeneratorDirectory(), feedName + ".xml"); + + if ("show".equals(action)) { + doShow(file, feedName, response); + return; + } + + if ("create".equals(action)) { + doCreateFeed(request, response, feedName, file); + return; + } + + if ("delete".equals(action)) { + doDeleteFeed(request, response, feedName, file); + return; + } + + if ("additem".equals(action)) { + doAddItem(request, response, feedName, file); + return; + } + + throw new ServletException("action '" + action + "' is unknown "); + + } + + protected void addFieldValue(Field field, String value, Map<Field, Object> values) { + if (value != null && !"".equals(value.trim())) { + values.put(field, value); + } + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSHelper.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/RSSHelper.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSHelper.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,128 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; -import java.net.MalformedURLException; -import java.util.List; -import org.apache.commons.collections.map.ReferenceMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author poussin - */ -public class RSSHelper { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static final Log log = LogFactory.getLog(RSSHelper.class); - - /** - * - * @return une nouvelle instance de RssHelper en utilisant les implantations - * definies dans RSSConfig. - * @throws java.lang.Exception pour tout pb lors de l'instanciation des objects - */ - public static RSSHelper newDefaultInstance() throws Exception { - FeedURLResolver r = RSSConfig.DEFAULT_RESOLVER_CLASS.newInstance(); - FeedRenderer rr = RSSConfig.DEFAULT_RENDERER_CLASS.newInstance(); - RSSHelper helper = new RSSHelper(r,rr); - return helper; - } - - /** La classe permettant de resoudre les urls */ - protected FeedURLResolver resolver = null; - /** on utilise des soft reference pour eviter de trop utiliser la memoire - key: String, value: FeedData */ - protected ReferenceMap feeds = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT); - - protected FeedRenderer renderer = null; - - /** - * Utilise un SimpleFeedURLResolver comme resolver de feed - */ - public RSSHelper() { - this(new SimpleFeedURLResolver(), new FeedHTMLRenderer(new HTMLScriptCleaner())); - } - - public RSSHelper(FeedURLResolver resolver, FeedRenderer renderer) { - this.resolver = resolver; - this.renderer = renderer; - } - - public void setResolver(FeedURLResolver resolver) { - this.resolver = resolver; - } - - public void setRenderer(FeedRenderer renderer) { - this.renderer = renderer; - } - - public FeedRenderer getRenderer() { - return renderer; - } - - public FeedURLResolver getResolver() { - return resolver; - } - - public void removeFeed(String feedName) { - feeds.remove(feedName); - } - - /** - * Permet de recuperer un certain nombre d'item du feed demande - * - * @param feedName nom du feed souhaite, l'url sera resolu avec le FeedURLResolver - * @param representation indique les champs en sortie souhaites (ex: n-nt) - * @param nbItem le nombre d'item du feed souhaite - * @param forceReload un flag pour forcer la relecture du feed - * @return le code html representant le feed - */ - public String getHTML(String feedName, String representation, Integer nbItem, boolean forceReload) { - try { - FeedData feed = (FeedData) feeds.get(feedName); - if (forceReload || feed == null || feed.getLastRetrived() + RSSConfig.TIME_FORCE_RETRIEVED < System.currentTimeMillis()) { - feed = resolver.resolv(feedName); - if (feed==null) { - log.warn("could not find feed for "+feedName); - return "<span class='feed-error'>No feed found for " + feedName + "</span>"; - } - feeds.put(feedName, feed); - } - - FeedRendererConfig c; - if (representation != null) { - c = new FeedRendererConfig(representation); - } else { - c = feed.getRendererConfig(); - } - - int nb; - if (nbItem != null) { - nb = nbItem; - } else { - nb = feed.getNbItem(); - } - - SyndFeed sf = feed.getFeed(); - //TODO Deal with NPE... if feed is null - List syndEntries = sf.getEntries(); - if (nb >= 0 && syndEntries.size() >= nb) { - syndEntries = syndEntries.subList(syndEntries.size() - nb, syndEntries.size()); - } - SyndEntry [] items = (SyndEntry[])syndEntries.toArray(new SyndEntry[syndEntries.size()]); - - String result = renderer.render(c, sf, items); - return result; - } catch (MalformedURLException eee) { - log.warn("Can't resolv feed url: " + feedName, eee); - return "<span class='feed-error'>" + eee.getMessage() + "</span>"; - } - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSHelper.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/RSSHelper.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSHelper.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSHelper.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,146 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import java.net.MalformedURLException; +import java.util.List; +import org.apache.commons.collections.map.ReferenceMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author poussin + */ +public class RSSHelper { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static final Log log = LogFactory.getLog(RSSHelper.class); + + /** + * + * @return une nouvelle instance de RssHelper en utilisant les implantations + * definies dans RSSConfig. + * @throws java.lang.Exception pour tout pb lors de l'instanciation des objects + */ + public static RSSHelper newDefaultInstance() throws Exception { + FeedURLResolver r = RSSConfig.DEFAULT_RESOLVER_CLASS.newInstance(); + FeedRenderer rr = RSSConfig.DEFAULT_RENDERER_CLASS.newInstance(); + RSSHelper helper = new RSSHelper(r,rr); + return helper; + } + + /** La classe permettant de resoudre les urls */ + protected FeedURLResolver resolver = null; + /** on utilise des soft reference pour eviter de trop utiliser la memoire + key: String, value: FeedData */ + protected ReferenceMap feeds = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT); + + protected FeedRenderer renderer = null; + + /** + * Utilise un SimpleFeedURLResolver comme resolver de feed + */ + public RSSHelper() { + this(new SimpleFeedURLResolver(), new FeedHTMLRenderer(new HTMLScriptCleaner())); + } + + public RSSHelper(FeedURLResolver resolver, FeedRenderer renderer) { + this.resolver = resolver; + this.renderer = renderer; + } + + public void setResolver(FeedURLResolver resolver) { + this.resolver = resolver; + } + + public void setRenderer(FeedRenderer renderer) { + this.renderer = renderer; + } + + public FeedRenderer getRenderer() { + return renderer; + } + + public FeedURLResolver getResolver() { + return resolver; + } + + public void removeFeed(String feedName) { + feeds.remove(feedName); + } + + /** + * Permet de recuperer un certain nombre d'item du feed demande + * + * @param feedName nom du feed souhaite, l'url sera resolu avec le FeedURLResolver + * @param representation indique les champs en sortie souhaites (ex: n-nt) + * @param nbItem le nombre d'item du feed souhaite + * @param forceReload un flag pour forcer la relecture du feed + * @return le code html representant le feed + */ + public String getHTML(String feedName, String representation, Integer nbItem, boolean forceReload) { + try { + FeedData feed = (FeedData) feeds.get(feedName); + if (forceReload || feed == null || feed.getLastRetrived() + RSSConfig.TIME_FORCE_RETRIEVED < System.currentTimeMillis()) { + feed = resolver.resolv(feedName); + if (feed==null) { + log.warn("could not find feed for "+feedName); + return "<span class='feed-error'>No feed found for " + feedName + "</span>"; + } + feeds.put(feedName, feed); + } + + FeedRendererConfig c; + if (representation != null) { + c = new FeedRendererConfig(representation); + } else { + c = feed.getRendererConfig(); + } + + int nb; + if (nbItem != null) { + nb = nbItem; + } else { + nb = feed.getNbItem(); + } + + SyndFeed sf = feed.getFeed(); + //TODO Deal with NPE... if feed is null + List syndEntries = sf.getEntries(); + if (nb >= 0 && syndEntries.size() >= nb) { + syndEntries = syndEntries.subList(syndEntries.size() - nb, syndEntries.size()); + } + SyndEntry [] items = (SyndEntry[])syndEntries.toArray(new SyndEntry[syndEntries.size()]); + + String result = renderer.render(c, sf, items); + return result; + } catch (MalformedURLException eee) { + log.warn("Can't resolv feed url: " + feedName, eee); + return "<span class='feed-error'>" + eee.getMessage() + "</span>"; + } + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSIOUtil.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/RSSIOUtil.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSIOUtil.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,225 +0,0 @@ -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndCategory; -import com.sun.syndication.feed.synd.SyndCategoryImpl; -import com.sun.syndication.feed.synd.SyndContent; -import com.sun.syndication.feed.synd.SyndContentImpl; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndEntryImpl; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.SyndFeedInput; -import com.sun.syndication.io.SyndFeedOutput; -import com.sun.syndication.io.XmlReader; -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.net.URL; -import java.text.ParseException; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * helper to read or save a feed - * @author tony - */ -public class RSSIOUtil { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static final Log log = LogFactory.getLog(RSSIOUtil.class); - - /** - * Load a feed from his url - * @param url location of feed - * @return the java pojo feed - * @throws java.lang.IllegalArgumentException - * @throws com.sun.syndication.io.FeedException - * @throws java.io.IOException - */ - public static SyndFeed readFeed(URL url) throws IllegalArgumentException, FeedException, IOException { - SyndFeedInput input = new SyndFeedInput(); - SyndFeed feed = input.build(new XmlReader(url)); - return feed; - } - - /** - * save a feed into a file. - * @param file - * @param feed - * @throws java.io.IOException - * @throws com.sun.syndication.io.FeedException - */ - public static void saveFeed(File file, SyndFeed feed) throws IOException, FeedException { - SyndFeedOutput output = new SyndFeedOutput(); - output.output(feed, file); - } - - /** - * save a feed into a writer. - * @param writer - * @param feed - * @throws java.io.IOException - * @throws com.sun.syndication.io.FeedException - */ - public static void saveFeed(Writer writer, SyndFeed feed) throws IOException, FeedException { - SyndFeedOutput output = new SyndFeedOutput(); - output.output(feed, writer); - } - - public static SyndFeed createFeed(EnumMap<Field, String> feedProperties, FeedType type, Map<Field, Object> values) throws ParseException { - SyndFeed feed = new SyndFeedImpl(); - feed.setFeedType(type.getType()); - feed.setEncoding("utf-8"); - fillFeed(values, feedProperties, feed, false); - return feed; - } - - public static EnumSet<Field> updateFeed(URL url, EnumMap<Field, String> feedProperties, Map<Field, Object> values) throws ParseException, IllegalArgumentException, FeedException, IOException { - SyndFeed feed = RSSIOUtil.readFeed(url); - return updateFeed(feed, feedProperties, values); - } - - public static EnumSet<Field> updateFeed(SyndFeed feed, EnumMap<Field, String> feedProperties, Map<Field, Object> values) throws ParseException, IllegalArgumentException, FeedException, IOException { - EnumSet<Field> modifieds = fillFeed(values, feedProperties, feed, true); - return modifieds; - } - - @SuppressWarnings({"unchecked"}) - protected static SyndFeed addItemToFeed(SyndFeed feed, SyndEntry item, int nbEntries, Map<Field, Object> values) throws IOException, IllegalArgumentException, FeedException, ParseException { - List<SyndEntry> entries = feed.getEntries(); - if (!entries.isEmpty()) { - // always sort by publication date - java.util.Collections.sort(entries, new FeedEntryComparator()); - // keep only nbEntries -1 entries - while (entries.size() > nbEntries - 1) { - entries.remove(0); - } - } - entries.add(item); - if (log.isDebugEnabled()) { - log.debug("new item " + item); - } - return feed; - } - - public static SyndEntry createFeedItem(EnumMap<Field, String> itemProperties, Map<Field, Object> values) throws ParseException { - - SyndEntry feedEntry = new SyndEntryImpl(); - - for (Entry<Field, Object> entry : values.entrySet()) { - Field field = entry.getKey(); - String name = itemProperties.get(field); - if (name == null) { - // this field is not managed - log.warn("the field " + field + " is not managed in item"); - continue; - } - Object value = entry.getValue(); - Object realValue; - switch (field) { - case TIME: - realValue = RSSGenerator.DATE_PARSER.parse((String) value); - break; - case DESCRIPTION: - //TODO Deal with xml content ? - SyndContent description = new SyndContentImpl(); - description.setType("text/plain"); - feedEntry.setDescription(description); - realValue = String.valueOf(value); - break; - default: - realValue = value; - } - setFieldValue(feedEntry, name, realValue); - } - - return feedEntry; - } - - protected static EnumSet<Field> fillFeed(Map<Field, Object> values, EnumMap<Field, String> feedProperties, SyndFeed feed, boolean treateModfied) throws ParseException { - EnumSet<Field> modifieds = EnumSet.noneOf(Field.class); - - for (Entry<Field, Object> entry : values.entrySet()) { - Field field = entry.getKey(); - String name = feedProperties.get(field); - if (name == null) { - // this field is not managed - log.warn("the field " + field + " is not managed in feed"); - continue; - } - Object value = entry.getValue(); - Object realValue; - switch (field) { - case TIME: - realValue = RSSGenerator.DATE_PARSER.parse((String) value); - break; - case CATEGORY: - List<String> categoriesAsList = new java.util.ArrayList<String>(); - if (value instanceof List) { - categoriesAsList = (List) value; - } else { - // categories as String - String cats = String.valueOf(value); - String[] categories = cats.split(RSSGeneratorConfig.DEFAULT_LIST_SEPARATOR); - categoriesAsList = java.util.Arrays.asList(categories); - } - realValue = new java.util.ArrayList<SyndCategory>(); - for (String cat : categoriesAsList) { - SyndCategory scat = new SyndCategoryImpl(); - scat.setName(cat); - ((List) realValue).add(scat); - } - break; - default: - realValue = value; - } - if (treateModfied) { - Object oldValue = getFieldValue(feed, name); - if (oldValue == null) { - if (realValue != null) { - modifieds.add(field); - } - } else { - if (!oldValue.equals(realValue)) { - modifieds.add(field); - } - } - } - setFieldValue(feed, name, realValue); - } - return modifieds; - } - - protected static void setFieldValue(Object dst, String name, Object value) { - if (value == null) { - // null value is not managed - log.warn("null value for field " + name + " is not managed"); - return; - } - try { - BeanUtils.setProperty(dst, name, value); - } catch (Exception ex) { - log.warn("could not access property " + name, ex); - } - } - - protected static Object getFieldValue(Object dst, String name) { - try { - return BeanUtils.getProperty(dst, name); - } catch (Exception ex) { - log.warn("could not access property " + name, ex); - return null; - } - } - - protected RSSIOUtil() { - // no instance - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSIOUtil.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/RSSIOUtil.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSIOUtil.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSIOUtil.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,243 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndCategoryImpl; +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.SyndFeedOutput; +import com.sun.syndication.io.XmlReader; +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.net.URL; +import java.text.ParseException; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * helper to read or save a feed + * @author tony + */ +public class RSSIOUtil { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static final Log log = LogFactory.getLog(RSSIOUtil.class); + + /** + * Load a feed from his url + * @param url location of feed + * @return the java pojo feed + * @throws java.lang.IllegalArgumentException + * @throws com.sun.syndication.io.FeedException + * @throws java.io.IOException + */ + public static SyndFeed readFeed(URL url) throws IllegalArgumentException, FeedException, IOException { + SyndFeedInput input = new SyndFeedInput(); + SyndFeed feed = input.build(new XmlReader(url)); + return feed; + } + + /** + * save a feed into a file. + * @param file + * @param feed + * @throws java.io.IOException + * @throws com.sun.syndication.io.FeedException + */ + public static void saveFeed(File file, SyndFeed feed) throws IOException, FeedException { + SyndFeedOutput output = new SyndFeedOutput(); + output.output(feed, file); + } + + /** + * save a feed into a writer. + * @param writer + * @param feed + * @throws java.io.IOException + * @throws com.sun.syndication.io.FeedException + */ + public static void saveFeed(Writer writer, SyndFeed feed) throws IOException, FeedException { + SyndFeedOutput output = new SyndFeedOutput(); + output.output(feed, writer); + } + + public static SyndFeed createFeed(EnumMap<Field, String> feedProperties, FeedType type, Map<Field, Object> values) throws ParseException { + SyndFeed feed = new SyndFeedImpl(); + feed.setFeedType(type.getType()); + feed.setEncoding("utf-8"); + fillFeed(values, feedProperties, feed, false); + return feed; + } + + public static EnumSet<Field> updateFeed(URL url, EnumMap<Field, String> feedProperties, Map<Field, Object> values) throws ParseException, IllegalArgumentException, FeedException, IOException { + SyndFeed feed = RSSIOUtil.readFeed(url); + return updateFeed(feed, feedProperties, values); + } + + public static EnumSet<Field> updateFeed(SyndFeed feed, EnumMap<Field, String> feedProperties, Map<Field, Object> values) throws ParseException, IllegalArgumentException, FeedException, IOException { + EnumSet<Field> modifieds = fillFeed(values, feedProperties, feed, true); + return modifieds; + } + + @SuppressWarnings({"unchecked"}) + protected static SyndFeed addItemToFeed(SyndFeed feed, SyndEntry item, int nbEntries, Map<Field, Object> values) throws IOException, IllegalArgumentException, FeedException, ParseException { + List<SyndEntry> entries = feed.getEntries(); + if (!entries.isEmpty()) { + // always sort by publication date + java.util.Collections.sort(entries, new FeedEntryComparator()); + // keep only nbEntries -1 entries + while (entries.size() > nbEntries - 1) { + entries.remove(0); + } + } + entries.add(item); + if (log.isDebugEnabled()) { + log.debug("new item " + item); + } + return feed; + } + + public static SyndEntry createFeedItem(EnumMap<Field, String> itemProperties, Map<Field, Object> values) throws ParseException { + + SyndEntry feedEntry = new SyndEntryImpl(); + + for (Entry<Field, Object> entry : values.entrySet()) { + Field field = entry.getKey(); + String name = itemProperties.get(field); + if (name == null) { + // this field is not managed + log.warn("the field " + field + " is not managed in item"); + continue; + } + Object value = entry.getValue(); + Object realValue; + switch (field) { + case TIME: + realValue = RSSGenerator.DATE_PARSER.parse((String) value); + break; + case DESCRIPTION: + //TODO Deal with xml content ? + SyndContent description = new SyndContentImpl(); + description.setType("text/plain"); + feedEntry.setDescription(description); + realValue = String.valueOf(value); + break; + default: + realValue = value; + } + setFieldValue(feedEntry, name, realValue); + } + + return feedEntry; + } + + protected static EnumSet<Field> fillFeed(Map<Field, Object> values, EnumMap<Field, String> feedProperties, SyndFeed feed, boolean treateModfied) throws ParseException { + EnumSet<Field> modifieds = EnumSet.noneOf(Field.class); + + for (Entry<Field, Object> entry : values.entrySet()) { + Field field = entry.getKey(); + String name = feedProperties.get(field); + if (name == null) { + // this field is not managed + log.warn("the field " + field + " is not managed in feed"); + continue; + } + Object value = entry.getValue(); + Object realValue; + switch (field) { + case TIME: + realValue = RSSGenerator.DATE_PARSER.parse((String) value); + break; + case CATEGORY: + List<String> categoriesAsList = new java.util.ArrayList<String>(); + if (value instanceof List) { + categoriesAsList = (List) value; + } else { + // categories as String + String cats = String.valueOf(value); + String[] categories = cats.split(RSSGeneratorConfig.DEFAULT_LIST_SEPARATOR); + categoriesAsList = java.util.Arrays.asList(categories); + } + realValue = new java.util.ArrayList<SyndCategory>(); + for (String cat : categoriesAsList) { + SyndCategory scat = new SyndCategoryImpl(); + scat.setName(cat); + ((List) realValue).add(scat); + } + break; + default: + realValue = value; + } + if (treateModfied) { + Object oldValue = getFieldValue(feed, name); + if (oldValue == null) { + if (realValue != null) { + modifieds.add(field); + } + } else { + if (!oldValue.equals(realValue)) { + modifieds.add(field); + } + } + } + setFieldValue(feed, name, realValue); + } + return modifieds; + } + + protected static void setFieldValue(Object dst, String name, Object value) { + if (value == null) { + // null value is not managed + log.warn("null value for field " + name + " is not managed"); + return; + } + try { + BeanUtils.setProperty(dst, name, value); + } catch (Exception ex) { + log.warn("could not access property " + name, ex); + } + } + + protected static Object getFieldValue(Object dst, String name) { + try { + return BeanUtils.getProperty(dst, name); + } catch (Exception ex) { + log.warn("could not access property " + name, ex); + return null; + } + } + + protected RSSIOUtil() { + // no instance + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSServlet.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/RSSServlet.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSServlet.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,155 +0,0 @@ -package org.codelutin.rss; - -import java.io.*; - -import javax.servlet.*; -import javax.servlet.http.*; - -/** - * <p> - * Servlet permettant de retourner un feed RSSHelper en une representation HTML. - * Si la servlet est appele sans parametre alors le code JS permettant d'utiliser - * cette servlet en Ajax est retourne. - * </p><p> - * Sinon la servlet peut prendre en parametre: - * <li> feedName: le nom du feed souhaite - * <li> nbItem: le nombre d'item du feed a retourner - * <li> feedRepr: le chaine permettant de connaitre les champs du feed voulu - * </p><p> - * Utilisation dans une page HTML. Dans le header ajouter - * <pre> - * <script src="url/to/RSSServlet"></script> - * </pre> - * Dans le corps placer un element div avec un id particulier. - * Et soit a la fin de la page soit juste apres le div, ajouter le script - * <pre> - * rssinclude('feedName', 'divid', 5, 'n-n'); - * </pre> - * </p> - * @author poussin - */ -public class RSSServlet extends BaseServlet<RSSHelper> { - - /** - * Le code JavaScript a utilise dans les pages clientes - * - * Provient du fichier rssinclude.js - * cat rssinclude.js |sed 's/"/\\"/g' |sed -re 's/^(.*)$/"\1\\n" +/' - */ - protected static String js = - "function rssincludeUpdateDiv(div, background) {\n" + - " // mettre background a false est utile lorsque l'on appelle la methode\n" + - " // depuis une fenetre que l'on ferme ensuite\n" + - " var serlvetUrl = \"%1$s\"; \n" + - " win = window;\n" + - " var xhr = null;\n" + - " var error=null;\n" + - " var feedName = div.getAttribute(\"feedName\");\n" + - " if (!feedName) // pas de feed name, fatal error\n" + - " error = \"<span class='feed-error'>Aucun feed name detecte...</span>\"; \n" + - " else if(win.XMLHttpRequest) // Firefox, Opera detected\n" + - " xhr = new win.XMLHttpRequest();\n" + - " else if(win.ActiveXObject) // Internet Explorer detected\n" + - " xhr = new win.ActiveXObject(\"Microsoft.XMLHTTP\");\n" + - " else // XMLHttpRequest non supporte par le navigateur\n" + - " error = \"<span class='feed-error'>Votre navigateur ne supporte pas les objets XMLHTTPRequest...</span>\"; \n" + - " if (!!error) { div.innerHTML = error; return; } \n" + - " \n" + - " var nbItem = div.getAttribute(\"nbItem\");\n" + - " var feedRepr = div.getAttribute(\"feedRepr\"); \n" + - " var forceReload = div.getAttribute(\"forceReload\"); \n" + - " var url = serlvetUrl+(serlvetUrl.indexOf('?')>-1?'&':'?')+\"feedName=\" + escape(feedName); \n" + - " if (!!nbItem) {url += '&nbItem=' + escape(nbItem);} \n" + - " if (!!feedRepr) {url += '&feedRepr=' + escape(feedRepr);}\n" + - " if (!!forceReload) {url += '&forceReload=true';}\n" + - "\n" + - " xhr.open(\"GET\", url, !!background);\n" + - " xhr.onreadystatechange = function() {\n" + - " if(xhr.readyState == 1) div.innerHTML = \"Chargement du flux '\"+feedName+\"'\";\n" + - " if(xhr.readyState == 4) div.innerHTML = xhr.responseText;\n" + - " }\n" + - " xhr.send(null);\n" + - "}\n" + - "var initRss =function () {\n" + - " var divs = document.getElementsByTagName(\"div\"); \n" + - " var i = 0;var max=divs.length; \n" + - " var toTreate = [];\n" + - " while (i < max) {\n" + - " var div = divs[i++];\n" + - " if (div.getAttribute('name')=='rssinclude') toTreate[toTreate.length] = div;\n" + - " }\n" + - " i=0;max = toTreate.length;\n" + - " while (i<max) rssincludeUpdateDiv(toTreate[i++], true);" + - "}\n" + - "if (window.addEventListener) window.addEventListener( 'load', initRss,false);\n" + - "else if (window.attachEvent) window.attachEvent( 'onload', initRss);"; - - private static final long serialVersionUID = 1L; - - /** - * @param url current url to add in script - * @return the rssinclude script, patched with url - */ - public static String getJs(String url) { - String code = String.format(js, url); - return code; - } - - public void doJs(HttpServletResponse response, HttpServletRequest request) throws IOException { - // on renvoie le code js - response.setContentType("text/plain;charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - String code = getJs(request.getRequestURL().toString()); - out.println(code); - } finally { - out.close(); - } - } - - public void doRender(HttpServletResponse response, HttpServletRequest request, String feedName) throws IOException { - response.setContentType("text/html;charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - String feedRepr = request.getParameter("feedRepr"); - Integer nbItem = convertToInt(request.getParameter("nbItem")); - boolean forceReload = "true".equalsIgnoreCase(request.getParameter("forceReload")); - out.println(delegate.getHTML(feedName, feedRepr, nbItem, forceReload)); - } finally { - out.close(); - } - } - - @Override - protected ConfigInitializer<ServletConfig,? > newConfigInitializer() { - return new RSSConfig.RSSConfigInitializer<ServletConfig>() { - - protected String getConfigValue(ServletConfig config, String fullConfigName) { - return config.getInitParameter(fullConfigName); - } - }; - } - - @Override - protected RSSHelper newDelegate() throws Exception { - return RSSHelper.newDefaultInstance(); - } - - /** - * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. - * @param request servlet request - * @param response servlet response - * @throws java.io.IOException TODO - * @throws ServletException TODO - */ - @Override - protected void processRequest(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - String feedName = request.getParameter("feedName"); - if (feedName == null || "".equals(feedName)) { - doJs(response, request); - } else { - doRender(response, request, feedName); - } - } -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSServlet.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/RSSServlet.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSServlet.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/RSSServlet.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,173 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.codelutin.rss; + +import java.io.*; + +import javax.servlet.*; +import javax.servlet.http.*; + +/** + * <p> + * Servlet permettant de retourner un feed RSSHelper en une representation HTML. + * Si la servlet est appele sans parametre alors le code JS permettant d'utiliser + * cette servlet en Ajax est retourne. + * </p><p> + * Sinon la servlet peut prendre en parametre: + * <li> feedName: le nom du feed souhaite + * <li> nbItem: le nombre d'item du feed a retourner + * <li> feedRepr: le chaine permettant de connaitre les champs du feed voulu + * </p><p> + * Utilisation dans une page HTML. Dans le header ajouter + * <pre> + * <script src="url/to/RSSServlet"></script> + * </pre> + * Dans le corps placer un element div avec un id particulier. + * Et soit a la fin de la page soit juste apres le div, ajouter le script + * <pre> + * rssinclude('feedName', 'divid', 5, 'n-n'); + * </pre> + * </p> + * @author poussin + */ +public class RSSServlet extends BaseServlet<RSSHelper> { + + /** + * Le code JavaScript a utilise dans les pages clientes + * + * Provient du fichier rssinclude.js + * cat rssinclude.js |sed 's/"/\\"/g' |sed -re 's/^(.*)$/"\1\\n" +/' + */ + protected static String js = + "function rssincludeUpdateDiv(div, background) {\n" + + " // mettre background a false est utile lorsque l'on appelle la methode\n" + + " // depuis une fenetre que l'on ferme ensuite\n" + + " var serlvetUrl = \"%1$s\"; \n" + + " win = window;\n" + + " var xhr = null;\n" + + " var error=null;\n" + + " var feedName = div.getAttribute(\"feedName\");\n" + + " if (!feedName) // pas de feed name, fatal error\n" + + " error = \"<span class='feed-error'>Aucun feed name detecte...</span>\"; \n" + + " else if(win.XMLHttpRequest) // Firefox, Opera detected\n" + + " xhr = new win.XMLHttpRequest();\n" + + " else if(win.ActiveXObject) // Internet Explorer detected\n" + + " xhr = new win.ActiveXObject(\"Microsoft.XMLHTTP\");\n" + + " else // XMLHttpRequest non supporte par le navigateur\n" + + " error = \"<span class='feed-error'>Votre navigateur ne supporte pas les objets XMLHTTPRequest...</span>\"; \n" + + " if (!!error) { div.innerHTML = error; return; } \n" + + " \n" + + " var nbItem = div.getAttribute(\"nbItem\");\n" + + " var feedRepr = div.getAttribute(\"feedRepr\"); \n" + + " var forceReload = div.getAttribute(\"forceReload\"); \n" + + " var url = serlvetUrl+(serlvetUrl.indexOf('?')>-1?'&':'?')+\"feedName=\" + escape(feedName); \n" + + " if (!!nbItem) {url += '&nbItem=' + escape(nbItem);} \n" + + " if (!!feedRepr) {url += '&feedRepr=' + escape(feedRepr);}\n" + + " if (!!forceReload) {url += '&forceReload=true';}\n" + + "\n" + + " xhr.open(\"GET\", url, !!background);\n" + + " xhr.onreadystatechange = function() {\n" + + " if(xhr.readyState == 1) div.innerHTML = \"Chargement du flux '\"+feedName+\"'\";\n" + + " if(xhr.readyState == 4) div.innerHTML = xhr.responseText;\n" + + " }\n" + + " xhr.send(null);\n" + + "}\n" + + "var initRss =function () {\n" + + " var divs = document.getElementsByTagName(\"div\"); \n" + + " var i = 0;var max=divs.length; \n" + + " var toTreate = [];\n" + + " while (i < max) {\n" + + " var div = divs[i++];\n" + + " if (div.getAttribute('name')=='rssinclude') toTreate[toTreate.length] = div;\n" + + " }\n" + + " i=0;max = toTreate.length;\n" + + " while (i<max) rssincludeUpdateDiv(toTreate[i++], true);" + + "}\n" + + "if (window.addEventListener) window.addEventListener( 'load', initRss,false);\n" + + "else if (window.attachEvent) window.attachEvent( 'onload', initRss);"; + + private static final long serialVersionUID = 1L; + + /** + * @param url current url to add in script + * @return the rssinclude script, patched with url + */ + public static String getJs(String url) { + String code = String.format(js, url); + return code; + } + + public void doJs(HttpServletResponse response, HttpServletRequest request) throws IOException { + // on renvoie le code js + response.setContentType("text/plain;charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + String code = getJs(request.getRequestURL().toString()); + out.println(code); + } finally { + out.close(); + } + } + + public void doRender(HttpServletResponse response, HttpServletRequest request, String feedName) throws IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + String feedRepr = request.getParameter("feedRepr"); + Integer nbItem = convertToInt(request.getParameter("nbItem")); + boolean forceReload = "true".equalsIgnoreCase(request.getParameter("forceReload")); + out.println(delegate.getHTML(feedName, feedRepr, nbItem, forceReload)); + } finally { + out.close(); + } + } + + @Override + protected ConfigInitializer<ServletConfig,? > newConfigInitializer() { + return new RSSConfig.RSSConfigInitializer<ServletConfig>() { + + protected String getConfigValue(ServletConfig config, String fullConfigName) { + return config.getInitParameter(fullConfigName); + } + }; + } + + @Override + protected RSSHelper newDelegate() throws Exception { + return RSSHelper.newDefaultInstance(); + } + + /** + * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. + * @param request servlet request + * @param response servlet response + * @throws java.io.IOException TODO + * @throws ServletException TODO + */ + @Override + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String feedName = request.getParameter("feedName"); + if (feedName == null || "".equals(feedName)) { + doJs(response, request); + } else { + doRender(response, request, feedName); + } + } +} Deleted: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java =================================================================== --- lutinrss/trunk/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,26 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * Par defaut retourne un FeedData ou la chaine passer est convertie en URL, - * le nombre d'item est positionne a -1 et le renderer a n-natd - * @author poussin - */ -public class SimpleFeedURLResolver implements FeedURLResolver { - - public FeedData resolv(String ask) throws MalformedURLException { - URL url = new URL(ask); - FeedData result = new FeedData(url); - result.setNbItem(RSSConfig.DEFAULT_NB_ITEM); - result.setRendererConfig(RSSConfig.DEFAULT_RENDERER_CONFIG); - return result; - } - -} Copied: lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java (from rev 118, lutinrss/trunk/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java) =================================================================== --- lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java (rev 0) +++ lutinrss/tags/2.3.8/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,44 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * Par defaut retourne un FeedData ou la chaine passer est convertie en URL, + * le nombre d'item est positionne a -1 et le renderer a n-natd + * @author poussin + */ +public class SimpleFeedURLResolver implements FeedURLResolver { + + public FeedData resolv(String ask) throws MalformedURLException { + URL url = new URL(ask); + FeedData result = new FeedData(url); + result.setNbItem(RSSConfig.DEFAULT_NB_ITEM); + result.setRendererConfig(RSSConfig.DEFAULT_RENDERER_CONFIG); + return result; + } + +} Copied: lutinrss/tags/2.3.8/src/site/fr/rst/Todo.rst (from rev 116, lutinrss/trunk/src/site/fr/rst/Todo.rst) =================================================================== --- lutinrss/tags/2.3.8/src/site/fr/rst/Todo.rst (rev 0) +++ lutinrss/tags/2.3.8/src/site/fr/rst/Todo.rst 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,5 @@ +==== +TODO +==== + +Reste a faire ? \ No newline at end of file Deleted: lutinrss/tags/2.3.8/src/site/fr/rst/index.rst =================================================================== --- lutinrss/trunk/src/site/fr/rst/index.rst 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/site/fr/rst/index.rst 2008-10-09 15:17:48 UTC (rev 121) @@ -1,12 +0,0 @@ -RSS Servlet/Ajax -================ - -<script src="lutinrss.js"> -rss("rss1", "url", max, login, password) -</script> -<div id="rss1"></div> - -- si pas de fichier html pour l'url demandée ou plus vielle que N - - récupération de de l'url et sauvegarde en html -- renvoi du html -< \ No newline at end of file Copied: lutinrss/tags/2.3.8/src/site/fr/rst/index.rst (from rev 117, lutinrss/trunk/src/site/fr/rst/index.rst) =================================================================== --- lutinrss/tags/2.3.8/src/site/fr/rst/index.rst (rev 0) +++ lutinrss/tags/2.3.8/src/site/fr/rst/index.rst 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,18 @@ +RSS Servlet/Ajax +================ + +.. contents:: + +Utilisation +=========== + +A faire ... + +<script src="lutinrss.js"> +rss("rss1", "url", max, login, password) +</script> +<div id="rss1"></div> + +- si pas de fichier html pour l'url demandée ou plus vielle que N + - récupération de de l'url et sauvegarde en html +- renvoi du html Copied: lutinrss/tags/2.3.8/src/site/site.xml (from rev 117, lutinrss/trunk/src/site/site.xml) =================================================================== --- lutinrss/tags/2.3.8/src/site/site.xml (rev 0) +++ lutinrss/tags/2.3.8/src/site/site.xml 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="${project.name}"> + + <publishDate format="dd/MM/yyyy"/> + + <skin> + <groupId>org.codelutin</groupId> + <artifactId>maven-lutin-skin</artifactId> + <version>0.2</version> + </skin> + + <bannerLeft> + <name>${project.name}</name> + </bannerLeft> + + <bannerRight> + <src>http://www.codelutin.com/images/lutinorange-codelutin.png</src> + <href>${project.organization.url}</href> + </bannerRight> + + + <poweredBy> + <logo href="http://maven.apache.org" name="Maven" img="images/logos/maven-feather.png"/> + <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/> + <logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText" + img="images/restructuredtext-logo.png"/> + </poweredBy> + + <body> + <links> + <item name="Labs" href="http://labs.libre-entreprise.org/"/> + <item name="Code Lutin" href="http://www.codelutin.com/"/> + </links> + + <menu ref="parent"/> + + <menu name="Utilisateur"> + <item href="index.html" name="Accueil"/> + </menu> + + <menu name="Téléchargement"> + <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}" + name="la dernière version sur le repository maven"/> + <item href="${labs.builder.url}/org/codelutin/${project.artifactId}" + name="Voir toutes les versions sur le repository maven"/> + <!--item href="http://labs.libre-entreprise.org/frs/?group_id=${labs.id}&release_id=252" + name="la dernière release"/--> + </menu> + + <menu name="Developpeur"> + <item name="Todo" href="Todo.html"/> + </menu> + + <menu ref="reports"/> + + </body> +</project> \ No newline at end of file Deleted: lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java =================================================================== --- lutinrss/trunk/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,203 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.codelutin.rss; - -import com.sun.syndication.feed.synd.SyndCategory; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; -import java.io.File; -import java.net.MalformedURLException; -import java.text.ParseException; -import java.util.List; -import java.util.Map; - -/** - * - * @author tony - */ -public class RSSGeneratorHelperTest extends junit.framework.TestCase { - - static RSSGenerator helper; - static File f; - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (helper == null) { - helper = RSSGenerator.newDefaultInstance(); - } - if (f == null) { - f = getFeedFile(); - } - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testCreateFeed() throws Exception { - - Map<Field, Object> values = new java.util.HashMap<Field, Object>(); - values.put(Field.NAME, "feedName : " + f.getName()); - values.put(Field.DESCRIPTION, "feedDescription : " + f.getName()); - values.put(Field.LINK, f.toURI().toURL() + ""); - values.put(Field.AUTHOR, "feed author"); - values.put(Field.CATEGORY, java.util.Arrays.asList("categorie1","categorie2")); - values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); - - assertFalse(f.exists()); - RSSGenerator.log.info("feedFile : " + f); - helper.createFeedFile(f.toURI().toURL(), helper.getFormat(), values); - // no lock - assertFalse(helper.getWriteFileLock(f).exists()); - // file exist - assertTrue(f.exists()); - - SyndFeed feed = RSSIOUtil.readFeed(f.toURI().toURL()); - - if (RSSGenerator.log.isDebugEnabled()) { - RSSGenerator.log.debug(feed); - } - - assertEquals(feed.getFeedType(), helper.getFormat().getType()); - assertEquals(feed.getLink(), values.get(Field.LINK)); - assertEquals(feed.getTitle(), values.get(Field.NAME)); - assertEquals(feed.getDescription(), values.get(Field.DESCRIPTION)); - assertEquals(feed.getAuthor(), values.get(Field.AUTHOR)); - List cats = (List) values.get(Field.CATEGORY); - for (Object o : feed.getCategories()) { - SyndCategory cat = (SyndCategory) o; - assertTrue(cats.contains(cat.getName())); - } - assertEquals(feed.getPublishedDate(), RSSGenerator.DATE_PARSER.parse((String) values.get(Field.TIME))); - - } - - public void testCreateFeedAlreadyExisting() throws Exception { - - Map<Field, Object> values = new java.util.HashMap<Field, Object>(); - values.put(Field.NAME, "feedName : " + f.getName()); - values.put(Field.DESCRIPTION, "feedDescription : " + f.getName()); - values.put(Field.LINK, f.toURI().toURL() + ""); - values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); - - assertTrue(f.exists()); - - try { - helper.createFeedFile(f.toURI().toURL(), helper.getFormat(), values); - // file already exist, can not reach this code - fail(); - } catch (IllegalStateException e) { - assertTrue(true); - } - // no write lock - assertFalse(helper.getWriteFileLock(f).exists()); - - } - - public void testAddFeedEntry() throws Exception { - assertTrue(f.exists()); - Map<Field, Object> values = createEntry(0); - - helper.addItemToFeedFile(f.toURI().toURL(), 2, values); - - SyndFeed feed = RSSIOUtil.readFeed(f.toURI().toURL()); - - List entries = feed.getEntries(); - assertEquals(1, entries.size()); - - if (RSSGenerator.log.isDebugEnabled()) { - RSSGenerator.log.debug(feed); - } - - SyndEntry entry = (SyndEntry) entries.get(0); - - assertEntry(entry, values); - } - - public void testAddFeedEntryToMax() throws Exception { - - assertTrue(f.exists()); - SyndFeed feed = RSSIOUtil.readFeed(f.toURI().toURL()); - - List entries = feed.getEntries(); - assertEquals(1, entries.size()); - SyndEntry firsEntry = (SyndEntry) entries.get(0); - - Map<Field, Object> values; - - int nbMaxEntries = 10; - - for (int i = 1; i < nbMaxEntries; i++) { - values = createEntry(i); - helper.addItemToFeedFile(f.toURI().toURL(), nbMaxEntries, values); - feed = RSSIOUtil.readFeed(f.toURI().toURL()); - - entries = feed.getEntries(); - assertEquals(i + 1, entries.size()); - - SyndEntry entry = (SyndEntry) entries.get(i); - - assertEntry(entry, values); - } - - // feed file contains max items - - values = createEntry(nbMaxEntries); - - helper.addItemToFeedFile(f.toURI().toURL(), nbMaxEntries, values); - - feed = RSSIOUtil.readFeed(f.toURI().toURL()); - - entries = feed.getEntries(); - - assertEquals(nbMaxEntries, entries.size()); - - SyndEntry entry = (SyndEntry) entries.get(nbMaxEntries - 1); - - assertEntry(entry, values); - - // check orginal first entry is no more present - entry = (SyndEntry) entries.get(0); - assertFalse(firsEntry.getTitle().equals(entry.getTitle())); - } - - public void testCleanFile() throws Exception { - try { - assertNotNull(f); - assertTrue(f.exists()); - // lock is delete - assertFalse(helper.getWriteFileLock(f).exists()); - } finally { - if (f != null) { - f.deleteOnExit(); - } - } - } - - protected void assertEntry(SyndEntry entry, Map<Field, Object> values) throws ParseException { - assertEquals(entry.getLink(), values.get(Field.LINK)); - assertEquals(entry.getTitle(), values.get(Field.NAME)); - assertEquals(entry.getDescription().getValue(), values.get(Field.DESCRIPTION)); - assertEquals(entry.getAuthor(), values.get(Field.AUTHOR)); - assertEquals(entry.getPublishedDate(), RSSGenerator.DATE_PARSER.parse((String) values.get(Field.TIME))); - } - - protected File getFeedFile() { - return helper.getFeedFile(getClass().getSimpleName() + "-" + System.nanoTime()); - } - - protected Map<Field, Object> createEntry(int number) throws MalformedURLException { - Map<Field, Object> values = new java.util.HashMap<Field, Object>(); - values.put(Field.NAME, "entryName : " + f.getName() + "-" + number); - values.put(Field.DESCRIPTION, "entryDescription : " + f.getName() + "-" + number); - values.put(Field.AUTHOR, "author-" + number); - values.put(Field.LINK, f.toURI().toURL() + "/entry-" + number); - values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); - return values; - } - -} Copied: lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java (from rev 118, lutinrss/trunk/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java) =================================================================== --- lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java (rev 0) +++ lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSGeneratorHelperTest.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,221 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import java.io.File; +import java.net.MalformedURLException; +import java.text.ParseException; +import java.util.List; +import java.util.Map; + +/** + * + * @author tony + */ +public class RSSGeneratorHelperTest extends junit.framework.TestCase { + + static RSSGenerator helper; + static File f; + + @Override + protected void setUp() throws Exception { + super.setUp(); + if (helper == null) { + helper = RSSGenerator.newDefaultInstance(); + } + if (f == null) { + f = getFeedFile(); + } + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testCreateFeed() throws Exception { + + Map<Field, Object> values = new java.util.HashMap<Field, Object>(); + values.put(Field.NAME, "feedName : " + f.getName()); + values.put(Field.DESCRIPTION, "feedDescription : " + f.getName()); + values.put(Field.LINK, f.toURI().toURL() + ""); + values.put(Field.AUTHOR, "feed author"); + values.put(Field.CATEGORY, java.util.Arrays.asList("categorie1","categorie2")); + values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); + + assertFalse(f.exists()); + RSSGenerator.log.info("feedFile : " + f); + helper.createFeedFile(f.toURI().toURL(), helper.getFormat(), values); + // no lock + assertFalse(helper.getWriteFileLock(f).exists()); + // file exist + assertTrue(f.exists()); + + SyndFeed feed = RSSIOUtil.readFeed(f.toURI().toURL()); + + if (RSSGenerator.log.isDebugEnabled()) { + RSSGenerator.log.debug(feed); + } + + assertEquals(feed.getFeedType(), helper.getFormat().getType()); + assertEquals(feed.getLink(), values.get(Field.LINK)); + assertEquals(feed.getTitle(), values.get(Field.NAME)); + assertEquals(feed.getDescription(), values.get(Field.DESCRIPTION)); + assertEquals(feed.getAuthor(), values.get(Field.AUTHOR)); + List cats = (List) values.get(Field.CATEGORY); + for (Object o : feed.getCategories()) { + SyndCategory cat = (SyndCategory) o; + assertTrue(cats.contains(cat.getName())); + } + assertEquals(feed.getPublishedDate(), RSSGenerator.DATE_PARSER.parse((String) values.get(Field.TIME))); + + } + + public void testCreateFeedAlreadyExisting() throws Exception { + + Map<Field, Object> values = new java.util.HashMap<Field, Object>(); + values.put(Field.NAME, "feedName : " + f.getName()); + values.put(Field.DESCRIPTION, "feedDescription : " + f.getName()); + values.put(Field.LINK, f.toURI().toURL() + ""); + values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); + + assertTrue(f.exists()); + + try { + helper.createFeedFile(f.toURI().toURL(), helper.getFormat(), values); + // file already exist, can not reach this code + fail(); + } catch (IllegalStateException e) { + assertTrue(true); + } + // no write lock + assertFalse(helper.getWriteFileLock(f).exists()); + + } + + public void testAddFeedEntry() throws Exception { + assertTrue(f.exists()); + Map<Field, Object> values = createEntry(0); + + helper.addItemToFeedFile(f.toURI().toURL(), 2, values); + + SyndFeed feed = RSSIOUtil.readFeed(f.toURI().toURL()); + + List entries = feed.getEntries(); + assertEquals(1, entries.size()); + + if (RSSGenerator.log.isDebugEnabled()) { + RSSGenerator.log.debug(feed); + } + + SyndEntry entry = (SyndEntry) entries.get(0); + + assertEntry(entry, values); + } + + public void testAddFeedEntryToMax() throws Exception { + + assertTrue(f.exists()); + SyndFeed feed = RSSIOUtil.readFeed(f.toURI().toURL()); + + List entries = feed.getEntries(); + assertEquals(1, entries.size()); + SyndEntry firsEntry = (SyndEntry) entries.get(0); + + Map<Field, Object> values; + + int nbMaxEntries = 10; + + for (int i = 1; i < nbMaxEntries; i++) { + values = createEntry(i); + helper.addItemToFeedFile(f.toURI().toURL(), nbMaxEntries, values); + feed = RSSIOUtil.readFeed(f.toURI().toURL()); + + entries = feed.getEntries(); + assertEquals(i + 1, entries.size()); + + SyndEntry entry = (SyndEntry) entries.get(i); + + assertEntry(entry, values); + } + + // feed file contains max items + + values = createEntry(nbMaxEntries); + + helper.addItemToFeedFile(f.toURI().toURL(), nbMaxEntries, values); + + feed = RSSIOUtil.readFeed(f.toURI().toURL()); + + entries = feed.getEntries(); + + assertEquals(nbMaxEntries, entries.size()); + + SyndEntry entry = (SyndEntry) entries.get(nbMaxEntries - 1); + + assertEntry(entry, values); + + // check orginal first entry is no more present + entry = (SyndEntry) entries.get(0); + assertFalse(firsEntry.getTitle().equals(entry.getTitle())); + } + + public void testCleanFile() throws Exception { + try { + assertNotNull(f); + assertTrue(f.exists()); + // lock is delete + assertFalse(helper.getWriteFileLock(f).exists()); + } finally { + if (f != null) { + f.deleteOnExit(); + } + } + } + + protected void assertEntry(SyndEntry entry, Map<Field, Object> values) throws ParseException { + assertEquals(entry.getLink(), values.get(Field.LINK)); + assertEquals(entry.getTitle(), values.get(Field.NAME)); + assertEquals(entry.getDescription().getValue(), values.get(Field.DESCRIPTION)); + assertEquals(entry.getAuthor(), values.get(Field.AUTHOR)); + assertEquals(entry.getPublishedDate(), RSSGenerator.DATE_PARSER.parse((String) values.get(Field.TIME))); + } + + protected File getFeedFile() { + return helper.getFeedFile(getClass().getSimpleName() + "-" + System.nanoTime()); + } + + protected Map<Field, Object> createEntry(int number) throws MalformedURLException { + Map<Field, Object> values = new java.util.HashMap<Field, Object>(); + values.put(Field.NAME, "entryName : " + f.getName() + "-" + number); + values.put(Field.DESCRIPTION, "entryDescription : " + f.getName() + "-" + number); + values.put(Field.AUTHOR, "author-" + number); + values.put(Field.LINK, f.toURI().toURL() + "/entry-" + number); + values.put(Field.TIME, RSSGenerator.DATE_PARSER.format(new java.util.Date())); + return values; + } + +} Deleted: lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSTest.java =================================================================== --- lutinrss/trunk/src/test/java/org/codelutin/rss/RSSTest.java 2008-09-24 20:21:41 UTC (rev 111) +++ lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSTest.java 2008-10-09 15:17:48 UTC (rev 121) @@ -1,90 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.codelutin.rss; - -import java.util.ArrayList; -import java.util.List; -import junit.framework.TestCase; -import org.apache.commons.beanutils.BeanUtils; - -/** - * - * @author poussin - */ -public class RSSTest extends TestCase { - - public RSSTest(String testName) { - super(testName); - } - - public void testBeanUtils() throws Exception { -// RSSConfig.class.getField("TIME_FORCE_RETRIEVED").set(null, 10); - System.out.println("TIME:" + RSSConfig.TIME_FORCE_RETRIEVED); - System.out.println("RENDER:" + RSSConfig.DEFAULT_RENDERER_CLASS); - BeanUtils.setProperty(new RSSConfig(), "TIME_FORCE_RETRIEVED", "10"); - BeanUtils.setProperty(new RSSConfig(), "DEFAULT_RENDERER_CLASS", FeedRenderer.class.getName()); - System.out.println("TIME:" + RSSConfig.TIME_FORCE_RETRIEVED); - System.out.println("RENDER:" + RSSConfig.DEFAULT_RENDERER_CLASS); - assertEquals("java.lang.String", BeanUtils.getProperty("Object", "class.name")); - } - - public void testCleaner() throws Exception { - String s = "debut<Script src='toto.js'>et du script</scRipt>milieu<scripT>encore du code\n</script>fin"; - - HTMLCleaner cleaner = new HTMLScriptCleaner(); - assertEquals("debutmilieufin", cleaner.clean(s)); - } - - public void testRendererConfig() throws Exception { - FeedRendererConfig c = new FeedRendererConfig("indat-ndat"); - - List<Field> l1 = new ArrayList<Field>(); - l1.add(Field.IMAGE); - l1.add(Field.NAME); - l1.add(Field.DESCRIPTION); - l1.add(Field.AUTHOR); - l1.add(Field.TIME); - - List<Field> l2 = new ArrayList<Field>(); - l2.add(Field.NAME); - l2.add(Field.DESCRIPTION); - l2.add(Field.AUTHOR); - l2.add(Field.TIME); - - assertEquals(l1, c.getFeedFieldOrder()); - assertEquals(l2, c.getItemFieldOrder()); - assertEquals("indat-ndat", c.getString()); - } - - /** - * Test of getHTML method, of class RSSHelper. - * TODO do the test, for the moment, do not launch it... - * @throws Exception if any pb - */ - public void _testGetHTML() throws Exception { - System.out.println("getHTML"); - String feedName = "http://localhost/rss/rss_1.0.xml"; - String feedRepr = "n-ndat"; - int nbItem = -1; - RSSHelper instance = new RSSHelper(); - String expResult = ""; - String result = instance.getHTML(feedName, feedRepr, nbItem,false); - System.out.println("***" + result); - result = instance.getHTML(feedName, feedRepr, nbItem,false); - System.out.println("***" + result); - - Thread.sleep(2000); - - result = instance.getHTML(feedName, feedRepr, nbItem,false); - System.out.println("***" + result); - result = instance.getHTML(feedName, feedRepr, nbItem,false); - System.out.println("***" + result); - // assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); - } - -} Copied: lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSTest.java (from rev 118, lutinrss/trunk/src/test/java/org/codelutin/rss/RSSTest.java) =================================================================== --- lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSTest.java (rev 0) +++ lutinrss/tags/2.3.8/src/test/java/org/codelutin/rss/RSSTest.java 2008-10-09 15:17:48 UTC (rev 121) @@ -0,0 +1,108 @@ +/** + * *##% LutinRSS + * Copyright (C) 2008 CodeLutin + * + * This program 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 3 of the + * License, or (at your option) any later version. + * + * 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.rss; + +import java.util.ArrayList; +import java.util.List; +import junit.framework.TestCase; +import org.apache.commons.beanutils.BeanUtils; + +/** + * + * @author poussin + */ +public class RSSTest extends TestCase { + + public RSSTest(String testName) { + super(testName); + } + + public void testBeanUtils() throws Exception { +// RSSConfig.class.getField("TIME_FORCE_RETRIEVED").set(null, 10); + System.out.println("TIME:" + RSSConfig.TIME_FORCE_RETRIEVED); + System.out.println("RENDER:" + RSSConfig.DEFAULT_RENDERER_CLASS); + BeanUtils.setProperty(new RSSConfig(), "TIME_FORCE_RETRIEVED", "10"); + BeanUtils.setProperty(new RSSConfig(), "DEFAULT_RENDERER_CLASS", FeedRenderer.class.getName()); + System.out.println("TIME:" + RSSConfig.TIME_FORCE_RETRIEVED); + System.out.println("RENDER:" + RSSConfig.DEFAULT_RENDERER_CLASS); + assertEquals("java.lang.String", BeanUtils.getProperty("Object", "class.name")); + } + + public void testCleaner() throws Exception { + String s = "debut<Script src='toto.js'>et du script</scRipt>milieu<scripT>encore du code\n</script>fin"; + + HTMLCleaner cleaner = new HTMLScriptCleaner(); + assertEquals("debutmilieufin", cleaner.clean(s)); + } + + public void testRendererConfig() throws Exception { + FeedRendererConfig c = new FeedRendererConfig("indat-ndat"); + + List<Field> l1 = new ArrayList<Field>(); + l1.add(Field.IMAGE); + l1.add(Field.NAME); + l1.add(Field.DESCRIPTION); + l1.add(Field.AUTHOR); + l1.add(Field.TIME); + + List<Field> l2 = new ArrayList<Field>(); + l2.add(Field.NAME); + l2.add(Field.DESCRIPTION); + l2.add(Field.AUTHOR); + l2.add(Field.TIME); + + assertEquals(l1, c.getFeedFieldOrder()); + assertEquals(l2, c.getItemFieldOrder()); + assertEquals("indat-ndat", c.getString()); + } + + /** + * Test of getHTML method, of class RSSHelper. + * TODO do the test, for the moment, do not launch it... + * @throws Exception if any pb + */ + public void _testGetHTML() throws Exception { + System.out.println("getHTML"); + String feedName = "http://localhost/rss/rss_1.0.xml"; + String feedRepr = "n-ndat"; + int nbItem = -1; + RSSHelper instance = new RSSHelper(); + String expResult = ""; + String result = instance.getHTML(feedName, feedRepr, nbItem,false); + System.out.println("***" + result); + result = instance.getHTML(feedName, feedRepr, nbItem,false); + System.out.println("***" + result); + + Thread.sleep(2000); + + result = instance.getHTML(feedName, feedRepr, nbItem,false); + System.out.println("***" + result); + result = instance.getHTML(feedName, feedRepr, nbItem,false); + System.out.println("***" + result); + // assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); + } + +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org