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.jetspeed.om.impl;
018:
019: import java.util.Locale;
020:
021: import org.apache.jetspeed.om.common.LocalizedField;
022: import org.apache.jetspeed.util.HashCodeBuilder;
023: import org.apache.jetspeed.util.JetspeedLongObjectID;
024: import org.apache.pluto.om.common.ObjectID;
025:
026: /**
027: * LocalizedFieldImpl
028: * <br/>
029: * Implementation that represents a string value and the locale of that string
030: *
031: * @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
032: * @version $Id: LocalizedFieldImpl.java 516448 2007-03-09 16:25:47Z ate $
033: *
034: */
035: public class LocalizedFieldImpl implements LocalizedField {
036: protected String value;
037: protected String name;
038: protected Locale locale;
039:
040: protected long parentId;
041: protected JetspeedLongObjectID id;
042:
043: public LocalizedFieldImpl() {
044:
045: }
046:
047: public LocalizedFieldImpl(Locale locale, String value) {
048: this .locale = locale;
049: this .value = value;
050: }
051:
052: /* (non-Javadoc)
053: * @see org.apache.jetspeed.om.common.LocalizedField#getLocale()
054: */
055: public Locale getLocale() {
056: return locale;
057: }
058:
059: /* (non-Javadoc)
060: * @see org.apache.jetspeed.om.common.LocalizedField#setLocale(java.util.Locale)
061: */
062: public void setLocale(Locale locale) {
063: this .locale = locale;
064: }
065:
066: /* (non-Javadoc)
067: * @see org.apache.jetspeed.om.common.LocalizedField#getValue()
068: */
069: public String getValue() {
070: return value;
071: }
072:
073: /* (non-Javadoc)
074: * @see org.apache.jetspeed.om.common.LocalizedField#setValue(java.lang.String)
075: */
076: public void setValue(String value) {
077: this .value = value;
078: }
079:
080: /**
081: *
082: */
083: public ObjectID getId() {
084: return id;
085: }
086:
087: public void setLanguage(String language) {
088: if (language != null) {
089: String[] localeArray = language.split("[-|_]");
090: String country = "";
091: String variant = "";
092: for (int i = 0; i < localeArray.length; i++) {
093: if (i == 0) {
094: language = localeArray[i];
095: } else if (i == 1) {
096: country = localeArray[i];
097: } else if (i == 2) {
098: variant = localeArray[i];
099: }
100: }
101:
102: this .locale = new Locale(language, country, variant);
103: }
104: }
105:
106: public String getLanguage() {
107: if (this .locale != null) {
108: return this .locale.toString();
109: }
110: return null;
111: }
112:
113: /* (non-Javadoc)
114: * @see org.apache.jetspeed.om.common.LocalizedField#getName()
115: */
116: public String getName() {
117: return name;
118: }
119:
120: /* (non-Javadoc)
121: * @see org.apache.jetspeed.om.common.LocalizedField#setName(java.lang.String)
122: */
123: public void setName(String name) {
124: this .name = name;
125: }
126:
127: public String toString() {
128: return "Name: " + name + " Value: " + value + " Locale: "
129: + locale;
130: }
131:
132: public boolean equals(Object o) {
133: boolean result = false;
134:
135: if (o instanceof LocalizedFieldImpl && o != null) {
136: LocalizedFieldImpl localField = (LocalizedFieldImpl) o;
137:
138: result = (this .name == null) ? (localField.name == null)
139: : (this .name.equals(localField.name));
140: result = result
141: && ((this .value == null) ? (localField.value == null)
142: : (this .value.equals(localField.value)));
143: result = result
144: && ((this .locale == null) ? (localField.locale == null)
145: : (this .locale.equals(localField.locale)));
146: }
147:
148: return result;
149: }
150:
151: /**
152: * @see java.lang.Object#hashCode()
153: */
154: public int hashCode() {
155: HashCodeBuilder hasher = new HashCodeBuilder(27, 101);
156: hasher.append(name).append(value);
157: if (locale != null) {
158: hasher.append(locale.getCountry()).append(
159: locale.getLanguage()).append(locale.getVariant());
160: }
161: return hasher.toHashCode();
162: }
163: }
|