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:
021: /**
022: * Contains the logic to build the various combinations of file path, style and
023: * locale required while searching for Wicket resources. The full filename will
024: * be built like: <path>_<style>_<locale>.<extension>.
025: * <p>
026: * Resource matches will be attempted in the following order:
027: * <ol>
028: * <li>1. <path>_<style>_<locale>.<extension></li>
029: * <li>2. <path>_<locale>.<extension></li>
030: * <li>3. <path>_<style>.<extension></li>
031: * <li>4. <path>.<extension></li>
032: * </ol>
033: * <p>
034: * Locales may contain a language, a country and a region or variant.
035: * Combinations of these components will be attempted in the following order:
036: * <ol>
037: * <li>locale.toString() see javadoc for Locale for more details</li>
038: * <li><language>_<country></li>
039: * <li><language></li>
040: * </ol>
041: *
042: * @author Juergen Donnerstag
043: * @author Jonathan Locke
044: */
045: public class StyleAndVariationResourceNameIterator implements Iterator {
046: /** The base path */
047: private final String path;
048:
049: /** The style (see Session) */
050: private final String style;
051:
052: /** The variation (see Component) */
053: private final String variation;
054:
055: /** Internal state */
056: private int state = 0;
057:
058: /**
059: * Construct.
060: *
061: * @param path
062: * @param style
063: * @param variation
064: */
065: public StyleAndVariationResourceNameIterator(final String path,
066: final String style, final String variation) {
067: this .path = path;
068: this .style = style;
069: this .variation = variation;
070: }
071:
072: /**
073: *
074: * @see java.util.Iterator#hasNext()
075: */
076: public boolean hasNext() {
077: return (this .state < 3);
078: }
079:
080: /**
081: *
082: * @see java.util.Iterator#next()
083: */
084: public Object next() {
085: if (state == 0) {
086: state++;
087: if ((style != null) && (variation != null)) {
088: return path + '_' + style + '_' + variation;
089: }
090: }
091:
092: if (state == 1) {
093: state++;
094: if (style != null) {
095: return path + '_' + style;
096: }
097: }
098:
099: state = 3;
100: return path;
101: }
102:
103: /**
104: *
105: * @see java.util.Iterator#remove()
106: */
107: public void remove() {
108: }
109: }
|