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 154977 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.
[patch]
Enhancment and JUnits Patch Update 3 (Version 2)
129877_html_compress_empty_tags_2.txt (text/plain), 26.40 KB, created by
Ian Tewksbury
on 2009-12-23 11:01:48 EST
(
hide
)
Description:
Enhancment and JUnits Patch Update 3 (Version 2)
Filename:
MIME Type:
Creator:
Ian Tewksbury
Created:
2009-12-23 11:01:48 EST
Size:
26.40 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 23 Dec 2009 16:01:44 -0000 >@@ -27,6 +27,7 @@ > import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode; > import org.eclipse.wst.html.core.internal.Logger; > import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; >+import org.eclipse.wst.html.core.internal.validate.CMUtil; > import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupHandler; > import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; > import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; >@@ -52,6 +53,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 +107,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 +696,60 @@ > > 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(); >+ >+ //only compress tags if they are empty >+ if ((compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && >+ startTagStructuredDocumentRegion != null)) { >+ >+ //assume the end tag is omissible unless an CMElementDeclaration says otherwise >+ boolean endTagOmissible = true; >+ if(newNode instanceof IDOMElement) { >+ CMElementDeclaration dec = CMUtil.getDeclaration((IDOMElement)newNode); >+ if(dec != null) { >+ endTagOmissible = CMUtil.isEndTagOmissible(dec); >+ } >+ } >+ >+ //only compress end tags if its allowed for the tag in question >+ if(endTagOmissible) { >+ 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 >Index: src/org/eclipse/wst/html/core/internal/validate/CMUtil.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/CMUtil.java,v >retrieving revision 1.3 >diff -u -r1.3 CMUtil.java >--- src/org/eclipse/wst/html/core/internal/validate/CMUtil.java 10 Apr 2007 18:31:49 -0000 1.3 >+++ src/org/eclipse/wst/html/core/internal/validate/CMUtil.java 23 Dec 2009 16:01:44 -0000 >@@ -28,7 +28,7 @@ > import org.w3c.dom.Document; > import org.w3c.dom.Element; > >-final class CMUtil { >+public final class CMUtil { > > /** > * Never instantiate! >#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 23 Dec 2009 16:01:45 -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()); >#P org.eclipse.wst.html.core.tests >Index: src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java,v >retrieving revision 1.8 >diff -u -r1.8 HTMLCoreTestSuite.java >--- src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java 18 Sep 2007 17:01:52 -0000 1.8 >+++ src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java 23 Dec 2009 16:01:45 -0000 >@@ -13,6 +13,7 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > >+import org.eclipse.wst.html.core.tests.cleanup.TestHTMLCleanupProcessor; > import org.eclipse.wst.html.core.tests.format.TestFormatProcessorHTML; > import org.eclipse.wst.html.core.tests.misc.HTMLCorePreferencesTest; > import org.eclipse.wst.html.core.tests.misc.HTMLTagInfoTest; >@@ -47,5 +48,6 @@ > addTest(new TestSuite(BUG124835SetStyleAttributeValueTest.class)); > addTest(new TestSuite(TestFormatProcessorHTML.class)); > addTest(new TestSuite(TestCatalogContentModels.class)); >+ addTest(TestHTMLCleanupProcessor.suite()); > } > } >\ No newline at end of file >Index: testresources/HTMLCleanupProcessor/test1-expected.html >=================================================================== >RCS file: testresources/HTMLCleanupProcessor/test1-expected.html >diff -N testresources/HTMLCleanupProcessor/test1-expected.html >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testresources/HTMLCleanupProcessor/test1-expected.html 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> >+<html> >+<head> >+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> >+<title>Insert title here</title> >+</head> >+<body> >+ >+<br> >+ >+<br/> >+ >+</body> >+</html> >\ No newline at end of file >Index: testresources/HTMLCleanupProcessor/test2.html >=================================================================== >RCS file: testresources/HTMLCleanupProcessor/test2.html >diff -N testresources/HTMLCleanupProcessor/test2.html >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testresources/HTMLCleanupProcessor/test2.html 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,15 @@ >+<?xml version="1.0" encoding="ISO-8859-1" ?> >+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >+<html xmlns="http://www.w3.org/1999/xhtml"> >+<head> >+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> >+<title>Insert title here</title> >+</head> >+<body> >+ >+<br> >+ >+<br></br> >+ >+</body> >+</html> >\ No newline at end of file >Index: src/org/eclipse/wst/html/core/tests/cleanup/TestHTMLCleanupProcessor.java >=================================================================== >RCS file: src/org/eclipse/wst/html/core/tests/cleanup/TestHTMLCleanupProcessor.java >diff -N src/org/eclipse/wst/html/core/tests/cleanup/TestHTMLCleanupProcessor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/html/core/tests/cleanup/TestHTMLCleanupProcessor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,234 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.core.tests.cleanup; >+ >+import java.io.IOException; >+ >+import junit.extensions.TestSetup; >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl; >+import org.eclipse.wst.html.core.tests.ProjectUtil; >+import org.eclipse.wst.sse.core.StructuredModelManager; >+import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.utils.StringUtils; >+ >+public class TestHTMLCleanupProcessor extends TestCase { >+ /** >+ * The name of the project that all of these tests will use >+ */ >+ private static final String PROJECT_NAME = "TestHTMLCleanupProcessor"; >+ >+ /** >+ * The location of the testing files >+ */ >+ private static final String PROJECT_FILES = "/testresources/HTMLCleanupProcessor"; >+ >+ /** >+ * The project that all of the tests use >+ */ >+ private static IProject fProject; >+ >+ /** >+ * Default constructor >+ */ >+ public TestHTMLCleanupProcessor() { >+ super("Test HTML Cleanup Processor"); >+ } >+ >+ /** >+ * Constructor that takes a test name. >+ * >+ * @param name The name this test run should have. >+ */ >+ public TestHTMLCleanupProcessor(String name) { >+ super(name); >+ } >+ >+ /** >+ * <p>Use this method to add these tests to a larger test suite so set up >+ * and tear down can be performed</p> >+ * >+ * @return a {@link TestSetup} that will run all of the tests in this class >+ * with set up and tear down. >+ */ >+ public static Test suite() { >+ TestSuite ts = new TestSuite(TestHTMLCleanupProcessor.class); >+ return new TestHTMLCleanupProcessorSetup(ts); >+ >+ } >+ >+ /** >+ * <p><b>TEST:</b> collapsing empty tags in an html document</p> >+ */ >+ public void testCollapseEmptyTagsHTML()throws Exception { >+ HTMLCleanupProcessorImpl cleanupProcessor = getProcessorForForEmptyTagsTest(); >+ runTest("test1.html", "test1-expected.html", cleanupProcessor); >+ } >+ >+ /** >+ * <p><b>TEST:</b> collapsing empty tags in an xhtml document</p> >+ */ >+ public void testCollapseEmptyTagsXHTML()throws Exception { >+ HTMLCleanupProcessorImpl cleanupProcessor = getProcessorForForEmptyTagsTest(); >+ runTest("test2.html", "test2-expected.html", cleanupProcessor); >+ } >+ >+ /** >+ * @return a configured {@link HTMLCleanupProcessorImpl} for testing compressing empty tags >+ */ >+ private static HTMLCleanupProcessorImpl getProcessorForForEmptyTagsTest() { >+ HTMLCleanupProcessorImpl cleanupProcessor = new HTMLCleanupProcessorImpl(); >+ cleanupProcessor.getCleanupPreferences().setCompressEmptyElementTags(true); >+ cleanupProcessor.getCleanupPreferences().setInsertRequiredAttrs(false); >+ cleanupProcessor.getCleanupPreferences().setInsertMissingTags(true); >+ cleanupProcessor.getCleanupPreferences().setQuoteAttrValues(false); >+ cleanupProcessor.getCleanupPreferences().setFormatSource(false); >+ cleanupProcessor.getCleanupPreferences().setConvertEOLCodes(false); >+ >+ return cleanupProcessor; >+ } >+ >+ /** >+ * <p>Runs an {@link AbstractStructuredCleanupProcessor} test</p> >+ * >+ * @param originalFile file to clean up >+ * @param expectedResultsFile expected results of cleaning up the original file >+ * @param configuredCleanupProcessor the processor to use to do the cleaning >+ * >+ * @throws Exception tests can throw exceptions now and then >+ */ >+ private void runTest(String originalFile, String expectedResultsFile, >+ AbstractStructuredCleanupProcessor configuredCleanupProcessor) throws Exception { >+ >+ IStructuredModel model = null; >+ IStructuredModel expectedModel = null; >+ try { >+ model = getModelForEdit(originalFile); >+ expectedModel = getModelForEdit(expectedResultsFile); >+ >+ configuredCleanupProcessor.refreshCleanupPreferences = false; >+ configuredCleanupProcessor.cleanupModel(model); >+ configuredCleanupProcessor.refreshCleanupPreferences = true; >+ >+ model.save(); >+ >+ standardizeLineEndings(model.getStructuredDocument()); >+ standardizeLineEndings(expectedModel.getStructuredDocument()); >+ >+ assertEquals("Clean up results did not match expected results", >+ expectedModel.getStructuredDocument().get(), >+ model.getStructuredDocument().get()); >+ } finally { >+ if(model != null) { >+ model.releaseFromEdit(); >+ } >+ >+ if(expectedModel != null) { >+ expectedModel.releaseFromEdit(); >+ } >+ } >+ } >+ >+ /** >+ * <p>Given a file name in <code>fProject</code> attempts to get a model >+ * for it, if the file doesn't exist or it can't get the model the test fails.</p> >+ * >+ * @param filename >+ * @return >+ * @throws CoreException >+ * @throws IOException >+ */ >+ private IStructuredModel getModelForEdit(final String filename) throws IOException, CoreException { >+ IFile file = fProject.getFile(filename); >+ assertTrue("Test file " + file + " can not be found", file.exists()); >+ >+ IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit(file); >+ assertNotNull("Could not get model for " + file, model); >+ >+ return model; >+ } >+ >+ >+ /** >+ * <p>Line endings can be an issue when running tests on different OSs. >+ * This function standardizes the line endings to use <code>\n</code></p> >+ * >+ * <p>It will get the text from the given editor, change the line endings, >+ * and then save the editor</p> >+ * >+ * @param editor standardize the line endings of the text presented in this >+ * editor. >+ */ >+ private void standardizeLineEndings(IDocument doc) { >+ String contents = doc.get(); >+ contents = StringUtils.replace(contents, "\r\n", "\n"); >+ contents = StringUtils.replace(contents, "\r", "\n"); >+ doc.set(contents); >+ } >+ >+ /** >+ * <p>This inner class is used to do set up and tear down before and >+ * after (respectively) all tests in the inclosing class have run.</p> >+ */ >+ private static class TestHTMLCleanupProcessorSetup extends TestSetup { >+ private static final String WTP_AUTOTEST_NONINTERACTIVE = "wtp.autotest.noninteractive"; >+ private static String previousWTPAutoTestNonInteractivePropValue = null; >+ >+ /** >+ * Default constructor >+ * >+ * @param test do setup for the given test >+ */ >+ public TestHTMLCleanupProcessorSetup(Test test) { >+ super(test); >+ } >+ >+ /** >+ * <p>This is run once before all of the tests</p> >+ * >+ * @see junit.extensions.TestSetup#setUp() >+ */ >+ public void setUp() throws Exception { >+ fProject = ProjectUtil.createProject(PROJECT_NAME, null, null); >+ ProjectUtil.copyBundleEntriesIntoWorkspace(PROJECT_FILES, PROJECT_NAME); >+ >+ String noninteractive = System.getProperty(WTP_AUTOTEST_NONINTERACTIVE); >+ if (noninteractive != null) { >+ previousWTPAutoTestNonInteractivePropValue = noninteractive; >+ } else { >+ previousWTPAutoTestNonInteractivePropValue = "false"; >+ } >+ System.setProperty(WTP_AUTOTEST_NONINTERACTIVE, "true"); >+ } >+ >+ /** >+ * <p>This is run once after all of the tests have been run</p> >+ * >+ * @see junit.extensions.TestSetup#tearDown() >+ */ >+ public void tearDown() throws Exception { >+ fProject.delete(true, new NullProgressMonitor()); >+ >+ if (previousWTPAutoTestNonInteractivePropValue != null) { >+ System.setProperty(WTP_AUTOTEST_NONINTERACTIVE, previousWTPAutoTestNonInteractivePropValue); >+ } >+ } >+ } >+} >Index: testresources/HTMLCleanupProcessor/test2-expected.html >=================================================================== >RCS file: testresources/HTMLCleanupProcessor/test2-expected.html >diff -N testresources/HTMLCleanupProcessor/test2-expected.html >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testresources/HTMLCleanupProcessor/test2-expected.html 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,15 @@ >+<?xml version="1.0" encoding="ISO-8859-1" ?> >+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >+<html xmlns="http://www.w3.org/1999/xhtml"> >+<head> >+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> >+<title>Insert title here</title> >+</head> >+<body> >+ >+<br /> >+ >+<br/> >+ >+</body> >+</html> >\ No newline at end of file >Index: testresources/HTMLCleanupProcessor/test1.html >=================================================================== >RCS file: testresources/HTMLCleanupProcessor/test1.html >diff -N testresources/HTMLCleanupProcessor/test1.html >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testresources/HTMLCleanupProcessor/test1.html 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> >+<html> >+<head> >+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> >+<title>Insert title here</title> >+</head> >+<body> >+ >+<br> >+ >+<br></br> >+ >+</body> >+</html> >\ No newline at end of file >Index: src/org/eclipse/wst/html/core/tests/ProjectUtil.java >=================================================================== >RCS file: src/org/eclipse/wst/html/core/tests/ProjectUtil.java >diff -N src/org/eclipse/wst/html/core/tests/ProjectUtil.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/html/core/tests/ProjectUtil.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,127 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ * >+ *******************************************************************************/ >+package org.eclipse.wst.html.core.tests; >+ >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.net.URL; >+import java.util.Enumeration; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IProjectDescription; >+import org.eclipse.core.resources.IWorkspaceRunnable; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.Path; >+ >+/** >+ * >+ * @see org.eclipse.wst.xml.ui.tests.ProjectUtil Similar Project Utils >+ * @see org.eclipse.wst.css.ui.tests.ProjectUtil Similar Project Utils >+ * @see org.eclipse.wst.dtd.ui.tests.ProjectUtil Similar Project Utils >+ */ >+public class ProjectUtil { >+ public static IProject createProject(String name, IPath location, String[] natureIds) { >+ IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(name); >+ if (location != null) { >+ description.setLocation(location); >+ } >+ if (natureIds != null) { >+ description.setNatureIds(natureIds); >+ } >+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); >+ try { >+ project.create(description, new NullProgressMonitor()); >+ project.open(new NullProgressMonitor()); >+ } >+ catch (CoreException e) { >+ e.printStackTrace(); >+ } >+ return project; >+ } >+ >+ /** >+ * @param rootEntry - avoid trailing separators >+ * @param fullTargetPath >+ */ >+ public static void copyBundleEntriesIntoWorkspace(final String rootEntry, final String fullTargetPath) { >+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() { >+ public void run(IProgressMonitor monitor) throws CoreException { >+ _copyBundleEntriesIntoWorkspace(rootEntry, fullTargetPath); >+ ResourcesPlugin.getWorkspace().checkpoint(true); >+ } >+ }; >+ try { >+ ResourcesPlugin.getWorkspace().run(runnable, new NullProgressMonitor()); >+ } >+ catch (CoreException e) { >+ e.printStackTrace(); >+ } >+ } >+ >+ static void _copyBundleEntriesIntoWorkspace(final String rootEntry, final String fullTargetPath) throws CoreException { >+ Enumeration entries = HTMLCoreTestsPlugin.getDefault().getBundle().getEntryPaths(rootEntry); >+ while (entries != null && entries.hasMoreElements()) { >+ String entryPath = entries.nextElement().toString(); >+ String targetPath = new Path(fullTargetPath + "/" + entryPath.substring(rootEntry.length())).toString(); >+ if (entryPath.endsWith("/")) { >+ IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(targetPath)); >+ if (!folder.exists()) { >+ folder.create(true, true, new NullProgressMonitor()); >+ } >+ _copyBundleEntriesIntoWorkspace(entryPath, targetPath); >+ } >+ else { >+ _copyBundleEntryIntoWorkspace(entryPath, targetPath); >+ } >+ } >+ } >+ >+ static IFile _copyBundleEntryIntoWorkspace(String entryname, String fullPath) throws CoreException { >+ IFile file = null; >+ URL entry = HTMLCoreTestsPlugin.getDefault().getBundle().getEntry(entryname); >+ if (entry != null) { >+ try { >+ byte[] b = new byte[2048]; >+ InputStream input = entry.openStream(); >+ ByteArrayOutputStream output = new ByteArrayOutputStream(); >+ int i = -1; >+ while ((i = input.read(b)) > -1) { >+ output.write(b, 0, i); >+ } >+ file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath)); >+ if (file != null) { >+ if (!file.exists()) { >+ file.create(new ByteArrayInputStream(output.toByteArray()), true, new NullProgressMonitor()); >+ } >+ else { >+ file.setContents(new ByteArrayInputStream(output.toByteArray()), true, false, new NullProgressMonitor()); >+ } >+ } >+ } >+ catch (IOException e) { >+ e.printStackTrace(); >+ } >+ catch (CoreException e) { >+ e.printStackTrace(); >+ } >+ } >+ return file; >+ } >+} >\ No newline at end of file
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 Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 129877
:
154593
|
154654
|
154767
|
154974
|
154975
|
154976
|
154977
|
155369