Source Code Cross Referenced for HttpTokenList.java in  » Web-Server » Jigsaw » org » w3c » www » http » 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 » Jigsaw » org.w3c.www.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // HttpTokenList.java
002:        // $Id: HttpTokenList.java,v 1.13 2000/08/16 21:38:01 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1996.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.www.http;
007:
008:        import java.util.Vector;
009:
010:        /**
011:         * Parse a comma separated list of tokens.
012:         */
013:
014:        public class HttpTokenList extends BasicValue {
015:            /**
016:             * Convert tokens to lower case.
017:             */
018:            protected static final int CASE_LOWER = 0;
019:            /**
020:             * Don't touch cases of tokens.
021:             */
022:            protected static final int CASE_ASIS = 1;
023:            /**
024:             * Convert case to upper case.
025:             */
026:            protected static final int CASE_UPPER = 2;
027:
028:            protected String tokens[] = null;
029:            protected int casemode = 0;
030:
031:            /**
032:             * Parse the byte buffer to build the token list.
033:             */
034:
035:            protected void parse() {
036:                Vector toks = new Vector(8);
037:                ParseState ps = new ParseState();
038:                ParseState it = new ParseState();
039:
040:                ps.ioff = roff;
041:                ps.bufend = rlen;
042:                ps.spaceIsSep = false;
043:                while (HttpParser.nextItem(raw, ps) >= 0) {
044:                    it.ioff = ps.start;
045:                    it.bufend = ps.end;
046:                    HttpParser.unquote(raw, it);
047:                    switch (casemode) {
048:                    case CASE_LOWER:
049:                        toks.addElement(it.toString(raw, true));
050:                        break;
051:                    case CASE_ASIS:
052:                        toks.addElement(it.toString(raw));
053:                        break;
054:                    case CASE_UPPER:
055:                        toks.addElement(it.toString(raw, false));
056:                        break;
057:                    }
058:                    ps.prepare();
059:                }
060:                tokens = new String[toks.size()];
061:                toks.copyInto(tokens);
062:            }
063:
064:            protected void updateByteValue() {
065:                HttpBuffer buf = new HttpBuffer();
066:                if (tokens != null) {
067:                    for (int i = 0; i < tokens.length; i++) {
068:                        if (i > 0)
069:                            buf.append(',');
070:                        buf.append(tokens[i]);
071:                    }
072:                }
073:                raw = buf.getByteCopy();
074:                roff = 0;
075:                rlen = raw.length;
076:            }
077:
078:            /**
079:             * Get this token list value.
080:             * @return A list of tokens, encoded as a String array, or <strong>null
081:             *    </strong> if undefined.
082:             */
083:
084:            public Object getValue() {
085:                validate();
086:                return tokens;
087:            }
088:
089:            public void setValue(String tokens[]) {
090:                invalidateByteValue();
091:                this .tokens = tokens;
092:                isValid = true;
093:            }
094:
095:            /**
096:             * Add a token to this token list.
097:             * @param token The token to add.
098:             * @param always Always add to the list, even if the token us already 
099:             * present in the list.
100:             */
101:
102:            public void addToken(String token, boolean always) {
103:                validate();
104:                // Check if already set:
105:                if (!always) {
106:                    if (tokens != null) {
107:                        for (int i = 0; i < tokens.length; i++)
108:                            if (tokens[i].equals(token))
109:                                return;
110:                    }
111:                }
112:                // Add it to the token list:
113:                invalidateByteValue();
114:                if (tokens == null) {
115:                    tokens = new String[1];
116:                    tokens[0] = token;
117:                } else {
118:                    String newtoks[] = new String[tokens.length + 1];
119:                    System.arraycopy(tokens, 0, newtoks, 0, tokens.length);
120:                    newtoks[tokens.length] = token;
121:                    tokens = newtoks;
122:                }
123:            }
124:
125:            /**
126:             * Does this token list includes that token ?
127:             * @param token The token to look for.
128:             * @return A boolean, <strong>true</strong> if found, 
129:             * <strong>false</strong> otherwise.
130:             */
131:
132:            public boolean hasToken(String token, boolean caseSensitive) {
133:                validate();
134:                if (tokens == null)
135:                    return false;
136:                if (caseSensitive) {
137:                    for (int i = 0; i < tokens.length; i++)
138:                        if (tokens[i].equals(token))
139:                            return true;
140:                } else {
141:                    for (int i = 0; i < tokens.length; i++)
142:                        if (tokens[i].equalsIgnoreCase(token))
143:                            return true;
144:                }
145:                return false;
146:            }
147:
148:            /**
149:             * Create a parsed token list, for emitting.
150:             */
151:
152:            protected HttpTokenList(String tokens[]) {
153:                this .isValid = true;
154:                this .tokens = tokens;
155:            }
156:
157:            /**
158:             * Create a token list from a comma separated list of tokens.
159:             */
160:
161:            protected HttpTokenList(String tokens) {
162:                this .isValid = false;
163:                this .raw = new byte[tokens.length()];
164:                tokens.getBytes(0, raw.length, raw, 0);
165:                this .roff = 0;
166:                this .rlen = raw.length;
167:            }
168:
169:            /**
170:             * Create an empty token list for parsing.
171:             */
172:
173:            protected HttpTokenList() {
174:                this .isValid = false;
175:            }
176:
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.