if (quoteAttrValues) {
NamedNodeMap attributes = newNode.getAttributes();
if (attributes != null) {
int attributesLength = attributes.getLength();
ISourceGenerator generator = node.getModel().getGenerator();
for (int i = 0; i < attributesLength; i++) {
attributes = newNode.getAttributes();
attributesLength = attributes.getLength();
IDOMAttr eachAttr = (IDOMAttr) attributes.item(i);
//ITextRegion oldAttrValueRegion =
// eachAttr.getValueRegion();
String oldAttrValue = eachAttr.getValueRegionText();
if (oldAttrValue == null) {
IDOMModel structuredModel = node.getModel();
if (isXMLType(structuredModel)) {
String newAttrValue = "\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
if (eachAttr.getEqualRegion() != null)
// equal region exists
structuredDocument.replaceText(structuredDocument, eachAttr.getEndOffset(), 0, newAttrValue);
else
// no equal region
structuredDocument.replaceText(structuredDocument, eachAttr.getNameRegionTextEndOffset(), 0, "=".concat(newAttrValue)); //$NON-NLS-1$
newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save
// new
// node
}
} else {
//String oldAttrValue = oldAttrValueRegion.getText();
char quote = StringUtils.isQuoted(oldAttrValue) ? oldAttrValue.charAt(0) : DOUBLE_QUOTE;
String newAttrValue = generator.generateAttrValue(eachAttr, quote);
// There is a problem in
// StructuredDocumentRegionUtil.getAttrValue(ITextRegion)
// when the region is instanceof ContextRegion.
// Workaround for now...