Changeset 1481

Show
Ignore:
Timestamp:
11/20/08 08:17:53 (7 weeks ago)
Author:
marcelo
Message:

Rss/Atom syndication format refactoring

Location:
branches/dev-instedd
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • branches/dev-instedd/org.javarosa.demo/build.properties

    r1231 r1481  
    2525#device.identifier=Palm/TungstenC 
    2626device.identifier=Generic/DefaultColorPhone 
     27#device.identifier=Sony-Ericsson/P1i 
    2728#device.identifier=Generic/MppPhone 
    2829#device.identifier=Palm/Treo650 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/feed/FeedReader.java

    r1480 r1481  
    9393                                if(ISyndicationFormat.SX_ELEMENT_SYNC.equals(element.getName())){ 
    9494                                        sync = readSync(element); 
    95                                 } else if(ISyndicationFormat.SX_ELEMENT_ITEM_TITLE.equals(element.getName()) || "subtitle".equals(element.getName())){ 
     95                                } else if(this.syndicationFormat.isFeedItemTitle(element)){ 
    9696                                        title = element.getText(0); 
    97                                 } else if(ISyndicationFormat.SX_ELEMENT_ITEM_DESCRIPTION.equals(element.getName())){ 
     97                                } else if(this.syndicationFormat.isFeedItemDescription(element)){ 
    9898                                        description = element.getText(0); 
    99                                 } else if(ISyndicationFormat.SX_ELEMENT_ITEM_LINK.equals(element.getName())){ 
     99                                } else if(this.syndicationFormat.isFeedItemLink(element)){ 
    100100                                        link = element.getText(0); 
    101101                                } else if(!ISyndicationFormat.SX_ELEMENT_AUTHOR.equals(element.getName())){ 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/feed/FeedWriter.java

    r1291 r1481  
    5151                this.syndicationFormat.writeStartItem(writer); 
    5252                 
    53                 this.writeContent(writer, item.getContent()); 
     53                this.writeContent(writer, item.getSync(), item.getContent(), this.syndicationFormat); 
    5454                 
    5555                String by = this.identityProvider.getAuthenticatedUser(); 
     
    7070        }        
    7171                 
    72         private void writeContent(Writer writer, IContent content) throws Exception { 
    73                 String xmlContent = XMLContent.normalizeContent(content); 
    74                 if(xmlContent != null && xmlContent.trim().length() > 0){ 
    75                         writer.write(xmlContent); 
    76                 } 
    77                  
    78                 if(content instanceof XMLContent){ 
    79                         XMLContent contentAsXMLContent = (XMLContent) content; 
    80                         if(contentAsXMLContent.getTitle() != null && contentAsXMLContent.getTitle().trim().length() > 0){ 
    81                                 writer.write("<title>"); 
    82                                 writer.write(contentAsXMLContent.getTitle()); 
    83                                 writer.write("</title>"); 
    84                         } 
    85                          
    86                         if(contentAsXMLContent.getDescription() != null && contentAsXMLContent.getDescription().trim().length() > 0){ 
    87                                 writer.write("<description>"); 
    88                                 writer.write(contentAsXMLContent.getDescription()); 
    89                                 writer.write("</description>"); 
    90                         }                
    91                 } 
     72        private void writeContent(Writer writer, Sync sync, IContent content, ISyndicationFormat format) throws Exception { 
     73                content.addToFeedPayload(writer, sync, format); 
    9274        } 
    9375 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/feed/ISyndicationFormat.java

    r1480 r1481  
    11package org.mesh4j.sync.adapters.feed; 
    22 
     3import java.io.IOException; 
    34import java.io.Writer; 
    45import java.util.Date; 
     
    1415        Element getBaseElement(Document document); 
    1516 
     17        boolean isFeedItemTitle(Element element); 
     18        boolean isFeedItemDescription(Element element); 
     19        boolean isFeedItemLink(Element element); 
     20         
    1621        Date parseDate(String dateAsString); 
    1722        String formatDate(Date date); 
     
    2227        void writeEndDocument(Writer writer) throws Exception; 
    2328         
     29        void writeStartFeedItemTitle(Writer writer) throws IOException; 
     30        void writeEndFeedItemTitle(Writer writer) throws IOException; 
     31 
     32        void writeStartFeedItemDescription(Writer writer) throws IOException; 
     33        void writeEndFeedItemDescription(Writer writer) throws IOException; 
     34 
     35        void writeStartFeedItemLink(Writer writer) throws IOException; 
     36        void writeEndFeedItemLink(Writer writer) throws IOException; 
    2437 
    2538        // / <summary> 
     
    6275        public static final String SX_ATTRIBUTE_HISTORY_WHEN = "when"; 
    6376        public static final String SX_ATTRIBUTE_HISTORY_BY = "by"; 
    64          
    65         // sx:item 
    66         public static final String SX_ELEMENT_ITEM_TITLE = "title"; 
    67         public static final String SX_ELEMENT_ITEM_DESCRIPTION = "description"; 
    68         public static final String SX_ELEMENT_ITEM_LINK = "link"; 
    69                  
     77                         
    7078} 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/feed/XMLContent.java

    r1064 r1481  
    11package org.mesh4j.sync.adapters.feed; 
    22 
     3import java.io.Writer; 
     4 
    35import org.mesh4j.sync.model.Content; 
    4 import org.mesh4j.sync.model.IContent; 
     6import org.mesh4j.sync.model.Sync; 
    57 
    68 
     
    5961    } 
    6062 
    61         public static String normalizeContent(IContent content) { 
    62                 return content.getPayloadForFeed(); 
    63         } 
    64          
    65         public String getPayloadForFeed(){ 
    66                 return this.getPayload(); 
     63        public void addToFeedPayload(Writer writer, Sync sync, ISyndicationFormat format) throws Exception{ 
     64                format.writeStartFeedItemTitle(writer); 
     65                writer.write(this.getTitle()); 
     66                format.writeEndFeedItemTitle(writer); 
     67                 
     68                format.writeStartFeedItemDescription(writer); 
     69                writer.write(this.getDescription()); 
     70                format.writeEndFeedItemDescription(writer); 
     71 
     72                writer.write(this.getPayload()); 
    6773        } 
    6874} 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/feed/atom/AtomSyndicationFormat.java

    r994 r1481  
    11package org.mesh4j.sync.adapters.feed.atom; 
    22 
     3import java.io.IOException; 
    34import java.io.Writer; 
    45import java.util.Date; 
     
    1314        private static final String ATOM_ELEMENT_FEED = "feed"; 
    1415        private static final String ATOM_ELEMENT_ENTRY = "entry"; 
     16        public static final String FEED_ITEM_ELEMENT_TITLE = "title"; 
     17        public static final String FEED_ITEM_ELEMENT_DESCRIPTION = "content"; 
     18        public static final String FEED_ITEM_ELEMENT_LINK = "link"; 
    1519        public static final AtomSyndicationFormat INSTANCE = new AtomSyndicationFormat(); 
    1620 
     
    5559                return "ATOM"; 
    5660        } 
     61 
     62        public boolean isFeedItemDescription(Element element) { 
     63                return FEED_ITEM_ELEMENT_DESCRIPTION.equals(element.getName()); 
     64        } 
     65 
     66        public boolean isFeedItemLink(Element element) { 
     67                return FEED_ITEM_ELEMENT_LINK.equals(element.getName()); 
     68        } 
     69 
     70 
     71        public boolean isFeedItemTitle(Element element) { 
     72                return FEED_ITEM_ELEMENT_TITLE.equals(element.getName()); 
     73        } 
     74 
     75        public void writeStartFeedItemDescription(Writer writer) throws IOException { 
     76                writer.write("<content>"); 
     77        } 
     78         
     79        public void writeEndFeedItemDescription(Writer writer) throws IOException { 
     80                writer.write("</content>");      
     81        } 
     82 
     83        public void writeStartFeedItemLink(Writer writer) throws IOException { 
     84                writer.write("<link>");          
     85        } 
     86 
     87        public void writeEndFeedItemLink(Writer writer) throws IOException { 
     88                writer.write("</link>");         
     89        } 
     90         
     91        public void writeStartFeedItemTitle(Writer writer) throws IOException { 
     92                writer.write("<title>"); 
     93        } 
     94 
     95        public void writeEndFeedItemTitle(Writer writer) throws IOException { 
     96                writer.write("</title>"); 
     97        } 
    5798} 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/feed/rss/RssSyndicationFormat.java

    r994 r1481  
    11package org.mesh4j.sync.adapters.feed.rss; 
    22 
     3import java.io.IOException; 
    34import java.io.Writer; 
    45import java.util.Date; 
     
    1415        public static final String RSS_ELEMENT_ITEM = "item"; 
    1516        public static final String RSS_ELEMENT_CHANNEL = "channel"; 
     17        public static final String FEED_ITEM_ELEMENT_TITLE = "title"; 
     18        public static final String FEED_ITEM_ELEMENT_DESCRIPTION = "description"; 
     19        public static final String FEED_ITEM_ELEMENT_LINK = "link"; 
    1620        public static final RssSyndicationFormat INSTANCE = new RssSyndicationFormat(); 
    1721 
     
    7680        } 
    7781 
     82        public boolean isFeedItemDescription(Element element) { 
     83                return FEED_ITEM_ELEMENT_DESCRIPTION.equals(element.getName()); 
     84        } 
     85 
     86        public boolean isFeedItemLink(Element element) { 
     87                return FEED_ITEM_ELEMENT_LINK.equals(element.getName()); 
     88        } 
     89 
     90 
     91        public boolean isFeedItemTitle(Element element) { 
     92                return FEED_ITEM_ELEMENT_TITLE.equals(element.getName()); 
     93        } 
     94 
     95        public void writeStartFeedItemDescription(Writer writer) throws IOException { 
     96                writer.write("<description>"); 
     97        } 
     98         
     99        public void writeEndFeedItemDescription(Writer writer) throws IOException { 
     100                writer.write("</description>");  
     101        } 
     102 
     103        public void writeStartFeedItemLink(Writer writer) throws IOException { 
     104                writer.write("<link>");          
     105        } 
     106 
     107        public void writeEndFeedItemLink(Writer writer) throws IOException { 
     108                writer.write("</link>");         
     109        } 
     110         
     111        public void writeStartFeedItemTitle(Writer writer) throws IOException { 
     112                writer.write("<title>"); 
     113        } 
     114 
     115        public void writeEndFeedItemTitle(Writer writer) throws IOException { 
     116                writer.write("</title>"); 
     117        } 
    78118} 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/rms/storage/EntityContent.java

    r1064 r1481  
    11package org.mesh4j.sync.adapters.rms.storage; 
    22 
     3import java.io.Writer; 
     4 
    35import org.kxml2.kdom.Element; 
     6import org.mesh4j.sync.adapters.feed.ISyndicationFormat; 
    47import org.mesh4j.sync.model.Content; 
    58import org.mesh4j.sync.model.IContent; 
     9import org.mesh4j.sync.model.Sync; 
    610import org.mesh4j.sync.utils.XmlHelper; 
    711 
     
    7781        } 
    7882 
    79         public String getPayloadForFeed() { 
    80                 StringBuffer sb = new StringBuffer(); 
    81                 sb.append("<title>"); 
    82                 sb.append(this.entityName); 
    83                 sb.append("</title>"); 
     83        public void addToFeedPayload(Writer writer, Sync sync, ISyndicationFormat format) throws Exception{ 
     84                format.writeStartFeedItemTitle(writer); 
     85                writer.write(this.entityName); 
     86                format.writeEndFeedItemTitle(writer); 
    8487                 
    85                 sb.append("<description>"); 
    86                 sb.append("Sync id: " + this.getId()); 
    87                 sb.append(" version: " + this.getVersion()); 
    88                 sb.append("</description>"); 
    89                  
    90                 sb.append(this.getPayload()); 
    91                 return sb.toString(); 
     88                format.writeStartFeedItemDescription(writer); 
     89                writer.write("Sync id: " + this.getId() ); 
     90                writer.write(" version: " + this.getVersion()); 
     91                format.writeEndFeedItemDescription(writer); 
     92 
     93                writer.write(this.getPayload()); 
    9294        } 
    9395} 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/adapters/rms/storage/RmsRecordContent.java

    r1064 r1481  
    11package org.mesh4j.sync.adapters.rms.storage; 
    22 
     3import java.io.Writer; 
     4 
     5import org.mesh4j.sync.adapters.feed.ISyndicationFormat; 
    36import org.mesh4j.sync.model.IContent; 
     7import org.mesh4j.sync.model.Sync; 
    48import org.mesh4j.sync.validations.Guard; 
    59 
     
    9094        } 
    9195 
    92         public String getPayloadForFeed() { 
    93                 StringBuffer sb = new StringBuffer(); 
    94                 sb.append("<title>"); 
    95                 sb.append(this.entityName); 
    96                 sb.append("</title>"); 
     96        public void addToFeedPayload(Writer writer, Sync sync, ISyndicationFormat format) throws Exception{ 
     97                format.writeStartFeedItemTitle(writer); 
     98                writer.write(this.entityName); 
     99                format.writeEndFeedItemTitle(writer); 
    97100                 
    98                 sb.append("<description>"); 
    99                 sb.append("Sync id: " + this.syncId); 
    100                 sb.append(" version: " + this.getVersion()); 
    101                 sb.append("</description>"); 
    102                  
    103                 sb.append(this.payload); 
    104                 return sb.toString(); 
     101                format.writeStartFeedItemDescription(writer); 
     102                writer.write("Sync id: " + this.syncId ); 
     103                writer.write(" version: " + this.getVersion()); 
     104                format.writeEndFeedItemDescription(writer); 
     105 
     106                writer.write(this.payload); 
    105107        } 
    106108} 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/model/IContent.java

    r1064 r1481  
    11package org.mesh4j.sync.model; 
     2 
     3import java.io.Writer; 
     4 
     5import org.mesh4j.sync.adapters.feed.ISyndicationFormat; 
    26 
    37public interface IContent{ 
     
    1115        int getVersion(); 
    1216 
    13         String getPayloadForFeed(); 
    14  
     17        void addToFeedPayload(Writer writer, Sync sync, ISyndicationFormat format) throws Exception; 
    1518} 
  • branches/dev-instedd/org.mesh4j.sync/src/org/mesh4j/sync/model/NullContent.java

    r1064 r1481  
    11package org.mesh4j.sync.model; 
    22 
     3import java.io.Writer; 
     4 
     5import org.mesh4j.sync.adapters.feed.ISyndicationFormat; 
    36import org.mesh4j.sync.validations.Guard; 
    47 
     
    5255        } 
    5356 
    54         public String getPayloadForFeed() { 
    55                 StringBuffer sb = new StringBuffer(); 
    56                 sb.append("<title>deleted</title>");             
    57                 sb.append("<description>deleted</description>"); 
    58                 return sb.toString(); 
     57        public void addToFeedPayload(Writer writer, Sync sync, ISyndicationFormat format) throws Exception{ 
     58                format.writeStartFeedItemTitle(writer); 
     59                if(sync.isDeleted()){ 
     60                        writer.write("--DELETED--"); 
     61                } else { 
     62                        writer.write("--UNKNOWN--"); 
     63                } 
     64                format.writeEndFeedItemTitle(writer); 
     65                 
     66                format.writeStartFeedItemDescription(writer); 
     67                writer.write("Id: " + this.getId() + " version: " + this.getVersion()); 
     68                format.writeEndFeedItemDescription(writer); 
    5969        } 
    6070}