Example usage for javax.servlet.jsp.tagext TagSupport findAncestorWithClass

List of usage examples for javax.servlet.jsp.tagext TagSupport findAncestorWithClass

Introduction

In this page you can find the example usage for javax.servlet.jsp.tagext TagSupport findAncestorWithClass.

Prototype





@SuppressWarnings("unchecked")
public static final Tag findAncestorWithClass(Tag from, Class klass) 

Source Link

Document

Find the instance of a given class type that is closest to a given instance.

Usage

From source file:com.jada.taglib.language.LanguageTagSupport.java

public String findName() {
    if (indexed == null || !indexed.equals("true")) {
        return property;
    }/*from   ww  w.  j  a  va  2  s  .c  o  m*/
    LoopTagSupport loopTag = (LoopTagSupport) TagSupport.findAncestorWithClass(this, LoopTagSupport.class);

    String result = "";
    result += name + "[" + loopTag.getLoopStatus().getIndex() + "]." + property;
    return result;
}

From source file:com.jada.taglib.language.LanguageTagSupport.java

public String findName(String prop) {
    if (indexed == null || !indexed.equals("true")) {
        return prop;
    }/*from  www  .j a  v  a2s .  c om*/
    LoopTagSupport loopTag = (LoopTagSupport) TagSupport.findAncestorWithClass(this, LoopTagSupport.class);

    String result = "";
    result += name + "[" + loopTag.getLoopStatus().getIndex() + "]." + prop;
    return result;
}

From source file:net.ontopia.topicmaps.webed.taglibs.form.FormTag.java

@Override
public int doStartTag() throws JspException {
    NavigatorPageIF contextTag = FrameworkUtils.getContextTag(pageContext);
    if (contextTag == null)
        throw new JspTagException("<webed:form> must be nested" + " within a <tolog:context> tag, but no"
                + " <tolog:context> was found.");

    if (TagSupport.findAncestorWithClass(this, FormTag.class) != null)
        throw new JspTagException("<webed:form> cannot be nested");

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    boolean readonly = InteractionELSupport.getBooleanValue(this.readonly, false, pageContext);
    request.setAttribute(Constants.OKS_FORM_READONLY, readonly);

    // put the name of the action group to page scope
    // to allow child tags to access this information
    TagUtils.setActionGroup(pageContext, actiongroup);

    TagUtils.setCurrentFormTag(request, this);

    requestId = TagUtils.createRequestId();

    // -- try to lock variable
    UserIF user = FrameworkUtils.getUser(pageContext);
    if (lockVarname != null) {
        ActionRegistryIF registry = TagUtils.getActionRegistry(pageContext);
        if (registry == null)
            throw new JspException(
                    "No action registry! Check actions.xml for " + "errors; see log for details.");

        Collection lockColl = InteractionELSupport.extendedGetValue(lockVarname, pageContext);

        NamedLockManager lockMan = TagUtils.getNamedLockManager(pageContext.getServletContext());
        LockResult lockResult = lockMan.attemptToLock(user, lockColl, lockVarname, pageContext.getSession());
        lockVarname = lockResult.getName();

        Collection unlockable = lockResult.getUnlockable();
        request.setAttribute(Constants.LOCK_RESULT, lockResult);

        if (!unlockable.isEmpty()) {
            logger.warn("Unable to lock contents of variable '" + lockVarname + "'." + unlockable);
            // forward to error page if variable is locked
            ActionGroupIF ag = registry.getActionGroup(actiongroup);
            ActionForwardPageIF forwardPage = ag.getLockedForwardPage();
            if (forwardPage != null && forwardPage.getURL() != null) {
                String fwd_url = forwardPage.getURL();
                logger.info("Forward to lock error page: " + fwd_url);
                try {
                    ((HttpServletResponse) pageContext.getResponse()).sendRedirect(fwd_url);
                } catch (IOException ioe) {
                    logger.error("Problem occurred while forwarding: " + ioe.getMessage());
                    throw new JspException("I/O-Problem while forwarding to '" + fwd_url + "': " + ioe);
                }//w  ww.j  a v  a 2 s  .c  om
                return SKIP_PAGE;
            } else {
                logger.warn("No forward page found for lock situation. Setting form to be read-only");
                request.setAttribute(Constants.OKS_FORM_READONLY, Boolean.TRUE);
            }
        } else {
            logger.info("Locked contents of variable '" + lockVarname + "'.");
        }
    }

    // register a new action data set
    pageContext.setAttribute(FormTag.REQUEST_ID_ATTRIBUTE_NAME, requestId, PageContext.REQUEST_SCOPE);
    TagUtils.createActionDataSet(pageContext);

    return EVAL_BODY_BUFFERED;
}

