001package org.apache.maven.doxia.module.confluence.parser;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.doxia.util.ByLineSource;
023import org.apache.maven.doxia.parser.ParseException;
024
025/**
026 * <p>VerbatimBlockParser class.</p>
027 *
028 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
029 */
030public class VerbatimBlockParser
031    implements BlockParser
032{
033    static final String LS = System.getProperty( "line.separator" );
034
035    /** {@inheritDoc} */
036    public boolean accept( String line, ByLineSource source )
037    {
038        if ( line.startsWith( "{code" ) || line.startsWith( "{noformat}" ) )
039        {
040            return true;
041        }
042
043        return false;
044    }
045
046    /** {@inheritDoc} */
047    public Block visit( String line, ByLineSource source )
048        throws ParseException
049    {
050        StringBuilder text = new StringBuilder();
051
052        while ( ( line = source.getNextLine() ) != null )
053        {
054            if ( line.startsWith( "{code}" ) || line.startsWith( "{noformat}" ) )
055            {
056                break;
057            }
058
059            // TODO
060            text.append( line ).append( LS );
061        }
062
063        return new VerbatimBlock( text.toString() );
064    }
065}