This was my solution, works for me:

public abstract class AbstractBodyTransformerBehavior
        extends AbstractTransformerBehavior
{
protected abstract CharSequence transformBody(Component component, CharSequence body) throws Exception;

private static int indexOfCharacterInSequence(CharSequence haystack, char needle)
    {
        int max = haystack.length();

        for (int i = 0; i < max; i++){
            if (haystack.charAt(i) == needle){
                return i;
            }
        }

        return -1;
    }

private static int lastIndexOfCharacterInSequence(CharSequence haystack, char needle)
    {
        int max = haystack.length();

        for (int i = (max - 1); i >= 0; i--){
            if (haystack.charAt(i) == needle){
                return i;
            }
        }

        return -1;
    }

    @Override
public CharSequence transform(Component component, CharSequence output) throws Exception
    {
        int bodyStart = indexOfCharacterInSequence(output, '>') + 1;

        int bodyEnd = lastIndexOfCharacterInSequence(output, '<');

        if (bodyStart < 1 || bodyEnd < 0){
throw new WicketRuntimeException("Unable to find body for component: " + output);
        }

        StringBuilder sb = new StringBuilder(output.length());

        sb.append(output.subSequence(0, bodyStart));

sb.append(transformBody(component, output.subSequence(bodyStart, bodyEnd)));

        sb.append(output.subSequence(bodyEnd, output.length()));

        return sb;
    }
}


On 23/10/2012 11:04, Martin Grigorov wrote:
You just need to put something after the first closing tag and before
the last opening one.

For the first case it is something like (not tested, and better use
compiled Pattern):

String replaced = original.replaceAll("^(.*?>])(.*)", "$1"+theComment + "$2");

Once again I agree that having the two additional methods in
Behavior.java will simplify these use cases.

On Tue, Oct 23, 2012 at 11:55 AM, Decebal Suiu <decebal.s...@asf.ro> wrote:
AbstractTransformerBehavior can be a solution but I must parse the output to
retrieve the component tag body. For a particular situation (Jesse Long
situation) to parse the output it's not a big deal but in my situation
(something general for all my markup containers) I don't see a solution.
Maybe I suppose that all my container markups are divs (<div ...></div>). Is
it an util class in wicket that can help me with the parsing operation? I
want to retrieve the component tag body only.

Best regards,
Decebal



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653252.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to