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    
015    package org.apache.tapestry.parse;
016    
017    import java.util.Map;
018    
019    import org.apache.hivemind.Location;
020    import org.apache.hivemind.util.ToStringBuilder;
021    
022    /**
023     *  Represents localized text from the template.
024     *
025     *  @see TokenType#LOCALIZATION
026     * 
027     *  @author Howard Lewis Ship
028     *  @since 3.0
029     *
030     **/
031    
032    public class LocalizationToken extends TemplateToken
033    {
034        private String _tag;
035        private String _key;
036        private boolean _raw;
037        private Map _attributes;
038        
039        /**
040         *  Creates a new token.
041         * 
042         * 
043         *  @param tag the tag of the element from the template
044         *  @param key the localization key specified
045         *  @param raw if true, then the localized value contains markup that should not be escaped
046         *  @param attributes any additional attributes (beyond those used to define key and raw)
047         *  that were specified.  This value is retained, not copied.
048         *  @param location location of the tag which defines this token
049         * 
050         **/
051        
052        public LocalizationToken(String tag, String key, boolean raw, Map attributes, Location location)
053        {
054            super(TokenType.LOCALIZATION, location);
055            
056            _tag = tag;
057            _key = key;
058            _raw = raw;
059            _attributes = attributes;
060        }
061        
062        /**
063         *  Returns any attributes for the token, which may be null.  Do not modify
064         *  the return value.
065         * 
066         **/
067        
068        public Map getAttributes()
069        {
070            return _attributes;
071        }
072    
073        public boolean isRaw()
074        {
075            return _raw;
076        }
077    
078        public String getTag()
079        {
080            return _tag;
081        }
082    
083        public String getKey()
084        {
085            return _key;
086        }
087        
088        protected void extendDescription(ToStringBuilder builder)
089        {
090            builder.append("tag", _tag);
091            builder.append("key", _key);
092            builder.append("raw", _raw);
093        }
094    }