001package org.apache.commons.digester3.annotations.atom;
002
003import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
004
005import java.io.IOException;
006import java.util.Date;
007
008import org.apache.commons.beanutils.ConvertUtils;
009import org.apache.commons.beanutils.converters.DateConverter;
010import org.apache.commons.digester3.Digester;
011import org.apache.commons.digester3.annotations.FromAnnotationsRuleModule;
012import org.xml.sax.SAXException;
013
014/*
015 * Licensed to the Apache Software Foundation (ASF) under one
016 * or more contributor license agreements.  See the NOTICE file
017 * distributed with this work for additional information
018 * regarding copyright ownership.  The ASF licenses this file
019 * to you under the Apache License, Version 2.0 (the
020 * "License"); you may not use this file except in compliance
021 * with the License.  You may obtain a copy of the License at
022 *
023 *   http://www.apache.org/licenses/LICENSE-2.0
024 *
025 * Unless required by applicable law or agreed to in writing,
026 * software distributed under the License is distributed on an
027 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
028 * KIND, either express or implied.  See the License for the
029 * specific language governing permissions and limitations
030 * under the License.
031 */
032
033public final class Main
034{
035
036    /**
037     * @param args
038     */
039    public static void main( String[] args )
040    {
041        if ( args.length != 1 )
042        {
043            usage();
044            System.exit( -1 );
045        }
046
047        // Drive commons-beanutils how to convert dates
048        DateConverter dateConverter = new DateConverter();
049        dateConverter.setPatterns( new String[] { "yyyy-MM-dd'T'HH:mm" } );
050        ConvertUtils.register( dateConverter, Date.class );
051
052        String filename = args[0];
053
054        Digester digester = newLoader( new FromAnnotationsRuleModule()
055        {
056
057            @Override
058            protected void configureRules()
059            {
060                bindRulesFrom( Feed.class );
061            }
062
063        } ).newDigester();
064
065        try
066        {
067            Feed feed = digester.parse( filename );
068            System.out.println( feed );
069        }
070        catch ( IOException ioe )
071        {
072            System.out.println( "Error reading input file:" + ioe.getMessage() );
073            System.exit( -1 );
074        }
075        catch ( SAXException se )
076        {
077            System.out.println( "Error parsing input file:" + se.getMessage() );
078            System.exit( -1 );
079        }
080    }
081
082    private static void usage()
083    {
084        System.out.println( "Usage: java org.apache.commons.digester3.edsl.atom.Main xmlcontent.xml" );
085    }
086
087}