Source Code Cross Referenced for PublishHandler.java in  » Web-Server » Brazil » sunlabs » brazil » handler » 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 » Brazil » sunlabs.brazil.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * PublishHandler.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1999-2000 Sun Microsystems, Inc.
007:         *
008:         * Sun Public License Notice
009:         *
010:         * The contents of this file are subject to the Sun Public License Version 
011:         * 1.0 (the "License"). You may not use this file except in compliance with 
012:         * the License. A copy of the License is included as the file "license.terms",
013:         * and also available at http://www.sun.com/
014:         * 
015:         * The Original Code is from:
016:         *    Brazil project web application Framework release 1.1.
017:         * The Initial Developer of the Original Code is: suhler.
018:         * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019:         * All Rights Reserved.
020:         * 
021:         * Contributor(s): cstevens, suhler.
022:         *
023:         * Version:  1.13
024:         * Created by suhler on 99/03/31
025:         * Last modified by suhler on 00/12/11 13:27:09
026:         */
027:
028:        package sunlabs.brazil.handler;
029:
030:        import java.io.File;
031:        import java.io.FileOutputStream;
032:        import java.io.IOException;
033:        import java.util.Properties;
034:        import java.util.StringTokenizer;
035:        import sunlabs.brazil.server.FileHandler;
036:        import sunlabs.brazil.server.Handler;
037:        import sunlabs.brazil.server.Request;
038:        import sunlabs.brazil.server.Server;
039:
040:        /**
041:         * Handler for supporting publishing from Communicator.
042:         * Launches an authentication handler to protect the content
043:         * from malicious users.
044:         * <p>
045:         * Looks for <code>PUT</code> requests, and creates or modifies the
046:         * content as indicated.
047:         * <p>
048:         * The following request properties are used:
049:         * <dl class=props>
050:         * <dt>prefix	<dd> The URL prefix required for all documents
051:         * <dt>session	<dd> The the name of request property holding the session
052:         *		information to provide the credentials for posting.  The
053:         *		default is "SessionID".
054:         * </dl>
055:         *
056:         * @author		Stephen Uhler
057:         * @version		1.13, 00/12/11
058:         */
059:
060:        public class PublishHandler implements  Handler {
061:            private static final String PREFIX = "prefix"; // URL prefix for proxy
062:            private static final String SESSION = "session";
063:
064:            public String urlPrefix = "";
065:            public String session = "SessionID";
066:
067:            public String propsPrefix; // my prefix into the properties file
068:
069:            /**
070:             * Start up the authentication handler.
071:             */
072:
073:            public boolean init(Server server, String prefix) {
074:                this .propsPrefix = prefix;
075:
076:                Properties props = server.props;
077:                urlPrefix = props.getProperty(prefix + PREFIX, urlPrefix);
078:                session = props.getProperty(prefix + SESSION, session);
079:
080:                return true;
081:            }
082:
083:            /**
084:             * Make sure this is one of our "PUT" requests.
085:             * Look up the credentials for this request.
086:             * If no credentials are found, prompt the user for them.
087:             * IF OK, save file to proper spot.
088:             */
089:
090:            public boolean respond(Request request) throws IOException {
091:                if (!request.url.startsWith(urlPrefix)
092:                        || !request.method.equals("PUT")) {
093:                    return false;
094:                }
095:
096:                /*
097:                 * screen out bad requests
098:                 */
099:
100:                if (request.postData == null) {
101:                    request.sendError(400, "No content to put");
102:                    return true;
103:                }
104:
105:                if (request.headers.get("Content-Range") != null) {
106:                    request.sendError(501, "Can't handle partial puts");
107:                    return true;
108:                }
109:
110:                /*
111:                 * Get the credentials left by the auth handler.
112:                 */
113:
114:                String credentials = request.props.getProperty(session, "");
115:
116:                /*
117:                 * Make sure the credentials are valid for this prefix
118:                 */
119:
120:                StringTokenizer st = new StringTokenizer(credentials);
121:                boolean ok = false;
122:                while (st.hasMoreTokens()) {
123:                    String prefix = st.nextToken();
124:                    if (request.url.startsWith(prefix)) {
125:                        ok = true;
126:                        request.log(Server.LOG_DIAGNOSTIC, propsPrefix,
127:                                "file: " + request.url + " matches: " + prefix);
128:                        break;
129:                    }
130:                }
131:
132:                /*
133:                 * OK, now try to save the file.
134:                 */
135:
136:                String root = request.props.getProperty(FileHandler.ROOT, ".");
137:                File file = new File(root + FileHandler.urlToPath(request.url));
138:
139:                request.log(Server.LOG_INFORMATIONAL, propsPrefix + "root: "
140:                        + root);
141:
142:                int code = (file.exists()) ? 204 : 201;
143:
144:                FileOutputStream out;
145:                try {
146:                    out = new FileOutputStream(file);
147:                } catch (IOException e) {
148:                    request.sendError(403, "Permission denied", file
149:                            .getAbsolutePath());
150:                    return true;
151:                }
152:                out.write(request.postData);
153:                out.close();
154:                request.sendResponse("Update of " + request.url + " succeeded",
155:                        "text/html", code);
156:                return true;
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.