commit a0b22c45f07ffa468450dd4aa053d46e4e362c9f
Author: joehni <[email protected]>
AuthorDate: Tue, 30 Apr 2013 20:14:56 +0200
Commit: joehni <[email protected]>
CommitDate: Tue, 30 Apr 2013 20:14:56 +0200
Simplify AddFirstChildToHeader rule.
diff --git
a/xsite-core/src/main/java/org/codehaus/xsite/extractors/sitemesh/rules/AddFirstChildClassToHeader.java
b/xsite-core/src/main/java/org/codehaus/xsite/extractors/sitemesh/rules/AddFirstChildClassToHeader.java
index 39fcfc0..425e037 100644
---
a/xsite-core/src/main/java/org/codehaus/xsite/extractors/sitemesh/rules/AddFirstChildClassToHeader.java
+++
b/xsite-core/src/main/java/org/codehaus/xsite/extractors/sitemesh/rules/AddFirstChildClassToHeader.java
@@ -4,33 +4,24 @@ import com.opensymphony.module.sitemesh.html.BasicRule;
import com.opensymphony.module.sitemesh.html.CustomTag;
import com.opensymphony.module.sitemesh.html.Tag;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
/**
* 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 firstChildIsHeader = true;
- private final Pattern pattern;
+ private boolean firstChild = false;
public AddFirstChildClassToHeader() {
- pattern = Pattern.compile("^H[1-9]$", Pattern.CASE_INSENSITIVE);
- }
-
- public boolean shouldProcess(String tag) {
- final Matcher matcher = pattern.matcher(tag);
- return tag.equalsIgnoreCase("p") || matcher.matches();
+ super(new String[]{"p", "div", "h1", "h2", "h3", "h4", "h5", "h6"});
}
public void process(Tag tag) {
- if (firstChildIsHeader) {
- if (!tag.getName().equalsIgnoreCase("p")) {
+ if (!firstChild) {
+ if (tag.getName().charAt(0) == 'h') {
final CustomTag customTag = new CustomTag(tag);
customTag.addAttribute("class", "FirstChild");
tag = customTag;
}
- firstChildIsHeader = false;
+ firstChild = true;
}
tag.writeTo(currentBuffer());
}