01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rewriter.util.xml;
06:
07: import com.sun.portal.rewriter.util.Constants;
08: import com.sun.portal.rewriter.util.collections.ListMap;
09:
10: import java.util.List;
11:
12: public class Tag {
13: private static final String EMPTY_ATTRIBUTE_VALUE = "null";
14: static final String EMPTY_TAG_NAME = EMPTY_ATTRIBUTE_VALUE;
15:
16: private ListMap map = new ListMap(); //ordered collection
17: private String name = ""; //name of the tag
18:
19: public Tag() {
20:
21: }//constructor
22:
23: public Tag(String aName) {
24: name = aName;
25: }
26:
27: public String getName() {
28: return name;
29: }//getName()
30:
31: public void setName(final String aTagName) {
32: name = aTagName;
33: }//setName()
34:
35: /**
36: * Look for a key in case insensitive manner and return the value
37: */
38: public String get(final String aKey) {
39: final Object matchKey = map.matchesWith(aKey);
40: if (matchKey != null) {
41: Object value = map.get(matchKey);
42: return (String) value;
43: }
44:
45: return null;
46: }//get()
47:
48: public ListMap getAttributeMap() {
49: return ListMap.unmodifiableListMap(map);
50: }//getAttributeMap()
51:
52: public void put(final String aKey, final String aValue) {
53: map.put(aKey, aValue);
54: }//put()
55:
56: public String toString() {
57: final StringBuffer sb = new StringBuffer();
58:
59: if (!name.equals(EMPTY_TAG_NAME)) {
60: sb.append(name);
61: sb.append(Constants.SPACE);
62: }
63:
64: final List record = map.keyList();
65: for (int i = 0; i < record.size(); i++) {
66: Object key = record.get(i);
67: sb.append(key);
68: sb.append(Constants.SPACE);
69: Object s = map.get(key);
70: if (!s.equals(EMPTY_ATTRIBUTE_VALUE)) {
71: sb.append(Constants.EQUALS);
72: sb.append(Constants.SPACE);
73: sb.append('"');
74: sb.append(s);
75: sb.append('"');
76: }
77:
78: if (i < record.size()) {
79: sb.append(Constants.SPACE);
80: }
81: }//for loop
82: return sb.toString();
83: }//toString()
84: }//class Tag
|