001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup;
018
019/**
020 * This class is for framework purposes only, which is why the class is (default) protected.
021 * <p>
022 * A RawMarkup element represents a hunk of unparsed HTML containing any arbitrary content.
023 * 
024 * @see MarkupElement
025 * @author Jonathan Locke
026 */
027public class RawMarkup extends MarkupElement
028{
029        /** The raw markup string * */
030        private final CharSequence string;
031
032        /**
033         * Create a RawMarkup element referencing an uninterpreted markup string.
034         * 
035         * @param string
036         *            The raw markup
037         */
038        public RawMarkup(final CharSequence string)
039        {
040                this.string = string;
041        }
042
043        /**
044         * Compare with a given object
045         * 
046         * @param o
047         *            The object to compare with
048         * @return True if equal
049         */
050        @Override
051        public boolean equals(final Object o)
052        {
053                if (o instanceof CharSequence)
054                {
055                        return string.equals(o);
056                }
057
058                if (o instanceof RawMarkup)
059                {
060                        return string.equals(((RawMarkup)o).string);
061                }
062
063                return false;
064        }
065
066        /**
067         * @see org.apache.wicket.markup.MarkupElement#equalTo(org.apache.wicket.markup.MarkupElement)
068         */
069        @Override
070        public boolean equalTo(final MarkupElement element)
071        {
072                if (element instanceof RawMarkup)
073                {
074                        return toString().equals(element.toString());
075                }
076                return false;
077        }
078
079        /**
080         * We must override hashCode since we overrode equals.
081         * 
082         * @return Hashcode for this object
083         */
084        @Override
085        public int hashCode()
086        {
087                return string.hashCode();
088        }
089
090        /**
091         * @see org.apache.wicket.markup.MarkupElement#toCharSequence()
092         */
093        @Override
094        public CharSequence toCharSequence()
095        {
096                return string;
097        }
098
099        /**
100         * @return This raw markup string
101         */
102        @Override
103        public String toString()
104        {
105                return string.toString();
106        }
107
108        /**
109         * @see MarkupElement#toUserDebugString()
110         */
111        @Override
112        public String toUserDebugString()
113        {
114                return "[Raw markup]";
115        }
116}