Package com.sun.jsftemplating.layout.descriptors

Examples of com.sun.jsftemplating.layout.descriptors.LayoutElement


  // Sanity check
  if (id == null) {
      return null;
  }

  LayoutElement result = null;
  try {
      result = findLayoutElementById(
        LayoutDefinitionManager.
      getLayoutDefinition(ctx, layoutDefKey), id);
  } catch (LayoutDefinitionException ex) {
View Full Code Here


  if (elt.getUnevaluatedId().equals(id)) {
      return elt;
  }

  // Iterate over children and recurse (depth first)
  LayoutElement child = null;
  Iterator<LayoutElement> it = elt.getChildLayoutElements().iterator();
  while (it.hasNext()) {
      child = it.next();
// FIXME: Handle LayoutCompositions / LayoutInserts
      if (child instanceof LayoutComponent) {
View Full Code Here

  List<Handler> handlers = new ArrayList<Handler>();
  TemplateReader reader = env.getReader();
  TemplateParser parser = reader.getTemplateParser();
  Handler parentHandler = null;
  Stack<Handler> handlerStack = new Stack<Handler>();
  LayoutElement parent = env.getParent();

  // Skip whitespace...
  parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
  int ch = -1;

  // We now support 2 syntaxes:
  //   <!event type="beforeCreate">[handlers]</event>
  //   <!beforeCreate [handlers] />
  // If "eventName" is event, look for type and the closing '>' before
  // trying to parse the handlers.
  boolean useBodyContent = false;
  boolean createHandlerDefinitionOnLayoutDefinition = false;
  if (eventName.equals("handler")) {
      // We have a <handler id="foo"> tag...
      createHandlerDefinitionOnLayoutDefinition = true;
      useBodyContent = true;

      // Read type="...", no other options are supported at this time
      NameValuePair nvp = parser.getNVP(null);
      if (!nvp.getName().equals("id")) {
    throw new SyntaxException(
        "When defining and event, you must supply the event type! "
        + "Found \"...event " + nvp.getName() + "\" instead.");
      }
      eventName = nvp.getValue().toString();

      // Ensure the next character is '>'
      parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
      ch = parser.nextChar();
      if (ch != '>') {
    throw new SyntaxException(
        "Syntax error in event definition, found: '...handler id=\""
        + eventName + "\" " + ((char) ch)
        + "\'.  Expected closing '>' for opening handler element.");
      }

      // Get ready to read the handlers now...
      parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
      ch = parser.nextChar();
  } else if (eventName.equals("event")) {
      // We have the new syntax...
      useBodyContent = true;

      // Read type="...", no other options are supported at this time
      NameValuePair nvp = parser.getNVP(null);
      if (!nvp.getName().equals("type")) {
    throw new SyntaxException(
        "When defining and event, you must supply the event type! "
        + "Found \"...event " + nvp.getName() + "\" instead.");
      }
      eventName = nvp.getValue().toString();

      // Ensure the next character is '>'
      parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
      ch = parser.nextChar();
      if (ch != '>') {
    throw new SyntaxException(
        "Syntax error in event definition, found: '...event type=\""
        + eventName + "\" " + ((char) ch)
        + "\'.  Expected closing '>' for opening event element.");
      }

      // Get ready to read the handlers now...
      parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
      ch = parser.nextChar();
  } else {
      // Make sure to read the first char for the old syntax...
      ch = parser.nextChar();
  }

  // Read the Handler(s)...
  while (ch != -1) {
      if (useBodyContent) {
    // If we're using the new format.... check for "</event>"
    if (ch == '<') {
        // Just unread the '<', framework will validate the rest
        parser.unread('<');
        break;
    }
      } else {
    if ((ch == '/') || (ch == '>')) {
        // We found the end in the case where the handlers are
        // inside the tag (old syntax).
        break;
    }
      }
      // Check for {}'s
      if ((ch == LEFT_CURLY) || (ch == RIGHT_CURLY)) {
    if (ch == LEFT_CURLY) {
        // We are defining child handlers
        handlerStack.push(parentHandler);
        parentHandler = handler;
    } else {
        // We are DONE defining child handlers
        if (handlerStack.empty()) {
      throw new SyntaxException("Encountered unmatched '"
          + RIGHT_CURLY + "' when parsing handlers for '"
          + eventName + "' event.");
        }
        parentHandler = handlerStack.pop();
    }

    // ';' or ',' characters may appear between handlers
    parser.skipCommentsAndWhiteSpace(
      TemplateParser.SIMPLE_WHITE_SPACE + ",;");

    // We need to "continue" b/c we need to check next ch again
    ch = parser.nextChar();
    continue;
      }

      // Get Handler ID / Definition
      parser.unread(ch);

      // Read a Handler
      handler = readHandler(parser, eventName, parent);

      // Add the handler to the appropriate place
      if (parentHandler == null) {
    handlers.add(handler);
      } else {
    parentHandler.addChildHandler(handler);
      }

      // Look at the next character...
      ch = parser.nextChar();
  }
  if (ch == -1) {
      // Make sure we didn't get to the end of the file
      throw new SyntaxException("Unexpected EOF encountered while "
    + "parsing handlers for event '" + eventName + "'!");
  }

  // Do some checks to make sure everything is good...
  if (!handlerStack.empty()) {
      throw new SyntaxException("Unmatched '" + LEFT_CURLY
        + "' when parsing handlers for '" + eventName
        + "' event.");
  }
  if (!useBodyContent) {
      // Additional checks for old syntax...
      if (ch == '>') {
    throw new SyntaxException("Handlers for event '" + eventName
        + "' did not end with '/&gt;' but instead ended with '&gt;'!");
      }
      if (ch == '/') {
    // Make sure we have a "/>"...
    parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
    ch = parser.nextChar();
    if (ch != '>') {
        throw new SyntaxException("Expected '/&gt;' a end of '"
      + eventName + "' event.  But found '/"
      + (char) ch + "'.");
    }
    reader.popTag();   // Get rid of this event tag from the Stack
    ctx.endSpecial(env, eventName);
      }
  } else {
      // We need to recurse in order for the end-tag code to properly
      // close out the context and make everything run correctly...
      // Process child LayoutElements (should be none)
      reader.process(EVENT_PROCESSING_CONTEXT, parent,
    LayoutElementUtil.isLayoutComponentChild(parent));
  }

  // Set the Handlers on the parent...
  if (createHandlerDefinitionOnLayoutDefinition) {
      HandlerDefinition def = new HandlerDefinition(eventName);
      def.setChildHandlers(handlers);
      parent.getLayoutDefinition().setHandlerDefinition(eventName, def);
  } else {
      parent.setHandlers(eventName, handlers);
  }
    }
View Full Code Here

    // NOTE: 'handler' in handlerContext will change.
    // before we execute this Handler.
    // FIRST: Execute handlerDef child handlers
    List<Handler> handlers = handlerDef.getChildHandlers();
    Object retVal = null;
    LayoutElement elt = handlerContext.getLayoutElement();
    if (handlers.size() > 0) {
        retVal = elt.dispatchHandlers(handlerContext, handlers);
        if (retVal != null) {
      result = retVal;
        }
    }

    // NEXT: Execute instance child handlers
    // Useful for applying a condition to a group
    handlers = getChildHandlers();
    if (handlers.size() > 0) {
        retVal = elt.dispatchHandlers(handlerContext, handlers);
        if (retVal != null) {
      result = retVal;
        }
    }
      }
View Full Code Here

     */
    public static void buildUIComponentTree(FacesContext context, UIComponent parent, LayoutElement elt) {
// FIXME: Consider processing *ALL* LayoutElements so that <if> and others
// FIXME: have meaning when inside other components.
  Iterator<LayoutElement> it = elt.getChildLayoutElements().iterator();
  LayoutElement childElt;
  UIComponent child = null;
  while (it.hasNext()) {
      childElt = it.next();
      if (childElt instanceof LayoutFacet) {
    if (!((LayoutFacet) childElt).isRendered()) {
        // The contents of this should be a single UIComponent
        buildUIComponentTree(context, parent, childElt);
    }
    // NOTE: LayoutFacets that aren't JSF facets aren't
    // NOTE: meaningful in this context
      } else if (childElt instanceof LayoutComposition) {
    LayoutComposition compo = ((LayoutComposition) childElt);
    String template = compo.getTemplate();
    if (template != null) {
        // Add LayoutComposition to the stack
        LayoutComposition.push(context, childElt);

        try {
      // Add the template here.
      buildUIComponentTree(context, parent, LayoutDefinitionManager.getLayoutDefinition(
        context, template));
        } catch (LayoutDefinitionException ex) {
      if (((LayoutComposition) childElt).isRequired()) {
          throw ex;
      }
        }

        // Remove the LayoutComposition from the stack
        LayoutComposition.pop(context);
    } else {
        // In this case we don't have a template, so instead we
        // render the body
        buildUIComponentTree(context, parent, childElt);
    }
      } else if (childElt instanceof LayoutInsert) {
    Stack<LayoutElement> stack =
        LayoutComposition.getCompositionStack(context);
    if (stack.empty()) {
        // No template-client found...
        // Is this supposed to do nothing?  Or throw an exception?
        throw new IllegalArgumentException(
          "'ui:insert' encountered, however, no "
          + "'ui:composition' was used!");
    }

    // Get associated UIComposition
    String insertName = ((LayoutInsert) childElt).getName();
    if (insertName == null) {
        // include everything
        buildUIComponentTree(context, parent, stack.get(0));
    } else {
        // First resolve any EL in the insertName
        insertName = "" + ((LayoutInsert) childElt).resolveValue(
          context, parent, insertName);

        // Search for specific LayoutDefine
        LayoutElement def = LayoutInsert.findLayoutDefine(
          context, parent, stack, insertName);
        if (def == null) {
      // Not found include the body-content of the insert
      buildUIComponentTree(context, parent, childElt);
        } else {
View Full Code Here

     */
    public void process(ProcessingContext ctx, ProcessingContextEnvironment env, String name) throws IOException {
  // Get the reader
  TemplateReader reader = env.getReader();

  LayoutElement parent = env.getParent();
  if (trimming) {
      // First remove the current children on the LD (trimming == true)
      parent = parent.getLayoutDefinition();
      parent.getChildLayoutElements().clear();
  }

  // Next get the attributes
  List<NameValuePair> nvps =
      reader.readNameValuePairs(name, templateAttName, true);

  // Create new LayoutComposition
  LayoutComposition compElt = new LayoutComposition(
      parent,
      LayoutElementUtil.getGeneratedId(name, reader.getNextIdNumber()),
      trimming);

  // Look for required attribute
  // Find the template name
  for (NameValuePair nvp : nvps) {
      if (nvp.getName().equals(templateAttName)) {
    compElt.setTemplate((String) nvp.getValue());
      } else if (nvp.getName().equals(REQUIRED_ATTRIBUTE)) {
    compElt.setRequired(nvp.getValue().toString());
      } else {
                // We are going to treat extra attributes on compositions to be
                // ui:param values
                compElt.setParameter(nvp.getName(), nvp.getValue());
      }
  }

  parent.addChildLayoutElement(compElt);

  // See if this is a single tag or not...
  TemplateParser parser = reader.getTemplateParser();
  int ch = parser.nextChar();
  if (ch == '/') {
View Full Code Here

  // Skip any white space...
  parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);

  // Get the parent and define name
  LayoutElement parent = env.getParent();
  String id = (String) parser.getNVP(NAME_ATTRIBUTE, true).getValue();

  // Create new LayoutDefine
  LayoutDefine compElt = new LayoutDefine(parent, id);
  parent.addChildLayoutElement(compElt);

  // Skip any white space or extra junk...
  String theRest = parser.readUntil('>', true).trim();
  if (theRest.endsWith("/")) {
      reader.popTag()// Don't look for end tag
View Full Code Here

  // Skip any white space...
  parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);

  // Get the parent and insert name
  LayoutElement parent = env.getParent();
  String id = (String) parser.getNVP(NAME_ATTRIBUTE, true).getValue();

  // Create new LayoutInsert
  LayoutInsert compElt = new LayoutInsert(parent, id);
  compElt.setName(id);
  parent.addChildLayoutElement(compElt);

  // Skip any white space or extra junk...
  String theRest = parser.readUntil('>', true).trim();
  if (theRest.endsWith("/")) {
      reader.popTag()// Don't look for end tag
View Full Code Here

    // Found a IF_ELEMENT
    layElt.addChildLayoutElement(
        createLayoutIf(layElt, childNode));
      } else if (name.equalsIgnoreCase(ATTRIBUTE_ELEMENT)) {
    // Found a ATTRIBUTE_ELEMENT
    LayoutElement childElt =
        createLayoutAttribute(layElt, childNode);
    if (childElt != null) {
        layElt.addChildLayoutElement(childElt);
    }
      } else if (name.equalsIgnoreCase(MARKUP_ELEMENT)) {
View Full Code Here

      throw new RuntimeException("'" + CONDITION_ATTRIBUTE
        + "' attribute not found on '" + IF_ELEMENT + "' Element!");
  }

  // Create new LayoutIf
  LayoutElement ifElt =  new LayoutIf(parent, condition);

  // Add children...
  addChildLayoutElements(ifElt, node);

  // Return the if
View Full Code Here

TOP

Related Classes of com.sun.jsftemplating.layout.descriptors.LayoutElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.