Source Code Cross Referenced for FileIndex.java in  » Web-Server » simple » simple » http » serve » 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 » simple » simple.http.serve 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * FileIndex.java December 2005
003:         *
004:         * Copyright (C) 2005, Niall Gallagher <niallg@users.sf.net>
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
013:         * GNU Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General 
016:         * Public License along with this library; if not, write to the 
017:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
018:         * Boston, MA  02111-1307  USA
019:         */
020:
021:        package simple.http.serve;
022:
023:        import simple.util.parse.URIParser;
024:        import simple.util.net.URI;
025:        import simple.util.net.Path;
026:        import java.util.Locale;
027:        import java.io.File;
028:
029:        /**
030:         * The <code>FileIndex</code> provides an implementation of an index
031:         * that makes use of the OS file system to acquire meta data. This
032:         * will acquire information directly from the URI target, as well as
033:         * a MIME database maintained within the <code>Content.xml</code> file.
034:         * This caches all meta data acquired so that there is no expense in
035:         * re-acquiring the data. This allows for faster meta data retrieval
036:         * and facilitates the implementation of the meta data cache used.
037:         * 
038:         * @author Niall Gallagher
039:         *
040:         * @see simple.http.serve.FileIndexer
041:         */
042:        final class FileIndex implements  Index {
043:
044:            /**
045:             * This is the source indexer used to acquire the meta data.
046:             */
047:            private Indexer indexer;
048:
049:            /**
050:             * This is the path portion of the specified URI target.
051:             */
052:            private Path path;
053:
054:            /**
055:             * This is the OS specific file referencing the resource. 
056:             */
057:            private File file;
058:
059:            /**
060:             * This is the MIME type resolved for the resource.
061:             */
062:            private String type;
063:
064:            /**
065:             * This is the locale specific to the URI specified.
066:             */
067:            private Locale locale;
068:
069:            /**
070:             * This contains all the information regarding the URI.
071:             */
072:            private URI target;
073:
074:            /**
075:             * Constructor for the <code>FileIndex</code> object. This uses a
076:             * URI target to acquire the meta data for the resource. The URI
077:             * provides the resource name and path and also provides a hint
078:             * for the MIME type of the resource from the file extension.
079:             *
080:             * @param indexer this is the source indexer for this instance
081:             * @param target this is the URI target that is to be indexed
082:             */
083:            public FileIndex(Indexer indexer, String target) {
084:                this (indexer, new URIParser(target));
085:            }
086:
087:            /**
088:             * Constructor for the <code>FileIndex</code> object. This uses a
089:             * URI target to acquire the meta data for the resource. The URI
090:             * provides the resource name and path and also provides a hint
091:             * for the MIME type of the resource from the file extension.
092:             *
093:             * @param indexer this is the source indexer for this instance
094:             * @param target this is the URI target that is to be indexed
095:             */
096:            public FileIndex(Indexer indexer, URI target) {
097:                this .indexer = indexer;
098:                this .target = target;
099:            }
100:
101:            /**
102:             * This is used to get the path that this object refers to. 
103:             * This should be the fully qualified normalized path. This
104:             * refers to the OS system specific path that this represents.
105:             *
106:             * @return this returns the OS specific path for the target
107:             */
108:            public String getContentType() {
109:                if (type == null) {
110:                    type = getContentType(target);
111:                }
112:                return type;
113:            }
114:
115:            /**
116:             * This is used to get the path that this object refers to. 
117:             * This should be the fully qualified normalized path. This
118:             * refers to the OS system specific path that this represents.
119:             *
120:             * @param target the index target to get the real path for
121:             * 
122:             * @return this returns the OS specific path for the target
123:             */
124:            public String getContentType(URI target) {
125:                return indexer.getContentType(target);
126:            }
127:
128:            /**
129:             * This gets the locale for this index object the locale is
130:             * set to the <code>Locale.getDefault</code> if there is no
131:             * locale information available for the index target. This
132:             * will provide the <code>Context.getLocale</code> object.
133:             * 
134:             * @return this returns the locale for this index target
135:             */
136:            public Locale getLocale() {
137:                if (locale == null) {
138:                    locale = getLocale(target);
139:                }
140:                return locale;
141:            }
142:
143:            /**
144:             * This gets the locale for this index object the locale is
145:             * set to the <code>Locale.getDefault</code> if there is no
146:             * locale information available for the index target. This
147:             * will provide the <code>Context.getLocale</code> object.
148:             *
149:             * @param target the index target to get the locale for
150:             * 
151:             * @return this returns the locale for this index target
152:             */
153:            public Locale getLocale(URI target) {
154:                return indexer.getLocale(target);
155:            }
156:
157:            /**
158:             * This is used to acquire the <code>File</code> reference
159:             * for the index target. This is typically rooted at a
160:             * base path, for instance the <code>Context</code> root
161:             * is typically used. This allows the file to be opened,
162:             * deleted, or read should the need arise in a service.
163:             *
164:             * @return this returns the OS file for the resource
165:             */
166:            public File getFile() {
167:                if (file == null) {
168:                    file = getFile(target);
169:                }
170:                return file;
171:            }
172:
173:            /**
174:             * This is used to acquire the <code>File</code> reference
175:             * for the index target. This is typically rooted at a
176:             * base path, for instance the <code>Context</code> root
177:             * is typically used. This allows the file to be opened,
178:             * deleted, or read should the need arise in a service.
179:             *
180:             * @param target the index target to get the OS file for
181:             * 
182:             * @return this returns the OS file for the resource
183:             */
184:            public File getFile(URI target) {
185:                return indexer.getFile(target);
186:            }
187:
188:            /**
189:             * This is used to acquire the <code>Path</code> object that 
190:             * exposes various parts of the URI path. This can be used 
191:             * to extract the individual path segments as strings as 
192:             * well as the file extension and various other details.
193:             *
194:             * @return this returns a path object with various details
195:             */
196:            public Path getPath() {
197:                if (path == null) {
198:                    path = getPath(target);
199:                }
200:                return path;
201:            }
202:
203:            /**
204:             * This is used to acquire the <code>Path</code> object that 
205:             * exposes various parts of the URI path. This can be used 
206:             * to extract the individual path segments as strings as 
207:             * well as the file extension and various other details.
208:             *
209:             * @param target the index target to get the URI path for
210:             * 
211:             * @return this returns a path object with various details
212:             */
213:            public Path getPath(URI target) {
214:                return indexer.getPath(target);
215:            }
216:
217:            /**
218:             * This is used to get the path that this object refers to. 
219:             * This should be the fully qualified normalized path. This
220:             * refers to the OS system specific path that this represents.
221:             *
222:             * @return this returns the OS specific path for the target
223:             */
224:            public String getRealPath() {
225:                return getFile().getAbsolutePath();
226:            }
227:
228:            /**
229:             * This is used to acquire the <code>File</code> directory
230:             * for the index target. This is typically rooted at a
231:             * base path, for instance the <code>Context</code> root
232:             * is typically used. This allows resources within the 
233:             * same directory to be acquired easily.
234:             * 
235:             * @return this returns the OS file for the directory
236:             */
237:            public File getDirectory() {
238:                return getFile().getParentFile();
239:            }
240:
241:            /**
242:             * This is used to acquire the normalized URI style path for
243:             * the index target. This allows the path to be used within
244:             * the <code>Mapper</code> and other such objects that need
245:             * a normalized URI style path to resolve resources.
246:             *
247:             * @return this returns the normalized path for the target
248:             */
249:            public String getRequestPath() {
250:                return getPath().getPath();
251:            }
252:
253:            /**
254:             * This allows the name for this object to be acquired. The
255:             * name usually refers to the last entry in the path. So if
256:             * the index target path was "/usr/bin/" the name is "bin".
257:             *
258:             * @return this returns the name of this index target
259:             */
260:            public String getName() {
261:                return getPath().getName();
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.