001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.dp.xml;
006:
007: import org.w3c.dom.Document;
008: import org.w3c.dom.Element;
009:
010: import java.util.Map;
011: import java.util.Iterator;
012:
013: import com.sun.portal.desktop.context.DPContext;
014:
015: import com.sun.portal.desktop.dp.DPError;
016: import com.sun.portal.desktop.dp.DPLocale;
017: import com.sun.portal.desktop.dp.DPProperty;
018: import com.sun.portal.desktop.dp.DPRoot;
019:
020: /**
021: * @deprecated Use LocalePropertiesFilter instead.
022: * @see com.sun.portal.provides.context.LocalePropertiesFilter
023: */
024: class XMLDPLocale extends XMLDPCollection implements DPLocale,
025: XMLDPTags {
026:
027: XMLDPLocale(DPContext dpc, DPRoot r, Document d, String name) {
028: this (dpc, r, createElement(dpc, d, name));
029: }
030:
031: XMLDPLocale(DPContext dpc, DPRoot r, Document d, String lang,
032: String country, String variant) {
033: this (dpc, r, createElement(dpc, d, lang, country, variant));
034: }
035:
036: XMLDPLocale(DPContext dpc, DPRoot r, Document d, String lang,
037: String country, String variant, Map m) {
038: this (dpc, r,
039: createElement(dpc, r, d, lang, country, variant, m));
040: }
041:
042: XMLDPLocale(DPContext dpc, DPRoot r, Element e) {
043: super (dpc, r, e);
044: }
045:
046: public short getType() {
047: return LOCALE_DP;
048: }
049:
050: public String getTag() {
051: return LOCALE_TAG;
052: }
053:
054: public String getLanguage() {
055: return getElement().getAttribute("language");
056: }
057:
058: public String getCountry() {
059: return getElement().getAttribute("country");
060: }
061:
062: public String getVariant() {
063: return getElement().getAttribute("variant");
064: }
065:
066: protected Element getMergedElement() {
067: Map map = getCollectionValue();
068: Element e = createElement(getContext(), getRoot(),
069: getDocument(), getLanguage(), getCountry(),
070: getVariant(), map);
071: return e;
072: }
073:
074: static Element createElement(DPContext dpc, Document d,
075: String lang, String country, String variant) {
076: Element e = createElement(dpc, d, LOCALE_TAG);
077: if (lang != null && lang.length() > 0) {
078: e.setAttribute(LANGUAGE_KEY, lang);
079: } else {
080: throw new DPError(
081: "XMLDPLocale.createElement(): language was null in Locale");
082: }
083: if (country != null) {
084: e.setAttribute(COUNTRY_KEY, country);
085: }
086: if (variant != null) {
087: e.setAttribute(VARIANT_KEY, variant);
088: }
089:
090: setDefaultsElement(e);
091:
092: return e;
093: }
094:
095: private static Element createElement(DPContext dpc, DPRoot r,
096: Document d, String lang, String country, String variant,
097: Map m) {
098: Element e = createElement(dpc, d, lang, country, variant);
099:
100: XMLDPFactory factory = XMLDPFactory.getInstance();
101: for (Iterator i = m.keySet().iterator(); i.hasNext();) {
102: String name = (String) i.next();
103: Object o = m.get(name);
104: DPProperty dpp = factory.createProperty(dpc, r, d, name, o);
105: XMLDPProperty xmlDPP = (XMLDPProperty) dpp;
106: Element newElement = xmlDPP.getElement();
107: e.appendChild(newElement);
108: }
109:
110: setDefaultsElement(e);
111:
112: return e;
113: }
114:
115: public void appendLanguageAttr(StringBuffer b) {
116: b.append(" " + LANGUAGE_KEY + "=\"").append(getLanguage())
117: .append("\"");
118: }
119:
120: public void appendCountryAttr(StringBuffer b) {
121: b.append(" " + COUNTRY_KEY + "=\"").append(getCountry())
122: .append("\"");
123: }
124:
125: public void appendVariantAttr(StringBuffer b) {
126: if (!getVariant().equals("")) {
127: b.append(" " + VARIANT_KEY + "=\"").append(getVariant())
128: .append("\"");
129: }
130: }
131:
132: public void toXML(StringBuffer b, int indent) {
133: if (isDummy()) {
134: return;
135: }
136: indentBuffer(b, indent);
137: appendStartTag(b);
138: appendLanguageAttr(b);
139: appendCountryAttr(b);
140: appendVariantAttr(b);
141: appendMergeAttr(b);
142: appendLockAttr(b);
143: appendAdvancedAttr(b);
144: appendPropagateAttr(b);
145: b.append(">\n");
146:
147: appendChildProperty(b, indent);
148:
149: indentBuffer(b, indent);
150: appendEndTag(b);
151: }
152: }
|