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 48 public class CSSPageRuleImpl implements CSSPageRule, Serializable { 49 50 private CSSStyleSheetImpl _parentStyleSheet = null; 51 private CSSRule _parentRule = null; 52 private String _ident = null; 53 private String _pseudoPage = null; 54 private CSSStyleDeclaration _style = null; 55 56 public CSSPageRuleImpl( 57 CSSStyleSheetImpl parentStyleSheet, 58 CSSRule parentRule, 59 String ident, 60 String pseudoPage) { 61 _parentStyleSheet = parentStyleSheet; 62 _parentRule = parentRule; 63 _ident = ident; 64 _pseudoPage = pseudoPage; 65 } 66 67 public short getType() { 68 return PAGE_RULE; 69 } 70 71 public String getCssText() { 72 String sel = getSelectorText(); 73 return "@page " 74 + sel + ((sel.length() > 0) ? " " : "") 75 + getStyle().getCssText(); 76 } 77 78 public void setCssText(String cssText) throws DOMException { 79 if (_parentStyleSheet != null && _parentStyleSheet.isReadOnly()) { 80 throw new DOMExceptionImpl( 81 DOMException.NO_MODIFICATION_ALLOWED_ERR, 82 DOMExceptionImpl.READ_ONLY_STYLE_SHEET); 83 } 84 85 try { 86 InputSource is = new InputSource(new StringReader (cssText)); 87 CSSOMParser parser = new CSSOMParser(); 88 CSSRule r = parser.parseRule(is); 89 90 if (r.getType() == CSSRule.PAGE_RULE) { 92 _ident = ((CSSPageRuleImpl)r)._ident; 93 _pseudoPage = ((CSSPageRuleImpl)r)._pseudoPage; 94 _style = ((CSSPageRuleImpl)r)._style; 95 } else { 96 throw new DOMExceptionImpl( 97 DOMException.INVALID_MODIFICATION_ERR, 98 DOMExceptionImpl.EXPECTING_PAGE_RULE); 99 } 100 } catch (CSSException e) { 101 throw new DOMExceptionImpl( 102 DOMException.SYNTAX_ERR, 103 DOMExceptionImpl.SYNTAX_ERROR, 104 e.getMessage()); 105 } catch (IOException e) { 106 throw new DOMExceptionImpl( 107 DOMException.SYNTAX_ERR, 108 DOMExceptionImpl.SYNTAX_ERROR, 109 e.getMessage()); 110 } 111 } 112 113 public CSSStyleSheet getParentStyleSheet() { 114 return _parentStyleSheet; 115 } 116 117 public CSSRule getParentRule() { 118 return _parentRule; 119 } 120 121 public String getSelectorText() { 122 return ((_ident != null) ? _ident : "") 123 + ((_pseudoPage != null) ? ":" + _pseudoPage : ""); 124 } 125 126 public void setSelectorText(String selectorText) throws DOMException { 127 } 128 129 public CSSStyleDeclaration getStyle() { 130 return _style; 131 } 132 133 protected void setIdent(String ident) { 134 _ident = ident; 135 } 136 137 protected void setPseudoPage(String pseudoPage) { 138 _pseudoPage = pseudoPage; 139 } 140 141 public void setStyle(CSSStyleDeclarationImpl style) { 142 _style = style; 143 } 144 } 145 | Popular Tags |