/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.wicket.markup.parser;

import java.text.ParseException;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.HtmlSpecialTag;
import org.apache.wicket.markup.Markup;
import org.apache.wicket.markup.MarkupElement;
import org.apache.wicket.markup.MarkupParser;
import org.apache.wicket.markup.MarkupResourceStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Base class for markup filters
 * 
 * @author Jonathan Locke
 * @author Juergen Donnerstag
 */
public abstract class AbstractMarkupFilter implements IMarkupFilter
{
	/** Log. */
	private static final Logger log = LoggerFactory.getLogger(AbstractMarkupFilter.class);

	/** The markup created by reading the markup file */
	private final MarkupResourceStream markupResourceStream;

	/** The next MarkupFilter in the chain */
	private IMarkupFilter parent;

	/**
	 * Construct.
	 */
	public AbstractMarkupFilter()
	{
		this(null);
	}

	public AbstractMarkupFilter(final MarkupResourceStream markupResourceStream)
	{
		this.markupResourceStream = markupResourceStream;
	}


	/**
	 * @return The next MarkupFilter in the chain
	 */
	@Override
	public IMarkupFilter getNextFilter()
	{
		return parent;
	}

	/**
	 * Set new parent.
	 * 
	 * @param parent
	 *            The parent of this component The next element in the chain
	 */
	@Override
	public void setNextFilter(final IMarkupFilter parent)
	{
		this.parent = parent;
	}

	/**
	 * Get the next xml element from the markup. If eof, than retun null. Ignore raw markup. Invoke
	 * nextTag(tag) if a tag was found.
	 */
	@Override
	public MarkupElement nextElement() throws ParseException
	{
		MarkupElement elem = getNextFilter().nextElement();
		if (elem != null)
		{
			if (elem instanceof ComponentTag)
			{
				elem = onComponentTag((ComponentTag)elem);
			}
			else if (elem instanceof HtmlSpecialTag)
			{
				elem = onSpecialTag((HtmlSpecialTag)elem);
			}
		}
		return elem;
	}

	/**
	 * Invoked when a ComponentTag was found.
	 * <p>
	 * By default this method is also called for WicketTags.
	 * 
	 * @param tag
	 * @return Usually the same as the tag attribute
	 * @throws ParseException
	 */
	protected abstract MarkupElement onComponentTag(ComponentTag tag) throws ParseException;

	/**
	 * Invoked when a WicketTag was found.
	 * 
	 * @param tag
	 * @return Usually the same as the tag attribute
	 * @throws ParseException
	 */
// Not yet used
// protected MarkupElement onWicketTag(final WicketTag tag) throws ParseException
// {
// return onComponentTag(tag);
// }

	/**
	 * Invoked when a tags (e.g. DOCTYPE, PROCESSING_INSTRUCTIION, etc. which have been identified
	 * as special tags by the xml parser.
	 * 
	 * @param tag
	 * @return Usually the same as the tag attribute
	 * @throws ParseException
	 */
	protected MarkupElement onSpecialTag(final HtmlSpecialTag tag) throws ParseException
	{
		// log.error(tag.toString());
		return tag;
	}

// /**
// * Invoked if current element is raw markup
// *
// * @param rawMarkup
// * @return Usually the same as the tag attribute
// */
// Not yet used
// protected MarkupElement onRawMarkup(final MarkupElement rawMarkup)
// {
// return rawMarkup;
// }

	@Override
	public void postProcess(final Markup markup)
	{
	}

	protected MarkupResourceStream getMarkupResourceStream() {
		return markupResourceStream;
	}

	/**
	 * @return the namespace of the loaded markup
	 */
	protected String getWicketNamespace()
	{
		String wicketNamespace;
		if (markupResourceStream != null)
		{
			wicketNamespace = markupResourceStream.getWicketNamespace();
		}
		else {
			wicketNamespace = MarkupParser.WICKET;
		}
		return wicketNamespace;
	}
}

@@ -3211,147 +3211,8 @@
 %09 */
-%0A// Not yet used%0A// protected MarkupElement onWicketTag(final WicketTag tag) throws ParseException%0A// %7B%0A// return onComponentTag(tag);%0A// %7D
 %0A%0A%09/
@@ -3546,308 +3546,21 @@
 %7B%0A%09%09
-// log.error(tag.toString());%0A%09%09return tag;%0A%09%7D%0A%0A// /**%0A// * Invoked if current element is raw markup%0A// *%0A// * @param rawMarkup%0A// * @return Usually the same as the tag attribute%0A// */%0A// Not yet used%0A// protected MarkupElement onRawMarkup(final MarkupElement rawMarkup)%0A// %7B%0A// return rawMarkup;%0A// 
+return tag;%0A%09
 %7D%0A%0A%09

Remove commented (not implemented) code