下面列出了怎么用javax.servlet.jsp.tagext.JspTag的API类实例代码及写法,或者点击链接到github查看源代码。
public JspContextWrapper(JspTag jspTag, JspContext jspContext,
ArrayList<String> nestedVars, ArrayList<String> atBeginVars,
ArrayList<String> atEndVars, Map<String,String> aliases) {
this.jspTag = jspTag;
this.invokingJspCtxt = (PageContext) jspContext;
if (jspContext instanceof JspContextWrapper) {
rootJspCtxt = ((JspContextWrapper)jspContext).rootJspCtxt;
}
else {
rootJspCtxt = invokingJspCtxt;
}
this.nestedVars = nestedVars;
this.atBeginVars = atBeginVars;
this.atEndVars = atEndVars;
this.pageAttributes = new HashMap<>(16);
this.aliases = aliases;
if (nestedVars != null) {
this.originalNestedVars = new HashMap<>(nestedVars.size());
} else {
this.originalNestedVars = null;
}
syncBeginTagFile();
}
protected void init( ServletConfig config ) {
int maxSize=-1;
String maxSizeS=getOption(config, OPTION_MAXSIZE, null);
if( maxSizeS != null ) {
try {
maxSize=Integer.parseInt(maxSizeS);
} catch( Exception ex) {
maxSize=-1;
}
}
if( maxSize <0 ) {
maxSize=Constants.MAX_POOL_SIZE;
}
this.handlers = new JspTag[maxSize];
this.current = -1;
this.resourceInjector = (ResourceInjector)
config.getServletContext().getAttribute(
Constants.JSP_RESOURCE_INJECTOR_CONTEXT_ATTRIBUTE);
}
/**
* Gets the next available tag handler from this tag handler pool,
* instantiating one if this tag handler pool is empty.
*
* @param handlerClass Tag handler class
*
* @return Reused or newly instantiated tag handler
*
* @throws JspException if a tag handler cannot be instantiated
*/
public <T extends JspTag> JspTag get(Class<T> handlerClass)
throws JspException {
synchronized( this ) {
if (current >= 0) {
return handlers[current--];
}
}
// Out of sync block - there is no need for other threads to
// wait for us to construct a tag for this thread.
JspTag tagHandler = null;
try {
if (resourceInjector != null) {
tagHandler = resourceInjector.createTagHandlerInstance(
handlerClass);
} else {
tagHandler = handlerClass.newInstance();
}
} catch (Exception e) {
throw new JspException(e.getMessage(), e);
}
return tagHandler;
}
/**
* Adds the given tag handler to this tag handler pool, unless this tag
* handler pool has already reached its capacity, in which case the tag
* handler's release() method is called.
*
* @param handler JspTag handler to add to this tag handler pool
*/
public void reuse(JspTag handler) {
synchronized( this ) {
if (current < (handlers.length - 1)) {
handlers[++current] = handler;
return;
}
}
// There is no need for other threads to wait for us to release
if (handler instanceof Tag) {
((Tag)handler).release();
}
if (resourceInjector != null) {
resourceInjector.preDestroy(handler);
}
}
@Override
public void setParent(JspTag parent) {
if (parent != null && this.parents.size() > 0) {
boolean valid = false;
for (Class<? extends BaseTag> clazz : this.parents) {
if (clazz.isAssignableFrom(parent.getClass())) {
valid = true;
break;
}
}
if (!valid) {
final StringBuilder error = new StringBuilder("Invalid parent for ");
error.append(this).append(": ").append(parent);
throw new IllegalArgumentException(error.toString());
}
}
this.parent = parent;
super.setParent(parent);
}
/**
* {@link ParameterAware}を探して、コールバックします。
* まず、直接の親タグが{@link ParameterAware}かどうか判定します。
* そうであれば、コールバックして終了します。
* もし、直接の親タグが{@link ParameterAware}ない場合、
* {@link SimpleTagSupport#findAncestorWithClass(JspTag, Class)}を利用して、
* ルートまで{@link ParameterAware}を探して辿ります。
* それでも見つからない場合、処理を終了します。
* @throws JspException {@link JspException}
* @throws IOException {@link IOException}
*/
@Override
public void doTag() throws JspException, IOException {
super.doTag();
Args.checkNotEmpty(getName());
JspTag s = getParent();
if (!ParameterAware.class.isInstance(s)) {
s = SimpleTagSupport.findAncestorWithClass(this, ParameterAware.class);
}
if (s == null) return;
ParameterAware parent = (ParameterAware) s;
if (getValues() != null) {
parent.awareParameter(name, getValues());
} else {
parent.awareParameter(name, getValue());
}
}
/**
* If necessary, wraps a {@link SimpleTag} into a {@link Tag}.
*
* @param tag The tag to (possibly) wrap.
* @return The wrapped tag, or the tag passed as parameter if it was not necessary.
*/
public static Tag wrapTag(JspTag tag) {
if (tag == null) {
return null;
}
if (tag instanceof Tag)
{
return (Tag) tag;
}
if (tag instanceof SimpleTag)
{
return new TagAdapter((SimpleTag) tag);
}
throw new VelocityToolsJspException(
"Cannot get tag that is not a Tag nor a SimpleTag, class "
+ tag.getClass().getCanonicalName());
}
public JspFragmentHelper( int discriminator, JspContext jspContext,
JspTag parentTag )
{
this.discriminator = discriminator;
this.jspContext = jspContext;
if(jspContext instanceof PageContext) {
_jspx_page_context = (PageContext)jspContext;
} else {
_jspx_page_context = null;
}
this.parentTag = parentTag;
}
@Override
public void setParent(JspTag parent) {
if (parent instanceof Nav) {
super.setElement("li");
}
super.setParent(parent);
}
@Override
public void setParent(JspTag parent) {
if (parent instanceof Container) {
throw new IllegalArgumentException("Bootstrap containers may not be nested");
}
super.setParent(parent);
}
@Override
public void setParent(JspTag parent) {
if (parent != null) {
final Carousel carousel = (Carousel) parent;
super.setAttribute("href", "#" + carousel.getId(true));
}
}
@Override
public void setParent(JspTag parent) {
if (parent != null) {
if (parent instanceof Carousel) {
((Carousel) parent).addItem(this);
}
}
super.setParent(parent);
}
@Override
public void setParent(JspTag parent) {
if (parent instanceof Carousel) {
this.carousel = (Carousel) parent;
}
super.setParent(parent);
}
@Override
public void doTag() throws JspException, IOException {
final JspTag parent = super.getParent();
if (parent instanceof ButtonGroup) {
final ButtonGroup buttonGroup = (ButtonGroup) parent;
if (buttonGroup.getFacet(JustifiedFacet.class).getValue()) {
if ("button".equals(super.getElement())) {
super.wrapIn(new ButtonGroup());
return;
}
}
}
super.doTag();
}
@Override
public void setParent(JspTag parent) {
if (parent instanceof Nav) {
super.setElement("li");
}
super.setParent(parent);
}
@Override
public boolean isEEComponent(final Class<?> impl) {
return Servlet.class.isAssignableFrom(impl)
|| Filter.class.isAssignableFrom(impl)
|| ServletContextListener.class.isAssignableFrom(impl)
|| JspTag.class.isAssignableFrom(impl);
}
/**
* Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.JspUtils#setLatestTag(org.apache.velocity.context.Context, javax.servlet.jsp.tagext.JspTag)}.
*/
@Test
public void testSetLatestTag()
{
Context context = createMock(Context.class);
JspTag tag = createMock(JspTag.class);
expect(context.put(LATEST_TAG_ATTRIBUTE_NAME, tag)).andReturn(null);
replay(context, tag);
JspUtils.setLatestTag(context, tag);
verify(context, tag);
}
/**
* Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.JspUtils#getLatestJspTag(org.apache.velocity.context.Context)}.
*/
@Test
public void testGetLatestJspTag()
{
Context context = createMock(Context.class);
JspTag tag = createMock(JspTag.class);
expect(context.get(LATEST_TAG_ATTRIBUTE_NAME)).andReturn(tag);
replay(context, tag);
assertSame(tag, JspUtils.getLatestJspTag(context));
verify(context, tag);
}
private ELContextWrapper(ELContext wrapped, JspTag jspTag, PageContext pageContext) {
this.wrapped = wrapped;
this.jspTag = jspTag;
this.pageContext = pageContext;
}
public JspTag getParentTag() {
return this.parentTag;
}
public JspTag getParent() {
return null;
}
public JspTag getParent() {
return null;
}
public JspTag getParentTag() {
return this.parentTag;
}
public JspTag getParentTag() {
return this.parentTag;
}
public JspTag getParentTag() {
return this.parentTag;
}
public JspTag getParent() {
return this.parent;
}
public void setParent(JspTag arg0) {
}
public void setParent(JspTag arg0) {
}
/**
* Constructs a tag handler pool with the given capacity.
*
* @param capacity Tag handler pool capacity
* @deprecated Use static getTagHandlerPool
*/
public TagHandlerPool(int capacity) {
this.handlers = new JspTag[capacity];
this.current = -1;
}
/**
* Instantiates and injects the given tag handler class.
*
* @param clazz the tag handler class to be instantiated and injected
*
* @throws Exception if an error has occurred during instantiation or
* injection
*/
public <T extends JspTag> T createTagHandlerInstance(Class<T> clazz)
throws Exception;