Search in sources :

Example 1 with CSSDocumentLoader

use of org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader in project webtools.sourceediting by eclipse.

the class CSSStyleSheetImpl method createCSSRule.

/**
 * @return org.w3c.dom.css.CSSRule
 * @param rule
 *            java.lang.String
 */
public CSSRule createCSSRule(String rule) {
    CSSDocumentLoader loader = new CSSDocumentLoader();
    IStructuredDocument structuredDocument = (IStructuredDocument) loader.createNewStructuredDocument();
    structuredDocument.set(rule);
    // CSSModelParser modelParser = new CSSModelParser((CSSDocumentImpl) getOwnerDocument());
    CSSModelParser modelParser = new CSSModelParser(getOwnerDocument());
    return modelParser.createCSSRule(structuredDocument.getRegionList());
}
Also used : CSSDocumentLoader(org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 2 with CSSDocumentLoader

use of org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader in project webtools.sourceediting by eclipse.

the class CSSCorePreferencesTest method testDelimiterPreferences.

/**
 * Tests line delimiter preferences by making sure document created
 * follows line delimiter preference.
 */
public void testDelimiterPreferences() {
    // check if content type preferences match
    String preferredDelimiter = ContentTypeEncodingPreferences.getPreferredNewLineDelimiter(ContentTypeIdForCSS.ContentTypeID_CSS);
    Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForCSS.ContentTypeID_CSS);
    String gatewayDelimiter = prefs.get(CommonEncodingPreferenceNames.END_OF_LINE_CODE, null);
    assertEquals("ContentTypeEncodingPreferences and ContentBasedPreferenceGateway preferences do not match", gatewayDelimiter, preferredDelimiter);
    // set a particular line delimiter
    prefs.put(CommonEncodingPreferenceNames.END_OF_LINE_CODE, CommonEncodingPreferenceNames.LF);
    // create document
    CSSDocumentLoader loader = new CSSDocumentLoader();
    IEncodedDocument document = loader.createNewStructuredDocument();
    String documentDelimiter = document.getPreferredLineDelimiter();
    // verify delimiter in document matches preference
    assertEquals("Delimiter in document does not match preference", CommonEncodingPreferenceNames.STRING_LF, documentDelimiter);
    // return to original preference
    prefs.remove(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
}
Also used : CSSDocumentLoader(org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader) ContentTypeEncodingPreferences(org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 3 with CSSDocumentLoader

use of org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader in project webtools.sourceediting by eclipse.

the class TestCSSDecl method testCSSStyleDeclItemSTYLE_SHEET.

public void testCSSStyleDeclItemSTYLE_SHEET() {
    String value = "color: blue;";
    IDocumentLoader loader = new CSSDocumentLoader();
    IStructuredDocument sharedStructuredDocument = (IStructuredDocument) loader.createNewStructuredDocument();
    ((CSSSourceParser) sharedStructuredDocument.getParser()).setParserMode(CSSSourceParser.MODE_STYLESHEET);
    sharedStructuredDocument.set(value);
    IStructuredDocumentRegion region = sharedStructuredDocument.getFirstStructuredDocumentRegion();
    assertNotNull(region);
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CSSDocumentLoader(org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 4 with CSSDocumentLoader

use of org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader in project webtools.sourceediting by eclipse.

the class TestCSSDecl method testCSSStyleDeclItemMODE_DECLARATION.

public void testCSSStyleDeclItemMODE_DECLARATION() {
    String value = "color: blue;";
    IDocumentLoader loader = new CSSDocumentLoader();
    IStructuredDocument sharedStructuredDocument = (IStructuredDocument) loader.createNewStructuredDocument();
    ((CSSSourceParser) sharedStructuredDocument.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION);
    sharedStructuredDocument.set(value);
    IStructuredDocumentRegion region = sharedStructuredDocument.getFirstStructuredDocumentRegion();
    assertNotNull(region);
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CSSDocumentLoader(org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 5 with CSSDocumentLoader

use of org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader in project webtools.sourceediting by eclipse.

the class TestCSSDecl method testCSSStyleDeclItem.

public void testCSSStyleDeclItem() {
    String value = "color: blue;";
    IDocumentLoader loader = new CSSDocumentLoader();
    IStructuredDocument sharedStructuredDocument = (IStructuredDocument) loader.createNewStructuredDocument();
    ((CSSSourceParser) sharedStructuredDocument.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
    sharedStructuredDocument.set(value);
    IStructuredDocumentRegion region = sharedStructuredDocument.getFirstStructuredDocumentRegion();
    assertNotNull(region);
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CSSDocumentLoader(org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Aggregations

CSSDocumentLoader (org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader)5 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)4 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)3 IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)3 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)3 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 ContentTypeEncodingPreferences (org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences)1 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)1 Preferences (org.osgi.service.prefs.Preferences)1