Java Code Examples for javax.servlet.jsp.tagext.TagSupport#findAncestorWithClass()
The following examples show how to use
javax.servlet.jsp.tagext.TagSupport#findAncestorWithClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformTag.java From java-technology-stack with MIT License | 5 votes |
@Override protected final int doStartTagInternal() throws JspException { if (this.value != null) { // Find the containing EditorAwareTag (e.g. BindTag), if applicable. EditorAwareTag tag = (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class); if (tag == null) { throw new JspException("TransformTag can only be used within EditorAwareTag (e.g. BindTag)"); } // OK, let's obtain the editor... String result = null; PropertyEditor editor = tag.getEditor(); if (editor != null) { // If an editor was found, edit the value. editor.setValue(this.value); result = editor.getAsText(); } else { // Else, just do a toString. result = this.value.toString(); } result = htmlEscape(result); if (this.var != null) { this.pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope)); } else { try { // Else, just print it out. this.pageContext.getOut().print(result); } catch (IOException ex) { throw new JspException(ex); } } } return SKIP_BODY; }
Example 2
Source File: ParamValueTag.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * When reach the end tag, fire this operation * * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag() */ public int doEndTag( ) throws JspException { // included in viewer tag ParamTag paramTag = (ParamTag) TagSupport .findAncestorWithClass( this, ParamTag.class ); if ( paramTag != null ) { if ( bodyContent != null ) { String bodyString = bodyContent.getString( ); if ( bodyString != null ) { bodyString = bodyString.trim( ); if ( !"".equals(bodyString) ) { // replace the value attribute with the content, if empty if ( param.getValue() == null || "".equals(param.getValue()) ) { param.setValue( bodyString ); } } } } paramTag.addValue( param ); } return super.doEndTag( ); }
Example 3
Source File: ParamDefTag.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * When reach the end tag, fire this operation * * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag() */ public int doEndTag( ) throws JspException { try { if ( __validate( ) ) { // included in parameterpage tag this.requesterTag = (RequesterTag) TagSupport .findAncestorWithClass( this, RequesterTag.class ); if ( requesterTag != null ) { this.viewer = requesterTag.viewer; if ( this.viewer.isCustom( ) ) { __beforeEndTag( ); __process( ); } } } } catch ( Exception e ) { __handleException( e ); } return super.doEndTag( ); }
Example 4
Source File: ParamTag.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * When reach the end tag, fire this operation * * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag() */ public int doEndTag( ) throws JspException { if ( param.validate( ) ) { // included in viewer tag AbstractViewerTag viewerTag = (AbstractViewerTag) TagSupport .findAncestorWithClass( this, AbstractViewerTag.class ); if ( viewerTag != null ) viewerTag.addParameter( param ); } return super.doEndTag( ); }
Example 5
Source File: SpanTag.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * ${@inheritDoc} */ public int doEndTag() throws JspException { ListCommand cmd = ListTagUtil.getCurrentCommand(this, pageContext); ListTag parent = (ListTag) TagSupport.findAncestorWithClass(this, ListTag.class); if (cmd.equals(ListCommand.TBL_ADDONS) && role.equals("header")) { renderHeader(parent); } else if (cmd.equals(ListCommand.BEFORE_RENDER) && role.equals("footer")) { renderFooter(parent); } return TagSupport.EVAL_PAGE; }
Example 6
Source File: PortletRenderTag.java From portals-pluto with Apache License 2.0 | 5 votes |
/** * * @see PortletTag */ public int doEndTag() throws JspException { // Ensure that the portlet render tag resides within a portlet tag. PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class); if (parentTag == null) { throw new JspException("Portlet render tag may only reside " + "within a pluto:portlet tag."); } // If the portlet is rendered successfully, print the rendering result. try { if (parentTag.getStatus() == PortletTag.SUCCESS) { StringBuffer buffer = parentTag.getPortalServletResponse().getInternalBuffer().getBuffer(); pageContext.getOut().print(buffer.toString()); } else { // Otherwise, print the error messages List<String> msgs = parentTag.getMessages(); if (msgs.isEmpty()) { pageContext.getOut().print(" Unknown error rendering portlet."); } else { for (String msg : msgs) { pageContext.getOut().print("<p>"); pageContext.getOut().print(msg); pageContext.getOut().print("</p>"); } } } } catch (IOException ex) { throw new JspException(ex); } // Return. return SKIP_BODY; }
Example 7
Source File: TransformTag.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected final int doStartTagInternal() throws JspException { if (this.value != null) { // Find the containing EditorAwareTag (e.g. BindTag), if applicable. EditorAwareTag tag = (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class); if (tag == null) { throw new JspException("TransformTag can only be used within EditorAwareTag (e.g. BindTag)"); } // OK, let's obtain the editor... String result = null; PropertyEditor editor = tag.getEditor(); if (editor != null) { // If an editor was found, edit the value. editor.setValue(this.value); result = editor.getAsText(); } else { // Else, just do a toString. result = this.value.toString(); } result = htmlEscape(result); if (this.var != null) { pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope)); } else { try { // Else, just print it out. pageContext.getOut().print(result); } catch (IOException ex) { throw new JspException(ex); } } } return SKIP_BODY; }
Example 8
Source File: TransformTag.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected final int doStartTagInternal() throws JspException { if (this.value != null) { // Find the containing EditorAwareTag (e.g. BindTag), if applicable. EditorAwareTag tag = (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class); if (tag == null) { throw new JspException("TransformTag can only be used within EditorAwareTag (e.g. BindTag)"); } // OK, let's obtain the editor... String result = null; PropertyEditor editor = tag.getEditor(); if (editor != null) { // If an editor was found, edit the value. editor.setValue(this.value); result = editor.getAsText(); } else { // Else, just do a toString. result = this.value.toString(); } result = htmlEscape(result); if (this.var != null) { pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope)); } else { try { // Else, just print it out. pageContext.getOut().print(result); } catch (IOException ex) { throw new JspException(ex); } } } return SKIP_BODY; }
Example 9
Source File: SpanTag.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * ${@inheritDoc} */ public int doEndTag() throws JspException { ListCommand cmd = ListTagUtil.getCurrentCommand(this, pageContext); ListTag parent = (ListTag) TagSupport.findAncestorWithClass(this, ListTag.class); if (cmd.equals(ListCommand.TBL_ADDONS) && role.equals("header")) { renderHeader(parent); } else if (cmd.equals(ListCommand.BEFORE_RENDER) && role.equals("footer")) { renderFooter(parent); } return TagSupport.EVAL_PAGE; }
Example 10
Source File: TransformTag.java From spring-analysis-note with MIT License | 5 votes |
@Override protected final int doStartTagInternal() throws JspException { if (this.value != null) { // Find the containing EditorAwareTag (e.g. BindTag), if applicable. EditorAwareTag tag = (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class); if (tag == null) { throw new JspException("TransformTag can only be used within EditorAwareTag (e.g. BindTag)"); } // OK, let's obtain the editor... String result = null; PropertyEditor editor = tag.getEditor(); if (editor != null) { // If an editor was found, edit the value. editor.setValue(this.value); result = editor.getAsText(); } else { // Else, just do a toString. result = this.value.toString(); } result = htmlEscape(result); if (this.var != null) { this.pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope)); } else { try { // Else, just print it out. this.pageContext.getOut().print(result); } catch (IOException ex) { throw new JspException(ex); } } } return SKIP_BODY; }
Example 11
Source File: FormTag.java From ontopia with Apache License 2.0 | 4 votes |
@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); } 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; }
Example 12
Source File: PortletModeAnchorTag.java From portals-pluto with Apache License 2.0 | 4 votes |
/** * Method invoked when the start tag is encountered. * @throws JspException if an error occurs. */ 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; }
Example 13
Source File: PortletTitleTag.java From portals-pluto with Apache License 2.0 | 4 votes |
/** * Method invoked when the start tag is encountered. This method retrieves the portlet title and print it to the * page. * * @see org.apache.pluto.container.services.PortalCallbackService#setTitle(HttpServletRequest, PortletWindow, String) * @see org.apache.pluto.driver.services.container.PortalCallbackServiceImpl#setTitle(HttpServletRequest, * PortletWindow, String) * * @throws JspException */ @SuppressWarnings("unchecked") public int doStartTag() throws JspException { // Ensure that the portlet title tag resides within a portlet tag. PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class); if (parentTag == null) { throw new JspException("Portlet title tag may only reside " + "within a pluto:portlet tag."); } // Print out the portlet title to page. try { Map<String, String> titles = (Map<String, String>) pageContext.getRequest().getAttribute(AttributeKeys.PORTLET_TITLE); String portletId = parentTag.getEvaluatedPortletId(); String title = null; if (titles != null) { title = titles.get(portletId); } if (title == null) { PortletWindowConfig windowConfig = PortletWindowConfig.fromId(portletId); try { ServletContext servletContext = pageContext.getServletContext(); DriverConfiguration driverConfig = (DriverConfiguration) servletContext.getAttribute(AttributeKeys.DRIVER_CONFIG); PortletConfig config = driverConfig.getPortletConfig(portletId); ServletRequest request = pageContext.getRequest(); Locale defaultLocale = request.getLocale(); ResourceBundle bundle = config.getResourceBundle(defaultLocale); title = bundle.getString("javax.portlet.title"); } catch (Throwable th) { if (LOG.isDebugEnabled()) { StringBuilder txt = new StringBuilder(128); txt.append("Could not obtain title for: " + windowConfig.getPortletName() + "\n"); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); th.printStackTrace(pw); pw.flush(); txt.append(sw.toString()); LOG.warn(txt.toString()); } } if (title == null) { title = "[ " + windowConfig.getPortletName() + " ]"; } } pageContext.getOut().print(title); } catch (IOException ex) { throw new JspException(ex); } return SKIP_BODY; }
Example 14
Source File: PortletPortalURLTag.java From portals-pluto with Apache License 2.0 | 4 votes |
/** * Creates the portal URL pointing to the current portlet with specified * portlet mode and window state, and print the URL to the page. * @see PortletTag */ public int doStartTag() throws JspException { // Ensure that the portlet render 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."); } // Create portal URL. HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); PortalRequestContext ctx = PortalRequestContext.getContext(request); PortalURL portalUrl = ctx.createPortalURL(); // Encode window state of the current portlet in the portal URL. String portletId = parentTag.getEvaluatedPortletId(); if (windowState != null) { portalUrl.setWindowState(portletId, new WindowState(windowState)); } // Encode portlet mode of the current portlet in the portal URL. if (portletMode != null) { portalUrl.setPortletMode(portletId, new PortletMode(portletMode)); } // Print the portal URL as a string to the page. try { pageContext.getOut().print(response.encodeURL(portalUrl.toString())); } catch (IOException ex) { throw new JspException(ex); } // Skip the tag body. return SKIP_BODY; }
Example 15
Source File: PortletWindowStateAnchorTag.java From portals-pluto with Apache License 2.0 | 4 votes |
/** * Method invoked when the start tag is encountered. * @throws JspException if an error occurs. */ 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; }
Example 16
Source File: ColumnTag.java From spacewalk with GNU General Public License v2.0 | 4 votes |
private boolean isSortable() { ListTag parent = (ListTag) TagSupport.findAncestorWithClass(this, ListTag.class); return sortable && parent.getPageRowCount() > 0; }
Example 17
Source File: ColumnTag.java From uyuni with GNU General Public License v2.0 | 4 votes |
private boolean isSortable() { ListTag parent = (ListTag) TagSupport.findAncestorWithClass(this, ListTag.class); return sortable && parent.getPageRowCount() > 0; }