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


001:        /*
002:         * DirectoryTemplate.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 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): suhler.
022:         *
023:         * Version:  1.6
024:         * Created by suhler on 00/07/05
025:         * Last modified by suhler on 00/12/11 20:24:31
026:         */
027:
028:        package sunlabs.brazil.template;
029:
030:        import java.io.File;
031:        import java.util.Properties;
032:        import sunlabs.brazil.server.FileHandler;
033:        import sunlabs.brazil.server.Handler;
034:        import sunlabs.brazil.server.Request;
035:        import sunlabs.brazil.server.Server;
036:
037:        /**
038:         * Put current directory information (based on the URL) into the
039:         * request properties.
040:         * The <code>&lt;filelist&gt;</code> tag, if present in the document, 
041:         * triggers the generation of a directory and file listing, based on the
042:         * current URL.
043:         * <p>
044:         * Template Properties:
045:         * <dl class=props>
046:         * <dt>prepend	<dd>String to prepend to the properties "Directories" and
047:         *		"Files" That contain the directory and file lists respectively.
048:         * <dt>delimiter<dd>Delimiter character to separate entries, defaults to " ".
049:         * <dt>DirectoryName<dd>If set, use this as the directory name instead of
050:         *		deriving it from the URL.
051:         * <dt>debug	<dd>if set, a comment is emitted indicating where the
052:         *		file-list entitiy was encountered.
053:         * <dt>[prepend]Directories<dd>List of sub-directories in current directory
054:         * <dt>[prepend]Files	<dd>List of files with valid suffixes in
055:         *		current directory.
056:         * <dt>mime.xxx	<dd>An indication that suffix "xxx" is valid.
057:         * </dl>
058:         * This class may also be used as a handler, in which case the
059:         * property <code>prefix</code> is used to match the leading
060:         * portion of a URL>
061:         *
062:         * @author	Stephen Uhler
063:         * @version	%V% DirectoryTemplate.java
064:         */
065:
066:        public class DirectoryTemplate extends Template implements  Handler {
067:            private boolean done = false; // trigger the properties
068:            private String propsPrefix;
069:
070:            public boolean init(Server server, String prefix) {
071:                propsPrefix = prefix;
072:                return true;
073:            }
074:
075:            /**
076:             * Compute the directory info, and add it to the request properties.
077:             */
078:
079:            public boolean respond(Request request) {
080:                String prefix = request.props.getProperty(propsPrefix
081:                        + "prefix", "/");
082:
083:                if (request.url.startsWith(prefix)) {
084:                    getFiles(request, propsPrefix);
085:                }
086:                return false;
087:            }
088:
089:            /**
090:             * Reset at each page
091:             */
092:
093:            public boolean init(RewriteContext hr) {
094:                done = false;
095:                return true;
096:            }
097:
098:            /**
099:             * Turn on the directory calculator.  The presense of this tag
100:             * causes the files and subdirectories in the current directory
101:             * to be added to the request properties.
102:             */
103:
104:            public void tag_filelist(RewriteContext hr) {
105:                hr.killToken();
106:                if (hr.request.props.getProperty(hr.prefix + "debug") != null) {
107:                    hr.append("<!-- " + hr.getBody() + " -->");
108:                }
109:                if (!done) {
110:                    getFiles(hr.request, hr.prefix);
111:                    done = true;
112:                }
113:            }
114:
115:            /**
116:             * Generate properties containing the files and directories in
117:             * the "current" directory.  The current directory is taken from
118:             * the "DirectoryName" request property, or derived from the URL.
119:             * This functionality was culled from the FileHandler and
120:             * the Directory Handler.
121:             */
122:
123:            public void getFiles(Request request, String prefix) {
124:                // System.out.println("Generating directory entries");
125:                Properties props = request.props;
126:                String prepend = props.getProperty(prefix + "prepend", "");
127:                String delim = props.getProperty(prefix + "delimiter", " ");
128:                String dir = props.getProperty("DirectoryName");
129:                File file;
130:                if (dir == null) {
131:                    String name = FileHandler.urlToPath(request.url);
132:                    String root = props.getProperty(prefix + FileHandler.ROOT,
133:                            props.getProperty(FileHandler.ROOT, "."));
134:                    file = new File(root + name);
135:                    if (!file.isDirectory()) {
136:                        file = new File(file.getParent());
137:                    }
138:                    // System.out.println("Generating dir name: " + file);
139:                } else {
140:                    file = new File(dir);
141:                    // System.out.println("Using dir name: " + file);
142:                }
143:
144:                String[] list = file.list();
145:                StringBuffer dirs = new StringBuffer();
146:                StringBuffer files = new StringBuffer();
147:                if (list != null) {
148:                    String dsep = "";
149:                    String fsep = "";
150:                    for (int i = 0; i < list.length; i++) {
151:                        String name = list[i];
152:                        // System.out.println("working on: " + name);
153:                        int index = name.lastIndexOf(".");
154:                        if ((new File(file, name)).isDirectory()) {
155:                            dirs.append(dsep).append(name);
156:                            dsep = delim;
157:                        } else if (index > 0
158:                                && props.getProperty(FileHandler.MIME
159:                                        + name.substring(index)) != null) {
160:                            files.append(fsep).append(name);
161:                            fsep = delim;
162:                        }
163:                    }
164:                    props.put(prepend + "Directories", dirs.toString());
165:                    props.put(prepend + "Files", files.toString());
166:                    // System.out.println("Dirs=" + dirs +  "\nFiles=" + files);
167:                    request.log(Server.LOG_DIAGNOSTIC, prefix,
168:                            "Generating file and directory properties: "
169:                                    + list.length);
170:                }
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.