Source Code Cross Referenced for Parser.java in  » Web-Server » simple » simple » page » translate » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » simple » simple.page.translate 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Parser.java February 2006
003:         *
004:         * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
013:         * GNU Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General 
016:         * Public License along with this library; if not, write to the 
017:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
018:         * Boston, MA  02111-1307  USA
019:         */
020:
021:        package simple.page.translate;
022:
023:        import simple.util.parse.ParseBuffer;
024:
025:        /**
026:         * The <code>Parser</code> object is used to digest the tokens emitted
027:         * from the lexer. This will delegate the token parsing to objects
028:         * implementing the <code>Token</code> class. Each token emitted from
029:         * the lexical analysis phase is classified using a classification
030:         * object. Once classified a specific token type processes the text.
031:         * 
032:         * @author Niall Gallagher
033:         */
034:        final class Parser extends ParseBuffer {
035:
036:            /**
037:             * This is the document definition that is populated via parsing.
038:             */
039:            private Definition source;
040:
041:            /**
042:             * This is used to classify the tokens emitted from the lexer.
043:             */
044:            private Classifier factory;
045:
046:            /**
047:             * This is used if recursive processing of a token is required.
048:             */
049:            private Builder builder;
050:
051:            /**
052:             * Constructor for the <code>Parser</code> object. This requires
053:             * the document definition to be constructed as well as the builder
054:             * driving the process, the builder is required for the recursive
055:             * evaluation of included JSP sources via the include directive.
056:             *
057:             * @param source this is the document definition to populate
058:             * @param builder this is the object that builds the definition
059:             */
060:            public Parser(Definition source, Builder builder) {
061:                this .factory = new Classifier();
062:                this .builder = builder;
063:                this .source = source;
064:            }
065:
066:            /**
067:             * Each parser implementation must specify the boundaries of the
068:             * tokens it is prepared to classify and digest. This implementation
069:             * uses the standard JSP tags "&lt;%" and "%&gt;", however it can
070:             * just as easily use the PHP tag "&lt;?" and "?&gt;".
071:             *
072:             * @param lexer this is the lexer that emits the required tokens
073:             */
074:            public void begin(Lexer lexer) {
075:                lexer.match("<%", "%>");
076:            }
077:
078:            /**
079:             * This method is invoked by the lexer and is used to process an 
080:             * array of characters, which signifies the full text for a token.
081:             * The text provided to this method is guaranteed to contain either
082:             * a complete token, or plain text which is not a parsable token.
083:             *
084:             * @param text this contains only a single token or plain text
085:             */
086:            public void parse(char[] text) {
087:                parse(text, 0, text.length);
088:            }
089:
090:            /**
091:             * This method is invoked by the lexer and is used to process an 
092:             * array of characters, which signifies the full text for a token.
093:             * The text provided to this method is guaranteed to contain either
094:             * a complete token, or plain text which is not a parsable token.
095:             *
096:             * @param text this contains only a single token or plain text
097:             * @param off this is the offset within the buffer to read from
098:             * @param len the number of characters in the buffer to evaluate
099:             */
100:            public void parse(char[] text, int off, int len) {
101:                if (len > 2) {
102:                    if (text[off] == '<' && text[off + 1] == '%') {
103:                        if (count > 0) {
104:                            process(buf, 0, count);
105:                            clear();
106:                        }
107:                        process(text, off, len);
108:                        len = 0;
109:                    }
110:                }
111:                if (len > 0) {
112:                    append(text, off, len);
113:                }
114:            }
115:
116:            /**
117:             * Once a full token has been passed to the parser this method is
118:             * invoked to classify and process the token. This requires that
119:             * a full token is provided, this unlike the </code>parse</code>
120:             * method does not buffer the plain text tokens.
121:             *
122:             * @param text this contains only a single token or plain text
123:             * @param off this is the offset within the buffer to read from
124:             * @param len the number of characters in the buffer to evaluate
125:             */
126:            private void process(char[] text, int off, int len) {
127:                String data = new String(text, off, len);
128:                Token token = factory.getToken(data);
129:
130:                try {
131:                    token.process(source, builder);
132:                } catch (Exception e) {
133:                    e.printStackTrace();
134:                }
135:            }
136:
137:            /**
138:             * Once lexical analysis has finished this method is invoked. This
139:             * will force any buffered plain text to be processed so that the
140:             * full JSP source is processed and used in the document definition. 
141:             */
142:            public void finish() {
143:                if (count > 0) {
144:                    process(buf, 0, count);
145:                }
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.