Source Code Cross Referenced for Insert.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:         * Insert.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:        /**
024:         * The <code>Insert</code> object is used to parse the insert token
025:         * from the JSP. This will parse the token in such a way the data
026:         * from the model can be inserted into the JSP page. The following
027:         * token is parsed using this token implementation.
028:         * <pre>
029:         *
030:         *    &lt;%@ insert name="example" %&gt;
031:         * 
032:         * </pre>
033:         * This will push contents into the document definition for getting
034:         * the named attribute from the page model and displaying it. The 
035:         * result is that this token allows attributes to be printed easily.
036:         * 
037:         * @author Niall Gallagher
038:         */
039:        class Insert extends Token {
040:
041:            /**
042:             * This is used to collect the token parsed from the insert.
043:             */
044:            private TokenBuffer name;
045:
046:            /**
047:             * Constructor for the <code>Insert</code> token. This will
048:             * create a buffer, which can be used to accumulate the data
049:             * extracted from the supplied insert token.
050:             */
051:            public Insert() {
052:                this .name = new TokenBuffer();
053:            }
054:
055:            /**
056:             * Constructor for the <code>Insert</code> token. This will
057:             * create a buffer, which can be used to accumulate the data
058:             * extracted from the supplied insert token before parsing.
059:             *
060:             * @param token this is the insert token to be parsed
061:             */
062:            public Insert(String token) {
063:                this ();
064:                parse(token);
065:            }
066:
067:            /**
068:             * This method will supply code to the document definition that
069:             * will allow an attribute to be printed by the page. The data
070:             * inserted into the definition will be displayed in the body.
071:             *
072:             * @param source this is the source to push the code into
073:             * @param builder this is the builder driving the process
074:             */
075:            public void process(Definition source, Builder builder) {
076:                source.addContent("model.write(out, \"" + name + "\");");
077:            }
078:
079:            /**
080:             * This will clear the name token so that the parse can be reused
081:             * by the builder. In practice this method just satisfies the
082:             * contract of the token so that this object is not abstract.
083:             */
084:            protected void init() {
085:                name.clear();
086:            }
087:
088:            /**
089:             * This does not verify the token type, instead this will seek 
090:             * the '=' character. Once the '=' character has been encountered
091:             * the name is extracted as a quoted string, for example "name".
092:             */
093:            protected void parse() {
094:                scrap();
095:                name();
096:            }
097:
098:            /**
099:             * This is a quick and dirty means of parsing the token. This 
100:             * will basically seek the '=' character such the offset of
101:             * the buffer is on the start of the name, like "[n]ame".
102:             */
103:            private void scrap() {
104:                while (off < count) {
105:                    char next = buf[off];
106:
107:                    if (next == '=') {
108:                        while (off < count) {
109:                            next = buf[off++];
110:                            if (quote(next)) {
111:                                break;
112:                            }
113:                        }
114:                        break;
115:                    }
116:                    off++;
117:                }
118:            }
119:
120:            /**
121:             * This method will read all characters up to a space or the
122:             * next quotation chatacter, for example "'" or '"' will be
123:             * considered a terminal. Once this has finished the name will
124:             * be stored in the internal name buffer for processing.
125:             */
126:            private void name() {
127:                while (off < count) {
128:                    char next = buf[off++];
129:
130:                    if (space(next)) {
131:                        break;
132:                    } else if (quote(next)) {
133:                        break;
134:                    }
135:                    name.append(next);
136:                }
137:            }
138:
139:            /**
140:             * This is used to determine when the start and end of the name
141:             * has been encountered. The terminals are '"' and '"', which 
142:             * are legal quotations within the JSP syntax.
143:             *
144:             * @param ch this is the character to be evaluated
145:             *
146:             * @return this returns true if the character is a quote
147:             */
148:            private boolean quote(char ch) {
149:                return ch == '"' || ch == '\'';
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.