Source Code Cross Referenced for DirectoryResponder.java in  » Testing » StoryTestIQ » fitnesse » responders » files » 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 » Testing » StoryTestIQ » fitnesse.responders.files 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002:        // Released under the terms of the GNU General Public License version 2 or later.
003:        package fitnesse.responders.files;
004:
005:        import fitnesse.http.*;
006:        import fitnesse.*;
007:        import fitnesse.util.FileUtil;
008:        import fitnesse.authentication.*;
009:        import fitnesse.responders.*;
010:        import fitnesse.html.HtmlTableListingBuilder;
011:        import fitnesse.html.*;
012:        import java.io.File;
013:        import java.text.SimpleDateFormat;
014:        import java.util.*;
015:
016:        public class DirectoryResponder implements  SecureResponder {
017:            private String resource;
018:
019:            private File requestedDirectory;
020:
021:            private FitNesseContext context;
022:
023:            private SimpleDateFormat dateFormat = new SimpleDateFormat(
024:                    "MMM dd, yyyy, hh:mm a");
025:
026:            public DirectoryResponder(String resource, File requestedFile) {
027:                this .resource = resource;
028:                requestedDirectory = requestedFile;
029:            }
030:
031:            public Response makeResponse(FitNesseContext context,
032:                    Request request) throws Exception {
033:                this .context = context;
034:
035:                SimpleResponse simpleResponse = new SimpleResponse();
036:                if (!resource.endsWith("/"))
037:                    setRedirectForDirectory(simpleResponse);
038:                else
039:                    simpleResponse.setContent(makeDirectoryListingPage());
040:                return simpleResponse;
041:            }
042:
043:            private void setRedirectForDirectory(Response response) {
044:                if (!resource.startsWith("/"))
045:                    resource = "/" + resource;
046:                response.redirect(resource + "/");
047:            }
048:
049:            private String makeDirectoryListingPage() throws Exception {
050:                HtmlPage page = context.htmlPageFactory.newPage();
051:                page.title.use("Files: " + resource);
052:                page.header.use(HtmlUtil.makeBreadCrumbsWithPageType(resource,
053:                        "/", "Files Section"));
054:                page.actions.use(HtmlUtil.makeActionLink("/FrontPage",
055:                        "FrontPage", null, "f", false));
056:                page.main.use(makeRightColumn());
057:
058:                return page.html();
059:            }
060:
061:            private String makeRightColumn() throws Exception {
062:                TagGroup html = new TagGroup();
063:                html.add(addFiles(FileUtil
064:                        .getDirectoryListing(requestedDirectory)));
065:                html.add(HtmlUtil.HR.html());
066:                html.add(makeUploadForm());
067:                html.add(makeDirectoryForm());
068:                return html.html();
069:            }
070:
071:            private HtmlTag addFiles(File[] files) throws Exception {
072:                HtmlTableListingBuilder table = new HtmlTableListingBuilder();
073:                makeHeadingRow(table);
074:                addFileRows(files, table);
075:
076:                return table.getTable();
077:            }
078:
079:            private void addFileRows(File[] files, HtmlTableListingBuilder table)
080:                    throws Exception {
081:                for (int i = 0; i < files.length; i++) {
082:                    File file = files[i];
083:                    HtmlTag nameItem = makeLinkToFile(file);
084:                    HtmlElement sizeItem = new RawHtml(getSizeString(file));
085:                    HtmlElement dateItem = new RawHtml(dateFormat
086:                            .format(new Date(file.lastModified())));
087:                    TagGroup actionItem = new TagGroup();
088:                    actionItem.add(makeRenameButton(file.getName()));
089:                    actionItem.add("|");
090:                    actionItem.add(makeDeleteButton(file.getName()));
091:                    table.addRow(new HtmlElement[] { nameItem, sizeItem,
092:                            dateItem, actionItem });
093:                }
094:            }
095:
096:            private void makeHeadingRow(HtmlTableListingBuilder table)
097:                    throws Exception {
098:                HtmlTag nameHeading = HtmlUtil.makeSpanTag("caps", "Name");
099:                HtmlTag sizeHeading = HtmlUtil.makeSpanTag("caps", "Size");
100:                HtmlTag dateHeading = HtmlUtil.makeSpanTag("caps", "Date");
101:                HtmlTag actionHeading = HtmlUtil.makeSpanTag("caps", "Action");
102:                table.addRow(new HtmlTag[] { nameHeading, sizeHeading,
103:                        dateHeading, actionHeading });
104:            }
105:
106:            private HtmlTag makeDeleteButton(String filename) throws Exception {
107:                return HtmlUtil.makeLink(
108:                        "?responder=deleteConfirmation&filename=" + filename,
109:                        "Delete");
110:            }
111:
112:            private HtmlTag makeRenameButton(String filename) throws Exception {
113:                return HtmlUtil.makeLink(
114:                        "?responder=renameConfirmation&filename=" + filename,
115:                        "Rename");
116:            }
117:
118:            private HtmlTag makeLinkToFile(File file) {
119:                String href = file.getName();
120:                if (file.isDirectory()) {
121:                    href += "/";
122:                    HtmlTag image = new HtmlTag("img");
123:                    image.addAttribute("src", "/files/images/folder.gif");
124:                    image.addAttribute("class", "left");
125:                    HtmlTag link = HtmlUtil.makeLink(href, image);
126:                    link.add(file.getName());
127:                    return link;
128:                } else
129:                    return HtmlUtil.makeLink(href, file.getName());
130:            }
131:
132:            private HtmlTag makeUploadForm() throws Exception {
133:                HtmlTag uploadForm = HtmlUtil.makeFormTag("post", "/"
134:                        + resource);
135:                uploadForm.addAttribute("enctype", "multipart/form-data");
136:                uploadForm.addAttribute("class", "left");
137:                uploadForm.add("<!--upload form-->");
138:                uploadForm.add(HtmlUtil.makeSpanTag("caps", "Upload a file:"));
139:                uploadForm.add(HtmlUtil.makeInputTag("hidden", "responder",
140:                        "upload"));
141:                uploadForm.add(HtmlUtil.BR);
142:                uploadForm.add(HtmlUtil.makeInputTag("file", "file", ""));
143:                uploadForm.add(HtmlUtil.BR);
144:                uploadForm.add(HtmlUtil.makeInputTag("submit", "", "Upload"));
145:                return uploadForm;
146:            }
147:
148:            private HtmlTag makeDirectoryForm() throws Exception {
149:                HtmlTag dirForm = HtmlUtil.makeFormTag("get", "/" + resource);
150:                dirForm.addAttribute("class", "right");
151:                dirForm.add(HtmlUtil.makeInputTag("hidden", "responder",
152:                        "createDir"));
153:                dirForm.add("<!--create directory form-->");
154:                dirForm
155:                        .add(HtmlUtil
156:                                .makeSpanTag("caps", "Create a directory:"));
157:                dirForm.add(HtmlUtil.BR);
158:                dirForm.add(HtmlUtil.makeInputTag("text", "dirname", ""));
159:                dirForm.add(HtmlUtil.BR);
160:                dirForm.add(HtmlUtil.makeInputTag("submit", "", "Create"));
161:                return dirForm;
162:            }
163:
164:            public static String getSizeString(File file) {
165:                if (file.isDirectory())
166:                    return "";
167:                else
168:                    return file.length() + " bytes";
169:            }
170:
171:            public SecureOperation getSecureOperation() {
172:                return new AlwaysSecureOperation();
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.