Search in sources :

Example 16 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateXslFile.

private void generateXslFile(String resource, String xslfile, String cssfile, String folder) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        org.w3c.dom.Document document = builder.parse(new File(resource));
        org.w3c.dom.Element rootElement = document.getDocumentElement();
        //$NON-NLS-1$
        NodeList list = rootElement.getElementsByTagName("style");
        org.w3c.dom.Element element = (org.w3c.dom.Element) list.item(0);
        String value = element.getChildNodes().item(0).getNodeValue();
        if (value != null) {
            if (folder != null) {
                //$NON-NLS-1$
                CSSParserUtils.createCssFile(value, folder + File.separator + "default.css");
            }
            if (cssfile != null && !cssfile.equals("")) {
                //$NON-NLS-1$
                if (folder != null) {
                    String cssName = new File(cssfile).getName();
                    if (cssName.equalsIgnoreCase("default.css")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        cssName = "User_" + cssName;
                    }
                    File file = new File(folder + File.separator + cssName);
                    if (!file.exists()) {
                        file.createNewFile();
                    }
                    FileCopyUtils.copy(cssfile, folder + File.separator + cssName);
                }
                CSSRuleList ruleList = CSSParserUtils.parserCSSSelectors(null, cssfile);
                if (ruleList == null) {
                    return;
                } else {
                    String newValue = CSSParserUtils.generateCssStyle(cssfile, ruleList, value);
                    element.getChildNodes().item(0).setNodeValue(newValue);
                    // replace the old value and generate a new xsl file
                    DOMSource ds = new DOMSource(document);
                    StreamResult sr = new StreamResult(new File(xslfile));
                    TransformerFactory.newInstance().newTransformer().transform(ds, sr);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        ExceptionHandler.process(e);
    } catch (SAXException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } catch (TransformerConfigurationException e) {
        ExceptionHandler.process(e);
    } catch (TransformerException e) {
        ExceptionHandler.process(e);
    } catch (TransformerFactoryConfigurationError e) {
        ExceptionHandler.process(e);
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) NodeList(org.w3c.dom.NodeList) Element(org.dom4j.Element) IOException(java.io.IOException) CSSRuleList(org.w3c.dom.css.CSSRuleList) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 17 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class CSSCharsetRuleTest method testCreateRule.

public void testCreateRule() {
    ICSSStyleSheet sheet = getStyleSheet();
    ICSSDocument doc = sheet;
    CSSCharsetRule newRule = doc.createCSSCharsetRule();
    newRule.setEncoding("iso-8859-1");
    sheet.insertRuleBefore(newRule, null);
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSCharsetRule);
    CSSCharsetRule charsetRule = (CSSCharsetRule) rule;
    assertEquals("iso-8859-1", charsetRule.getEncoding());
    assertEquals(RULE, charsetRule.getCssText());
}
Also used : CSSCharsetRule(org.w3c.dom.css.CSSCharsetRule) CSSRule(org.w3c.dom.css.CSSRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 18 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class CSSFontFamilyTest method testValueModification.

public void testValueModification() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList rules = sheet.getCssRules();
    assertEquals(4, rules.getLength());
    // Rule 1: No whitespace
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // Rule 1: No whitespace
    rule = rules.item(0);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times, serif", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times, serif", ((ICSSValue) value).getCSSValueText());
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times", ((ICSSValue) value).getCSSValueText());
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) 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 19 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class CSSPageRuleTest 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", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 1
    rule = ruleList.item(0);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(2, declaration.getLength());
    value = declaration.getPropertyCSSValue("size");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(2, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(CSSPrimitiveValue.CSS_IN, (float) 8.5));
    checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(CSSPrimitiveValue.CSS_IN, 11));
    value = declaration.getPropertyCSSValue("margin");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 2));
}
Also used : CSSPageRule(org.w3c.dom.css.CSSPageRule) 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) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 20 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class CSSPageRuleTest method testInsertText6.

public void testInsertText6() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // rule 6
    rule = ruleList.item(5);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    assertEquals("rotated", ((CSSPageRule) rule).getSelectorText());
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(1, declaration.getLength());
    value = declaration.getPropertyCSSValue("size");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "landscape"));
}
Also used : CSSPageRule(org.w3c.dom.css.CSSPageRule) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) 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)

Aggregations

CSSRuleList (org.w3c.dom.css.CSSRuleList)30 CSSRule (org.w3c.dom.css.CSSRule)29 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)19 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)19 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)17 CSSValue (org.w3c.dom.css.CSSValue)15 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)14 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)10 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)8 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 Path (org.eclipse.core.runtime.Path)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 CSSValueList (org.w3c.dom.css.CSSValueList)5 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2