01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.compiler.model.validation;
20:
21: import org.apache.beehive.netui.compiler.model.XmlModelWriter;
22: import org.apache.beehive.netui.compiler.model.XmlElementSupport;
23: import org.w3c.dom.Element;
24:
25: import java.util.Locale;
26: import java.util.HashMap;
27: import java.util.Map;
28: import java.util.Iterator;
29:
30: public class LocaleSet extends XmlElementSupport {
31: private Locale _locale;
32: private Map _entities = new HashMap();
33:
34: public LocaleSet() {
35: _locale = null; // default locale;
36: }
37:
38: public LocaleSet(Locale locale) {
39: _locale = locale;
40: }
41:
42: public Locale getLocale() {
43: return _locale;
44: }
45:
46: public ValidatableEntity getEntity(String entityName) {
47: return (ValidatableEntity) _entities.get(entityName);
48: }
49:
50: public void addValidatableEntity(ValidatableEntity entity) {
51: _entities.put(entity.getEntityName(), entity);
52: }
53:
54: public void writeToElement(XmlModelWriter xw, Element element) {
55: if (_locale != null) {
56: setElementAttribute(element, "language", _locale
57: .getLanguage());
58: setElementAttribute(element, "country", _locale
59: .getCountry());
60: setElementAttribute(element, "variant", _locale
61: .getVariant());
62: }
63:
64: for (Iterator i = _entities.values().iterator(); i.hasNext();) {
65: ValidatableEntity entity = (ValidatableEntity) i.next();
66: String entityName = entity.getEntityName();
67: Element formElementToUse = findChildElement(xw, element,
68: "form", "name", entityName, true, null);
69: entity.writeXML(xw, formElementToUse);
70: }
71: }
72: }
|