use of org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences in project webtools.sourceediting by eclipse.
the class HTMLConverter method cleanupModel.
public void cleanupModel(IDOMModel model) {
if (model == null)
return;
HTMLCleanupProcessorImpl processor = new HTMLCleanupProcessorImpl();
IStructuredCleanupPreferences pref = processor.getCleanupPreferences();
// backup options
boolean compressEmptyElementTags = pref.getCompressEmptyElementTags();
boolean insertRequiredAttrs = pref.getInsertRequiredAttrs();
boolean insertMissingTags = pref.getInsertMissingTags();
boolean quoteAttrValues = pref.getQuoteAttrValues();
boolean formatSource = pref.getFormatSource();
int tagNameCase = pref.getTagNameCase();
int attrNameCase = pref.getAttrNameCase();
// setup options
pref.setCompressEmptyElementTags(true);
pref.setInsertRequiredAttrs(true);
pref.setInsertMissingTags(true);
pref.setQuoteAttrValues(true);
pref.setFormatSource(false);
if (model.getDocument().isXMLType()) {
// XHTML
pref.setTagNameCase(HTMLCorePreferenceNames.LOWER);
pref.setAttrNameCase(HTMLCorePreferenceNames.LOWER);
} else {
pref.setTagNameCase(HTMLCorePreferenceNames.ASIS);
pref.setAttrNameCase(HTMLCorePreferenceNames.ASIS);
}
processor.cleanupModel(model);
// set back options
pref.setCompressEmptyElementTags(compressEmptyElementTags);
pref.setInsertRequiredAttrs(insertRequiredAttrs);
pref.setInsertMissingTags(insertMissingTags);
pref.setQuoteAttrValues(quoteAttrValues);
pref.setFormatSource(formatSource);
pref.setTagNameCase(tagNameCase);
pref.setAttrNameCase(attrNameCase);
}
use of org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences in project webtools.sourceediting by eclipse.
the class HTMLCleanupProcessorImpl method 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;
}
use of org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences in project webtools.sourceediting by eclipse.
the class CleanupTester method testCleanupInsertTags.
public void testCleanupInsertTags() throws IOException, IOException {
// get model
IStructuredModel structuredModel = getModel("invoice.xml");
// init CleanupPreferences
IStructuredCleanupPreferences cleanupPreferences = fCleanupProcessor.getCleanupPreferences();
cleanupPreferences.setCompressEmptyElementTags(false);
cleanupPreferences.setInsertRequiredAttrs(false);
cleanupPreferences.setInsertMissingTags(true);
cleanupPreferences.setQuoteAttrValues(false);
cleanupPreferences.setFormatSource(false);
cleanupPreferences.setConvertEOLCodes(false);
// cleanup
((AbstractStructuredCleanupProcessor) fCleanupProcessor).refreshCleanupPreferences = false;
fCleanupProcessor.cleanupModel(structuredModel);
((AbstractStructuredCleanupProcessor) fCleanupProcessor).refreshCleanupPreferences = true;
// compare
String cleaned = structuredModel.getStructuredDocument().get();
String expectedFileName = "invoice.afterCleanupInsertTags.xml";
String expected = getFile(expectedFileName);
compare(expectedFileName, expected, cleaned);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences in project webtools.sourceediting by eclipse.
the class CleanupTester method testCleanupInsertTagsQuoteAttrs.
public void testCleanupInsertTagsQuoteAttrs() throws UnsupportedEncodingException, IOException {
// get model
IStructuredModel structuredModel = getModel("invoice.xml");
// use for debugging
// String precleaned = structuredModel.getStructuredDocument().get();
// init CleanupPreferences
IStructuredCleanupPreferences cleanupPreferences = fCleanupProcessor.getCleanupPreferences();
cleanupPreferences.setCompressEmptyElementTags(false);
cleanupPreferences.setInsertRequiredAttrs(false);
cleanupPreferences.setInsertMissingTags(true);
cleanupPreferences.setQuoteAttrValues(true);
cleanupPreferences.setFormatSource(false);
cleanupPreferences.setConvertEOLCodes(false);
// cleanup
((AbstractStructuredCleanupProcessor) fCleanupProcessor).refreshCleanupPreferences = false;
fCleanupProcessor.cleanupModel(structuredModel);
((AbstractStructuredCleanupProcessor) fCleanupProcessor).refreshCleanupPreferences = true;
// compare
String cleaned = structuredModel.getStructuredDocument().get();
String expectedFileName = "invoice.afterCleanupInsertTagsQuoteAttrs.xml";
String expected = getFile(expectedFileName);
compare(expectedFileName, expected, cleaned);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences in project webtools.sourceediting by eclipse.
the class CleanupTester method testCleanupHTMLtwice.
public void testCleanupHTMLtwice() throws UnsupportedEncodingException, IOException {
// get model
IStructuredModel structuredModel = getModel("cleanup.afterCleanup.html");
// init CleanupPreferences
IStructuredCleanupPreferences cleanupPreferences = fHTMLCleanupProcessor.getCleanupPreferences();
cleanupPreferences.setTagNameCase(HTMLCorePreferenceNames.UPPER);
cleanupPreferences.setAttrNameCase(HTMLCorePreferenceNames.LOWER);
cleanupPreferences.setCompressEmptyElementTags(false);
cleanupPreferences.setInsertRequiredAttrs(false);
cleanupPreferences.setInsertMissingTags(true);
cleanupPreferences.setQuoteAttrValues(true);
cleanupPreferences.setFormatSource(false);
cleanupPreferences.setConvertEOLCodes(false);
// cleanup
((AbstractStructuredCleanupProcessor) fHTMLCleanupProcessor).refreshCleanupPreferences = false;
fHTMLCleanupProcessor.cleanupModel(structuredModel);
((AbstractStructuredCleanupProcessor) fHTMLCleanupProcessor).refreshCleanupPreferences = true;
// compare
String cleaned = structuredModel.getStructuredDocument().get();
String expectedFileName = "cleanup.afterCleanup.html";
String expected = getFile(expectedFileName);
compare(expectedFileName, expected, cleaned);
// release model
structuredModel.releaseFromRead();
}
Aggregations