Source Code Cross Referenced for ResourceNameIterator.java in  » J2EE » wicket » org » apache » wicket » util » resource » locator » 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 » J2EE » wicket » org.apache.wicket.util.resource.locator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.wicket.util.resource.locator;
018:
019:        import java.util.Iterator;
020:        import java.util.Locale;
021:
022:        import org.apache.wicket.WicketRuntimeException;
023:        import org.apache.wicket.util.string.Strings;
024:
025:        /**
026:         * Contains the logic to locate a resource based on a path, a style (see
027:         * {@link org.apache.wicket.Session}), a locale and a extension strings. The full filename
028:         * will be built like:
029:         * <path>_<style>_<locale>.<extension>.
030:         * <p>
031:         * Resource matches will be attempted in the following order:
032:         * <ol>
033:         * <li>1. &lt;path&gt;_&lt;style&gt;_&lt;locale&gt;.&lt;extension&gt;</li>
034:         * <li>2. &lt;path&gt;_&lt;locale&gt;.&lt;extension&gt;</li>
035:         * <li>3. &lt;path&gt;_&lt;style&gt;.&lt;extension&gt;</li>
036:         * <li>4. &lt;path&gt;.&lt;extension&gt;</li>
037:         * </ol>
038:         * <p>
039:         * Locales may contain a language, a country and a region or variant.
040:         * Combinations of these components will be attempted in the following order:
041:         * <ol>
042:         * <li>locale.toString() see javadoc for Locale for more details</li>
043:         * <li>&lt;language&gt;_&lt;country&gt;</li>
044:         * <li>&lt;language&gt;</li>
045:         * </ol>
046:         * <p>
047:         * Extensions may be a comma separated list of extensions, e.g. "properties,xml"
048:         * 
049:         * @author Juergen Donnerstag
050:         */
051:        public class ResourceNameIterator implements  Iterator {
052:            // The locale to search for the resource file
053:            private final Locale locale;
054:
055:            // The extensions (comma separated) to search for the resource file
056:            private final String extensions;
057:
058:            // The various iterators used to locate the resource file
059:            private final Iterator styleIterator;
060:            private LocaleResourceNameIterator localeIterator;
061:            private Iterator extenstionsIterator;
062:
063:            // The latest exact Locale used
064:            private Locale currentLocale;
065:
066:            /**
067:             * Construct.
068:             * 
069:             * @param path
070:             *            The path of the resource without extension
071:             * @param style
072:             *            A theme or style (see {@link org.apache.wicket.Session})
073:             * @param locale
074:             *            The Locale to apply
075:             * @param extensions
076:             *            the filname's extensions (comma separated)
077:             */
078:            public ResourceNameIterator(String path, final String style,
079:                    final Locale locale, final String extensions) {
080:                this .locale = locale;
081:                if (extensions == null) {
082:                    this .extensions = Strings.afterLast(path, '.');
083:                    path = Strings.beforeLast(path, '.');
084:                } else {
085:                    this .extensions = extensions;
086:                }
087:
088:                this .styleIterator = new StyleAndVariationResourceNameIterator(
089:                        path, style, null);
090:            }
091:
092:            /**
093:             * Get the exact Locale which has been used for the latest resource path.
094:             * 
095:             * @return current Locale
096:             */
097:            public final Locale getLocale() {
098:                return this .currentLocale;
099:            }
100:
101:            /**
102:             * @see java.util.Iterator#hasNext()
103:             */
104:            public boolean hasNext() {
105:                // Most inner loop. Loop through all extensions provided
106:                if (this .extenstionsIterator != null) {
107:                    if (this .extenstionsIterator.hasNext() == true) {
108:                        return true;
109:                    }
110:
111:                    // If there are no more extensions, than return to the next outer
112:                    // loop (locale), get the next value from that loop and start
113:                    // over again with the first extension in the list.
114:                    extenstionsIterator = null;
115:                }
116:
117:                // 2nd inner loop: Loop through all Locale combinations
118:                if (this .localeIterator != null) {
119:                    while (this .localeIterator.hasNext()) {
120:                        // Get the next Locale from the iterator and start the next
121:                        // inner iterator over again.
122:                        String newPath = (String) this .localeIterator.next();
123:                        this .currentLocale = this .localeIterator.getLocale();
124:                        this .extenstionsIterator = new ExtensionResourceNameIterator(
125:                                newPath, this .extensions);
126:                        if (this .extenstionsIterator.hasNext() == true) {
127:                            return true;
128:                        }
129:                    }
130:                    this .localeIterator = null;
131:                }
132:
133:                // Most outer loop: Loop through all combinations of styles and
134:                // variations
135:                while (this .styleIterator.hasNext()) {
136:                    String newPath = (String) this .styleIterator.next();
137:
138:                    this .localeIterator = new LocaleResourceNameIterator(
139:                            newPath, this .locale);
140:                    while (this .localeIterator.hasNext()) {
141:                        newPath = (String) this .localeIterator.next();
142:                        this .currentLocale = this .localeIterator.getLocale();
143:                        this .extenstionsIterator = new ExtensionResourceNameIterator(
144:                                newPath, this .extensions);
145:                        if (this .extenstionsIterator.hasNext() == true) {
146:                            return true;
147:                        }
148:                    }
149:                }
150:
151:                // No more combinations found. End of iteration.
152:                return false;
153:            }
154:
155:            /**
156:             * @see java.util.Iterator#next()
157:             */
158:            public Object next() {
159:                if (extenstionsIterator != null) {
160:                    return extenstionsIterator.next();
161:                }
162:                throw new WicketRuntimeException(
163:                        "Illegal call of next(). Iterator not properly initialized");
164:            }
165:
166:            /**
167:             * @see java.util.Iterator#remove()
168:             */
169:            public void remove() {
170:                // ignore
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.