All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ajax4jsf.framework.renderer.compiler.TextElement Maven / Gradle / Ivy

Go to download

Ajax4jsf is an open source extension to the JavaServer Faces standard that adds AJAX capability to JSF applications without requiring the writing of any JavaScript.

The newest version!
/**
 * Licensed under the Common Development and Distribution License,
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.sun.com/cddl/
 *   
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package org.ajax4jsf.framework.renderer.compiler;

import java.io.IOException;

import javax.faces.FacesException;

/**
 * @author [email protected] (latest modification by $Author: sergeysmirnov $)
 * @version $Revision: 1.1 $ $Date: 2006/04/28 02:04:15 $
 *
 */
public class TextElement extends ElementBase {
	
	private String text = null;
	
	private boolean escape = false;

	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.renderer.compiler.RootElement#encode(javax.faces.render.Renderer, javax.faces.context.FacesContext, javax.faces.component.UIComponent)
	 */
	public void encode(TemplateContext context) throws IOException {
		// TODO Auto-generated method stub
		String textValue = getString(context);
		
		if (isEscape()) {
			context.getWriter().writeText(textValue, null);
		} else {
			context.getWriter().write(textValue.toString());
		}
	}

	
	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.renderer.compiler.ElementBase#encode(org.ajax4jsf.framework.renderer.compiler.TemplateContext, java.lang.String)
	 */
	public void encode(TemplateContext context, String breakPoint) throws IOException {
		// Text not contain breakpoints.
		encode(context);
	}


	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.renderer.compiler.ElementBase#getString(org.ajax4jsf.framework.renderer.compiler.TemplateContext)
	 */
	public String getString(TemplateContext context) throws FacesException {
		
		String textValue = super.getString(context);
		// If value not set - return element body.
		if (textValue.length()==0 && null != getText()) {
			textValue = getText();
		} 
		return textValue;
	}


	/**
	 * @return Returns the text.
	 */
	public String getText() {
		return text;
	}

	/**
	 * @param text The text to set.
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * @return Returns the escape.
	 */
	public boolean isEscape() {
		return escape;
	}

	/**
	 * @param escape The escape to set.
	 */
	public void setEscape(boolean escape) {
		this.escape = escape;
	}


	public String getTag() {
		return HtmlCompiler.NS_PREFIX+HtmlCompiler.VERBATUM_TAG;
	}

	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.renderer.compiler.ElementBase#getAllowedClasses()
	 */
	protected Class[] getAllowedClasses() {
		// TODO Auto-generated method stub
		return new Class[]{
				MethodCallElement.class,
				ResourceElement.class,
				ClassElement.class				
		};
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy