Example usage for javax.servlet.jsp.tagext Tag getParent

List of usage examples for javax.servlet.jsp.tagext Tag getParent

Introduction

In this page you can find the example usage for javax.servlet.jsp.tagext Tag getParent.

Prototype


Tag getParent();

Source Link

Document

Get the parent (closest enclosing tag handler) for this tag handler.

Usage

From source file:net.mlw.vlh.web.util.JspUtils.java

public static Tag getParent(Tag self, Class klass) throws JspException {
    Tag tag = self.getParent();

    while (!(klass.isAssignableFrom(tag.getClass()))) {
        tag = tag.getParent();//from ww w .j  av a  2 s  .c om
        if (tag == null) {
            final String message = "Parent tag of class " + klass + " of the tag's class " + self
                    + " was not found.";
            LOGGER.error(message);
            throw new JspException(message);
        }
    }
    return tag;
}

From source file:org.hdiv.web.util.TagUtils.java

/**
 * Determine whether the supplied {@link Tag} has any ancestor tag of the
 * supplied type.//ww  w  .  ja  va2s. c  o m
 * 
 * @param tag the tag whose ancestors are to be checked
 * @param ancestorTagClass the ancestor {@link Class} being searched for
 * @return <code>true</code> if the supplied {@link Tag} has any ancestor
 *         tag of the supplied type
 * @throws IllegalArgumentException if either of the supplied arguments is
 *             <code>null</code>; or if the supplied
 *             <code>ancestorTagClass</code> is not type-assignable to the
 *             {@link Tag} class
 */
public static Tag getAncestorOfType(Tag tag, Class ancestorTagClass) {

    Assert.notNull(tag, "Tag cannot be null");
    Assert.notNull(ancestorTagClass, "Ancestor tag class cannot be null");
    if (!Tag.class.isAssignableFrom(ancestorTagClass)) {
        throw new IllegalArgumentException(
                "Class '" + ancestorTagClass.getName() + "' is not a valid Tag type");
    }
    Tag ancestor = tag.getParent();
    while (ancestor != null) {
        if (ancestorTagClass.isAssignableFrom(ancestor.getClass())) {
            return ancestor;
        }
        ancestor = ancestor.getParent();
    }
    return null;
}

From source file:lucee.runtime.tag.MailParam.java

