1 30 31 package com.steadystate.css.dom; 32 33 import java.io.IOException ; 34 import java.io.Serializable ; 35 import java.io.StringReader ; 36 import org.w3c.dom.*; 37 import org.w3c.dom.css.*; 38 import org.w3c.css.sac.*; 39 import com.steadystate.css.parser.*; 40 41 public class CSSFontFaceRuleImpl implements CSSFontFaceRule, Serializable { 42 43 private CSSStyleSheetImpl _parentStyleSheet = null; 44 private CSSRule _parentRule = null; 45 private CSSStyleDeclarationImpl _style = null; 46 47 public CSSFontFaceRuleImpl(CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule) { 48 _parentStyleSheet = parentStyleSheet; 49 _parentRule = parentRule; 50 } 51 52 public short getType() { 53 return FONT_FACE_RULE; 54 } 55 56 public String getCssText() { 57 return "@font-face " + getStyle().getCssText(); 58 } 59 60 public void setCssText(String cssText) throws DOMException { 61 if (_parentStyleSheet != null && _parentStyleSheet.isReadOnly()) { 62 throw new DOMExceptionImpl( 63 DOMException.NO_MODIFICATION_ALLOWED_ERR, 64 DOMExceptionImpl.READ_ONLY_STYLE_SHEET); 65 } 66 67 try { 68 InputSource is = new InputSource(new StringReader (cssText)); 69 CSSOMParser parser = new CSSOMParser(); 70 CSSRule r = parser.parseRule(is); 71 72 if (r.getType() == CSSRule.FONT_FACE_RULE) { 74 _style = ((CSSFontFaceRuleImpl)r)._style; 75 } else { 76 throw new DOMExceptionImpl( 77 DOMException.INVALID_MODIFICATION_ERR, 78 DOMExceptionImpl.EXPECTING_FONT_FACE_RULE); 79 } 80 } catch (CSSException e) { 81 throw new DOMExceptionImpl( 82 DOMException.SYNTAX_ERR, 83 DOMExceptionImpl.SYNTAX_ERROR, 84 e.getMessage()); 85 } catch (IOException e) { 86 throw new DOMExceptionImpl( 87 DOMException.SYNTAX_ERR, 88 DOMExceptionImpl.SYNTAX_ERROR, 89 e.getMessage()); 90 } 91 } 92 93 public CSSStyleSheet getParentStyleSheet() { 94 return _parentStyleSheet; 95 } 96 97 public CSSRule getParentRule() { 98 return _parentRule; 99 } 100 101 public CSSStyleDeclaration getStyle() { 102 return _style; 103 } 104 105 public void setStyle(CSSStyleDeclarationImpl style) { 106 _style = style; 107 } 108 } 109 | Popular Tags |