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

net.smartlab.web.page.PaginateTei Maven / Gradle / Ivy

/*
 * The SmartWeb Framework
 * Copyright (C) 2004-2006
 *
 * 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
 *
 * For further informations on the SmartWeb Framework please visit
 *
 *                        http://smartweb.sourceforge.net
 */
 
package net.smartlab.web.page;

import java.util.Enumeration;

import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.ValidationMessage;
import javax.servlet.jsp.tagext.VariableInfo;

/**
 * Additional features for the PaginateTag.
 * 
 * @author rlogiacco
 */
public class PaginateTei extends TagExtraInfo {

	/**
	 * @see javax.servlet.jsp.tagext.TagExtraInfo#getVariableInfo(javax.servlet.jsp.tagext.TagData)
	 */
	public final VariableInfo[] getVariableInfo(TagData data) {
		return new VariableInfo[] {new VariableInfo("paginator", "net.smartlab.web.page.Paginator", true, VariableInfo.NESTED)};
	}

	/**
	 * @see javax.servlet.jsp.tagext.TagExtraInfo#isValid(javax.servlet.jsp.tagext.TagData)
	 */
	public boolean isValid(TagData tagData) {
		boolean hasHref = false;
		boolean hasForm = false;

		Enumeration attributes = tagData.getAttributes();
		while (attributes.hasMoreElements()) {
			String attribute = (String)attributes.nextElement();
			if (attribute.equals("href")) {
				hasHref = true;
			} else if (attribute.equals("form")) {
				hasForm = true;
			}
		}
		if (hasHref && hasForm) {
			// ERROR
			return false;
		}
		return true;
	}

	/**
	 * @see javax.servlet.jsp.tagext.TagExtraInfo#validate(javax.servlet.jsp.tagext.TagData)
	 */
	public ValidationMessage[] validate(TagData tagData) {
		boolean hasHref = false;
		boolean hasForm = false;
		
		Enumeration attributes = tagData.getAttributes();
		while (attributes.hasMoreElements()) {
			String attribute = (String)attributes.nextElement();
			if (attribute.equals("href")) {
				hasHref = true;
			} else if (attribute.equals("form")) {
				hasForm = true;
			}
		}
		if (hasHref && hasForm) {
			return new ValidationMessage[] {new ValidationMessage(tagData.getId(), "Page tag has both href and form attributes")};
		}
		return null;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy