Hi Andreas,
While you are looking at the feed generator code, I've some additional
use case for you.
I implemented a simple OpenSearch service the other day.
As you can see it's an RSS 2.0 feed with in addition some specific
opensearch tags.
I think that with the feed generator code it's going to be a problem to
add these tags unless we add some groovy hooks (or implement opensearch
in the feed generator code).
It's not really urgent or important as we can still use the script based
implementation for OpenSearch but it would be nice to be able to use the
same feed generator code for opensearch as for all searches.
Ludovic
Andreas Schaefer a écrit :
  Hi
 Based on this JIRA report:
        
http://jira.xwiki.org/jira/browse/XWIKI-4430
 it would be necessary to create a new set of methods just to be able
 to pass an additional parameter to the calls. Because this makes it
 harder and harder to deal with Plugin I would suggest to use a
 Parameter Container which could contain:
 - Feed Type (Blog, Web, etc)
 - Type (Query, List or Feed )
 - List
 or
 - Query, Count and Start
 or
 - Feed
 - Metadata
 - Object Class Name
 - Output Type (RSS, Atom etc)
 Then we would only need 2 major methods:
 - SyncdFeed getFeed( FeedParams )
 - String getFeedOutput( FeedParams )
 This is what I came up so far (without the Feed Type):
      /**
       * @see #getBlogFeed(String, int, int, Map)
       * @see #getFeedOutput(SyndFeed, String)
       */
      public String getBlogFeedOutput( FeedParams params)
      {
          SyndFeed feed = getBlogFeed( params );
          String ret = getFeedOutput( feed, params.getOutputType() );
          return ret;
      }
      public SyndFeed getBlogFeed( FeedParams params)
      {
          Map<String, Object> myMetaData = Collections.emptyMap();
          if( params.getMetaData() != null ) {
              myMetaData = params.getMetaData();
          }
          Map<String, Object> blogMappings = null;
          if( params.getObjectClassName() == null ) {
              blogMappings = BLOG_FIELDS_MAPPING;
          } else {
              blogMappings = new HashMap<String, Object>();
              blogMappings.put(SyndEntryDocumentSource.FIELD_TITLE,
 params.getObjectClassName() + "_title");
              blogMappings.put
 (SyndEntryDocumentSource.FIELD_DESCRIPTION, params.getObjectClassName
 () + "_content");
              blogMappings.put
 (SyndEntryDocumentSource.FIELD_CATEGORIES, params.getObjectClassName()
 + "_category");
              blogMappings.put(SyndEntryDocumentSource.CONTENT_LENGTH,
 new Integer(400));
          }
          SyndFeed blogFeed = null;
          if( params.getType() == FeedParams.Type.QUERY ) {
              String query = params.getQuery();
              if (query == null) {
                  XWikiRequest request = getXWikiContext().getRequest();
                  String category = request.getParameter("category");
                  if (category == null || category.equals("")) {
                      query =
                          ", BaseObject as obj where
 obj.name=doc.fullName and obj.className='" + BLOG_POST_CLASS_NAME + "'
 and obj.name<>'" + BLOG_POST_TEMPLATE_NAME + "' order by
 doc.creationDate desc";
                  } else {
                      query =
                          ", BaseObject as obj, DBStringListProperty as
 prop join prop.list list where obj.name=doc.fullName and
 obj.className='" + BLOG_POST_CLASS_NAME + "' and
obj.name<>'" +
 BLOG_POST_TEMPLATE_NAME + "' and obj.id=prop.id.id and
 prop.id.name='category' and list = '"
                              + category + "' order by doc.creationDate
 desc";
                  }
              }
              blogFeed =  getFeed(
                  query, params.getCount(), params.getStart(),
 getSyndEntrySource(SyndEntryDocumentSource.class.getName(),
 blogMappings), Collections.EMPTY_MAP, fillBlogFeedMetadata(myMetaData)
              );
          } else {
              blogFeed = getFeed(
                  params.getEntries(), getSyndEntrySource
 (SyndEntryDocumentSource.class.getName(), blogMappings),
 Collections.EMPTY_MAP, fillBlogFeedMetadata(myMetaData)
 //                params.getEntries(), getSyndEntrySource
 (SyndEntryDocumentSource.class.getName(), blogMappings), myMetaData,
 fillBlogFeedMetadata(myMetaData)
              );
          }
          if (blogFeed != null) {
              blogFeed.setImage(getDefaultFeedImage());
          }
          return blogFeed;
      }
        public static class FeedParams {
          public enum Type {
              QUERY,
              LIST
          }
          private static final String DEFAULT_OUTPUT_TYPE = "rss_2.0";
          private static final int DEFAULT_COUNT = 10;
          private static final int DEFAULT_START = 0;
          private Type type;
                private List<Object> entries;
          private String query;
          private int count = DEFAULT_COUNT;
          private int start = DEFAULT_START;
                private Map<String, Object> metaData;
                private String outputType = DEFAULT_OUTPUT_TYPE;
                private String objectClassName;
          public FeedParams( List<Object> entries, String
 objectClassName, Map<String, Object> metaData, String outputType ) {
              this.type = Type.LIST;
              this.entries = entries;
              this.metaData = metaData;
              this.outputType = outputType == null ?
 DEFAULT_OUTPUT_TYPE : outputType;
              this.objectClassName = objectClassName;
          }
          public FeedParams( String query, Integer count, Integer
 start, String objectClassName, Map<String, Object> metaData, String
 outputType ) {
              this.type = Type.QUERY;
              this.count = count == null ? DEFAULT_COUNT : count;
              this.start = start == null ? DEFAULT_START: start;
              this.metaData = metaData;
              this.outputType = outputType == null ?
 DEFAULT_OUTPUT_TYPE : outputType;
              this.objectClassName = objectClassName;
          }
          public Type getType() {
              return type;
          }
          public String getQuery() {
              return query;
          }
          public int getCount() {
              return count;
          }
          public int getStart() {
              return start;
          }
          public List<Object> getEntries() {
              return entries;
          }
          public Map<String, Object> getMetaData() {
              return metaData;
          }
          public String getOutputType() {
              return outputType;
          }
          public String getObjectClassName() {
              return objectClassName;
          }
      }
 What do you think?
 -Andy
 _______________________________________________
 devs mailing list
 devs(a)xwiki.org
 
http://lists.xwiki.org/mailman/listinfo/devs