KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > steadystate > css > dom > CSSUnknownRuleImpl


1 /*
2  * CSSUnknownRuleImpl.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: CSSUnknownRuleImpl.java,v 1.2 2005/04/28 20:57:20 waldbaer Exp $
29  */

30
31 package com.steadystate.css.dom;
32
33 import java.io.Serializable JavaDoc;
34 import org.w3c.dom.*;
35 import org.w3c.dom.css.*;
36
37 /*
38  *
39  * @author David Schweinsberg
40  * @version $Release$
41  */

42 public class CSSUnknownRuleImpl implements CSSUnknownRule, Serializable JavaDoc {
43
44     CSSStyleSheetImpl _parentStyleSheet = null;
45     CSSRule _parentRule = null;
46     String JavaDoc _text = null;
47
48     public CSSUnknownRuleImpl(
49             CSSStyleSheetImpl parentStyleSheet,
50             CSSRule parentRule,
51             String JavaDoc text) {
52         _parentStyleSheet = parentStyleSheet;
53         _parentRule = parentRule;
54         _text = text;
55     }
56
57     public short getType() {
58         return UNKNOWN_RULE;
59     }
60
61     public String JavaDoc getCssText() {
62         return _text;
63     }
64
65     public void setCssText(String JavaDoc cssText) throws DOMException {
66 /*
67         if( _parentStyleSheet != null && _parentStyleSheet.isReadOnly() )
68         throw new DOMExceptionImpl(
69         DOMException.NO_MODIFICATION_ALLOWED_ERR,
70         DOMExceptionImpl.READ_ONLY_STYLE_SHEET );
71
72         try
73         {
74             //
75             // Parse the rule string and retrieve the rule
76             //
77             StringReader sr = new StringReader( cssText );
78             CSS2Parser parser = new CSS2Parser( sr );
79             ASTStyleSheetRuleSingle ssrs = parser.styleSheetRuleSingle();
80             CSSRule r = (CSSRule) ssrs.jjtGetChild( 0 );
81
82             //
83             // The rule must be an unknown rule
84             //
85             if( r.getType() == CSSRule.UNKNOWN_RULE )
86             {
87                 _text = ((ASTUnknownRule)r)._text;
88                 setChildren( ((SimpleNode)r).getChildren() );
89             }
90             else
91             {
92                 throw new DOMExceptionImpl(
93                 DOMException.INVALID_MODIFICATION_ERR,
94                 DOMExceptionImpl.EXPECTING_UNKNOWN_RULE );
95             }
96         }
97         catch( ParseException e )
98         {
99             throw new DOMExceptionImpl(
100             DOMException.SYNTAX_ERR,
101             DOMExceptionImpl.SYNTAX_ERROR,
102             e.getMessage() );
103         }
104 */

105     }
106
107     public CSSStyleSheet getParentStyleSheet() {
108         return _parentStyleSheet;
109     }
110
111     public CSSRule getParentRule() {
112         return _parentRule;
113     }
114     
115     public String JavaDoc toString() {
116         return getCssText();
117     }
118 }
119
Popular Tags