Search in sources :

Example 1 with CSSSourceParser

use of org.eclipse.wst.css.core.internal.parser.CSSSourceParser in project webtools.sourceediting by eclipse.

the class CSSModelImpl method createDocument.

private CSSDocumentImpl createDocument() {
    CSSDocumentImpl doc = null;
    int parserMode = CSSSourceParser.MODE_STYLESHEET;
    if (ownerNode == null) {
        // this case is external CSS file
        // parameters
        doc = (CSSStyleSheetImpl) DOMCSSImpl.createCSSStyleSheet(null, null);
        // are
        // for
        // STYLE-tag
        parserMode = CSSSourceParser.MODE_STYLESHEET;
    } else if (ownerNode instanceof org.w3c.dom.Element && ((Element) ownerNode).getTagName().toUpperCase().equals("STYLE")) {
        // $NON-NLS-1$
        // this case is STYLE-tag
        Element style = (Element) ownerNode;
        doc = (CSSStyleSheetImpl) // $NON-NLS-1$
        DOMCSSImpl.createCSSStyleSheet(// $NON-NLS-1$
        style.getAttribute("TITLE"), // $NON-NLS-1$
        style.getAttribute("MEDIA"));
        parserMode = CSSSourceParser.MODE_STYLESHEET;
    } else if (ownerNode instanceof org.w3c.dom.Element || ownerNode instanceof org.w3c.dom.Attr) {
        // Inline attributes
        doc = (CSSStyleDeclarationImpl) DOMCSSImpl.createCSSStyleDeclaration();
        parserMode = CSSSourceParser.MODE_DECLARATION;
    }
    RegionParser regionParser = getStructuredDocument().getParser();
    if (regionParser instanceof CSSSourceParser) {
        ((CSSSourceParser) regionParser).setParserMode(parserMode);
    }
    return doc;
}
Also used : Element(org.w3c.dom.Element) Element(org.w3c.dom.Element) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)

Example 2 with CSSSourceParser

use of org.eclipse.wst.css.core.internal.parser.CSSSourceParser in project webtools.sourceediting by eclipse.

the class CSSUrlTest method testDeclaration2.

/**
 * Declaration: without quotes, with surrounded space
 */
public void testDeclaration2() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    ((CSSSourceParser) document.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
    // $NON-NLS-1$
    document.set("background-image: url(  white space.gif  );");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(1, urls.length);
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[0].getUrl());
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 3 with CSSSourceParser

use of org.eclipse.wst.css.core.internal.parser.CSSSourceParser in project webtools.sourceediting by eclipse.

the class CSSUrlTest method testDeclaration3.

/**
 * Declaration: with single quote
 */
public void testDeclaration3() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    ((CSSSourceParser) document.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
    // $NON-NLS-1$
    document.set("background-image: url(\'white space.gif\');");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(1, urls.length);
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[0].getUrl());
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 4 with CSSSourceParser

use of org.eclipse.wst.css.core.internal.parser.CSSSourceParser in project webtools.sourceediting by eclipse.

the class CSSUrlTest method testDeclaration1.

/**
 * Declaration: without quotes
 */
public void testDeclaration1() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    ((CSSSourceParser) document.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
    // $NON-NLS-1$
    document.set("background-image: url(white space.gif);");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(1, urls.length);
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[0].getUrl());
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 5 with CSSSourceParser

use of org.eclipse.wst.css.core.internal.parser.CSSSourceParser 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)

Aggregations

CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)12 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)10 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)7 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)4 CSSDocumentLoader (org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader)3 IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)3 RegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)1 DOMException (org.w3c.dom.DOMException)1 Element (org.w3c.dom.Element)1