Search in sources :

Example 31 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class JSPedCSSSourceParserTest method createModel.

private ICSSModel createModel(boolean isFragment) {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = // $NON-NLS-1$
        !isFragment ? // $NON-NLS-1$
        modelManager.getModelForEdit("cssjsptest" + index_jsp++ + ".jsp", new NullInputStream(), null) : // $NON-NLS-1$
        modelManager.getModelForEdit("cssjsptest" + index_jspf++ + ".jspf", new NullInputStream(), null);
        // $NON-NLS-1$
        model.getStructuredDocument().setLineDelimiter(commonEOL);
    } catch (Exception e) {
        StringWriter s = new StringWriter();
        e.printStackTrace(new PrintWriter(s));
        fail(s.toString());
    }
    return (ICSSModel) model;
}
Also used : StringWriter(java.io.StringWriter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NullInputStream(org.eclipse.jst.jsp.core.tests.NullInputStream) PrintWriter(java.io.PrintWriter)

Example 32 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSFontFaceRuleTest method _testInsertText1.

public void _testInsertText1() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFaceRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 1
    rule = ruleList.item(0);
    assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
    assertTrue(rule instanceof CSSFontFaceRule);
    declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(4, declaration.getLength());
    value = declaration.getPropertyCSSValue("font-family");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Swiss 721"));
    value = declaration.getPropertyCSSValue("src");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "swiss721blk.pfr"));
    value = declaration.getPropertyCSSValue("font-style");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "normal"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
    value = declaration.getPropertyCSSValue("font-weight");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 800));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 900));
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSValueList(org.w3c.dom.css.CSSValueList) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 33 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSFontFaceRuleTest method _testInsertText3.

public void _testInsertText3() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFaceRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 3
    rule = ruleList.item(2);
    assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
    assertTrue(rule instanceof CSSFontFaceRule);
    declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(5, declaration.getLength());
    value = declaration.getPropertyCSSValue("src");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(4, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Alabama Italic"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://www.fonts.org/A/alabama-italic"));
    checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_FORMAT, "truetype"));
    value = declaration.getPropertyCSSValue("panose-1");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(10, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 2));
    checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 4));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
    checkPrimitiveNumber(valueList.item(3), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 2));
    checkPrimitiveNumber(valueList.item(4), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
    checkPrimitiveNumber(valueList.item(5), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 4));
    checkPrimitiveNumber(valueList.item(6), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
    checkPrimitiveNumber(valueList.item(7), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 9));
    checkPrimitiveNumber(valueList.item(8), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 3));
    checkPrimitiveNumber(valueList.item(9), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 3));
    value = declaration.getPropertyCSSValue("font-family");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Alabama"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "serif"));
    value = declaration.getPropertyCSSValue("font-weight");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(5, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 300));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 400));
    checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(4), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 500));
    value = declaration.getPropertyCSSValue("font-style");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "oblique"));
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSValueList(org.w3c.dom.css.CSSValueList) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 34 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSStyleRuleTest method testInsertTextStrings.

public void testInsertTextStrings() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSStyleRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    rule = ruleList.item(1);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    assertEquals(11, declaration.getLength());
    // 01
    value = declaration.getPropertyCSSValue("STRING");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "string"));
    // 02
    value = declaration.getPropertyCSSValue("URI");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://www.ibm.com/"));
    // 03
    value = declaration.getPropertyCSSValue("IDENT");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "left"));
    // 04
    value = declaration.getPropertyCSSValue("HASH");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_HASH, "#abcdef"));
    // 05
    value = declaration.getPropertyCSSValue("URANGE");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_URANGE, "U+20A7"));
    // 06
    value = declaration.getPropertyCSSValue("SLASH");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_SLASH, "/"));
    // 07
    value = declaration.getPropertyCSSValue("COMMA");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    // 08
    value = declaration.getPropertyCSSValue("INHERIT_PRIMITIVE");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE, "inherit"));
    // 09
    value = declaration.getPropertyCSSValue("ATTR");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_ATTR, "KEY"));
    // 10
    value = declaration.getPropertyCSSValue("FORMAT");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_FORMAT, "truedoc"));
    // 11
    value = declaration.getPropertyCSSValue("LOCAL");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Excelsior Roman"));
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 35 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class TestCSSDecl method testCSSModel.

public void testCSSModel() {
    ICSSModel model = FileUtil.createModel();
    try {
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.set(getHTMLDocumentText());
        IStructuredDocumentRegion region = structuredDocument.getFirstStructuredDocumentRegion();
        assertNotNull(region);
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)82 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)41 CSSRule (org.w3c.dom.css.CSSRule)21 CSSRuleList (org.w3c.dom.css.CSSRuleList)20 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)14 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)14 CSSValue (org.w3c.dom.css.CSSValue)14 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)11 IModelProvideAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter)8 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)7 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)7 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 Path (org.eclipse.core.runtime.Path)6 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)6 Element (org.w3c.dom.Element)6