CSSOMParser.java in  » Swing-Library » Lobo-Java-Web-Browser » com » steadystate » css » parser » 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.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


        /*
         * CSSOMParser.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: CSSOMParser.java,v 1.11 2008/03/08 17:53:59 xamjadmin Exp $
         */

        package com.steadystate.css.parser;

        import java.io.*;
        import java.util.*;
        import org.w3c.dom.css.*;
        import org.w3c.css.sac.*;
        import com.steadystate.css.dom.*;

        /** 
         *
         * @author  David Schweinsberg
         * @version $Release$
         */
        public class CSSOMParser {
            private static final String PARSER = "com.steadystate.css.parser.SACParser";

            private Parser _parser = null;
            private CSSStyleSheetImpl _parentStyleSheet = null;

            //private CSSRule _parentRule = null;

            /** Creates new CSSOMParser */
            public CSSOMParser() {
                try {
                    //Modifying to always use local parser. 
                    //The commented code does not perform as
                    //well and has class loader issues. (Jose 6/3/2007)

                    //setProperty("org.w3c.css.sac.parser", PARSER);
                    //ParserFactory factory = new ParserFactory();
                    //_parser = factory.makeParser();

                    _parser = new com.steadystate.css.parser.SACParser();
                } catch (Exception e) {
                    System.err.println(e.getMessage());
                }
            }

            public CSSStyleSheet parseStyleSheet(InputSource source)
                    throws IOException {
                CSSOMHandler handler = new CSSOMHandler();
                _parser.setDocumentHandler(handler);
                _parser.parseStyleSheet(source);
                return (CSSStyleSheet) handler.getRoot();
            }

            public CSSStyleDeclaration parseStyleDeclaration(InputSource source)
                    throws IOException {
                CSSStyleDeclarationImpl sd = new CSSStyleDeclarationImpl(null);
                parseStyleDeclaration(sd, source);
                return sd;
            }

            public void parseStyleDeclaration(CSSStyleDeclaration sd,
                    InputSource source) throws IOException {
                Stack nodeStack = new Stack();
                nodeStack.push(sd);
                CSSOMHandler handler = new CSSOMHandler(nodeStack);
                _parser.setDocumentHandler(handler);
                _parser.parseStyleDeclaration(source);
            }

            public CSSValue parsePropertyValue(InputSource source)
                    throws IOException {
                CSSOMHandler handler = new CSSOMHandler();
                _parser.setDocumentHandler(handler);
                return new CSSValueImpl(_parser.parsePropertyValue(source));
            }

            public CSSRule parseRule(InputSource source) throws IOException {
                CSSOMHandler handler = new CSSOMHandler();
                _parser.setDocumentHandler(handler);
                _parser.parseRule(source);
                return (CSSRule) handler.getRoot();
            }

            public SelectorList parseSelectors(InputSource source)
                    throws IOException {
                HandlerBase handler = new HandlerBase();
                _parser.setDocumentHandler(handler);
                return _parser.parseSelectors(source);
            }

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

            //    public void setParentRule(CSSRule parentRule) {
            //        _parentRule = parentRule;
            //    }

            class CSSOMHandler implements  DocumentHandler {

                private Stack _nodeStack;
                private Object _root = null;

                public CSSOMHandler(Stack nodeStack) {
                    _nodeStack = nodeStack;
                }

                public CSSOMHandler() {
                    _nodeStack = new Stack();
                }

                public Object getRoot() {
                    return _root;
                }

                public void startDocument(InputSource source)
                        throws CSSException {
                    if (_nodeStack.empty()) {
                        CSSStyleSheetImpl ss = new CSSStyleSheetImpl();
                        _parentStyleSheet = ss;

                        // Create the rule list
                        CSSRuleListImpl rules = new CSSRuleListImpl();
                        ss.setRuleList(rules);
                        _nodeStack.push(ss);
                        _nodeStack.push(rules);
                    } else {
                        // Error
                    }
                }

                public void endDocument(InputSource source) throws CSSException {

                    // Pop the rule list and style sheet nodes
                    _nodeStack.pop();
                    _root = _nodeStack.pop();
                }

                public void comment(String text) throws CSSException {
                }

                public void ignorableAtRule(String atRule) throws CSSException {

                    // Create the unknown rule and add it to the rule list
                    CSSUnknownRuleImpl ir = new CSSUnknownRuleImpl(
                            _parentStyleSheet, null, atRule);
                    if (!_nodeStack.empty()) {
                        ((CSSRuleListImpl) _nodeStack.peek()).add(ir);
                    } else {
                        //                _nodeStack.push(ir);
                        _root = ir;
                    }
                }

                public void namespaceDeclaration(String prefix, String uri)
                        throws CSSException {
                }

                public void importStyle(String uri, SACMediaList media,
                        String defaultNamespaceURI) throws CSSException {

                    // Create the import rule and add it to the rule list
                    CSSImportRuleImpl ir = new CSSImportRuleImpl(
                            _parentStyleSheet, null, uri, new MediaListImpl(
                                    media));
                    if (!_nodeStack.empty()) {
                        ((CSSRuleListImpl) _nodeStack.peek()).add(ir);
                    } else {
                        //                _nodeStack.push(ir);
                        _root = ir;
                    }
                }

                public void startMedia(SACMediaList media) throws CSSException {

                    // Create the media rule and add it to the rule list
                    CSSMediaRuleImpl mr = new CSSMediaRuleImpl(
                            _parentStyleSheet, null, new MediaListImpl(media));
                    if (!_nodeStack.empty()) {
                        ((CSSRuleListImpl) _nodeStack.peek()).add(mr);
                    }

                    // Create the rule list
                    CSSRuleListImpl rules = new CSSRuleListImpl();
                    mr.setRuleList(rules);
                    _nodeStack.push(mr);
                    _nodeStack.push(rules);
                }

                public void endMedia(SACMediaList media) throws CSSException {

                    // Pop the rule list and media rule nodes
                    _nodeStack.pop();
                    _root = _nodeStack.pop();
                }

                public void startPage(String name, String pseudo_page)
                        throws CSSException {

                    // Create the page rule and add it to the rule list
                    CSSPageRuleImpl pr = new CSSPageRuleImpl(_parentStyleSheet,
                            null, name, pseudo_page);
                    if (!_nodeStack.empty()) {
                        ((CSSRuleListImpl) _nodeStack.peek()).add(pr);
                    }

                    // Create the style declaration
                    CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(
                            pr);
                    pr.setStyle(decl);
                    _nodeStack.push(pr);
                    _nodeStack.push(decl);
                }

                public void endPage(String name, String pseudo_page)
                        throws CSSException {

                    // Pop both the style declaration and the page rule nodes
                    _nodeStack.pop();
                    _root = _nodeStack.pop();
                }

                public void startFontFace() throws CSSException {

                    // Create the font face rule and add it to the rule list
                    CSSFontFaceRuleImpl ffr = new CSSFontFaceRuleImpl(
                            _parentStyleSheet, null);
                    if (!_nodeStack.empty()) {
                        ((CSSRuleListImpl) _nodeStack.peek()).add(ffr);
                    }

                    // Create the style declaration
                    CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(
                            ffr);
                    ffr.setStyle(decl);
                    _nodeStack.push(ffr);
                    _nodeStack.push(decl);
                }

                public void endFontFace() throws CSSException {

                    // Pop both the style declaration and the font face rule nodes
                    _nodeStack.pop();
                    _root = _nodeStack.pop();
                }

                public void startSelector(SelectorList selectors)
                        throws CSSException {

                    // Create the style rule and add it to the rule list
                    CSSStyleRuleImpl sr = new CSSStyleRuleImpl(
                            _parentStyleSheet, null, selectors);
                    if (!_nodeStack.empty()) {
                        ((CSSRuleListImpl) _nodeStack.peek()).add(sr);
                    }

                    // Create the style declaration
                    CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(
                            sr);
                    sr.setStyle(decl);
                    _nodeStack.push(sr);
                    _nodeStack.push(decl);
                }

                public void endSelector(SelectorList selectors)
                        throws CSSException {

                    // Pop both the style declaration and the style rule nodes
                    _nodeStack.pop();
                    _root = _nodeStack.pop();
                }

                public void property(String name, LexicalUnit value,
                        boolean important) throws CSSException {
                    CSSStyleDeclarationImpl decl = (CSSStyleDeclarationImpl) _nodeStack
                            .peek();
                    decl.addProperty(new Property(name,
                            new CSSValueImpl(value), important));
                }
            }

            public static void setProperty(String key, String val) {
                Properties props = System.getProperties();
                props.put(key, val);
                System.setProperties(props);
            }
        }
w___ww___.___j___av_a___2___s_._c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.