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

org.ajax4jsf.framework.renderer.compiler.PlainElement 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.context.ResponseWriter;

import org.xml.sax.Attributes;

/**
 * @author [email protected] (latest modification by $Author: sergeysmirnov $)
 * @version $Revision: 1.1 $ $Date: 2006/04/28 02:04:20 $
 *
 */
public class PlainElement extends ElementBase {


	private String namespace = "";
	private String tag = null;
	
	private String[][] attrs = null;
	
	private boolean encodeStart = true;

	private boolean encodeEnd = true;
	/**
	 * @param attrs
	 */
	public PlainElement(String namespace, String tag, Attributes attrs) {
		// Set modifable attributes implementation to ability of
		// modifications.
		this.attrs = new String[attrs.getLength()][2];
		this.namespace = namespace;
		this.tag = tag;
		int currentAttribute = 0;
		// remove non-passed attributes, parse special.
		for (int i = 0; i < attrs.getLength(); i++) {
			String qName = attrs.getQName(i); 
			String value = attrs.getValue(i);
			if (qName.equals(HtmlCompiler.NS_PREFIX+"start")) {
				this.encodeStart = "true".equals(value);
			} else if (qName.equals(HtmlCompiler.NS_PREFIX+"end")) {
				this.encodeEnd = "true".equals(value);
			} else {
				this.attrs[currentAttribute][0]=qName;
				this.attrs[currentAttribute++][1]=value;
			}
			
		}
		// squize array if nessesary.
		if (currentAttribute < attrs.getLength()) {
			String[][] newattrs = new String[currentAttribute][2];
			System.arraycopy(this.attrs,0,newattrs,0,currentAttribute);
			this.attrs = newattrs;
		}
	}

	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.renderer.compiler.CompiledXML#encode(javax.faces.render.Renderer, javax.faces.context.FacesContext, javax.faces.component.UIComponent)
	 */
	public void encodeBegin(TemplateContext context) throws IOException {
		ResponseWriter writer = context.getWriter();
		if (this.encodeStart) {
			writer.startElement(getTag(), context.getComponent());
			// write attributes
			for (int i = 0; i < attrs.length; i++) {
				writer.writeAttribute(attrs[i][0], attrs[i][1], null);
			}
		}
	}

	public void encodeEnd(TemplateContext context) throws IOException {
		ResponseWriter writer = context.getWriter();

		if (this.encodeEnd) {
			writer.endElement(getTag());
		}

	}

	/**
	 * @return Returns the tag.
	 */
	public String getTag() {
		return tag;
	}

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

	/**
	 * @return Returns the attrs.
	 */
	public String[][] getAttrs() {
		return attrs;
	}

	/**
	 * @return Returns the encodeEnd.
	 */
	public boolean isEncodeEnd() {
		return encodeEnd;
	}

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

	/**
	 * @return Returns the encodeStart.
	 */
	public boolean isEncodeStart() {
		return encodeStart;
	}

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

	/**
	 * @return Returns the namespace.
	 */
	public String getNamespace() {
		return namespace;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy