001
014
015 package com.liferay.util;
016
017 import com.liferay.portal.kernel.util.CharPool;
018 import com.liferay.portal.kernel.util.StringPool;
019
020 import com.sun.syndication.feed.synd.SyndContent;
021 import com.sun.syndication.feed.synd.SyndEntry;
022 import com.sun.syndication.feed.synd.SyndFeed;
023 import com.sun.syndication.io.FeedException;
024 import com.sun.syndication.io.SyndFeedOutput;
025
026 import java.util.List;
027
028 import org.jdom.IllegalDataException;
029
030
035 public class RSSUtil extends com.liferay.portal.kernel.util.RSSUtil {
036
037 public static String export(SyndFeed feed) throws FeedException {
038 RSSThreadLocal.setExportRSS(true);
039
040 feed.setEncoding(StringPool.UTF8);
041
042 SyndFeedOutput output = new SyndFeedOutput();
043
044 try {
045 return output.outputString(feed);
046 }
047 catch (IllegalDataException ide) {
048
049
050
051 _regexpStrip(feed);
052
053 return output.outputString(feed);
054 }
055 }
056
057 private static String _regexpStrip(String text) {
058 text = Normalizer.normalizeToAscii(text);
059
060 char[] array = text.toCharArray();
061
062 for (int i = 0; i < array.length; i++) {
063 String s = String.valueOf(array[i]);
064
065 if (!s.matches(_REGEXP_STRIP)) {
066 array[i] = CharPool.SPACE;
067 }
068 }
069
070 return new String(array);
071 }
072
073 private static void _regexpStrip(SyndFeed syndFeed) {
074 syndFeed.setTitle(_regexpStrip(syndFeed.getTitle()));
075 syndFeed.setDescription(_regexpStrip(syndFeed.getDescription()));
076
077 List<SyndEntry> syndEntries = syndFeed.getEntries();
078
079 for (SyndEntry syndEntry : syndEntries) {
080 syndEntry.setTitle(_regexpStrip(syndEntry.getTitle()));
081
082 SyndContent syndContent = syndEntry.getDescription();
083
084 syndContent.setValue(_regexpStrip(syndContent.getValue()));
085 }
086 }
087
088 private static final String _REGEXP_STRIP = "[\\d\\w]";
089
090 }