@Override
public int doStartTag() throws PageException {

    if (content != null) {
        required("mailparam", "file", file);
        String filename = ListUtil.last(file, "/\\", true);
        Resource res = SystemUtil.getTempDirectory().getRealResource(filename);
        if (res.exists())
            ResourceUtil.removeEL(res, true);
        try {//www.j  a  va 2 s .c  om
            IOUtil.write(res, content);
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
        this.file = ResourceUtil.getCanonicalPathEL(res);
        remove = true;
    } else if (!StringUtil.isEmpty(this.file)) {
        Resource res = ResourceUtil.toResourceNotExisting(pageContext, this.file);
        if (res != null) {
            if (res.exists())
                pageContext.getConfig().getSecurityManager().checkFileLocation(res);
            this.file = ResourceUtil.getCanonicalPathEL(res);
        }
    }

    // check attributes
    boolean hasFile = !StringUtil.isEmpty(file);
    boolean hasName = !StringUtil.isEmpty(name);
    // both attributes
    if (hasName && hasFile) {
        throw new ApplicationException(
                "Wrong Context for tag MailParam, you cannot use attribute file and name together");
    }
    // no attributes
    if (!hasName && !hasFile) {
        throw new ApplicationException(
                "Wrong Context for tag MailParam, you must use attribute file or attribute name for this tag");
    }

    // get Mail Tag
    Tag parent = getParent();
    while (parent != null && !(parent instanceof Mail)) {
        parent = parent.getParent();
    }

    if (parent instanceof Mail) {
        Mail mail = (Mail) parent;
        mail.setParam(type, file, name, value, disposition, contentID, remove);
    } else {
        throw new ApplicationException("Wrong Context, tag MailParam must be inside a Mail tag");
    }
    return SKIP_BODY;
}

From source file:com.wabacus.system.tags.component.AbsComponentTag.java

protected AbsComponentTag getMyComponentParentTag() {
    Tag tagParent = this.getParent();
    while (tagParent != null) {
        if (tagParent instanceof AbsComponentTag) {//?
            return (AbsComponentTag) tagParent;
        }/*from   w ww  . j av  a  2 s  .com*/
        tagParent = tagParent.getParent();
    }
    return null;
}

From source file:com.adito.core.CoreUtil.java

/**
 * @param clazz/* w  ww .  jav a 2 s  .c o  m*/
 * @param tag
 * @return Tag
 */
public static Tag getParentTagOfClass(Class clazz, Tag tag) {
    while ((tag = tag.getParent()) != null) {
        if (tag.getClass().equals(clazz)) {
            return tag;
        }
    }
    return null;
}

From source file:com.redhat.rhn.frontend.taglibs.ColumnTag.java

/**
 * Returns the ListDisplayTag that serves as the parent tag.
 * Returns null if no ListDisplayTag is found.
 * @return the parent ListDisplayTag//from   w  ww. j  a v a 2s. co  m
 */
public ListDisplayTag findListDisplay() {
    Tag tagParent = getParent();
    while (tagParent != null && !(tagParent instanceof ListDisplayTag)) {
        tagParent = tagParent.getParent();
    }
    return (ListDisplayTag) tagParent;
}

From source file:com.redhat.rhn.frontend.taglibs.ColumnTag.java

/**
 * Returns the ListDisplayTag that serves as the parent tag.
 * Returns null if no ListDisplayTag is found.
 * @return the parent ListDisplayTag//from ww w. j a va 2s  . c  o  m
 */
public UnpagedListDisplayTag findUnpagedListDisplay() {
    Tag tagParent = getParent();
    while (tagParent != null && !(tagParent instanceof UnpagedListDisplayTag)) {
        tagParent = tagParent.getParent();
    }
    return (UnpagedListDisplayTag) tagParent;
}

From source file:org.apache.struts.faces.taglib.JavascriptValidatorTag.java

/**
 * <p>Return the <code>clientId</code> of the form component for which
 * we are rendering validation Javascript.</p>
 *
 * @exception IllegalStateException if we are not nested inside a
 *  UIComponentTag with a child FormComponent matching our form name
 *//*from www .j a  v a 2s .  com*/
private String getFormClientId() {

    // Return any cached value
    if (formClientId != null) {
        return (formClientId);
    }

    // Locate our parent tag that is a component tag
    Tag parent = getParent();
    while (parent != null) {
        if (parent instanceof UIComponentTag) {
            break;
        }
        parent = parent.getParent();
    }
    if (parent == null) {
        throw new IllegalArgumentException("Not nested inside a UIComponentTag");
    }

    // Are we nested inside our corresponding form tag?
    UIComponent parentComponent = ((UIComponentTag) parent).getComponentInstance();
    if (parentComponent instanceof FormComponent) {
        if (formName.equals((String) parentComponent.getAttributes().get("beanName"))) {
            formClientId = parentComponent.getClientId(FacesContext.getCurrentInstance());
            return (formClientId);
        }
    }

    // Scan the children of this tag's component
    Iterator kids = ((UIComponentTag) parent).getComponentInstance().getChildren().iterator();
    while (kids.hasNext()) {
        UIComponent kid = (UIComponent) kids.next();
        if (!(kid instanceof FormComponent)) {
            continue;
        }
        if (formName.equals((String) kid.getAttributes().get("beanName"))) {
            formClientId = kid.getClientId(FacesContext.getCurrentInstance());
            return (formClientId);
        }
    }
    throw new IllegalArgumentException("Cannot find child FormComponent for form '" + formName + "'");

}

From source file:org.jboss.dashboard.ui.taglib.formatter.FragmentValueTag.java

public final int doStartTag() throws JspException {
    try {/*  ww  w . ja  v a 2 s  .co  m*/
        Tag parentTag = getParent();
        while (parentTag instanceof FragmentValueTag) {
            parentTag = parentTag.getParent();
        }
        if (!(parentTag instanceof FragmentTag))
            throw new JspException(
                    "Wrong nesting: fragmentValue named " + name + " must be inside a fragment.");
        FragmentTag parentFragment = (FragmentTag) parentTag;
        value = parentFragment.getParam(name);

        String valueName = id == null ? VALUE_NAME : id;
        if (value == null)
            pageContext.removeAttribute(valueName);
        else
            pageContext.setAttribute(valueName, value);
    } catch (Exception e) {
        log.error("Error:", e);
        throw new JspException(e);
    }
    return EVAL_BODY_AGAIN;
}

From source file:org.squale.welcom.taglib.button.ButtonTag.java

/**
 * @return retourne le formulaire contenant ce bouton
 *///from  w  ww  . j  a  v  a  2 s. c  o m
private FormTag getFormTag() {
    Tag tag = getParent();
    while (tag != null) {
        if (tag instanceof FormTag) {
            return (FormTag) tag;
        }
        tag = tag.getParent();
    }
    return null;
}