001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.behavior;
018
019import org.apache.wicket.Component;
020import org.apache.wicket.MarkupContainer;
021import org.apache.wicket.markup.ComponentTag;
022import org.apache.wicket.settings.DebugSettings;
023import org.apache.wicket.util.lang.Classes;
024
025/**
026 * <p>A behavior that applies to {@link MarkupContainer}s with associated markup.
027 * It adds an attribute named <em>namespace:className</em> to
028 * the markup element of {@link ComponentTag} with value the fully
029 * qualified class name of the markup container.</p>
030 *
031 * <p>It is used internally by Wicket when {@link org.apache.wicket.settings.DebugSettings.ClassOutputStrategy#TAG_ATTRIBUTE} is active.</p>
032 *
033 * @see DebugSettings#setOutputMarkupContainerClassNameStrategy(DebugSettings.ClassOutputStrategy)  
034 */
035public class OutputMarkupContainerClassNameBehavior extends Behavior {
036
037    public static final OutputMarkupContainerClassNameBehavior INSTANCE = new OutputMarkupContainerClassNameBehavior();
038
039    private OutputMarkupContainerClassNameBehavior()
040    {}
041
042    @Override
043    public void onComponentTag(Component component, ComponentTag tag) {
044        super.onComponentTag(component, tag);
045
046        if (component instanceof MarkupContainer)
047        {
048            String namespace = tag.getNamespace();
049            if (namespace == null)
050            {
051                namespace = "wicket";
052            }
053            tag.put(namespace + ":className", Classes.name(component.getClass()));
054        }
055    }
056
057    @Override
058    public boolean isTemporary(Component component) {
059        return true;
060    }
061}