/*****************************************************************************
 * Copyright (c) 2013, theborakompanioni (http://www.example.org)
 * 
 * Licensed 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 at.pollux.thymeleaf.shiro.processor.attribute;

import org.thymeleaf.Arguments;
import org.thymeleaf.dom.Element;
import org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor;

import at.pollux.thymeleaf.shiro.dialect.ShiroFacade;

public class PrincipalAttrProcessor extends AbstractTextChildModifierAttrProcessor {

    public static final PrincipalAttrProcessor create() {
        return new PrincipalAttrProcessor();
    }

    private static final String ATTRIBUTE_NAME = "principal";
    private static final int PRECEDENCE = 300;

    protected PrincipalAttrProcessor() {
        super(ATTRIBUTE_NAME);
    }

    @Override
    public int getPrecedence() {
        return PRECEDENCE;
    }

    @Override
    protected String getText(final Arguments arguments, final Element element, final String attributeName) {
        final String type = element.getAttributeValue("type");
        final String property = element.getAttributeValue("property");

        return ShiroFacade.getPrincipalText(type, property);
    }
}
@@ -1751,16 +1751,179 @@
 erty%22);%0A
+%09if (element.hasAttribute(%22type%22)) %7B%0A%09    element.removeAttribute(%22type%22);%0A%09%7D%0A%09if (element.hasAttribute(%22property%22)) %7B%0A%09    element.removeAttribute(%22property%22);%0A%09%7D
 %0A       

Remove type and property attributes if any when there is a shiro:principal attribute.