Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/steadystate/css/dom/CSSFontFaceRuleImpl.java


1   /*
2    * CSSFontFaceRuleImpl.java
3    *
4    * Steady State CSS2 Parser
5    *
6    * Copyright (C) 1999, 2002 Steady State Software Ltd.  All rights reserved.
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *
22   * To contact the authors of the library, write to Steady State Software Ltd.,
23   * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England
24   *
25   * http://www.steadystate.com/css/
26   * mailto:css@steadystate.co.uk
27   *
28   * $Id: CSSFontFaceRuleImpl.java,v 1.1.1.1 2003/12/28 21:22:47 davidsch Exp $
29   */
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              // The rule must be a font face rule
73              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 }