/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.util; import com.liferay.portal.kernel.util.CharPool; import com.liferay.portal.kernel.util.StringPool; import com.sun.syndication.feed.synd.SyndContent; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.SyndFeedOutput; import java.util.List; import org.jdom.IllegalDataException; /** * @author Brian Wing Shun Chan * @author Eduardo Garcia * @see com.liferay.rss.util.RSSUtil */ public class RSSUtil extends com.liferay.portal.kernel.util.RSSUtil { public static String export(SyndFeed feed) throws FeedException { RSSThreadLocal.setExportRSS(true); feed.setEncoding(StringPool.UTF8); SyndFeedOutput output = new SyndFeedOutput(); try { return output.outputString(feed); } catch (IllegalDataException ide) { // LEP-4450 _regexpStrip(feed); return output.outputString(feed); } } private static String _regexpStrip(String text) { text = Normalizer.normalizeToAscii(text); char[] array = text.toCharArray(); for (int i = 0; i < array.length; i++) { String s = String.valueOf(array[i]); if (!s.matches(_REGEXP_STRIP)) { array[i] = CharPool.SPACE; } } return new String(array); } private static void _regexpStrip(SyndFeed syndFeed) { syndFeed.setTitle(_regexpStrip(syndFeed.getTitle())); syndFeed.setDescription(_regexpStrip(syndFeed.getDescription())); List<SyndEntry> syndEntries = syndFeed.getEntries(); for (SyndEntry syndEntry : syndEntries) { syndEntry.setTitle(_regexpStrip(syndEntry.getTitle())); SyndContent syndContent = syndEntry.getDescription(); syndContent.setValue(_regexpStrip(syndContent.getValue())); } } private static final String _REGEXP_STRIP = "[\\d\\w]"; }