public static UIComponent addTransient(
      FacesContext context, ServletRequest req, UIComponent parent, String prevId, Class childClass)
      throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();

      BodyContent body = parentTag.getBodyContent();

      if (body != null) addVerbatim(parent, body);
    }

    UIComponent child = null;
    ;

    if (child == null) child = (UIComponent) childClass.newInstance();

    child.setTransient(true);

    addChild(parent, prevId, child);

    return child;
  }
  public static UIComponent addFacet(
      FacesContext context,
      ServletRequest req,
      UIComponent parent,
      String facetName,
      ValueExpression binding,
      Class childClass)
      throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();
    }

    UIComponent child = null;

    if (binding != null) child = (UIComponent) binding.getValue(context.getELContext());

    if (child == null) child = (UIComponent) childClass.newInstance();

    if (parent != null) parent.getFacets().put(facetName, child);

    if (binding != null) binding.setValue(context.getELContext(), child);

    return child;
  }
  public static UIComponent addPersistent(
      FacesContext context,
      ServletRequest req,
      UIComponent parent,
      ValueExpression binding,
      Class childClass)
      throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();

      BodyContent body = parentTag.getBodyContent();

      addVerbatim(parent, body);
    }

    UIComponent child = null;

    if (binding != null) child = (UIComponent) binding.getValue(context.getELContext());

    if (child == null) {
      child = (UIComponent) childClass.newInstance();

      // jsf/3251
      if (binding != null) binding.setValue(context.getELContext(), child);
    }

    if (parent != null) parent.getChildren().add(child);

    return child;
  }
  public static UIComponent findPersistent(
      FacesContext context, ServletRequest req, UIComponent parent, String id) throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    BodyContent body = null;

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();

      body = parentTag.getBodyContent();
    }

    if (parent != null) {
      List<UIComponent> children = parent.getChildren();
      int size = children.size();

      String prevId = null;
      for (int i = 0; i < size; i++) {
        UIComponent child = children.get(i);

        if (id.equals(child.getId())) {
          if (body != null) addVerbatim(parent, prevId, body);

          return child;
        }

        if (child.getId() != null) prevId = child.getId();
      }
    }

    return null;
  }
Esempio n. 5
0
  /**
   * Login as the admin user so that a yazd user account can be administered.
   *
   * <p>Includes body of tag if admin user was authorized based on the yazd.tag.properties
   * yazd.admin.username and yazd.admin.password, and a valid yazd username was found in the HTTP
   * input parameter "username".
   *
   * @throws JspException on system level error
   * @return <b>SKIP_BODY</b> on failure to authorize as admin user or user to administer could not
   *     be found, <b>EVAL_BODY_INCLUDE</b> if admin succeeded
   */
  public final int doStartTag() throws JspException {
    // Initialize YazdState
    js = (YazdState) pageContext.getAttribute("yazdUserState", PageContext.SESSION_SCOPE);
    if (js == null) {
      throw new JspException("Yazd admin tag could not get yazd state.");
    }

    // Initialize YazdRequest
    jr = (YazdRequest) pageContext.getAttribute("yazdUserRequest", PageContext.REQUEST_SCOPE);
    if (jr == null) {
      throw new JspException("Yazd admin tag could not get yazd request.");
    }

    // Get username and password of admin
    String username = TagPropertyManager.getTagProperty("yazd.admin.username");
    String password = TagPropertyManager.getTagProperty("yazd.admin.password");
    if (username == null || username.length() == 0 || password == null || password.length() == 0)
      return SKIP_BODY;

    // Get admin user authorization
    try {
      auth = AuthorizationFactory.getAuthorization(username, password);
    } catch (UnauthorizedException ue) {
      return SKIP_BODY;
    }

    // Get the user to administer from the "username" HTTP input parameter
    ServletRequest req = pageContext.getRequest();
    String tmp;
    if ((tmp = req.getParameter("username")) != null) return SKIP_BODY;

    try {
      ForumFactory ff = ForumFactory.getInstance(auth);
      ProfileManager pm = ff.getProfileManager();
      user = pm.getUser(tmp);
    } catch (Exception e) {
    }

    if (user == null) {
      jr.addError("User \"" + tmp + "\" not found");
      return SKIP_BODY;
    }

    return EVAL_BODY_INCLUDE;
  }
  public static UIComponent findFacet(
      FacesContext context, ServletRequest req, UIComponent parent, String facetName)
      throws Exception {
    if (context == null) FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();
    }

    if (parent != null) return parent.getFacet(facetName);
    else return null;
  }