View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package com.sun.syndication.io.impl;
18  
19  import com.sun.syndication.io.WireFeedGenerator;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  /***
28   * Generates an XML document (JDOM Document) out of a Feed.
29   * <p>
30   * It can generate all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and
31   * Atom 0.3 feed.
32   * <p>
33   * WireFeedGenerator instances are thread safe.
34   * <p>
35   * Generators for a specific type must extend this class and register in the generator list.
36   * (Right now registration is hardcoded in the WireFeedGenerator constructor).
37   * <p>
38   * @author Alejandro Abdelnur
39   *
40   */
41  public class FeedGenerators {
42      private Map _generators;
43  
44      private List _types;
45  
46      private Map loadGenerators(String defaultFile,String fileProperty) {
47          Map map = new HashMap();
48          PlugableClasses pClasses = new PlugableClasses(defaultFile,fileProperty,Constants.FEED_GENERATORS_KEY,
49                                                         true,FeedGenerators.class.getClassLoader());
50          Object[] generators;
51          try {
52              generators = pClasses.createInstances();
53          }
54          catch (Exception ex) {
55              throw new RuntimeException(ex);
56          }
57          for (int i=0;i<generators.length;i++) {
58  
59              WireFeedGenerator generator  = (WireFeedGenerator) generators[i];
60              map.put(generator.getType(),generator);
61          }
62          return map;
63      }
64  
65      public FeedGenerators() {
66          this(Constants.DEFAULT_IMPLS_FILE,Constants.IMPLS_SYSTEM_PROPERTY);
67      }
68  
69      public FeedGenerators(String defaultFile,String fileProperty) {
70          _generators = loadGenerators(defaultFile,fileProperty);
71          _types = Collections.unmodifiableList(new ArrayList(_generators.keySet()));
72      }
73  
74      public List getSupportedFeedTypes() {
75          return _types;
76      }
77  
78      public WireFeedGenerator getGenerator(String feedType) {
79          return (WireFeedGenerator) _generators.get(feedType);
80      }
81  
82  }