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.extensions.wizard;
018
019import org.apache.wicket.markup.html.basic.Label;
020import org.apache.wicket.model.IModel;
021import org.apache.wicket.model.Model;
022
023/**
024 * A wizard step that displays the provided static content without expecting any input.
025 * 
026 * @author eelcohillenius
027 */
028public class StaticContentStep extends WizardStep
029{
030        private static final long serialVersionUID = 1L;
031
032        /**
033         * Whether HTML codes should be rendered as is (true), or should be escaped (false).
034         */
035        private final boolean allowHtml;
036
037        /** The model that provided the actual content. */
038        private IModel<?> content;
039
040        /**
041         * Constructor for if you want to set all the properties yourself.
042         * 
043         * @param allowHtml
044         *            If true, any html of the content will be rendered as is. Otherwise, it will be
045         *            escaped.
046         */
047        public StaticContentStep(final boolean allowHtml)
048        {
049                this.allowHtml = allowHtml;
050                add(new Label("content", ""));
051        }
052
053        /**
054         * Construct.
055         * 
056         * @param title
057         *            The title of this step
058         * @param summary
059         *            The summary of this step
060         * @param content
061         *            The content of the step panel
062         * @param allowHtml
063         *            If true, any html of the content will be rendered as is. Otherwise, it will be
064         *            escaped.
065         */
066        public StaticContentStep(final IModel<String> title, final IModel<String> summary,
067                final IModel<?> content, final boolean allowHtml)
068        {
069                super(title, summary);
070                this.content = content;
071                this.allowHtml = allowHtml;
072                add(new Label("content", content).setEscapeModelStrings(!allowHtml));
073        }
074
075        /**
076         * Construct.
077         * 
078         * @param title
079         *            The title of this step
080         * @param summary
081         *            The summary of this step
082         * @param content
083         *            The content of the step panel
084         * @param allowHtml
085         *            If true, any html of the content will be rendered as is. Otherwise, it will be
086         *            escaped.
087         */
088        public StaticContentStep(final IModel<String> title, final IModel<String> summary,
089                final String content, final boolean allowHtml)
090        {
091                this(title, summary, new Model<>(content), allowHtml);
092        }
093
094        /**
095         * Construct.
096         * 
097         * @param title
098         *            The title of this step
099         * @param summary
100         *            The summary of this step
101         * @param content
102         *            The content of the step panel
103         * @param allowHtml
104         *            If true, any html of the content will be rendered as is. Otherwise, it will be
105         *            escaped.
106         */
107        public StaticContentStep(final String title, final String summary, final IModel<?> content,
108                final boolean allowHtml)
109        {
110                this(new Model<String>(title), new Model<>(summary), content, allowHtml);
111        }
112
113        /**
114         * Construct.
115         * 
116         * @param title
117         *            The title of this step
118         * @param summary
119         *            The summary of this step
120         * @param content
121         *            The content of the step panel
122         * @param allowHtml
123         *            If true, any html of the content will be rendered as is. Otherwise, it will be
124         *            escaped.
125         */
126        public StaticContentStep(final String title, final String summary, final String content,
127                final boolean allowHtml)
128        {
129                this(title, summary, new Model<>(content), allowHtml);
130        }
131
132        /**
133         * Gets whether html is allowed as output.
134         * 
135         * @return Whether html is allowed as output
136         */
137        public final boolean getAllowHtml()
138        {
139                return allowHtml;
140        }
141
142        /**
143         * Gets the content from the content model.
144         * 
145         * @return The content
146         */
147        public final String getContent()
148        {
149                return (content != null) ? (String)content.getObject() : null;
150        }
151
152        /**
153         * Gets the content model.
154         * 
155         * @return The content model
156         */
157        public final IModel<?> getContentModel()
158        {
159                return content;
160        }
161
162        /**
163         * Sets the content model.
164         * 
165         * @param <T>
166         *            The model object type
167         * 
168         * @param content
169         *            The content model
170         */
171        public final <T> void setContentModel(final IModel<T> content)
172        {
173                this.content = content;
174                replace(new Label("content", content).setEscapeModelStrings(!allowHtml));
175        }
176}