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

com.sun.faces.taglib.html_basic.CommandTagParserImpl Maven / Gradle / Ivy

There is a newer version: 4.1.1
Show newest version
/*
 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package com.sun.faces.taglib.html_basic;

import com.sun.faces.RIConstants;
import com.sun.faces.taglib.TagParser;
import com.sun.faces.taglib.ValidatorInfo;
import org.xml.sax.Attributes;

import java.text.MessageFormat;
import java.util.ResourceBundle;

/**
 * 

Parses the command tag attributes and verifies that the required * attributes are present

*/ public class CommandTagParserImpl implements TagParser { //********************************************************************* // Validation and configuration state (protected) // PENDING(edburns): Make this localizable private StringBuffer failureMessages; // failureMessages private boolean failed; private ValidatorInfo validatorInfo; //********************************************************************* // Constructor and lifecycle management /** *

CommandTagParserImpl constructor

*/ public CommandTagParserImpl() { failed = false; failureMessages = new StringBuffer(); } /** *

Set the validator info object that has the current tag * information

* * @param validatorInfo object with current tag info */ @Override public void setValidatorInfo(ValidatorInfo validatorInfo) { this.validatorInfo = validatorInfo; } /** *

Get the failure message

* * @return String Failure message */ @Override public String getMessage() { return failureMessages.toString(); } /** *

Return false if validator conditions have not been met

* * @return boolean false if validation conditions have not been met */ @Override public boolean hasFailed() { return failed; } /** *

Parse the starting element. Parcel out to appropriate * handler method.

*/ @Override public void parseStartElement() { String ns = validatorInfo.getNameSpace(); String ln = validatorInfo.getLocalName(); if (ns.equals(RIConstants.HTML_NAMESPACE)) { if (ln.equals("commandButton")) { handleCommandButton(); } } } /** *

Parse the end element

*/ @Override public void parseEndElement() { //no parsing required } //********************************************************************* // Private methods /** *

set failed flag to true unless tag has a value attribute

. *

*

PRECONDITION: qn is a commandButton

*/ private void handleCommandButton() { Attributes attrs = validatorInfo.getAttributes(); String ln = validatorInfo.getLocalName(); boolean hasValue = false; boolean hasImage = false; boolean hasBinding = false; for (int i = 0; i < attrs.getLength(); i++) { if (attrs.getLocalName(i).equals("value")) { hasValue = true; } if (attrs.getLocalName(i).equals("image")) { hasImage = true; } if (attrs.getLocalName(i).equals("binding")) { hasBinding = true; } } if (failed = (!hasBinding && !(hasValue || hasImage))) { Object[] obj = new Object[1]; obj[0] = ln; ResourceBundle rb = ResourceBundle.getBundle( RIConstants.TLV_RESOURCE_LOCATION); failureMessages.append( MessageFormat.format(rb.getString("TLV_COMMAND_ERROR"), obj)); failureMessages.append("\n"); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy