4 Replies Latest reply on Jul 20, 2008 9:58 PM by susnet.susanne.susnet.se

    CDATA and formattedText in RSS XML

    susnet.susanne.susnet.se

      I want to create a RSS feed.


      The problem is this:


      
      <description>
      
      <![CDATA[ 
      
      <s:formattedText value="#{blogEntry.content}" />
      
      ]]>
      
      </description>



      The s:formattedText is generated as


      <description>
      
      <![CDATA[
      
           &lt;s:formattedText value="And here goes my text
      
      where swedish chars å,ä,ö has been replaced by ouml; &aring; and &auml; bla bla bla etc etc until the end of the text./&gt;
      
           ]]>
      
      </description>



      Question is: How do I combine the CDATA tag with s:formattedText?



      My whole RSS xml file looks like this:



      <?xml version="1.0" encoding="ISO-8859-1"?>
      
      <rss version="2.0"      
      
           xmlns:ui="http://java.sun.com/jsf/facelets"
      
           xmlns:h="http://java.sun.com/jsf/html"     
      
           xmlns:s="http://jboss.com/products/seam/taglib"
      
           xmlns:f="http://java.sun.com/jsf/core">
      
        <f:view>
      
        <channel>
      
          <title>Recepten.se RSS</title>
      
          <description>RSS 2.0 Channel</description>
      
          <language>sv-se</language>
      
          <h:outputText escape="false" value="&lt;link>http://www.recepten.se/blogg&lt;/link>"/>
      
          <ui:repeat value="#{latestBlogEntries}" var="blogEntry">
      
            <item>
      
           <title><h:outputText escape="false" value="#{blogEntry.title}"/></title>          
      
           <description>
      
           <![CDATA[
      
           <s:formattedText value="#{blogEntry.content}" />
      
           ]]>
      
           </description>
      
           <pubDate><h:outputText value="#{blogEntry.published}">
      
               <f:convertDateTime locale="en_US" timezone="GMT" pattern="EEE, dd MMM yyyy HH:mm:ss z"/>
      
           </h:outputText></pubDate>
      
           <guid isPermaLink="true">http://www.recepten.se#{blogEntry.URL}</guid>
      
            </item>
      
          </ui:repeat>    
      
        </channel>   
      
        </f:view>
      
      </rss>




      Any help is appreciated!

        • 1. Re: CDATA and formattedText in RSS XML
          gavin.king

          Call the Seam Text parser directly in code, instead of using s:formattedText. It's in the org.jboss.seam.text package.

          • 2. Re: CDATA and formattedText in RSS XML
            susnet.susanne.susnet.se

            Thanks for your answer, it solved my problem!


            If someone else wonder how, I post my code here. I added the following method to my blogEntry entity:



            import java.io.Reader;
            
            import java.io.Serializable;
            
            import java.io.StringReader;
            
            import java.util.*;
            
            import javax.faces.context.FacesContext;
            
            import javax.persistence.*;
            
            import javax.servlet.http.HttpServletResponse;
            
            import org.jboss.seam.text.*;
            
            
            public String getFormattedContent() {
            
                   HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance ().getExternalContext ().getResponse ();
            
                   response.setContentType ("application/rss+xml");
            
            
                   Reader r = new StringReader(content);
            
                   SeamTextLexer lexer = new SeamTextLexer(r);
            
                   SeamTextParser parser = new SeamTextParser(lexer);
            
                   try {
            
                        parser.startRule();           
            
                   }
            
                   catch (Exception e) {
            
                        System.out.println(e.getMessage());
            
                   }
            
                  return parser.toString();
            
              }



            where content is the String property containing the seam text.

            • 3. Re: CDATA and formattedText in RSS XML
              tony.herstell1

              This code appears not to work.
              Some problem with new SeamTextParser(lexer)


              Any ideas?

              • 4. Re: CDATA and formattedText in RSS XML
                susnet.susanne.susnet.se

                This code I use in production with Seam 2.0.2.SP1 and it works just fine. It is the same as the code above except that I add the CDATA strings to start and end of the string that i return (and also don't print the CDATA string in the xhtml file).


                public String getFormattedContent() {
                       HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance ().getExternalContext ().getResponse ();
                       response.setContentType ("application/rss+xml");
                
                       Reader r = new StringReader(content);
                       SeamTextLexer lexer = new SeamTextLexer(r);
                       SeamTextParser parser = new SeamTextParser(lexer);
                       try {
                            parser.startRule();           
                       }
                       catch (Exception e) {
                            System.out.println(e.getMessage());
                       }
                      StringBuilder formattedContentBuilder = new StringBuilder();
                       formattedContentBuilder.append("<![CDATA[");
                       formattedContentBuilder.append(parser.toString());
                       formattedContentBuilder.append("]]>");
                      return formattedContentBuilder.toString();
                  }