View Javadoc

1   package org.apache.commons.digester3.annotations.atom;
2   
3   import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
4   
5   import java.io.IOException;
6   import java.util.Date;
7   
8   import org.apache.commons.beanutils.ConvertUtils;
9   import org.apache.commons.beanutils.converters.DateConverter;
10  import org.apache.commons.digester3.Digester;
11  import org.apache.commons.digester3.annotations.FromAnnotationsRuleModule;
12  import org.xml.sax.SAXException;
13  
14  /*
15   * Licensed to the Apache Software Foundation (ASF) under one
16   * or more contributor license agreements.  See the NOTICE file
17   * distributed with this work for additional information
18   * regarding copyright ownership.  The ASF licenses this file
19   * to you under the Apache License, Version 2.0 (the
20   * "License"); you may not use this file except in compliance
21   * with the License.  You may obtain a copy of the License at
22   *
23   *   http://www.apache.org/licenses/LICENSE-2.0
24   *
25   * Unless required by applicable law or agreed to in writing,
26   * software distributed under the License is distributed on an
27   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
28   * KIND, either express or implied.  See the License for the
29   * specific language governing permissions and limitations
30   * under the License.
31   */
32  
33  public final class Main
34  {
35  
36      /**
37       * @param args
38       */
39      public static void main( String[] args )
40      {
41          if ( args.length != 1 )
42          {
43              usage();
44              System.exit( -1 );
45          }
46  
47          // Drive commons-beanutils how to convert dates
48          DateConverter dateConverter = new DateConverter();
49          dateConverter.setPatterns( new String[] { "yyyy-MM-dd'T'HH:mm" } );
50          ConvertUtils.register( dateConverter, Date.class );
51  
52          String filename = args[0];
53  
54          Digester digester = newLoader( new FromAnnotationsRuleModule()
55          {
56  
57              @Override
58              protected void configureRules()
59              {
60                  bindRulesFrom( Feed.class );
61              }
62  
63          } ).newDigester();
64  
65          try
66          {
67              Feed feed = digester.parse( filename );
68              System.out.println( feed );
69          }
70          catch ( IOException ioe )
71          {
72              System.out.println( "Error reading input file:" + ioe.getMessage() );
73              System.exit( -1 );
74          }
75          catch ( SAXException se )
76          {
77              System.out.println( "Error parsing input file:" + se.getMessage() );
78              System.exit( -1 );
79          }
80      }
81  
82      private static void usage()
83      {
84          System.out.println( "Usage: java org.apache.commons.digester3.edsl.atom.Main xmlcontent.xml" );
85      }
86  
87  }