From source file:it.cnr.icar.eric.client.ui.thin.components.taglib.GraphMenuNodeTag.java

public int doStartTag() throws JspException {

    FacesContext context = FacesContext.getCurrentInstance();
    Graph graph = (Graph) ((Util.getValueBinding("#{sessionScope.graph_menu}").getValue(context)));
    // In the postback case, graph and the node exist already.So make sure
    // it doesn't created again.
    if (graph.findNodeByName(name) != null) {
        return BodyTag.EVAL_BODY_BUFFERED;
    }/*from  w  w w  .  ja va  2s. c o  m*/
    Node node = new Node(name, label, action, icon, enabled, expanded);

    // get the immediate ancestor/parent of this node.
    GraphMenuNodeTag parentNode = null;
    try {
        parentNode = (GraphMenuNodeTag) TagSupport.findAncestorWithClass(this, GraphMenuNodeTag.class);
    } catch (Exception e) {
        System.out.println("Exception while locating GraphMenuNodeTag.class");
    }

    if (parentNode == null) {
        // then this should be root
        try {
            graph.setRoot(node);
        } catch (JAXRException ex) {
            log.error(ex);
        }
    } else {
        Node nodeToAdd = graph.findNodeByName(parentNode.getName());
        // this node should exist
        if (nodeToAdd != null) {
            try {
                nodeToAdd.addChild(node);
            } catch (JAXRException ex) {
                log.error(ex);
            }
        }
    }

    return BodyTag.EVAL_BODY_BUFFERED;
}

From source file:it.cnr.icar.eric.client.ui.thin.components.taglib.GraphTreeNodeTag.java

public int doStartTag() throws JspException {

    FacesContext context = FacesContext.getCurrentInstance();

    Graph graph = (Graph) ((Util.getValueBinding("#{sessionScope.graph_tree}").getValue(context)));
    // In the postback case, graph and the node exist already.So make sure
    // it doesn't created again.
    if (graph.findNodeByName(getName()) != null) {
        return BodyTag.EVAL_BODY_BUFFERED;
    }/*from   ww w . ja  va 2s  .c  om*/
    Node node = new Node(name, label, action, icon, enabled, expanded);

    // get the immediate ancestor/parent tag of this tag.
    GraphTreeNodeTag parentNode = null;
    try {
        parentNode = (GraphTreeNodeTag) TagSupport.findAncestorWithClass(this, GraphTreeNodeTag.class);
    } catch (Exception e) {
        System.out.println("Exception while locating GraphTreeNodeTag.class");
    }
    // if this tag has no parent that is a node tag,
    if (parentNode == null) {
        // then this should be root
        try {
            graph.setRoot(node);
        } catch (JAXRException ex) {
            log.error(ex);
        }
    } else {
        // add the node to its parent node.
        Node nodeToAdd = graph.findNodeByName(parentNode.getName());
        // this node should exist
        if (nodeToAdd != null) {
            try {
                nodeToAdd.addChild(node);
            } catch (JAXRException ex) {
                log.error(ex);
            }
        }
    }

    return BodyTag.EVAL_BODY_BUFFERED;
}

From source file:com.googlecode.jtiger.modules.ecside.tag.TagUtils.java

public static TableModel getModel(Tag tag) {
    TableTag tableTag = (TableTag) TagSupport.findAncestorWithClass(tag, TableTag.class);
    return tableTag.getModel();
}

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

