mapentrytag.java
来自「jakarta-taglibs」· Java 代码 · 共 92 行
JAVA
92 行
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.apache.taglibs.jms;
import javax.jms.JMSException;
import javax.servlet.ServletContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
/** Adds a map entry to the outer Map Message tag
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision: 1.2 $
*/
public class MapEntryTag extends AbstractBodyTag {
/** Stores the name of the map entry */
private String name;
/** Stores the value of the map entry */
private Object value;
// BodyTag interface
//-------------------------------------------------------------------------
public int doStartTag() throws JspException {
if ( value != null ) {
fireAddMapEntry();
return SKIP_BODY;
}
return EVAL_BODY_TAG;
}
public int doAfterBody() throws JspException {
BodyContent body = getBodyContent();
value = body.getString();
body.clearBody();
fireAddMapEntry();
return EVAL_PAGE;
}
public void release() {
name = null;
value = null;
}
// Properties
//-------------------------------------------------------------------------
/** Sets the name of the HTTP header
*/
public void setName(String name) {
this.name = name;
}
/** Sets the value of the HTTP header.
* If no value is set then the body of the tag is used
*/
public void setValue(Object value) {
this.value = value;
}
// Implementation methods
//-------------------------------------------------------------------------
protected void fireAddMapEntry() throws JspException {
try {
MapMessageTag tag = (MapMessageTag) findAncestorWithClass( this, MapMessageTag.class );
if ( tag == null ) {
throw new JspException("<jms:mapEntry> tag must be within a <jms:mapMessage> tag");
}
tag.addEntry( name, value );
}
catch (JMSException e) {
throw new JspException( "Failed to set MapMessage entry name: " + name + " value: " + value + ". Reason: " + e, e );
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?