}
public String changeTagCase(String contents, boolean uppercase) {
Source source = new Source(contents);
source.fullSequentialParse();
OutputDocument outputDocument = new OutputDocument(source);
List<Tag> tags = source.getAllTags();
int pos = 0;
for (Tag tag : tags) {
Element tagElement = tag.getElement();
if (tagElement == null) {
System.out.println(tag.getName());
} else {
StartTag startTag = tagElement.getStartTag();
Attributes attributes = startTag.getAttributes();
if (attributes != null) {
for (Attribute attribute : startTag.getAttributes()) {
if (uppercase) {
outputDocument.replace(attribute.getNameSegment(), attribute.getNameSegment().toString()
.toUpperCase());
} else {
outputDocument.replace(attribute.getNameSegment(), attribute.getNameSegment().toString()
.toLowerCase());
}
}
}
if (uppercase) {
outputDocument.replace(tag.getNameSegment(), tag.getNameSegment().toString().toUpperCase());
} else {
outputDocument.replace(tag.getNameSegment(), tag.getNameSegment().toString().toLowerCase());
}
pos = tag.getEnd();
}
}
return outputDocument.toString();
}