private boolean isSortable() {
    ListTag parent = (ListTag) TagSupport.findAncestorWithClass(this, ListTag.class);
    return sortable && parent.getPageRowCount() > 0;
}

From source file:org.apache.pluto.driver.tags.PortletModeAnchorTag.java

/**
 * Method invoked when the start tag is encountered.
 * @throws JspException  if an error occurs.
 *//*  w  ww  .  j  a v a2 s  .c  o  m*/
public int doStartTag() throws JspException {

    // Ensure that the modeAnchor tag resides within a portlet tag.
    PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class);
    if (parentTag == null) {
        throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag.");
    }

    portletId = parentTag.getPortletId();
    // Evaluate portlet ID attribute.
    evaluatePortletId();

    // Retrieve the portlet window config for the evaluated portlet ID.
    ServletContext servletContext = pageContext.getServletContext();
    DriverConfiguration driverConfig = (DriverConfiguration) servletContext
            .getAttribute(AttributeKeys.DRIVER_CONFIG);

    if (isPortletModeAllowed(driverConfig, portletMode)) {
        // Retrieve the portal environment.
        PortalRequestContext portalEnv = PortalRequestContext
                .getContext((HttpServletRequest) pageContext.getRequest());

        PortalURL portalUrl = portalEnv.createPortalURL();
        portalUrl.setPortletMode(evaluatedPortletId, new PortletMode(portletMode));

        // Build a string buffer containing the anchor tag
        StringBuffer tag = new StringBuffer();
        //            tag.append("<a class=\"" + ToolTips.CSS_CLASS_NAME + "\" href=\"" + portalUrl.toString() + "\">");
        //            tag.append("<span class=\"" + portletMode + "\"></span>");
        //            tag.append("<span class=\"" + ToolTips.CSS_CLASS_NAME + "\">");
        //            tag.append(ToolTips.forMode(new PortletMode(portletMode)));
        //            tag.append("</span></a>");
        tag.append("<a title=\"");
        tag.append(ToolTips.forMode(new PortletMode(portletMode)));
        tag.append("\" ");
        tag.append("href=\"" + portalUrl.toString() + "\">");
        tag.append("<span class=\"" + portletMode + "\"></span>");
        tag.append("</a>");
        // Print the mode anchor tag.
        try {
            JspWriter out = pageContext.getOut();
            out.print(tag.toString());
        } catch (IOException ex) {
            throw new JspException(ex);
        }
    }

    // Continue to evaluate the tag body.
    return EVAL_BODY_INCLUDE;
}

From source file:org.apache.pluto.driver.tags.PortletModeDropDownTag.java

/**
 * Method invoked when the start tag is encountered.
 * @throws JspException  if an error occurs.
 *//*from  ww  w  .  j a v a 2s  .  c o  m*/
