Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 154593 Details for
Bug 129877
[formatting] HTML cleanup document should offer compress empty element tags
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Enhancment Patch
129877_html_compress_empty_tags.txt (text/plain), 6.77 KB, created by
Ian Tewksbury
on 2009-12-16 15:32:10 EST
(
hide
)
Description:
Enhancment Patch
Filename:
MIME Type:
Creator:
Ian Tewksbury
Created:
2009-12-16 15:32:10 EST
Size:
6.77 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.html.core >Index: src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java,v >retrieving revision 1.17 >diff -u -r1.17 ElementNodeCleanupHandler.java >--- src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java 28 Mar 2007 22:14:06 -0000 1.17 >+++ src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java 16 Dec 2009 20:28:21 -0000 >@@ -52,6 +52,7 @@ > import org.w3c.dom.Element; > import org.w3c.dom.NamedNodeMap; > import org.w3c.dom.Node; >+import org.w3c.dom.NodeList; > > // nakamori_TODO: check and remove CSS formatting > >@@ -105,10 +106,12 @@ > // there are any > // insertMissingTags() will return the new missing start tag if one is > // missing >+ // then compress any empty element tags > // applyTagNameCase() will return the renamed node. > // The renamed/new node will be saved and returned to caller when all > // cleanup is done. > renamedNode = insertMissingTags(renamedNode); >+ renamedNode = compressEmptyElementTag(renamedNode); > renamedNode = insertRequiredAttrs(renamedNode); > renamedNode = applyTagNameCase(renamedNode); > applyAttrNameCase(renamedNode); >@@ -692,4 +695,45 @@ > > return result; > } >+ >+ /** >+ * <p>Compress empty element tags if the prefence is set to do so</p> >+ * >+ * @copyof org.eclipse.wst.xml.core.internal.cleanup.ElementNodeCleanupHandler#compressEmptyElementTag >+ * >+ * @param node the {@link IDOMNode} to possible compress >+ * @return the compressed node if the given node should be compressed, else the node as it was given >+ */ >+ private IDOMNode compressEmptyElementTag(IDOMNode node) { >+ boolean compressEmptyElementTags = getCleanupPreferences().getCompressEmptyElementTags(); >+ IDOMNode newNode = node; >+ >+ IStructuredDocumentRegion startTagStructuredDocumentRegion = newNode.getFirstStructuredDocumentRegion(); >+ IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getLastStructuredDocumentRegion(); >+ >+ if (compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && startTagStructuredDocumentRegion != null) { >+ ITextRegionList regions = startTagStructuredDocumentRegion.getRegions(); >+ ITextRegion lastRegion = regions.get(regions.size() - 1); >+ // format children and end tag if not empty element tag >+ if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) { >+ NodeList childNodes = newNode.getChildNodes(); >+ if (childNodes == null || childNodes.getLength() == 0 || (childNodes.getLength() == 1 && (childNodes.item(0)).getNodeType() == Node.TEXT_NODE && ((childNodes.item(0)).getNodeValue().trim().length() == 0))) { >+ IDOMModel structuredModel = newNode.getModel(); >+ IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); >+ >+ int startTagStartOffset = newNode.getStartOffset(); >+ int offset = endTagStructuredDocumentRegion.getStart(); >+ int length = endTagStructuredDocumentRegion.getLength(); >+ structuredDocument.replaceText(structuredDocument, offset, length, ""); //$NON-NLS-1$ >+ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save >+ >+ offset = startTagStructuredDocumentRegion.getStart() + lastRegion.getStart(); >+ structuredDocument.replaceText(structuredDocument, offset, 0, "/"); //$NON-NLS-1$ >+ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save >+ } >+ } >+ } >+ >+ return newNode; >+ } > } >\ No newline at end of file >#P org.eclipse.wst.html.ui >Index: src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java,v >retrieving revision 1.8 >diff -u -r1.8 CleanupDialogHTML.java >--- src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java 15 Dec 2009 13:12:02 -0000 1.8 >+++ src/org/eclipse/wst/html/ui/internal/edit/ui/CleanupDialogHTML.java 16 Dec 2009 20:28:21 -0000 >@@ -28,6 +28,7 @@ > 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.xml.ui.internal.XMLUIMessages; > > public class CleanupDialogHTML extends Dialog implements SelectionListener { > >@@ -37,6 +38,7 @@ > protected Button fRadioButtonAttrNameCaseAsis; > protected Button fRadioButtonAttrNameCaseLower; > protected Button fRadioButtonAttrNameCaseUpper; >+ protected Button fCheckBoxCompressEmptyElementTags; > protected Button fCheckBoxInsertRequiredAttrs; > protected Button fCheckBoxInsertMissingTags; > protected Button fCheckBoxQuoteAttrValues; >@@ -118,6 +120,11 @@ > layout.makeColumnsEqualWidth = true; > composite.setLayout(layout); > >+ // Compress empty element tags >+ fCheckBoxCompressEmptyElementTags = new Button(composite, SWT.CHECK); >+ fCheckBoxCompressEmptyElementTags.setText(XMLUIMessages.Compress_empty_element_tags_UI_); >+ fCheckBoxCompressEmptyElementTags.addSelectionListener(this); >+ > // Insert missing required attrs > fCheckBoxInsertRequiredAttrs = new Button(composite, SWT.CHECK); > fCheckBoxInsertRequiredAttrs.setText(HTMLUIMessages.Insert_required_attributes_UI_); >@@ -196,6 +203,7 @@ > protected void initializeOptions() { > initializeOptionsForHTML(); > >+ fCheckBoxCompressEmptyElementTags.setSelection(getModelPreferences().getBoolean(HTMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS)); > fCheckBoxInsertRequiredAttrs.setSelection(getModelPreferences().getBoolean(HTMLCorePreferenceNames.INSERT_REQUIRED_ATTRS)); > fCheckBoxInsertMissingTags.setSelection(getModelPreferences().getBoolean(HTMLCorePreferenceNames.INSERT_MISSING_TAGS)); > fCheckBoxQuoteAttrValues.setSelection(getModelPreferences().getBoolean(HTMLCorePreferenceNames.QUOTE_ATTR_VALUES)); >@@ -235,6 +243,7 @@ > protected void storeOptions() { > storeOptionsForHTML(); > >+ getModelPreferences().setValue(HTMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS, fCheckBoxCompressEmptyElementTags.getSelection()); > getModelPreferences().setValue(HTMLCorePreferenceNames.INSERT_REQUIRED_ATTRS, fCheckBoxInsertRequiredAttrs.getSelection()); > getModelPreferences().setValue(HTMLCorePreferenceNames.INSERT_MISSING_TAGS, fCheckBoxInsertMissingTags.getSelection()); > getModelPreferences().setValue(HTMLCorePreferenceNames.QUOTE_ATTR_VALUES, fCheckBoxQuoteAttrValues.getSelection());
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 129877
:
154593
|
154654
|
154767
|
154974
|
154975
|
154976
|
154977
|
155369