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.rom.common;
06:
07: import com.sun.portal.rewriter.rom.Data;
08: import com.sun.portal.rewriter.rom.DataRule;
09: import com.sun.portal.rewriter.rom.Rule;
10: import com.sun.portal.rewriter.util.Constants;
11: import com.sun.portal.rewriter.util.StringHelper;
12: import com.sun.portal.rewriter.util.collections.ListMap;
13: import com.sun.portal.rewriter.util.re.Pattern;
14:
15: public final class TagText extends Data {
16: private String tag;
17: private String attributePatterns;
18: private ListMap attributeMap;
19:
20: public TagText(final String aTag) {
21: this (aTag, (String) null, null);
22: }//constructor
23:
24: public TagText(final String aTag, final String aAttributePatterns,
25: final String aSource) {
26: this (aTag, parseAttributes(StringHelper
27: .normalize(aAttributePatterns)), aSource);
28: attributePatterns = StringHelper.normalize(aAttributePatterns);
29: }//constructor
30:
31: public TagText(final String aTag, final ListMap aAttributeMap,
32: final String aSource) {
33: super (Rule.TAGTEXT, aSource);
34: tag = StringHelper.normalize(aTag);
35:
36: if (aAttributeMap != null) {
37: attributeMap = aAttributeMap;
38: } else {
39: attributeMap = ListMap.EMPTY_LISTMAP;
40: }
41:
42: if (attributePatterns == null) {
43: attributePatterns = attributeMap.toString();
44: }
45: }//constructor
46:
47: public String getTag() {
48: return tag;
49: }//getTag()
50:
51: public String getAttributePatterns() {
52: return attributePatterns;
53: }//getValuePatterns()
54:
55: ListMap getAttributeMap() {
56: return attributeMap;
57: }//getAttributePatternsMap()
58:
59: public TagText recycleMatchee(final String aTag,
60: final ListMap aAttributePatternsMap, final String aSource) {
61: tag = aTag;
62: attributeMap = aAttributePatternsMap;
63: setSource(aSource);
64: return this ;
65: }//recycleMatchee()
66:
67: public void writeCustomAttributes(final StringBuffer aBuffer) {
68: aBuffer.append(Rule.TAG).append(Constants.EQUALS).append(
69: Constants.DOUBLE_QUOTES).append(getTag()).append(
70: Constants.DOUBLE_QUOTES);
71:
72: if (getAttributePatterns().length() > 0) {
73: aBuffer.append(Constants.SINGLE_SPACE).append(
74: Rule.ATTRIBUTE_PATTERNS).append(Constants.EQUALS)
75: .append(Constants.DOUBLE_QUOTES).append(
76: getAttributePatterns()).append(
77: Constants.DOUBLE_QUOTES);
78: }
79: }//writeCustomAttributes()
80:
81: static final ListMap parseAttributes(final String aAttributePatterns) {
82: final Pattern[] c = DataRule
83: .createValuePatternSpec(aAttributePatterns);
84: final ListMap result = new ListMap();
85: for (int i = 0; i < c.length; i++) {
86: String[] temp = StringHelper.tokenize(c[i].getInput(), "=",
87: true, 2);
88: result.put(temp[0].trim(), temp[1].trim());
89: }
90:
91: return result;
92: }//parseAttributes()
93:
94: }//class TagText
|