CSSStyleSheetImpl.java in  » Swing-Library » Lobo-Java-Web-Browser » com » steadystate » css » dom » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » Swing Library » Lobo Java Web Browser » com.steadystate.css.dom 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


        /*
         * CSSStyleSheetImpl.java
         *
         * Steady State CSS2 Parser
         *
         * Copyright (C) 1999, 2002 Steady State Software Ltd.  All rights reserved.
         *
         * This library is free software; you can redistribute it and/or
         * modify it under the terms of the GNU Lesser General Public
         * License as published by the Free Software Foundation; either
         * version 2 of the License, or (at your option) any later version.
         *
         * This library is distributed in the hope that it will be useful,
         * but WITHOUT ANY WARRANTY; without even the implied warranty of
         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
         * Lesser General Public License for more details.
         *
         * You should have received a copy of the GNU Lesser General Public
         * License along with this library; if not, write to the Free Software
         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
         *
         * To contact the authors of the library, write to Steady State Software Ltd.,
         * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England
         *
         * http://www.steadystate.com/css/
         * mailto:[email protected]
         *
         * $Id: CSSStyleSheetImpl.java,v 1.5 2008/08/10 22:54:43 xamjadmin Exp $
         */

        package com.steadystate.css.dom;

        import java.io.IOException;
        import java.io.Serializable;
        import java.io.StringReader;
        import org.w3c.dom.*;
        import org.w3c.dom.stylesheets.*;
        import org.w3c.dom.css.*;
        import org.w3c.css.sac.*;
        import com.steadystate.css.parser.*;

        /**
         * TODO: Setting the media list
         *
         * @author David Schweinsberg
         * @version $Release$
         */
        public class CSSStyleSheetImpl implements  CSSStyleSheet, Serializable {
            public static final String KEY_DISABLED_CHANGED = "styleSheet.disabled.changed";
            private boolean _disabled = false;
            private Node _ownerNode = null;
            private StyleSheet _parentStyleSheet = null;
            private String _href = null;
            private String _title = null;
            private MediaList _media = null;
            private CSSRule _ownerRule = null;
            private boolean _readOnly = false;
            private CSSRuleListImpl _rules = null;

            public CSSStyleSheetImpl() {
            }

            public String getType() {
                return "text/css";
            }

            public boolean getDisabled() {
                return _disabled;
            }

            /**
             * We will need to respond more fully if a stylesheet is disabled, probably
             * by generating an event for the main application.
             */
            public void setDisabled(boolean disabled) {
                if (this ._disabled != disabled) {
                    _disabled = disabled;
                    Node node = this .getOwnerNode();
                    if (node != null) {
                        node.setUserData(KEY_DISABLED_CHANGED, Boolean
                                .valueOf(disabled), null);
                    }
                }
            }

            public void setDisabledOnly(boolean disabled) {
                this ._disabled = disabled;
            }

            public Node getOwnerNode() {
                return _ownerNode;
            }

            public StyleSheet getParentStyleSheet() {
                return _parentStyleSheet;
            }

            public String getHref() {
                return _href;
            }

            public String getTitle() {
                return _title;
            }

            public MediaList getMedia() {
                return _media;
            }

            public CSSRule getOwnerRule() {
                return _ownerRule;
            }

            public CSSRuleList getCssRules() {
                return _rules;
            }

            public int insertRule(String rule, int index) throws DOMException {
                if (_readOnly) {
                    throw new DOMExceptionImpl(
                            DOMException.NO_MODIFICATION_ALLOWED_ERR,
                            DOMExceptionImpl.READ_ONLY_STYLE_SHEET);
                }

                try {
                    InputSource is = new InputSource(new StringReader(rule));
                    CSSOMParser parser = new CSSOMParser();
                    parser.setParentStyleSheet(this );
                    CSSRule r = parser.parseRule(is);

                    if (getCssRules().getLength() > 0) {

                        // We need to check that this type of rule can legally go into
                        // the requested position.
                        int msg = -1;
                        if (r.getType() == CSSRule.CHARSET_RULE) {

                            // Index must be 0, and there can be only one charset rule
                            if (index != 0) {
                                msg = DOMExceptionImpl.CHARSET_NOT_FIRST;
                            } else if (getCssRules().item(0).getType() == CSSRule.CHARSET_RULE) {
                                msg = DOMExceptionImpl.CHARSET_NOT_UNIQUE;
                            }
                        } else if (r.getType() == CSSRule.IMPORT_RULE) {

                            // Import rules must preceed all other rules (except
                            // charset rules)
                            if (index <= getCssRules().getLength()) {
                                for (int i = 0; i < index; i++) {
                                    int rt = getCssRules().item(i).getType();
                                    if ((rt != CSSRule.CHARSET_RULE)
                                            || (rt != CSSRule.IMPORT_RULE)) {
                                        msg = DOMExceptionImpl.IMPORT_NOT_FIRST;
                                        break;
                                    }
                                }
                            }
                        }

                        if (msg > -1) {
                            throw new DOMExceptionImpl(
                                    DOMException.HIERARCHY_REQUEST_ERR, msg);
                        }
                    }

                    // Insert the rule into the list of rules
                    ((CSSRuleListImpl) getCssRules()).insert(r, index);

                } catch (ArrayIndexOutOfBoundsException e) {
                    throw new DOMExceptionImpl(DOMException.INDEX_SIZE_ERR,
                            DOMExceptionImpl.ARRAY_OUT_OF_BOUNDS, e
                                    .getMessage());
                } catch (CSSException e) {
                    throw new DOMExceptionImpl(DOMException.SYNTAX_ERR,
                            DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
                } catch (IOException e) {
                    throw new DOMExceptionImpl(DOMException.SYNTAX_ERR,
                            DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
                }
                return index;
            }

            public void deleteRule(int index) throws DOMException {
                if (_readOnly) {
                    throw new DOMExceptionImpl(
                            DOMException.NO_MODIFICATION_ALLOWED_ERR,
                            DOMExceptionImpl.READ_ONLY_STYLE_SHEET);
                }

                try {
                    ((CSSRuleListImpl) getCssRules()).delete(index);
                } catch (ArrayIndexOutOfBoundsException e) {
                    throw new DOMExceptionImpl(DOMException.INDEX_SIZE_ERR,
                            DOMExceptionImpl.ARRAY_OUT_OF_BOUNDS, e
                                    .getMessage());
                }
            }

            public boolean isReadOnly() {
                return _readOnly;
            }

            public void setReadOnly(boolean b) {
                _readOnly = b;
            }

            public void setOwnerNode(Node ownerNode) {
                _ownerNode = ownerNode;
            }

            public void setParentStyleSheet(StyleSheet parentStyleSheet) {
                _parentStyleSheet = parentStyleSheet;
            }

            public void setHref(String href) {
                _href = href;
            }

            public void setTitle(String title) {
                _title = title;
            }

            public void setMedia(String mediaText) {
                // MediaList _media = null;
            }

            public void setOwnerRule(CSSRule ownerRule) {
                _ownerRule = ownerRule;
            }

            public void setRuleList(CSSRuleListImpl rules) {
                _rules = rules;
            }

            public String toString() {
                return _rules.toString();
            }
        }
ww_w__._j___a_v_a2__s___.c__om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.