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 * The skin version works tightly with the skin family.
23 * This allows someone to create versions of their skin, like purple (no version),
24 * purple version v2, purple version v3.
25 * Then the user can say which skin version they want, like:
26 * <skin-family>purple</skin-family><skin-version>v3</skin-version> when they
27 * pick a skin in trinidad-config.xml.
28 * When creating a skin, you give it a version if you care about versioning.
29 */
30 final public class SkinVersion
31 {
32 /**
33 * Constructor that takes a version name.
34 * @param name the name of the version, like "v1". If name is null, it is converted to "".
35 * same skin family
36 */
37 public SkinVersion(String name)
38 {
39 this(name, false);
40 }
41
42 /**
43 * Constructor that takes a name and a defaultVersion.
44 * @param name the name of the version, like "v1". If name is null, it is converted to "".
45 * @param defaultVersion true if this skin is the default version for all skins with the
46 * same skin family
47 */
48 public SkinVersion(
49 String name,
50 boolean defaultVersion)
51 {
52 if(name == null)
53 name = "";
54
55 _default = defaultVersion;
56 _name = name;
57 }
58
59 public boolean isDefault()
60 {
61 return _default;
62 }
63
64 public String getName()
65 {
66 return _name;
67 }
68
69 @Override
70 final public boolean equals(Object o)
71 {
72 if (o == this)
73 return true;
74 if (!(o instanceof SkinVersion))
75 {
76 return false;
77 }
78 SkinVersion test = (SkinVersion)o;
79 return (test.isDefault() == this.isDefault()) &&
80 (test.getName().equals(this.getName()));
81 }
82
83 @Override
84 final public int hashCode()
85 {
86 int hash = 17;
87 hash = 37*hash + this.getName().hashCode();
88 hash = 37*hash + ((this.isDefault()) ? 1231 : 1237 );
89
90 return hash;
91 }
92
93 @Override
94 public String toString()
95 {
96 StringBuffer buffer = new StringBuffer("Version[");
97 buffer.append(getName());
98
99 boolean isDefault = isDefault();
100
101 if (isDefault)
102 {
103 buffer.append(',');
104 buffer.append("default");
105 }
106 return buffer.toString();
107 }
108
109 // If the skin doesn't explicitly have a version, then it will return EMPTY_SKIN_VERSION
110 // when skin.getVersion is callled. This makes our skin picking code cleaner.
111 public final static SkinVersion EMPTY_SKIN_VERSION = new SkinVersion("");
112
113 private final boolean _default;
114 private final String _name;
115 }