public int doStartTag() throws JspException {

    // Ensure that the modeAnchor tag resides within a portlet tag.
    PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class);
    if (parentTag == null) {
        throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag.");
    }

    portletId = parentTag.getPortletId();
    // Evaluate portlet ID attribute.
    evaluatePortletId();

    // Retrieve the portlet window config for the evaluated portlet ID.
    ServletContext servletContext = pageContext.getServletContext();
    DriverConfiguration driverConfig = (DriverConfiguration) servletContext
            .getAttribute(AttributeKeys.DRIVER_CONFIG);

    // Retrieve the portal environment.
    PortalRequestContext portalEnv = PortalRequestContext
            .getContext((HttpServletRequest) pageContext.getRequest());

    //find the current mode for use in 'selected' attrib of select option
    PortalURL requestedPortalUrl = portalEnv.getRequestedPortalURL();
    PortletWindowConfig windowConfig = PortletWindowConfig.fromId(evaluatedPortletId);
    // Retrieve the portlet container from servlet context.
    PortletContainer container = (PortletContainer) servletContext
            .getAttribute(AttributeKeys.PORTLET_CONTAINER);

    // Create the portlet window to render.
    PortletWindow window = new PortletWindowImpl(container, windowConfig, requestedPortalUrl);

    PortletMode currentMode = requestedPortalUrl.getPortletMode(window.getId().getStringId());

    //start the markup
    StringBuffer tag = new StringBuffer();
    //        String strCurrentMode = currentMode.toString();        
    //        tag.append("Current mode: " + currentMode.toString());
    tag.append(
            "<form action=\"\" name=\"modeSelectionForm\" style=\"display:inline\"><select onchange=\"self.location=this.options[this.selectedIndex].value\">");
    Set<PortletMode> modeSet = null;
    try {
        modeSet = driverConfig.getSupportedPortletModes(evaluatedPortletId);
    } catch (PortletContainerException e) {
        throw new JspException(e);
    }

    if (modeSet != null) {
        Iterator<PortletMode> i = modeSet.iterator();
        while (i.hasNext()) {
            PortletMode mode = i.next();

            PortalURL portalUrl = portalEnv.createPortalURL();
            portalUrl.setPortletMode(evaluatedPortletId, mode);

            // Build a string buffer containing the anchor tag
            tag.append("<option value=\"" + portalUrl.toString() + "\"");
            //Add 'selected' attribute for current mode.
            if (mode.equals(currentMode)) {
                tag.append(" selected=\"true\"");
            }
            tag.append(">");
            if (driverConfig.isPortletManagedMode(evaluatedPortletId, mode.toString())) {
                tag.append(getCustomModeDecorationName(driverConfig, mode));
            } else {
                tag.append(mode.toString().toUpperCase());
            }
            //               tag.append(mode.toString().toUpperCase());
            tag.append("</option>");
        }
    }
    tag.append("</select></form>");
    // Print the mode anchor tag.
    try {
        JspWriter out = pageContext.getOut();
        out.print(tag.toString());
    } catch (IOException ex) {
        throw new JspException(ex);
    }

    // Continue to evaluate the tag body.
    return EVAL_BODY_INCLUDE;
}

From source file:org.apache.pluto.driver.tags.PortletWindowStateAnchorTag.java

/**
 * Method invoked when the start tag is encountered.
 * @throws JspException  if an error occurs.
 *//*from  w w  w  .j  a v a 2  s .  co  m*/
public int doStartTag() throws JspException {

    // Ensure that the modeAnchor tag resides within a portlet tag.
    PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class);
    if (parentTag == null) {
        throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag.");
    }

    portletId = parentTag.getPortletId();
    // Evaluate portlet ID attribute.
    evaluatePortletId();

    // Retrieve the portlet window config for the evaluated portlet ID.
    ServletContext servletContext = pageContext.getServletContext();
    DriverConfiguration driverConfig = (DriverConfiguration) servletContext
            .getAttribute(AttributeKeys.DRIVER_CONFIG);

    if (isWindowStateAllowed(driverConfig, state)) {
        // Retrieve the portal environment.
        PortalRequestContext portalEnv = PortalRequestContext
                .getContext((HttpServletRequest) pageContext.getRequest());

        PortalURL portalUrl = portalEnv.createPortalURL();
        portalUrl.setWindowState(evaluatedPortletId, new WindowState(state));

        // Build a string buffer containing the anchor tag
        StringBuffer tag = new StringBuffer();
        //            tag.append("<a class=\"" + ToolTips.CSS_CLASS_NAME + "\" href=\"" + portalUrl.toString() + "\">");
        //            tag.append("<span class=\"" + state + "\"></span>");
        //            tag.append("<span class=\"" + ToolTips.CSS_CLASS_NAME + "\">");
        //            tag.append(ToolTips.forWindowState(new WindowState(state)));
        //            tag.append("</span></a>");
        tag.append("<a title=\"");
        tag.append(ToolTips.forWindowState(new WindowState(state)));
        tag.append("\" ");
        tag.append("href=\"" + portalUrl.toString() + "\">");
        tag.append("<img border=\"0\" src=\"" + icon + "\" />");
        tag.append("</a>");

        // Print the mode anchor tag.
        try {
            JspWriter out = pageContext.getOut();
            out.print(tag.toString());
        } catch (IOException ex) {
            throw new JspException(ex);
        }
    }

    // Continue to evaluate the tag body.
    return EVAL_BODY_INCLUDE;
}