[Lutinweb-commits] r1 - / trunk trunk/lutinrss trunk/lutinrss/src trunk/lutinrss/src/main trunk/lutinrss/src/main/java trunk/lutinrss/src/main/java/org trunk/lutinrss/src/main/java/org/codelutin trunk/lutinrss/src/main/java/org/codelutin/rss trunk/lutinrss/src/main/resources trunk/lutinrss/src/main/resources/i18n trunk/lutinrss/src/main/webapp trunk/lutinrss/src/main/webapp/WEB-INF trunk/lutinrss/src/site trunk/lutinrss/src/site/fr trunk/lutinrss/src/site/fr/rst trunk/lutinrss/src/test trunk/lutinrss/src/te
Author: bpoussin Date: 2008-04-18 16:23:03 +0000 (Fri, 18 Apr 2008) New Revision: 1 Added: trunk/ trunk/lutinrss/ trunk/lutinrss/LICENSE.txt trunk/lutinrss/pom.xml trunk/lutinrss/src/ trunk/lutinrss/src/main/ trunk/lutinrss/src/main/java/ trunk/lutinrss/src/main/java/org/ trunk/lutinrss/src/main/java/org/codelutin/ trunk/lutinrss/src/main/java/org/codelutin/rss/ trunk/lutinrss/src/main/java/org/codelutin/rss/FeedData.java trunk/lutinrss/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRenderer.java trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRendererConfig.java trunk/lutinrss/src/main/java/org/codelutin/rss/FeedURLResolver.java trunk/lutinrss/src/main/java/org/codelutin/rss/Field.java trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLCleaner.java trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java trunk/lutinrss/src/main/java/org/codelutin/rss/RSSConfig.java trunk/lutinrss/src/main/java/org/codelutin/rss/RSSHelper.java trunk/lutinrss/src/main/java/org/codelutin/rss/RSSServlet.java trunk/lutinrss/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java trunk/lutinrss/src/main/resources/ trunk/lutinrss/src/main/resources/i18n/ trunk/lutinrss/src/main/resources/i18n/lutinrss-en_GB.properties trunk/lutinrss/src/main/resources/i18n/lutinrss-fr_FR.properties trunk/lutinrss/src/main/webapp/ trunk/lutinrss/src/main/webapp/WEB-INF/ trunk/lutinrss/src/main/webapp/WEB-INF/web.xml trunk/lutinrss/src/main/webapp/rssinclude.js trunk/lutinrss/src/main/webapp/test.html trunk/lutinrss/src/site/ trunk/lutinrss/src/site/fr/ trunk/lutinrss/src/site/fr/rst/ trunk/lutinrss/src/site/fr/rst/index.rst trunk/lutinrss/src/test/ trunk/lutinrss/src/test/java/ trunk/lutinrss/src/test/java/org/ trunk/lutinrss/src/test/java/org/codelutin/ trunk/lutinrss/src/test/java/org/codelutin/rss/ trunk/lutinrss/src/test/java/org/codelutin/rss/RSSTest.java trunk/lutinrss/svn-commit.tmp Log: Ajout du projet lutinrss Added: trunk/lutinrss/LICENSE.txt =================================================================== --- trunk/lutinrss/LICENSE.txt (rev 0) +++ trunk/lutinrss/LICENSE.txt 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,280 @@ + 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 Added: trunk/lutinrss/pom.xml =================================================================== --- trunk/lutinrss/pom.xml (rev 0) +++ trunk/lutinrss/pom.xml 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,133 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<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> + + <!--lutinproject.xml--> +<!-- + <parent> + <groupId>lutinlib</groupId> + <artifactId>lutinproject</artifactId> + <version>2.2</version> + </parent> +--> + + <distributionManagement> + <site> + <id>labs</id> + <url>scp://labs.libre-entreprise.org/home/groups/${pom.artifactId}/htdocs/</url> + </site> + </distributionManagement> + + <!--A unique name for this project--> + <groupId>lutinlib</groupId> + <artifactId>lutinrss</artifactId> + <name>LutinRSS</name> + + <!--ejb, jar, war...--> + <packaging>war</packaging> + + <!--Version--> + <version>1.0</version> + + <!--Description--> + <description>Servlet pouvant �tre appeler depuis du JS pour r�cup�rer 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</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2</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>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>project</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <properties> +<!-- <maven.test.skip>true</maven.test.skip> --> + <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> Added: trunk/lutinrss/src/main/java/org/codelutin/rss/FeedData.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/FeedData.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/FeedData.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,66 @@ +package org.codelutin.rss; + + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.XmlReader; +import java.net.URL; +import java.util.Iterator; +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); + + protected URL url = null; + protected SyndFeed feed = null; + protected long lastRetrived = 0; + + public FeedData(URL url) { + this.url = url; + } + + /** + * Retourne la representation HTML du RSS + * + * @param nbItem le nombre d'item souhaite, si inferieur a 0, alors tous + * @return + */ + 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 { + SyndFeedInput input = new SyndFeedInput(); + feed = input.build(new XmlReader(url)); + lastRetrived = System.currentTimeMillis(); + } catch (Exception eee) { + log.warn("Can't get feed: " + url, eee); + } + } + } +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/FeedHTMLRenderer.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,133 @@ +/* + * 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); + + /** 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); + + public FeedHTMLRenderer(HTMLCleaner ... cleaners) { + for (HTMLCleaner cleaner : cleaners) { + addHTMLCleaner(cleaner); + } + + templates.put(Field.NAME, "<span class=\"%1$s\">%2$s</span>\n"); + 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"); + templates.put(Field.TIME, "<span class=\"%1$s\">%2$tF</span>\n"); + + classnames.put(Field.NAME, "name"); + 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.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.IMAGE, null); + itemProperties.put(Field.DESCRIPTION, "description.value"); + itemProperties.put(Field.AUTHOR, "author"); + itemProperties.put(Field.TIME, "publishedDate"); + } + + public void addHTMLCleaner(HTMLCleaner cleaner) { + cleaners.add(cleaner); + } + + /** + * 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) { + String result = ""; + 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); + } + } + result += String.format(template, classname, value); + } + return result; + } + + public String render(FeedRendererConfig config, SyndFeed feed, SyndEntry[] items) { + String result = ""; + for (Field f : config.getFeedFieldOrder()) { + String template = templates.get(f); + String classname = "feed-" + classnames.get(f); + String prop = feedProperties.get(f); + + if (!"".equals(prop)) { + try { + result += render(template, classname, BeanUtils.getProperty(feed, prop)); + } catch (Exception eee) { + log.warn("Can't get feed property value for property " + prop, eee); + } + } + } + + if (!"".equals(result)) { + result = "<div class='rss-feed'>\n" + result + "</div>\n"; + } + + result += "<ul class='rss-items'>\n"; + for (SyndEntry item : items) { + result += "<li>\n"; + for (Field f : config.getItemFieldOrder()) { + String template = templates.get(f); + String classname = "feedItem-" + classnames.get(f); + String prop = itemProperties.get(f); + + if (!"".equals(prop)) { + try { + result += render(template, classname, BeanUtils.getProperty(item, prop)); + } catch (Exception eee) { + log.warn("Can't get item property value for property " + prop, eee); + } + } + } + result += "</li>\n"; + } + result += "</ul>\n"; + + return result; + } + +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRenderer.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRenderer.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRenderer.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,26 @@ +/* + * 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); +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRendererConfig.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRendererConfig.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/FeedRendererConfig.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,114 @@ +/* + * 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()) { + switch (c) { + case 'n': + result.add(Field.NAME); + break; + case 'i': + result.add(Field.IMAGE); + break; + case 'd': + result.add(Field.DESCRIPTION); + break; + case 'a': + result.add(Field.AUTHOR); + break; + case 't': + result.add(Field.TIME); + break; + } + } + 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; + } + +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/FeedURLResolver.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/FeedURLResolver.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/FeedURLResolver.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,21 @@ +/* + * 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 URL resolv(String ask) throws MalformedURLException; +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/Field.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/Field.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/Field.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,17 @@ +/* + * 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, IMAGE, DESCRIPTION, AUTHOR, TIME +} + Added: trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLCleaner.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLCleaner.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLCleaner.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,17 @@ +/* + * 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); + +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/HTMLScriptCleaner.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,22 @@ +/* + * 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; + } + +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/RSSConfig.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/RSSConfig.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/RSSConfig.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,11 @@ +package org.codelutin.rss; + +/** + * + * @author poussin + */ +public class RSSConfig { + + /** Temps a partir duquel on reforce une recuperation */ + public static long TIME_FORCE_RETRIEVED = 1000; // 5 * 60 * 1000; +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/RSSHelper.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/RSSHelper.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/RSSHelper.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,87 @@ +/* + * 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.net.URL; +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(\"...\"); */ + private static final Log log = LogFactory.getLog(RSSHelper.class); + + /** 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; + } + + /** + * 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 + * @return le code html representant le feed + */ + public String getHTML(String feedName, String representation, int nbItem) { + try { + FeedData feed = (FeedData) feeds.get(feedName); + if (feed == null) { + URL url = resolver.resolv(feedName); + feed = new FeedData(url); + feeds.put(feedName, feed); + } + + SyndFeed sf = feed.getFeed(); + List syndEntries = sf.getEntries(); + if (nbItem >= 0 && syndEntries.size() >= nbItem) { + syndEntries = syndEntries.subList(syndEntries.size() - nbItem, syndEntries.size()); + } + SyndEntry [] items = (SyndEntry[])syndEntries.toArray(new SyndEntry[syndEntries.size()]); + + FeedRendererConfig c = new FeedRendererConfig(representation); + + 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>"; + } + } +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/RSSServlet.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/RSSServlet.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/RSSServlet.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,159 @@ +package org.codelutin.rss; + +import java.io.*; +import java.net.*; + +import javax.servlet.*; +import javax.servlet.http.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * <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 HttpServlet { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static final Log log = LogFactory.getLog(RSSServlet.class); + + /** + * L'objet permettant de recupérer la representation HTML d'un feed + */ + protected RSSHelper rss; + /** + * Le code JavaScript a utilise dans les pages clientes + */ + protected String js = + "function rssinclude(feedName, iddiv, nbItem, feedRepr) {\n" + + " var serlvetUrl = \"%1$s\";\n" + + " var div = document.getElementById(iddiv);\n" + + " var xhr = null;\n" + + " if(window.XMLHttpRequest) // Firefox\n" + + " xhr = new XMLHttpRequest();\n" + + " else if(window.ActiveXObject) // Internet Explorer\n" + + " xhr = new ActiveXObject(\"Microsoft.XMLHTTP\");\n" + + " else { // XMLHttpRequest non supporté par le navigateur\n" + + " div.innerHTML = \"<span class='feed-error'>Votre navigateur ne supporte pas les objets XMLHTTPRequest...</span>\";\n" + + " return;\n" + + " }\n" + + " if (!nbItem) {\n" + + " nbItem = -1;\n" + + " }\n" + + " if (!feedRepr) {\n" + + " feedRepr = \"\";\n" + + " }\n" + + " var param = \"feedName=\" + escape(feedName) + \"&nbItem=\" + escape(nbItem) + \"&feedRepr=\" + escape(feedRepr);\n" + + " var url = serlvetUrl + \"?\" + param;\n" + + " xhr.open(\"GET\", url, true);\n" + + " xhr.onreadystatechange = function() {\n" + + " if(xhr.readyState == 4) {\n" + + " div.innerHTML = xhr.responseText;\n" + + " }\n" + + " }\n" + + " xhr.send(null);\n" + + "}\n"; + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + rss = new RSSHelper(); + } + + /** + * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. + * @param request servlet request + * @param response servlet response + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String feedName = request.getParameter("feedName"); + if (feedName == null || "".equals(feedName)) { + // on renvoie le code js + response.setContentType("text/plain;charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + String code = String.format(js, request.getRequestURL().toString()); + out.println(code); + } finally { + out.close(); + } + } else { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + String feedRepr = request.getParameter("feedRepr"); + if (null == feedRepr || "".equals(feedRepr)) { + feedRepr = "n-ndat"; + } + int nbItem = convertToInt(request.getParameter("nbItem")); + + out.println(rss.getHTML(feedName, feedRepr, nbItem)); + + } finally { + out.close(); + } + } + } + + protected int convertToInt(String parameter) { + int result = -1; + 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> +} Added: trunk/lutinrss/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/SimpleFeedURLResolver.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,22 @@ +/* + * 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; + +/** + * + * @author poussin + */ +public class SimpleFeedURLResolver implements FeedURLResolver { + + public URL resolv(String ask) throws MalformedURLException { + URL result = new URL(ask); + return result; + } + +} Added: trunk/lutinrss/src/main/resources/i18n/lutinrss-en_GB.properties =================================================================== --- trunk/lutinrss/src/main/resources/i18n/lutinrss-en_GB.properties (rev 0) +++ trunk/lutinrss/src/main/resources/i18n/lutinrss-en_GB.properties 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1 @@ +#Tue Apr 15 21:14:24 CEST 2008 Added: trunk/lutinrss/src/main/resources/i18n/lutinrss-fr_FR.properties =================================================================== Added: trunk/lutinrss/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/lutinrss/src/main/webapp/WEB-INF/web.xml (rev 0) +++ trunk/lutinrss/src/main/webapp/WEB-INF/web.xml 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee + http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + + <display-name>RSSServlet</display-name> + + <servlet> + <servlet-name>RSSServlet</servlet-name> + <servlet-class>org.codelutin.rss.RSSServlet</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>RSSServlet</servlet-name> + <url-pattern>/RSSServlet</url-pattern> + </servlet-mapping> + +</web-app> Added: trunk/lutinrss/src/main/webapp/rssinclude.js =================================================================== --- trunk/lutinrss/src/main/webapp/rssinclude.js (rev 0) +++ trunk/lutinrss/src/main/webapp/rssinclude.js 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,32 @@ +function rssinclude(feedName, iddiv, nbItem, feedRepr) { + var serlvetUrl = "http://localhost:8080/lutinrss-1.0/RSSServlet"; + var div = document.getElementById(iddiv); + + var xhr = null; + if(window.XMLHttpRequest) // Firefox + xhr = new XMLHttpRequest(); + else if(window.ActiveXObject) // Internet Explorer + xhr = new ActiveXObject("Microsoft.XMLHTTP"); + else { // XMLHttpRequest non supporté par le navigateur + div.innerHTML = "<span class='feed-error'>Votre navigateur ne supporte pas les objets XMLHTTPRequest...</span>"; + return; + } + + if (!nbItem) { + nbItem = -1; + } + if (!feedRepr) { + feedRepr = ""; + } + + var param = "feedName=" + escape(feedName) + "&nbItem=" + escape(nbItem) + "&feedRepr=" + escape(feedRepr); + var url = serlvetUrl + "?" + param; + + xhr.open("GET", url, true); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4) { + div.innerHTML = xhr.responseText; + } + } + xhr.send(null); +} \ No newline at end of file Added: trunk/lutinrss/src/main/webapp/test.html =================================================================== --- trunk/lutinrss/src/main/webapp/test.html (rev 0) +++ trunk/lutinrss/src/main/webapp/test.html 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,35 @@ +<!-- + Document : test + Created on : 18 avr. 2008, 11:46:56 + Author : poussin +--> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + <head> + <title></title> + <style type="text/css"> + div {border: solid black;} + </style> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <script src="RSSServlet"></script> + </head> + <body> + <h1>Test RSS</h1> + <div id="lmi"></div> + <div id="lemonde"></div> + <div id="developpez"></div> + <div id="formatouvert"></div> + <div id="h2"></div> + <div id="opensi"></div> + + <script> + rssinclude("http://www.lemondeinformatique.fr/flux-rss/open-source/rss.xml", "lmi", 5, "indat-natd"); + rssinclude("http://www.lemonde.fr/rss/sequence/0,2-3208,1-0,0.xml", "lemonde", 5, "indat-natd"); + rssinclude("http://blog.developpez.com/xmlsrv/rss2.php?blog=42", "developpez", 5, "indat-natd"); + rssinclude("http://formats-ouverts.org/rss.php", "formatouvert", 5, "indat-natd"); + rssinclude("http://www.h2database.com/html/newsfeed-rss.xml", "h2", 5, "indat-natd"); + rssinclude("http://www.opensi.org/news.rss", "opensi", 5, "indat-natd"); + </script> + + </body> +</html> Added: trunk/lutinrss/src/site/fr/rst/index.rst =================================================================== --- trunk/lutinrss/src/site/fr/rst/index.rst (rev 0) +++ trunk/lutinrss/src/site/fr/rst/index.rst 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,12 @@ +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 Added: trunk/lutinrss/src/test/java/org/codelutin/rss/RSSTest.java =================================================================== --- trunk/lutinrss/src/test/java/org/codelutin/rss/RSSTest.java (rev 0) +++ trunk/lutinrss/src/test/java/org/codelutin/rss/RSSTest.java 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,81 @@ +/* + * 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 { + 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. + */ + 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); + System.out.println("***" + result); + result = instance.getHTML(feedName, feedRepr, nbItem); + System.out.println("***" + result); + + Thread.sleep(2000); + + result = instance.getHTML(feedName, feedRepr, nbItem); + System.out.println("***" + result); + result = instance.getHTML(feedName, feedRepr, nbItem); + 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."); + } + +} Added: trunk/lutinrss/svn-commit.tmp =================================================================== --- trunk/lutinrss/svn-commit.tmp (rev 0) +++ trunk/lutinrss/svn-commit.tmp 2008-04-18 16:23:03 UTC (rev 1) @@ -0,0 +1,4 @@ +ajout du projet lutinrss +--Cette ligne, et les suivantes ci-dessous, seront ignorées-- + +A .
participants (1)
-
bpoussin@users.labs.libre-entreprise.org