edu.jdomengine.core.attr.JDomPromptAttribute.java Source code

Java tutorial

Introduction

Here is the source code for edu.jdomengine.core.attr.JDomPromptAttribute.java

Source

/* 
 *   Copyright (C) 2014 Arnaud PETIT <arnaud.petit@minesdedouai.fr>
 *   
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 2.1 of the License, or (at your option) any later version.
 *   
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *   
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 *   MA 02110-1301 USA
 */

package edu.jdomengine.core.attr;

import org.apache.commons.lang.StringEscapeUtils;

import edu.jdomengine.interfaces.IJDom;
import edu.jdomengine.interfaces.IJDomNode;

/**
 * Class representing a prompt attribute, i.e. an element which asks the 
 * webmaster for its content.
 */
abstract public class JDomPromptAttribute extends JDomBaseAttribute {
    private static final long serialVersionUID = 1L;

    protected JDomPromptAttribute(IJDomNode node) {
        super(node);
    }

    protected String value = IJDom.EMPTY_STRING;

    /**
     * Sets the value of the element with a string, which will be preprocessed.
     * @param token the string token to set the value to.
     */
    public final void setValue(String token) {
        this.value = beforeSet(token);
    }

    /**
     * Sanitizes the token before setting it, adding spaces if it is part of
     * a list, and so on, but do not escape them, as the escape will be made
     * in the {@link JDomPromptAttribute#getValue()} method.
     * @param token the token to sanitize
     * @return the token sanitized
     */
    @SuppressWarnings("static-method")
    protected String beforeSet(String token) {
        return token;
    }

    @Override
    public String getValue() {
        return StringEscapeUtils.escapeHtml(this.value);
    }

}