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.Rule;
09: import com.sun.portal.rewriter.rom.TypedData;
10: import com.sun.portal.rewriter.util.Constants;
11: import com.sun.portal.rewriter.util.StringHelper;
12:
13: public final class Attribute extends Data implements TypedData {
14: private String name;
15: private String tag;
16: private final String valuePatterns;
17: private String type;
18:
19: public Attribute(final String aName) {
20: this (aName, null, null, null, null);
21: }//constructor
22:
23: public Attribute(final String aName, final String aTag,
24: final String aValuePatterns, final String aType,
25: final String aSource) {
26: super (Rule.ATTRIBUTE, aSource);
27:
28: name = StringHelper.normalize(aName,
29: Constants.DEFAULT_REGULAR_EXPRESSION);
30: tag = StringHelper.normalize(aTag,
31: Constants.DEFAULT_REGULAR_EXPRESSION);
32: valuePatterns = StringHelper.normalize(aValuePatterns);
33: type = StringHelper.normalize(aType, Rule.URL);
34: }//constructor
35:
36: public String getName() {
37: return name;
38: }//getName()
39:
40: public String getTag() {
41: return tag;
42: }//getTag()
43:
44: public String getValuePatterns() {
45: return valuePatterns;
46: }//getValuePatterns()
47:
48: public String getType() {
49: return type;
50: }//getType()
51:
52: public Attribute recycleMatchee(final String aName,
53: final String aTag, final String aType, final String aSource) {
54: type = aType;
55: name = aName;
56: tag = aTag;
57: setSource(aSource);
58: return this ;
59: }//recycleMatchee()
60:
61: public void writeCustomAttributes(final StringBuffer aBuffer) {
62: aBuffer.append(Rule.NAME).append(Constants.EQUALS).append(
63: Constants.DOUBLE_QUOTES).append(getName()).append(
64: Constants.DOUBLE_QUOTES);
65:
66: if (!getTag().equals(Constants.DEFAULT_REGULAR_EXPRESSION)) {
67: aBuffer.append(Constants.SINGLE_SPACE).append(Rule.TAG)
68: .append(Constants.EQUALS).append(
69: Constants.DOUBLE_QUOTES).append(getTag())
70: .append(Constants.DOUBLE_QUOTES);
71: }
72:
73: if (getValuePatterns().length() > 0) {
74: aBuffer.append(Constants.SINGLE_SPACE).append(
75: Rule.VALUE_PATTERNS).append(Constants.EQUALS)
76: .append(Constants.DOUBLE_QUOTES).append(
77: getValuePatterns()).append(
78: Constants.DOUBLE_QUOTES);
79: }
80:
81: if (!getType().equals(Rule.URL)) {
82: aBuffer.append(Constants.SINGLE_SPACE).append(Rule.TYPE)
83: .append(Constants.EQUALS).append(
84: Constants.DOUBLE_QUOTES).append(getType())
85: .append(Constants.DOUBLE_QUOTES);
86: }
87: }//writeCustomAttributes()
88:
89: }//class Attribute
|