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