package org.codehaus.xsite.extractors.sitemesh.rules;

import com.opensymphony.module.sitemesh.html.BasicRule;
import com.opensymphony.module.sitemesh.html.CustomTag;
import com.opensymphony.module.sitemesh.html.Tag;

/**
 * Rule for HTMLProcessor that adds class=""FirstChild" to the first header of the body if it is the first element.
 */
public class AddFirstChildClassToHeader extends BasicRule {
    private boolean firstChild = false;

    public AddFirstChildClassToHeader() {
    	super(new String[]{"p", "div", "h1", "h2", "h3", "h4", "h5", "h6"});
    }

    public void process(Tag tag) {
        if (!firstChild) {
            if (tag.getName().charAt(0) == 'h') {
                final CustomTag customTag = new CustomTag(tag);
                customTag.addAttribute("class", "FirstChild");
                tag = customTag;
            }
            firstChild = true;
        }
        tag.writeTo(currentBuffer());
    }
}
@@ -255,27 +255,25 @@
 dds 
+a 
 class
-=%22%22FirstChild%22
+ attribute
  to 
@@ -329,16 +329,67 @@
 lement.%0A
+ * The attribute value is by default %22FirstChild%22.%0A
  */%0Apubl
@@ -483,16 +483,49 @@
 = false;
+%0A%09private final String className;
 %0A%0A    pu
@@ -556,24 +556,114 @@
 oHeader() %7B%0A
+    %09this(%22FirstChild%22);%0A    %7D%0A%0A    public AddFirstChildClassToHeader(String className) %7B%0A
     %09super(n
@@ -724,16 +724,46 @@
 %22h6%22%7D);%0A
+%09%09this.className = className;%0A
     %7D%0A%0A 
@@ -985,28 +985,25 @@
 class%22, 
-%22FirstChild%22
+className
 );%0A     

Make class attribute value configurable.