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