1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
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  package org.apache.commons.betwixt;
17  
18  import java.io.FileInputStream;
19  import java.io.InputStream;
20  
21  import org.apache.commons.betwixt.io.BeanWriter;
22  import org.apache.commons.digester.rss.RSSDigester;
23  
24  /*** Reads an RSS file using Digesters's RSS demo then uses Betwixt
25    * to output it as XML again.
26    *
27    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
28    * @version $Revision: 1.4 $
29    */
30  public class RSSBeanWriter extends AbstractTestCase {
31      
32      public RSSBeanWriter(String testName) {
33          super(testName);
34      }
35  
36      public static void main(String[] args) throws Exception {
37          RSSBeanWriter sample = new RSSBeanWriter("RSS");
38          sample.run( args );
39      }
40      
41      public void run(String[] args) throws Exception {
42          RSSDigester digester = new RSSDigester();
43          Object bean = null;
44          if ( args.length > 0 ) {
45              bean = digester.parse( args[0] );
46          }
47          else {
48              InputStream in = new FileInputStream( getTestFile("src/test/org/apache/commons/betwixt/rss-example.xml") );
49              bean = digester.parse( in ); 
50              in.close();
51          }
52          
53          write( bean );
54      }
55          
56      public void write(Object bean) throws Exception {
57          BeanWriter writer = new BeanWriter();
58          writer.getXMLIntrospector().setAttributesForPrimitives(false);
59          writer.enablePrettyPrint();
60          writer.write( bean );
61      }
62  }
63