Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornitind2005-08-11 03:16:45 +0000
committernitind2005-08-11 03:16:45 +0000
commita676f2986b59f25046bc3ff92359836f86de1d61 (patch)
tree3eb3ed79b2195025f3d57eec28d9b7fbe84d7a37
parent41be8ced05b3d60c0840d24034a65b3c8ff48a6a (diff)
downloadwebtools.sourceediting-a676f2986b59f25046bc3ff92359836f86de1d61.tar.gz
webtools.sourceediting-a676f2986b59f25046bc3ff92359836f86de1d61.tar.xz
webtools.sourceediting-a676f2986b59f25046bc3ff92359836f86de1d61.zip
[104562] TVT 3.1 - TCT 323 - HTML Source Editor Document Cleanup
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/AbstractNodeCleanupHandler.java2
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java166
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/HTMLCleanupProcessorImpl.java35
-rw-r--r--bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupActionHTML.java33
-rw-r--r--bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java190
5 files changed, 268 insertions, 158 deletions
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/AbstractNodeCleanupHandler.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/AbstractNodeCleanupHandler.java
index 9f0e9ac6da..37ff30a16f 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/AbstractNodeCleanupHandler.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/AbstractNodeCleanupHandler.java
@@ -38,6 +38,8 @@ abstract class AbstractNodeCleanupHandler implements IStructuredCleanupHandler {
Preferences preferences = getModelPreferences();
if (preferences != null) {
+ fCleanupPreferences.setTagNameCase(preferences.getInt(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE));
+ fCleanupPreferences.setAttrNameCase(preferences.getInt(HTMLCorePreferenceNames.CLEANUP_ATTR_NAME_CASE));
fCleanupPreferences.setCompressEmptyElementTags(preferences.getBoolean(HTMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS));
fCleanupPreferences.setInsertRequiredAttrs(preferences.getBoolean(HTMLCorePreferenceNames.INSERT_REQUIRED_ATTRS));
fCleanupPreferences.setInsertMissingTags(preferences.getBoolean(HTMLCorePreferenceNames.INSERT_MISSING_TAGS));
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java
index 70a79f0a43..37560b3989 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java
@@ -70,7 +70,8 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
IDOMNode renamedNode = (IDOMNode) cleanupChildren(node);
// call quoteAttrValue() first so it will close any unclosed attr
- // quoteAttrValue() will return the new start tag if there is a structure change
+ // quoteAttrValue() will return the new start tag if there is a
+ // structure change
renamedNode = quoteAttrValue(renamedNode);
// insert tag close if missing
@@ -80,14 +81,16 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
IDOMModel structuredModel = renamedNode.getModel();
// save start offset before insertTagClose()
- // or else renamedNode.getStartOffset() will be zero if renamedNode replaced by insertTagClose()
+ // or else renamedNode.getStartOffset() will be zero if
+ // renamedNode replaced by insertTagClose()
int startTagStartOffset = renamedNode.getStartOffset();
// for start tag
IStructuredDocumentRegion startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();
insertTagClose(structuredModel, startTagStructuredDocumentRegion);
- // update renamedNode and startTagStructuredDocumentRegion after insertTagClose()
+ // update renamedNode and startTagStructuredDocumentRegion after
+ // insertTagClose()
renamedNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();
@@ -97,10 +100,13 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
insertTagClose(structuredModel, endTagStructuredDocumentRegion);
}
- // call insertMissingTags() next, it will generate implicit tags if there are any
- // insertMissingTags() will return the new missing start tag if one is missing
+ // call insertMissingTags() next, it will generate implicit tags if
+ // there are any
+ // insertMissingTags() will return the new missing start tag if one is
+ // missing
// applyTagNameCase() will return the renamed node.
- // The renamed/new node will be saved and returned to caller when all cleanup is done.
+ // The renamed/new node will be saved and returned to caller when all
+ // cleanup is done.
renamedNode = insertMissingTags(renamedNode);
renamedNode = insertRequiredAttrs(renamedNode);
renamedNode = applyTagNameCase(renamedNode);
@@ -110,33 +116,53 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
return renamedNode;
}
- private boolean shouldIgnoreCase(IDOMElement element) {
+ /**
+ * Checks if cleanup should modify case. Returns true case should be
+ * preserved, false otherwise.
+ *
+ * @param element
+ * @return true if element is case sensitive, false otherwise
+ */
+ private boolean shouldPreserveCase(IDOMElement element) {
// case option can be applied to no namespace tags
- return element.isGlobalTag();
+ return !element.isGlobalTag();
/*
- ModelQueryAdapter mqadapter = (ModelQueryAdapter) element.getAdapterFor(ModelQueryAdapter.class);
- ModelQuery mq = null;
- CMNode nodedecl = null;
- if (mqadapter != null)
- mq = mqadapter.getModelQuery();
- if (mq != null)
- nodedecl = mq.getCMNode(node);
- // if a Node isn't recognized as HTML or is and cares about case, do not alter it
- // if (nodedecl == null || (nodedecl instanceof HTMLCMNode && ((HTMLCMNode) nodedecl).shouldIgnoreCase()))
- if (! nodedecl.supports(HTMLCMProperties.SHOULD_IGNORE_CASE)) return false;
- return ((Boolean)cmnode.getProperty(HTMLCMProperties.SHOULD_IGNORE_CASE)).booleanValue();
+ * ModelQueryAdapter mqadapter = (ModelQueryAdapter)
+ * element.getAdapterFor(ModelQueryAdapter.class); ModelQuery mq =
+ * null; CMNode nodedecl = null; if (mqadapter != null) mq =
+ * mqadapter.getModelQuery(); if (mq != null) nodedecl =
+ * mq.getCMNode(node); // if a Node isn't recognized as HTML or is and
+ * cares about case, do not alter it // if (nodedecl == null ||
+ * (nodedecl instanceof HTMLCMNode && ((HTMLCMNode)
+ * nodedecl).shouldIgnoreCase())) if (!
+ * nodedecl.supports(HTMLCMProperties.SHOULD_IGNORE_CASE)) return
+ * false; return
+ * ((Boolean)cmnode.getProperty(HTMLCMProperties.SHOULD_IGNORE_CASE)).booleanValue();
*/
}
+ /**
+ * Checks if cleanup should force modifying element name to all lowercase.
+ *
+ * @param element
+ * @return true if cleanup should lowercase element name, false otherwise
+ */
+ private boolean isXMLTag(IDOMElement element) {
+ return element.isXMLTag();
+ }
+
protected void applyAttrNameCase(IDOMNode node) {
IDOMElement element = (IDOMElement) node;
if (element.isCommentTag())
return; // do nothing
int attrNameCase = HTMLCorePreferenceNames.ASIS;
-
- if (shouldIgnoreCase(element))
- attrNameCase = getCleanupPreferences().getAttrNameCase();
+ if (!shouldPreserveCase(element)) {
+ if (isXMLTag(element))
+ attrNameCase = HTMLCorePreferenceNames.LOWER;
+ else
+ attrNameCase = getCleanupPreferences().getAttrNameCase();
+ }
NamedNodeMap attributes = node.getAttributes();
int attributesLength = attributes.getLength();
@@ -148,7 +174,7 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
// 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 "LÝNK" in Turkish, where '?' in "LÝNK"
+ // (otherwise "link" would be converted to "L�NK" in Turkish, where '?' in "L�NK"
// is the "I Overdot Capital" in Turkish).
if (attrNameCase == HTMLCorePreferenceNames.LOWER)
newAttrName = oldAttrName.toLowerCase(Locale.US);
@@ -173,8 +199,12 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
int tagNameCase = HTMLCorePreferenceNames.ASIS;
- if (shouldIgnoreCase(element))
- tagNameCase = getCleanupPreferences().getTagNameCase();
+ if (!shouldPreserveCase(element)) {
+ if (isXMLTag(element))
+ tagNameCase = HTMLCorePreferenceNames.LOWER;
+ else
+ tagNameCase = getCleanupPreferences().getTagNameCase();
+ }
String oldTagName = node.getNodeName();
String newTagName = oldTagName;
@@ -183,7 +213,7 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
// 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 "LÝNK" in Turkish, where '?' in "LÝNK"
+ // (otherwise "link" would be converted to "L�NK" in Turkish, where '?' in "L�NK"
// is the "I Overdot Capital" in Turkish).
if (tagNameCase == HTMLCorePreferenceNames.LOWER)
newTagName = oldTagName.toLowerCase(Locale.US);
@@ -202,7 +232,9 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
int startTagNameLength = startTagStructuredDocumentRegion.getTextEndOffset(startTagNameRegion) - startTagNameStartOffset;
replaceSource(structuredModel, structuredDocument, startTagNameStartOffset, startTagNameLength, newTagName);
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagNameStartOffset); // save new node
+ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagNameStartOffset); // save
+ // new
+ // node
}
}
@@ -330,8 +362,7 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
if (element.isCommentTag()) {
// do nothing
- }
- else if (isEmptyElement(element)) {
+ } else if (isEmptyElement(element)) {
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
ITextRegionList regions = startStructuredDocumentRegion.getRegions();
@@ -341,29 +372,33 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
if (regions.size() > 1) {
ITextRegion regionBeforeTagClose = regions.get(regions.size() - 1 - 1);
- // insert a space separator before tag close if the previous region does not have extra spaces
+ // insert a space separator before tag close if the previous
+ // region does not have extra spaces
if (regionBeforeTagClose.getTextLength() == regionBeforeTagClose.getLength())
replaceSource(structuredModel, structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), 0, " "); //$NON-NLS-1$
}
- }
- else {
+ } else {
String tagName = node.getNodeName();
String endTag = END_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);
IDOMNode lastChild = (IDOMNode) node.getLastChild();
int endTagStartOffset = 0;
if (lastChild != null)
- // if this node has children, insert the end tag after the last child
+ // if this node has children, insert the end tag after the
+ // last child
endTagStartOffset = lastChild.getEndOffset();
else
- // if this node does not has children, insert the end tag after the start tag
+ // if this node does not has children, insert the end tag
+ // after the start tag
endTagStartOffset = node.getEndOffset();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
replaceSource(structuredModel, structuredDocument, endTagStartOffset, 0, endTag);
}
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save new node
+ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
+ // new
+ // node
return newNode;
}
@@ -385,14 +420,12 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
ITextRegionList regionList = startTagStructuredDocumentRegion.getRegions();
if (startTagStructuredDocumentRegion != null && regionList != null && regionList.get(regionList.size() - 1).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- }
- else {
+ } else {
if (startTagStructuredDocumentRegion == null) {
// start tag missing
if (isStartTagRequired(newNode))
newNode = insertStartTag(newNode);
- }
- else if (endTagStructuredDocumentRegion == null) {
+ } else if (endTagStructuredDocumentRegion == null) {
// end tag missing
if (isEndTagRequired(newNode))
newNode = insertEndTag(newNode);
@@ -417,7 +450,9 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
IDOMModel structuredModel = node.getModel();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
replaceSource(structuredModel, structuredDocument, startTagStartOffset, 0, startTag);
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save new node
+ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
+ // new
+ // node
return newNode;
}
@@ -432,7 +467,8 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
// insert ">" after lastRegion of flatNode
- // as in "<a</a>" if flatNode is for start tag, or in "<a></a" if flatNode is for end tag
+ // as in "<a</a>" if flatNode is for start tag, or in
+ // "<a></a" if flatNode is for end tag
replaceSource(structuredModel, structuredDocument, flatNode.getTextEndOffset(lastRegion), 0, ">"); //$NON-NLS-1$
}
}
@@ -446,9 +482,9 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
}
/**
- * The end tags of HTML EMPTY content type, such as IMG,
- * and HTML undefined tags are parsed separately from the start tags.
- * So inserting the missing start tag is useless and even harmful.
+ * The end tags of HTML EMPTY content type, such as IMG, and HTML
+ * undefined tags are parsed separately from the start tags. So inserting
+ * the missing start tag is useless and even harmful.
*/
protected boolean isStartTagRequired(IDOMNode node) {
if (node == null)
@@ -486,25 +522,29 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
attributes = newNode.getAttributes();
attributesLength = attributes.getLength();
IDOMAttr eachAttr = (IDOMAttr) attributes.item(i);
- //ITextRegion oldAttrValueRegion = eachAttr.getValueRegion();
+ // ITextRegion oldAttrValueRegion = eachAttr.getValueRegion();
String oldAttrValue = eachAttr.getValueRegionText();
if (oldAttrValue == null) {
IDOMModel structuredModel = node.getModel();
if (isXMLType(structuredModel)) {
- // TODO: Kit, please check. Is there any way to not rely on getting regions from attributes?
+ // TODO: Kit, please check. Is there any way to not
+ // rely on getting regions from attributes?
String newAttrValue = "=\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
replaceSource(structuredModel, structuredDocument, eachAttr.getNameRegionEndOffset(), 0, newAttrValue);
- newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save new node
+ newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save
+ // new
+ // node
}
- }
- else {
+ } else {
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.
+ // There is a problem in
+ // StructuredDocumentRegionUtil.getAttrValue(ITextRegion)
+ // when the region is instanceof ContextRegion.
// Workaround for now...
if (oldAttrValue.length() == 1) {
char firstChar = oldAttrValue.charAt(0);
@@ -523,7 +563,9 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
IDOMModel structuredModel = node.getModel();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
replaceSource(structuredModel, structuredDocument, attrValueStartOffset, attrValueLength, newAttrValue);
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save new node
+ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
+ // new
+ // node
}
}
}
@@ -562,12 +604,11 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
if (insertAttrs.size() > 0) {
IStructuredDocumentRegion startStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();
int index = startStructuredDocumentRegion.getEndOffset();
- ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion();
+ ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion();
if (lastRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) {
index--;
lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
- }
- else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
+ } else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
index = index - 2;
lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
}
@@ -584,14 +625,16 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
nameAndDefaultValue = ""; //$NON-NLS-1$
nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue));
- // BUG3381: MultiTextEdit applies all child TextEdit's basing on offsets
- // in the document before the first TextEdit, not after each
- // child TextEdit. Therefore, do not need to advance the index.
- //index += nameAndDefaultValue.length();
+ // BUG3381: MultiTextEdit applies all child
+ // TextEdit's basing on offsets
+ // in the document before the first TextEdit, not
+ // after each
+ // child TextEdit. Therefore, do not need to
+ // advance the index.
+ // index += nameAndDefaultValue.length();
}
multiTextEdit.apply(newNode.getStructuredDocument());
- }
- catch (BadLocationException e) {
+ } catch (BadLocationException e) {
throw new SourceEditingRuntimeException(e);
}
}
@@ -605,8 +648,7 @@ public class ElementNodeCleanupHandler extends AbstractNodeCleanupHandler {
protected ModelQuery getModelQuery(Node node) {
if (node.getNodeType() == Node.DOCUMENT_NODE) {
return ModelQueryUtil.getModelQuery((Document) node);
- }
- else {
+ } else {
return ModelQueryUtil.getModelQuery(node.getOwnerDocument());
}
}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/HTMLCleanupProcessorImpl.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/HTMLCleanupProcessorImpl.java
index 61dc1e3665..5b765c4f54 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/HTMLCleanupProcessorImpl.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/HTMLCleanupProcessorImpl.java
@@ -13,14 +13,18 @@ package org.eclipse.wst.html.core.internal.cleanup;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl;
+import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
+import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor;
import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupHandler;
+import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences;
+import org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences;
import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
-import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML;
import org.w3c.dom.Node;
-public class HTMLCleanupProcessorImpl extends CleanupProcessorXML {
-
+public class HTMLCleanupProcessorImpl extends AbstractStructuredCleanupProcessor {
+ private IStructuredCleanupPreferences fCleanupPreferences = null;
+
protected String getContentType() {
return ContentTypeIdForHTML.ContentTypeID_HTML;
}
@@ -29,6 +33,27 @@ public class HTMLCleanupProcessorImpl extends CleanupProcessorXML {
return HTMLCleanupHandlerFactory.getInstance().createHandler(node, getCleanupPreferences());
}
+ public IStructuredCleanupPreferences getCleanupPreferences() {
+ if (fCleanupPreferences == null) {
+ fCleanupPreferences = new StructuredCleanupPreferences();
+
+ Preferences preferences = getModelPreferences();
+ if (preferences != null) {
+ fCleanupPreferences.setTagNameCase(preferences.getInt(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE));
+ fCleanupPreferences.setAttrNameCase(preferences.getInt(HTMLCorePreferenceNames.CLEANUP_ATTR_NAME_CASE));
+ fCleanupPreferences.setCompressEmptyElementTags(preferences.getBoolean(HTMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS));
+ fCleanupPreferences.setInsertRequiredAttrs(preferences.getBoolean(HTMLCorePreferenceNames.INSERT_REQUIRED_ATTRS));
+ fCleanupPreferences.setInsertMissingTags(preferences.getBoolean(HTMLCorePreferenceNames.INSERT_MISSING_TAGS));
+ fCleanupPreferences.setQuoteAttrValues(preferences.getBoolean(HTMLCorePreferenceNames.QUOTE_ATTR_VALUES));
+ fCleanupPreferences.setFormatSource(preferences.getBoolean(HTMLCorePreferenceNames.FORMAT_SOURCE));
+ fCleanupPreferences.setConvertEOLCodes(preferences.getBoolean(HTMLCorePreferenceNames.CONVERT_EOL_CODES));
+ fCleanupPreferences.setEOLCode(preferences.getString(HTMLCorePreferenceNames.CLEANUP_EOL_CODE));
+ }
+ }
+
+ return fCleanupPreferences;
+ }
+
protected IStructuredFormatProcessor getFormatProcessor() {
return new HTMLFormatProcessorImpl();
}
@@ -36,4 +61,8 @@ public class HTMLCleanupProcessorImpl extends CleanupProcessorXML {
protected Preferences getModelPreferences() {
return HTMLCorePlugin.getDefault().getPluginPreferences();
}
+
+ protected void refreshCleanupPreferences() {
+ fCleanupPreferences = null;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupActionHTML.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupActionHTML.java
index 0eedfb667d..1e4f2335f7 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupActionHTML.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupActionHTML.java
@@ -13,11 +13,16 @@ package org.eclipse.wst.html.ui.internal.edit.ui;
import java.util.ResourceBundle;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl;
import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
import org.eclipse.wst.sse.ui.internal.actions.CleanupAction;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
public class CleanupActionHTML extends CleanupAction {
protected IStructuredCleanupProcessor fCleanupProcessor;
@@ -27,9 +32,11 @@ public class CleanupActionHTML extends CleanupAction {
}
protected Dialog getCleanupDialog(Shell shell) {
- if (fCleanupDialog == null)
+ if (fCleanupDialog == null) {
fCleanupDialog = new CleanupDialogHTML(shell);
-
+ }
+
+ ((CleanupDialogHTML)fCleanupDialog).setisXHTMLType(isXHTML());
return fCleanupDialog;
}
@@ -39,4 +46,26 @@ public class CleanupActionHTML extends CleanupAction {
return fCleanupProcessor;
}
+
+ private boolean isXHTML() {
+ boolean isxhtml = false;
+ ITextEditor textEditor = getTextEditor();
+ if (textEditor != null) {
+ IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ IStructuredModel model = null;
+ try {
+ model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
+ if (model instanceof IDOMModel) {
+ IDOMDocument domDocument = ((IDOMModel)model).getDocument();
+ if (domDocument != null)
+ isxhtml = domDocument.isXMLType();
+ }
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ }
+ return isxhtml;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java
index bab0c0d084..af2526043c 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java
@@ -12,6 +12,7 @@ package org.eclipse.wst.html.ui.internal.edit.ui;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
@@ -21,17 +22,12 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.help.WorkbenchHelp;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
-import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
import org.eclipse.wst.html.ui.internal.editor.IHelpContextIds;
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
-import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.cleanup.XMLCleanupPreferencesImpl;
-import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
public class CleanupDialogHTML extends Dialog implements SelectionListener {
@@ -49,14 +45,16 @@ public class CleanupDialogHTML extends Dialog implements SelectionListener {
protected Button fRadioButtonConvertEOLWindows;
protected Button fRadioButtonConvertEOLUnix;
protected Button fRadioButtonConvertEOLMac;
- protected IStructuredModel fModel = null;
protected Preferences fPreferences = null;
+ private boolean fIsXHTML = false;
+ private Group fTagNameCase;
+ private Group fAttrNameCase;
public CleanupDialogHTML(Shell shell) {
super(shell);
}
- public Control createDialogArea(Composite parent) {
+ protected Control createDialogArea(Composite parent) {
getShell().setText(HTMLUIMessages.Cleanup_UI_);
Composite composite = new Composite(parent, SWT.NULL);
@@ -66,47 +64,54 @@ public class CleanupDialogHTML extends Dialog implements SelectionListener {
return composite;
}
+ protected Control createButtonBar(Composite parent) {
+ Control c = super.createButtonBar(parent);
+ okButtonEnablement();
+ return c;
+ }
+
protected void createDialogAreaInCompositeForHTML(Composite composite) {
// Convert tag name case
- // d257064 need to associate group w/ radio buttons so radio buttons header can be read
- Group tagNameCase = new Group(composite, SWT.NONE);
- tagNameCase.setText(HTMLUIMessages.Tag_name_case_for_HTML_UI_);
+ // d257064 need to associate group w/ radio buttons so radio buttons
+ // header can be read
+ fTagNameCase = new Group(composite, SWT.NONE);
+ fTagNameCase.setText(HTMLUIMessages.Tag_name_case_for_HTML_UI_);
GridLayout hLayout = new GridLayout();
hLayout.numColumns = 3;
- tagNameCase.setLayout(hLayout);
- fRadioButtonTagNameCaseAsis = new Button(tagNameCase, SWT.RADIO);
+ fTagNameCase.setLayout(hLayout);
+ fRadioButtonTagNameCaseAsis = new Button(fTagNameCase, SWT.RADIO);
fRadioButtonTagNameCaseAsis.setText(HTMLUIMessages.Tag_name_case_As_is_UI_);
fRadioButtonTagNameCaseAsis.addSelectionListener(this);
- fRadioButtonTagNameCaseLower = new Button(tagNameCase, SWT.RADIO);
+ fRadioButtonTagNameCaseLower = new Button(fTagNameCase, SWT.RADIO);
fRadioButtonTagNameCaseLower.setText(HTMLUIMessages.Tag_name_case_Lower_UI_);
fRadioButtonTagNameCaseLower.addSelectionListener(this);
- fRadioButtonTagNameCaseUpper = new Button(tagNameCase, SWT.RADIO);
+ fRadioButtonTagNameCaseUpper = new Button(fTagNameCase, SWT.RADIO);
fRadioButtonTagNameCaseUpper.setText(HTMLUIMessages.Tag_name_case_Upper_UI_);
fRadioButtonTagNameCaseUpper.addSelectionListener(this);
// Convert attr name case
- // d257064 need to associate group w/ radio buttons so radio buttons header can be read
- Group attrNameCase = new Group(composite, SWT.NONE);
- attrNameCase.setText(HTMLUIMessages.Attribute_name_case_for_HTML_UI_);
- attrNameCase.setLayout(hLayout);
- fRadioButtonAttrNameCaseAsis = new Button(attrNameCase, SWT.RADIO);
+ // d257064 need to associate group w/ radio buttons so radio buttons
+ // header can be read
+ fAttrNameCase = new Group(composite, SWT.NONE);
+ fAttrNameCase.setText(HTMLUIMessages.Attribute_name_case_for_HTML_UI_);
+ fAttrNameCase.setLayout(hLayout);
+ fRadioButtonAttrNameCaseAsis = new Button(fAttrNameCase, SWT.RADIO);
fRadioButtonAttrNameCaseAsis.setText(HTMLUIMessages.Attribute_name_case_As_is_UI_);
fRadioButtonAttrNameCaseAsis.addSelectionListener(this);
- fRadioButtonAttrNameCaseLower = new Button(attrNameCase, SWT.RADIO);
+ fRadioButtonAttrNameCaseLower = new Button(fAttrNameCase, SWT.RADIO);
fRadioButtonAttrNameCaseLower.setText(HTMLUIMessages.Attribute_name_case_Lower_UI_);
fRadioButtonAttrNameCaseLower.addSelectionListener(this);
- fRadioButtonAttrNameCaseUpper = new Button(attrNameCase, SWT.RADIO);
+ fRadioButtonAttrNameCaseUpper = new Button(fAttrNameCase, SWT.RADIO);
fRadioButtonAttrNameCaseUpper.setText(HTMLUIMessages.Attribute_name_case_Upper_UI_);
fRadioButtonAttrNameCaseUpper.addSelectionListener(this);
}
protected void createDialogAreaInComposite(Composite composite) {
- if (isHTMLType()) {
- createDialogAreaInCompositeForHTML(composite);
- WorkbenchHelp.setHelp(composite, IHelpContextIds.CLEANUP_HTML_HELPID); // use HTML specific help
- }
- else
- WorkbenchHelp.setHelp(composite, org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds.CLEANUP_XML_HELPID); // use XML specific help
+ createDialogAreaInCompositeForHTML(composite);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.CLEANUP_HTML_HELPID); // use
+ // HTML
+ // specific
+ // help
GridLayout layout = new GridLayout();
layout.numColumns = 1;
@@ -159,26 +164,37 @@ public class CleanupDialogHTML extends Dialog implements SelectionListener {
}
protected void initializeOptionsForHTML() {
- int tagNameCase = getModelPreferences().getInt(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE);
- if (tagNameCase == HTMLCorePreferenceNames.UPPER)
- fRadioButtonTagNameCaseUpper.setSelection(true);
- else if (tagNameCase == HTMLCorePreferenceNames.LOWER)
+ boolean caseSensitive = isXHTMLType();
+
+ if (caseSensitive) {
fRadioButtonTagNameCaseLower.setSelection(true);
- else
- fRadioButtonTagNameCaseAsis.setSelection(true);
+ } else {
+ int tagNameCase = getModelPreferences().getInt(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE);
+ if (tagNameCase == HTMLCorePreferenceNames.UPPER) {
+ fRadioButtonTagNameCaseUpper.setSelection(true);
+ } else if (tagNameCase == HTMLCorePreferenceNames.LOWER)
+ fRadioButtonTagNameCaseLower.setSelection(true);
+ else
+ fRadioButtonTagNameCaseAsis.setSelection(true);
+ }
- int attrNameCase = getModelPreferences().getInt(HTMLCorePreferenceNames.CLEANUP_ATTR_NAME_CASE);
- if (attrNameCase == HTMLCorePreferenceNames.UPPER)
- fRadioButtonAttrNameCaseUpper.setSelection(true);
- else if (attrNameCase == HTMLCorePreferenceNames.LOWER)
+ if (caseSensitive) {
fRadioButtonAttrNameCaseLower.setSelection(true);
- else
- fRadioButtonAttrNameCaseAsis.setSelection(true);
+ } else {
+ int attrNameCase = getModelPreferences().getInt(HTMLCorePreferenceNames.CLEANUP_ATTR_NAME_CASE);
+ if (attrNameCase == HTMLCorePreferenceNames.UPPER) {
+ fRadioButtonAttrNameCaseUpper.setSelection(true);
+ } else if (attrNameCase == HTMLCorePreferenceNames.LOWER)
+ fRadioButtonAttrNameCaseLower.setSelection(true);
+ else
+ fRadioButtonAttrNameCaseAsis.setSelection(true);
+ }
+
+ enableCaseControls(!caseSensitive);
}
protected void initializeOptions() {
- if (isHTMLType())
- initializeOptionsForHTML();
+ initializeOptionsForHTML();
fCheckBoxInsertRequiredAttrs.setSelection(getModelPreferences().getBoolean(HTMLCorePreferenceNames.INSERT_REQUIRED_ATTRS));
fCheckBoxInsertMissingTags.setSelection(getModelPreferences().getBoolean(HTMLCorePreferenceNames.INSERT_MISSING_TAGS));
@@ -198,14 +214,14 @@ public class CleanupDialogHTML extends Dialog implements SelectionListener {
}
protected void storeOptionsForHTML() {
- if (fRadioButtonTagNameCaseUpper.getSelection())
+ if (!isXHTMLType() && fRadioButtonTagNameCaseUpper.getSelection())
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE, HTMLCorePreferenceNames.UPPER);
else if (fRadioButtonTagNameCaseLower.getSelection())
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE, HTMLCorePreferenceNames.LOWER);
else
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE, HTMLCorePreferenceNames.ASIS);
- if (fRadioButtonAttrNameCaseUpper.getSelection())
+ if (!isXHTMLType() && fRadioButtonAttrNameCaseUpper.getSelection())
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_ATTR_NAME_CASE, HTMLCorePreferenceNames.UPPER);
else if (fRadioButtonAttrNameCaseLower.getSelection())
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_ATTR_NAME_CASE, HTMLCorePreferenceNames.LOWER);
@@ -217,40 +233,24 @@ public class CleanupDialogHTML extends Dialog implements SelectionListener {
}
protected void storeOptions() {
- if (isHTMLType()) {
- storeOptionsForHTML();
- XMLCleanupPreferencesImpl.getInstance().setTagNameCase(getModelPreferences().getInt(HTMLCorePreferenceNames.CLEANUP_TAG_NAME_CASE));
- XMLCleanupPreferencesImpl.getInstance().setAttrNameCase(getModelPreferences().getInt(HTMLCorePreferenceNames.CLEANUP_ATTR_NAME_CASE));
- }
- else {
- XMLCleanupPreferencesImpl.getInstance().setTagNameCase(HTMLCorePreferenceNames.ASIS);
- XMLCleanupPreferencesImpl.getInstance().setAttrNameCase(HTMLCorePreferenceNames.ASIS);
- }
+ storeOptionsForHTML();
getModelPreferences().setValue(HTMLCorePreferenceNames.INSERT_REQUIRED_ATTRS, fCheckBoxInsertRequiredAttrs.getSelection());
getModelPreferences().setValue(HTMLCorePreferenceNames.INSERT_MISSING_TAGS, fCheckBoxInsertMissingTags.getSelection());
getModelPreferences().setValue(HTMLCorePreferenceNames.QUOTE_ATTR_VALUES, fCheckBoxQuoteAttrValues.getSelection());
getModelPreferences().setValue(HTMLCorePreferenceNames.FORMAT_SOURCE, fCheckBoxFormatSource.getSelection());
getModelPreferences().setValue(HTMLCorePreferenceNames.CONVERT_EOL_CODES, fCheckBoxConvertEOLCodes.getSelection());
- XMLCleanupPreferencesImpl.getInstance().setInsertMissingTags(fCheckBoxInsertMissingTags.getSelection());
- XMLCleanupPreferencesImpl.getInstance().setQuoteAttrValues(fCheckBoxQuoteAttrValues.getSelection());
- XMLCleanupPreferencesImpl.getInstance().setFormatSource(fCheckBoxFormatSource.getSelection());
- XMLCleanupPreferencesImpl.getInstance().setConvertEOLCodes(fCheckBoxConvertEOLCodes.getSelection());
+
if (fCheckBoxConvertEOLCodes.getSelection()) {
if (fRadioButtonConvertEOLUnix.getSelection()) {
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.LF);
- XMLCleanupPreferencesImpl.getInstance().setEOLCode(CommonEncodingPreferenceNames.LF);
- }
- else if (fRadioButtonConvertEOLMac.getSelection()) {
+ } else if (fRadioButtonConvertEOLMac.getSelection()) {
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.CR);
- XMLCleanupPreferencesImpl.getInstance().setEOLCode(CommonEncodingPreferenceNames.CR);
- }
- else {
+ } else {
getModelPreferences().setValue(HTMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.CRLF);
- XMLCleanupPreferencesImpl.getInstance().setEOLCode(CommonEncodingPreferenceNames.CRLF);
}
}
-
+
// explicitly save plugin preferences so values are stored
HTMLCorePlugin.getDefault().savePluginPreferences();
}
@@ -260,41 +260,18 @@ public class CleanupDialogHTML extends Dialog implements SelectionListener {
}
public void widgetSelected(SelectionEvent e) {
- getButton(OK).setEnabled((fRadioButtonTagNameCaseLower != null && (fRadioButtonTagNameCaseLower.getSelection() || fRadioButtonTagNameCaseUpper.getSelection())) || (fRadioButtonAttrNameCaseLower != null && (fRadioButtonAttrNameCaseLower.getSelection() || fRadioButtonAttrNameCaseUpper.getSelection())) || fCheckBoxInsertMissingTags.getSelection() || fCheckBoxQuoteAttrValues.getSelection() || fCheckBoxFormatSource.getSelection() || fCheckBoxConvertEOLCodes.getSelection() || (fRadioButtonConvertEOLUnix != null && (fRadioButtonConvertEOLUnix.getSelection() || fRadioButtonConvertEOLMac.getSelection() || fRadioButtonConvertEOLWindows.getSelection())));
if (e.widget == fCheckBoxConvertEOLCodes)
enableEOLCodeRadios(fCheckBoxConvertEOLCodes.getSelection());
- }
- public void setModel(IStructuredModel model) {
- fModel = model;
+ okButtonEnablement();
}
protected Preferences getModelPreferences() {
return HTMLCorePlugin.getDefault().getPluginPreferences();
}
- protected boolean isXMLType() {
- boolean result = false;
-
- if (fModel != null) {
- IModelHandler modelHandler = fModel.getModelHandler();
- if (modelHandler.getAssociatedContentTypeId().equals(ContentTypeIdForXML.ContentTypeID_XML))
- result = true;
- }
-
- return result;
- }
-
- protected boolean isHTMLType() {
- boolean result = true;
-
- if (fModel != null) {
- IModelHandler modelHandler = fModel.getModelHandler();
- if (modelHandler.getAssociatedContentTypeId().equals(ContentTypeIdForHTML.ContentTypeID_HTML))
- result = true;
- }
-
- return result;
+ private boolean isXHTMLType() {
+ return fIsXHTML;
}
protected void enableEOLCodeRadios(boolean enable) {
@@ -307,4 +284,35 @@ public class CleanupDialogHTML extends Dialog implements SelectionListener {
fRadioButtonConvertEOLWindows.setSelection(true);
}
}
+
+ /**
+ * Enables/disables the tag/attr case radio buttons
+ */
+ private void enableCaseControls(boolean enable) {
+ fTagNameCase.setEnabled(enable);
+ fRadioButtonTagNameCaseAsis.setEnabled(enable);
+ fRadioButtonTagNameCaseLower.setEnabled(enable);
+ fRadioButtonTagNameCaseUpper.setEnabled(enable);
+
+ fAttrNameCase.setEnabled(enable);
+ fRadioButtonAttrNameCaseAsis.setEnabled(enable);
+ fRadioButtonAttrNameCaseLower.setEnabled(enable);
+ fRadioButtonAttrNameCaseUpper.setEnabled(enable);
+ }
+
+ /**
+ * Enables/disables OK button
+ *
+ */
+ private void okButtonEnablement() {
+ boolean tagNameCaseCheck = ((fRadioButtonTagNameCaseUpper != null && fRadioButtonTagNameCaseUpper.getSelection()) || fRadioButtonTagNameCaseLower.getSelection());
+ boolean attrNameCaseCheck = ((fRadioButtonAttrNameCaseUpper != null && fRadioButtonAttrNameCaseUpper.getSelection()) || fRadioButtonAttrNameCaseLower.getSelection());
+ boolean eolCheck = fCheckBoxConvertEOLCodes.getSelection() && (fRadioButtonConvertEOLUnix.getSelection() || fRadioButtonConvertEOLMac.getSelection() || fRadioButtonConvertEOLWindows.getSelection());
+ boolean buttonEnabled = tagNameCaseCheck || attrNameCaseCheck || fCheckBoxInsertMissingTags.getSelection() || fCheckBoxQuoteAttrValues.getSelection() || fCheckBoxFormatSource.getSelection() || eolCheck;
+ getButton(IDialogConstants.OK_ID).setEnabled(buttonEnabled);
+ }
+
+ void setisXHTMLType(boolean isXHTML) {
+ fIsXHTML = isXHTML;
+ }
} \ No newline at end of file

Back to the top