Source Code Cross Referenced for HomeDirHandler.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:         * HomeDirHandler.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1998-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.9
024:         * Created by suhler on 98/09/14
025:         * Last modified by suhler on 00/12/11 13:26:57
026:         */
027:
028:        package sunlabs.brazil.handler;
029:
030:        import java.io.File;
031:        import sunlabs.brazil.server.FileHandler;
032:        import sunlabs.brazil.server.Handler;
033:        import sunlabs.brazil.server.Request;
034:        import sunlabs.brazil.server.Server;
035:        import java.io.IOException;
036:
037:        /**
038:         * Handler for converting ~username queries.
039:         * When invoked upstream of the
040:         * {@link FileHandler}
041:         * This provides Unix user's with individual home pages.
042:         *<p>
043:         *Properties:
044:         * <dl class=props>
045:         * <dt>subdir	<dd>Name of the directory in the user's home directory
046:         *		that represents the user's "doc root"
047:         * <dt>home	<dd>The mount-point for homre directories, 
048:         *		defaults to "/home/".
049:         * </dl>
050:         * Url's of the form:
051:         * <pre>/~[user]/stuff...</pre>
052:         * are transformed into
053:         * [home][user]/[subdir]/stuff....
054:         * <p>
055:         * Note:  This functionallity has been mostly subsumed by the
056:         * {@link UrlMapperHandler}.
057:         *
058:         * @author		Stephen Uhler
059:         * @version		1.9, 00/12/11
060:         */
061:
062:        public class HomeDirHandler implements  Handler {
063:            private String propsPrefix;
064:            private String docDir;
065:            private String home;
066:
067:            /**
068:             * Handler configuration property <b>subdir</b>.
069:             * The name of the directory in the user's home directory to use as the
070:             * document root for this request.
071:             * The default is <code>public_html</code>.
072:             */
073:            static final String DIR = "subdir"; // subdirectory for finding pages
074:            /**
075:             * Handler configuration property <b>home</b>.
076:             * The directory that user accounts live in.
077:             * The current implementation doesn't consult the password file, but
078:             * uses a static mapping from the userid to a directory.
079:             * The default is /home.
080:             * using the default settings, a url of the form:
081:             * <code>/~user/foo.html</code> gets translated into the file:
082:             * <code>/home/user/public_html/foo.html</code>.
083:             */
084:            static final String HOME = "home"; // where user's live - need both slashes
085:
086:            /**
087:             * Get and set the configuration parameters.
088:             */
089:
090:            public boolean init(Server server, String prefix) {
091:                propsPrefix = prefix;
092:                docDir = server.props.getProperty(propsPrefix + DIR,
093:                        "public_html");
094:                home = server.props.getProperty(propsPrefix + HOME, "/home/");
095:                return true;
096:            }
097:
098:            /**
099:             * If this is a ~user request, modify the <code>root</code> and
100:             * <code>url</code> properties of the request object.
101:             */
102:
103:            public boolean respond(Request request) throws IOException {
104:                String user;
105:                String url = "/";
106:                if (request.url.startsWith("/~")) {
107:                    int index = request.url.indexOf("/", 2);
108:                    if (index < 0) {
109:                        request.redirect(request.url + "/", null);
110:                        return true;
111:                    } else {
112:                        user = request.url.substring(2, index);
113:                        url = request.url.substring(index);
114:                    }
115:
116:                    String root = home + user + "/" + docDir;
117:                    File file = new File(root);
118:                    if (file.isDirectory()) {
119:                        request.url = url;
120:                        request.props.put(FileHandler.ROOT, root);
121:                        request.log(Server.LOG_INFORMATIONAL, propsPrefix
122:                                + ".. mapping " + user + " to "
123:                                + request.props.get(FileHandler.ROOT)
124:                                + " url: " + request.url);
125:                    }
126:                }
127:                return false;
128:            }
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.