001 // Copyright Apr 15, 2006 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014 package org.apache.tapestry.asset;
015
016 import java.util.Comparator;
017
018
019 /**
020 * Used to guarantee that whenever present, the PATH key entry
021 * of an asset service link is always appended last in that path
022 * string. This is required for certain relative url operations. (ie dojo baseRelativePath)
023 *
024 * @author jkuhnert
025 */
026 public class AssetComparator implements Comparator
027 {
028
029 /**
030 * {@inheritDoc}
031 */
032 public int compare(Object o1, Object o2)
033 {
034 if (!String.class.isInstance(o1) || !String.class.isInstance(o2))
035 return 1;
036
037 String key1 = (String)o1;
038 String key2 = (String)o2;
039
040 if (key1.toUpperCase().equals("PATH") && !key2.toUpperCase().equals("PATH"))
041 return 1;
042 else if (key2.toUpperCase().equals("PATH") && !key1.toUpperCase().equals("PATH"))
043 return -1;
044 else return key1.compareToIgnoreCase(key2);
045 }
046
047 }