From: <jbo...@li...> - 2005-11-21 18:45:47
|
Author: adamw Date: 2005-11-21 13:45:34 -0500 (Mon, 21 Nov 2005) New Revision: 1615 Added: trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/TextEscaping.java Modified: trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java Log: Text escaping, dates for atom, rdf Modified: trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java 2005-11-21 18:33:09 UTC (rev 1614) +++ trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java 2005-11-21 18:45:34 UTC (rev 1615) @@ -335,6 +335,9 @@ return param; } + private final static String RFC_822_DATE = "EEE, d MMM yyyy HH:mm:ss Z"; + private final static String RFC_3339_DATE = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + private void generateShotokuFeeds(String portalName, Map<String, Node> feedDefs, Properties props) { Set<String> parametrized = new HashSet<String>(Arrays.asList(props.getProperty( @@ -372,8 +375,11 @@ String dateFormat = attributes.get("dateFormat"); vc.put("dateFormat", new SimpleDateFormat( dateFormat == null ? "MM/dd/yy" : dateFormat)); + vc.put("rssDateFormat", new SimpleDateFormat(RFC_822_DATE)); + vc.put("rdfDateFormat", new SimpleDateFormat(RFC_3339_DATE)); vc.put("now", Calendar.getInstance().getTime()); vc.put("baseServerAddress", baseServerAddress); + vc.put("escape", new TextEscaping()); for (String project : projects) { String feedNameReplaced = feedName.replace(PROJECT_PARAM, Added: trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/TextEscaping.java =================================================================== --- trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/TextEscaping.java 2005-11-21 18:33:09 UTC (rev 1614) +++ trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/TextEscaping.java 2005-11-21 18:45:34 UTC (rev 1615) @@ -0,0 +1,128 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This 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 software 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.forge.feeds; + +import java.text.StringCharacterIterator; + +/** + * + * @author http://www.javapractices.com/Topic96.cjp + */ +public class TextEscaping { + /** + * Replace characters having special meaning <em>inside</em> HTML tags + * with their escaped equivalents, using character entities such as + * <tt>'&'</tt>. + * + * <P> + * The escaped characters are : + * <ul> + * <li> < + * <li> > + * <li> " + * <li> ' + * <li> \ + * <li> & + * </ul> + * + * <P> + * This method ensures that arbitrary text appearing inside a tag does not + * "confuse" the tag. For example, <tt>HREF='Blah.do?Page=1&Sort=ASC'</tt> + * does not comply with strict HTML because of the ampersand, and should be + * changed to <tt>HREF='Blah.do?Page=1&Sort=ASC'</tt>. This is + * commonly seen in building query strings. (In JSTL, the c:url tag performs + * this task automatically.) + */ + public static String tags(String aTagFragment) { + if (aTagFragment == null) + return null; + + final StringBuffer result = new StringBuffer(); + + final StringCharacterIterator iterator = new StringCharacterIterator( + aTagFragment); + char character = iterator.current(); + while (character != StringCharacterIterator.DONE) { + if (character == '<') { + result.append("<"); + } else if (character == '>') { + result.append(">"); + } else if (character == '\"') { + result.append("""); + } else if (character == '\'') { + result.append("'"); + } else if (character == '\\') { + result.append("\"); + } else if (character == '&') { + result.append("&"); + } else { + // the char is not a special one + // add it to the result as is + result.append(character); + } + character = iterator.next(); + } + return result.toString(); + } + + /** + * Return <tt>aText</tt> with all start-of-tag and end-of-tag characters + * replaced by their escaped equivalents. + * + * <P> + * If user input may contain tags which must be disabled, then call this + * method, not {@link #forHTMLTag}. This method is used for text appearing + * <em>outside</em> of a tag, while {@link #forHTMLTag} is used for text + * appearing <em>inside</em> an HTML tag. + * + * <P> + * It is not uncommon to see text on a web page presented erroneously, + * because <em>all</em> special characters are escaped (as in + * {@link #forHTMLTag}). In particular, the ampersand character is often + * escaped not once but <em>twice</em> : once when the original input + * occurs, and then a second time when the same item is retrieved from the + * database. This occurs because the ampersand is the only escaped character + * which appears in a character entity. + */ + public static String all(String aText) { + if (aText == null) + return null; + + final StringBuffer result = new StringBuffer(); + final StringCharacterIterator iterator = new StringCharacterIterator( + aText); + char character = iterator.current(); + while (character != StringCharacterIterator.DONE) { + if (character == '<') { + result.append("<"); + } else if (character == '>') { + result.append(">"); + } else { + // the char is not a special one + // add it to the result as is + result.append(character); + } + character = iterator.next(); + } + return result.toString(); + } +} |