1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.myfaces.trinidad.skin; 20 21 22 /** 23 * The skin version works tightly with the skin family. 24 * This allows someone to create versions of their skin, like purple (no version), 25 * purple version v2, purple version v3. 26 * Then the user can say which skin version they want, like: 27 * <skin-family>purple</skin-family><skin-version>v3</skin-version> when they 28 * pick a skin in trinidad-config.xml. 29 * When creating a skin, you give it a version if you care about versioning. 30 */ 31 final public class SkinVersion 32 { 33 /** 34 * Constructor that takes a version name. 35 * 36 * @param name the name of the version, like "v1". If name is "default" then we set default as 37 * true and name to null. If name is null, it is converted to "". 38 */ 39 public SkinVersion(String name) 40 { 41 this(_DEFAULT.equalsIgnoreCase(name) ? null : name, 42 _DEFAULT.equalsIgnoreCase(name) ? true : false); 43 } 44 45 /** 46 * Constructor that takes a name and a defaultVersion. 47 * 48 * @param name the name of the version, like "v1". If name is null, it is converted to 49 * "". 50 * @param defaultVersion true if this skin is the default version for all skins with the same skin 51 * family 52 */ 53 public SkinVersion( 54 String name, 55 boolean defaultVersion) 56 { 57 if (name == null) 58 name = ""; 59 60 _default = defaultVersion; 61 _name = name; 62 } 63 64 public boolean isDefault() 65 { 66 return _default; 67 } 68 69 public String getName() 70 { 71 return _name; 72 } 73 74 @Override 75 final public boolean equals(Object o) 76 { 77 if (o == this) 78 return true; 79 if (!(o instanceof SkinVersion)) 80 { 81 return false; 82 } 83 SkinVersion test = (SkinVersion) o; 84 return (test.isDefault() == this.isDefault()) && 85 (test.getName().equals(this.getName())); 86 } 87 88 @Override 89 final public int hashCode() 90 { 91 int hash = 17; 92 hash = 37 * hash + this.getName().hashCode(); 93 hash = 37 * hash + ((this.isDefault()) ? 1231 : 1237); 94 95 return hash; 96 } 97 98 @Override 99 public String toString() 100 { 101 if (isDefault()) 102 return _DEFAULT; 103 104 return getName(); 105 } 106 107 private final boolean _default; 108 private final String _name; 109 110 // If the skin doesn't explicitly have a version, then it will return EMPTY_SKIN_VERSION 111 // when skin.getVersion is called. This makes our skin picking code cleaner. 112 public static final SkinVersion EMPTY_SKIN_VERSION = new SkinVersion(""); 113 private static final String _DEFAULT = "default"; 114 }