Search in sources :

Example 1 with IStructuredCleanupPreferences

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);
}
Also used : IStructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences) HTMLCleanupProcessorImpl(org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl)

Example 2 with IStructuredCleanupPreferences

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;
}
Also used : IStructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences) StructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences) Preferences(org.eclipse.core.runtime.Preferences) IStructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences) StructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)

Example 3 with IStructuredCleanupPreferences

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();
}
Also used : IStructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 4 with IStructuredCleanupPreferences

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();
}
Also used : IStructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 5 with IStructuredCleanupPreferences

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();
}
Also used : IStructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IStructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences)12 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)7 Preferences (org.eclipse.core.runtime.Preferences)4 StructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)4 HTMLCleanupProcessorImpl (org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl)1