View Javadoc

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