Source Code Cross Referenced for HttpChallenge.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:        // HttpChallenge.java
002:        // $Id: HttpChallenge.java,v 1.20 2007/02/21 12:58:13 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 org.w3c.util.ArrayDictionary;
009:
010:        import java.lang.CloneNotSupportedException;
011:
012:        public class HttpChallenge extends BasicValue {
013:            String scheme = null;
014:            ArrayDictionary params = null;
015:            ArrayDictionary unqparams = null;
016:
017:            /**
018:             * get a copy of the challenge, used to add some output value
019:             * without hurting the challenge
020:             * @return the clone of this challenge
021:             */
022:            public HttpChallenge getClone() {
023:                try {
024:                    return (HttpChallenge) this .clone();
025:                } catch (CloneNotSupportedException ex) {
026:                    return null;
027:                }
028:            }
029:
030:            /**
031:             * parse.
032:             * @exception HttpParserException if parsing failed.
033:             */
034:            protected void parse() throws HttpParserException {
035:                ParseState ps = new ParseState(roff, rlen);
036:                // Get the auth scheme
037:                if (HttpParser.nextItem(raw, ps) < 0)
038:                    error("Invalid challenge: no scheme.");
039:                this .scheme = ps.toString(raw);
040:                // Get the list of params:
041:                ParseState it = new ParseState();
042:                it.separator = (byte) '=';
043:                ps.separator = (byte) ',';
044:                ps.prepare();
045:                while (HttpParser.nextItem(raw, ps) >= 0) {
046:                    it.prepare(ps);
047:                    // Get the param name
048:                    if (HttpParser.nextItem(raw, it) < 0)
049:                        error("Invalid challenge: no param name.");
050:                    String key = it.toString(raw, true);
051:                    // Get the param value:
052:                    it.prepare();
053:                    if (HttpParser.nextItem(raw, it) < 0)
054:                        error("Invalid challenge: no param value.");
055:                    it.ioff = it.start;
056:                    int offset = HttpParser.skipSpaces(raw, it);
057:                    if ((offset < raw.length) && (raw[offset] == '\"')) {
058:                        HttpParser.unquote(raw, it);
059:                        if (params == null) {
060:                            params = new ArrayDictionary(5, 5);
061:                        }
062:                        params.put(key, it.toString(raw));
063:                    } else {
064:                        if (unqparams == null) {
065:                            unqparams = new ArrayDictionary(5, 5);
066:                        }
067:                        unqparams.put(key, it.toString(raw));
068:                    }
069:                    ps.prepare();
070:                }
071:            }
072:
073:            protected void updateByteValue() {
074:                HttpBuffer buf = new HttpBuffer();
075:                buf.append(scheme);
076:                buf.append(' ');
077:                int len = 0;
078:                if (params != null) {
079:                    len = params.size();
080:                }
081:                if (unqparams != null) {
082:                    len += unqparams.size();
083:                }
084:                if (params != null) {
085:                    int plen = params.size();
086:                    for (int i = 0; i < plen; i++) {
087:                        String key = (String) params.keyAt(i);
088:                        if (key == null)
089:                            continue;
090:                        buf.appendQuoted(key, (byte) '=', (String) params
091:                                .elementAt(i));
092:                        len--;
093:                        if (len > 0) {
094:                            buf.append((byte) ',');
095:                            buf.append((byte) ' ');
096:                        }
097:                    }
098:                }
099:                if (unqparams != null) {
100:                    int unqlen = unqparams.size();
101:                    for (int i = 0; i < unqlen; i++) {
102:                        String key = (String) unqparams.keyAt(i);
103:                        if (key == null)
104:                            continue;
105:                        buf.append(key, (byte) '=', (String) unqparams
106:                                .elementAt(i));
107:                        len--;
108:                        if (len > 0) {
109:                            buf.append((byte) ',');
110:                            buf.append((byte) ' ');
111:                        }
112:                    }
113:                }
114:                raw = buf.getByteCopy();
115:                roff = 0;
116:                rlen = raw.length;
117:            }
118:
119:            public Object getValue() {
120:                validate();
121:                return this ;
122:            }
123:
124:            /**
125:             * Get the challenge scheme.
126:             * @return A String encoding the challenge scheme identifier.
127:             */
128:
129:            public String getScheme() {
130:                validate();
131:                return scheme;
132:            }
133:
134:            /**
135:             * Get an authentication parameter.
136:             * @param name The name of the parameter.
137:             * @return A String encoded value for this parameter, or <strong>null
138:             * </strong>
139:             */
140:
141:            public String getAuthParameter(String name) {
142:                validate();
143:                String res = null;
144:                if (params != null) {
145:                    res = (String) params.get(name);
146:                }
147:                if (res == null) {
148:                    if (unqparams != null) {
149:                        res = (String) unqparams.get(name);
150:                    }
151:                }
152:                return res;
153:            }
154:
155:            /**
156:             * Set an auth parameter value.
157:             * @param name The name of the parameter to set.
158:             * @param value The new value for this parameter.
159:             * @param quoted If true, the value will be quoted
160:             */
161:
162:            public void setAuthParameter(String name, String value,
163:                    boolean quoted) {
164:                invalidateByteValue();
165:                if (quoted) {
166:                    if (params == null) {
167:                        params = new ArrayDictionary(4, 4);
168:                    }
169:                    params.put(name, value);
170:                } else {
171:                    if (unqparams == null) {
172:                        unqparams = new ArrayDictionary(4, 4);
173:                    }
174:                    unqparams.put(name, value);
175:                }
176:            }
177:
178:            /**
179:             * Set an auth parameter value.
180:             * @param name The name of the parameter to set.
181:             * @param value The new value for this parameter.
182:             * The value will be quoted
183:             */
184:            public void setAuthParameter(String name, String value) {
185:                setAuthParameter(name, value, true);
186:            }
187:
188:            HttpChallenge(boolean isValid) {
189:                this .isValid = isValid;
190:            }
191:
192:            HttpChallenge(boolean isValid, String scheme) {
193:                this .isValid = isValid;
194:                this .scheme = scheme;
195:            }
196:
197:            public HttpChallenge() {
198:                super();
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.