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;
}
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());
}
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());
}
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());
}
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);
}
Aggregations