001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014 package org.apache.tapestry.markup;
015
016 import java.io.PrintWriter;
017
018
019 /**
020 * Used to hold markup attribute data for writing in a specific format.
021 *
022 * @author jkuhnert
023 */
024 public class DefaultAttribute implements Attribute
025 {
026 protected String _value;
027 protected boolean _raw;
028
029 public DefaultAttribute(String value, boolean raw)
030 {
031 _value = value;
032 _raw = raw;
033 }
034
035 public Object getValue()
036 {
037 return _value;
038 }
039
040 void append(Object value)
041 {
042 if (value == null)
043 return;
044
045 _value += " " + value;
046 }
047
048 void setRaw(boolean raw)
049 {
050 _raw = raw;
051 }
052
053 public boolean isRaw()
054 {
055 return _raw;
056 }
057
058 void print(String name, PrintWriter writer, MarkupFilter filter)
059 {
060 writer.print(' ');
061 writer.print(name);
062 writer.print("=\"");
063
064 if (_raw && _value != null) {
065
066 writer.write(_value);
067
068 } else if (_value != null) {
069
070 char[] data = _value.toCharArray();
071 filter.print(writer, data, 0, data.length, true);
072 }
073
074 writer.print('"');
075 }
076
077 public String toString()
078 {
079 return _value;
080 }
081 }