use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method applyAttrNameCase.
protected void applyAttrNameCase(IDOMNode node) {
IDOMElement element = (IDOMElement) node;
if (element.isCommentTag())
// do nothing
return;
int attrNameCase = HTMLCorePreferenceNames.ASIS;
if (!shouldPreserveCase(element)) {
if (isXMLTag(element))
attrNameCase = HTMLCorePreferenceNames.LOWER;
else
attrNameCase = getCleanupPreferences().getAttrNameCase();
}
NamedNodeMap attributes = node.getAttributes();
int attributesLength = attributes.getLength();
for (int i = 0; i < attributesLength; i++) {
IDOMNode eachAttr = (IDOMNode) attributes.item(i);
if (hasNestedRegion(eachAttr.getNameRegion()))
continue;
String oldAttrName = eachAttr.getNodeName();
String newAttrName = oldAttrName;
/*
* 254961 - all HTML tag names and attribute names should be in
* English even for HTML files in other languages like Japanese or
* Turkish. English locale should be used to convert between
* uppercase and lowercase (otherwise "link" would be converted to
* Turkish "I Overdot Capital").
*/
if (attrNameCase == HTMLCorePreferenceNames.LOWER)
newAttrName = oldAttrName.toLowerCase(Locale.US);
else if (attrNameCase == HTMLCorePreferenceNames.UPPER)
newAttrName = oldAttrName.toUpperCase(Locale.US);
if (newAttrName.compareTo(oldAttrName) != 0) {
int attrNameStartOffset = eachAttr.getStartOffset();
int attrNameLength = oldAttrName.length();
IDOMModel structuredModel = node.getModel();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
replaceSource(structuredModel, structuredDocument, attrNameStartOffset, attrNameLength, newAttrName);
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method cleanupCSSAttrValue.
/**
*/
protected void cleanupCSSAttrValue(IDOMNode node) {
if (node == null || node.getNodeType() != Node.ELEMENT_NODE)
return;
IDOMElement element = (IDOMElement) node;
if (!element.isGlobalTag())
return;
// $NON-NLS-1$
Attr attr = element.getAttributeNode("style");
if (attr == null)
return;
String value = getCSSValue(attr);
if (value == null)
return;
String oldValue = ((IDOMNode) attr).getValueSource();
if (oldValue != null && value.equals(oldValue))
return;
attr.setValue(value);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method insertMissingTags.
protected IDOMNode insertMissingTags(IDOMNode node) {
boolean insertMissingTags = getCleanupPreferences().getInsertMissingTags();
IDOMNode newNode = node;
if (insertMissingTags) {
IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
if (startTagStructuredDocumentRegion == null) {
// implicit start tag; generate tag for it
newNode = insertStartTag(node);
startTagStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();
}
IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getEndStructuredDocumentRegion();
ITextRegionList regionList = startTagStructuredDocumentRegion.getRegions();
if (startTagStructuredDocumentRegion != null && regionList != null && regionList.get(regionList.size() - 1).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
} else {
if (startTagStructuredDocumentRegion == null) {
// start tag missing
if (isStartTagRequired(newNode))
newNode = insertStartTag(newNode);
} else if (endTagStructuredDocumentRegion == null) {
// end tag missing
if (isEndTagRequired(newNode))
newNode = insertEndTag(newNode);
}
}
}
return newNode;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method applyTagNameCase.
protected IDOMNode applyTagNameCase(IDOMNode node) {
IDOMElement element = (IDOMElement) node;
if (element.isCommentTag())
// do nothing
return node;
int tagNameCase = HTMLCorePreferenceNames.ASIS;
if (!shouldPreserveCase(element)) {
if (isXMLTag(element))
tagNameCase = HTMLCorePreferenceNames.LOWER;
else
tagNameCase = getCleanupPreferences().getTagNameCase();
}
String oldTagName = node.getNodeName();
String newTagName = oldTagName;
IDOMNode newNode = node;
/*
* 254961 - all HTML tag names and attribute names should be in
* English even for HTML files in other languages like Japanese or
* Turkish. English locale should be used to convert between uppercase
* and lowercase (otherwise "link" would be converted to Turkish "I
* Overdot Capital").
*/
if (tagNameCase == HTMLCorePreferenceNames.LOWER)
newTagName = oldTagName.toLowerCase(Locale.US);
else if (tagNameCase == HTMLCorePreferenceNames.UPPER)
newTagName = oldTagName.toUpperCase(Locale.US);
IDOMModel structuredModel = node.getModel();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
if (startTagStructuredDocumentRegion != null) {
ITextRegionList regions = startTagStructuredDocumentRegion.getRegions();
if (regions != null && regions.size() > 0) {
ITextRegion startTagNameRegion = regions.get(1);
int startTagNameStartOffset = startTagStructuredDocumentRegion.getStartOffset(startTagNameRegion);
int startTagNameLength = startTagStructuredDocumentRegion.getTextEndOffset(startTagNameRegion) - startTagNameStartOffset;
if (!newTagName.equals(oldTagName))
replaceSource(structuredModel, structuredDocument, startTagNameStartOffset, startTagNameLength, newTagName);
// save
newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagNameStartOffset);
// new
// node
}
}
IStructuredDocumentRegion endTagStructuredDocumentRegion = node.getEndStructuredDocumentRegion();
if (endTagStructuredDocumentRegion != null) {
ITextRegionList regions = endTagStructuredDocumentRegion.getRegions();
if (regions != null && regions.size() > 0) {
ITextRegion endTagNameRegion = regions.get(1);
int endTagNameStartOffset = endTagStructuredDocumentRegion.getStartOffset(endTagNameRegion);
int endTagNameLength = endTagStructuredDocumentRegion.getTextEndOffset(endTagNameRegion) - endTagNameStartOffset;
if (startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && !newTagName.equals(oldTagName))
replaceSource(structuredModel, structuredDocument, endTagNameStartOffset, endTagNameLength, newTagName);
}
}
return newNode;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class CSSTextNodeCleanupHandler method cleanup.
public Node cleanup(Node node) {
if (node == null)
return node;
IDOMModel model = ((IDOMNode) node).getModel();
if (model == null)
return node;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return node;
if (!getCleanupPreferences().getFormatSource())
return node;
String content = getCSSContent(node);
if (content == null)
return node;
int offset = ((IDOMNode) node).getStartOffset();
int length = ((IDOMNode) node).getEndOffset() - offset;
replaceSource(model, this, offset, length, content);
return (IDOMNode) model.getIndexedRegion(offset);
}
Aggregations