Skip to content

Commit

Permalink
correctly look for existing class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
darkv committed Jul 22, 2015
1 parent a3ef07c commit 9f4a75b
Showing 1 changed file with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WOElement;
import com.webobjects.appserver.WOMessage;
Expand Down Expand Up @@ -145,33 +147,27 @@ public void didAppendToResponse(WOElement element, WOResponse response, WOContex
}

if (tagIndex != -1) {
int attributeOffset = -1;
boolean spacesFound = false;
for (int i = tagIndex; i < endIndex; i++) {
char ch = contentStr.charAt(i);
if (ch == ' ') {
spacesFound = true;
} else if (ch == '>' || ch == '/') {
if (attributeOffset > tagIndex + 1) {
attributeOffset = i;
}
break;
} else if (spacesFound) {
attributeOffset = i;
break;
}
}
if (attributeOffset != -1) {
String profilerID = markerStats._stats.cssID();
String profilerIDAttributeName = "class";
if (regionMatches(contentStr, attributeOffset, profilerIDAttributeName, 0, profilerIDAttributeName.length())) {
int openQuoteIndex = indexOf(contentStr, "\"", attributeOffset);
if (openQuoteIndex != -1) {
insert(contentStr, openQuoteIndex + 1, profilerID + " ");
}
String profilerIDAttributeName = "class";
String profilerIDAttributeStart = " " + profilerIDAttributeName + "=\"";
boolean foundClassAttribute = false;
int closeOffset = StringUtils.indexOf(contentStr, '>', tagIndex);
int attributeOffset = StringUtils.indexOf(contentStr, profilerIDAttributeName, tagIndex);
if (attributeOffset == -1 || attributeOffset > closeOffset) {
char ch = contentStr.charAt(closeOffset - 1);
if (ch == '/') {
attributeOffset = closeOffset - 1;
} else {
insert(contentStr, attributeOffset, " " + profilerIDAttributeName + "=\"" + profilerID + "\" ");
attributeOffset = closeOffset;
}
} else {
attributeOffset += profilerIDAttributeStart.length() -1;
foundClassAttribute = true;
}
String profilerID = markerStats._stats.cssID();
if (foundClassAttribute) {
insert(contentStr, attributeOffset, profilerID + " ");
} else {
insert(contentStr, attributeOffset, profilerIDAttributeStart + profilerID + "\"");
}
}
}
Expand Down

0 comments on commit 9f4a75b

Please sign in to comment.