Package com.sun.jsftemplating.layout

Examples of com.sun.jsftemplating.layout.SyntaxException


      element = processComposition(parent, "src", attrs, id, false);
  } else if ("ui:param".equals(nodeName)) {
      // Handle "param"
      Node nameAttNode = attrs.getNamedItem("name");
      if (nameAttNode == null) {
    throw new SyntaxException("The 'name' attribute is required on 'param'.");
      }
      Node valueNode = attrs.getNamedItem("value");
      if (valueNode == null) {
    throw new SyntaxException("The 'value' attribute is required on 'param'.");
      }

      // For now only handle cases where the parent is a LayoutComposition
      if (!(parent instanceof LayoutComposition)) {
    throw new SyntaxException("<" + nodeName
        + " name='" + nameAttNode.getNodeValue()
        + "' value='" + valueNode.getNodeValue()
        + "'> must be child of a 'composition' element!");
      }
      // Set the name=value on the parent LayoutComposition
      ((LayoutComposition) parent).setParameter(
    nameAttNode.getNodeValue(), valueNode.getNodeValue());
  } else if ("ui:remove".equals(nodeName)) {
      // Let the element remain null
  } else if ("ui:repeat".equals(nodeName)) {
  } else if ("ui:event".equals(nodeName)) {
      // per Ken, we need to append "/>" to allow the handler parser code
      // to end correctly
      String body = node.getTextContent();
      body = (body == null) ? "/>" : (body.trim() + "/>");
      Node type = node.getAttributes().getNamedItem("type");
      if (type == null) {
    // Ensure type != null
    throw new SyntaxException(
        "The 'type' attribute is required on 'ui:event'!");
      }
      String eventName = type.getNodeValue();
      InputStream is = new ByteArrayInputStream(body.getBytes());
      EventParserCommand command = new EventParserCommand();
      try {
    TemplateParser parser = new TemplateParser(is);
    parser.open()// Needed to initialize things.
    // Setup the reader...
    TemplateReader reader = new TemplateReader("foo", parser); // TODO: get a real ID
    reader.pushTag("event"); // The tag will be popped at the end
    // Read the handlers...
    command.process(new BaseProcessingContext(),
      new ProcessingContextEnvironment(reader, parent, true), eventName);
    // Clean up
    parser.close();
      } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
      } finally {
    if (is != null) {
        try {
      is.close();
        } catch (Exception e) {
      // ignore
        }
    }
      }
  } else if ("ui:if".equals(nodeName)) {
      // Handle "if" conditions
      String condition = attrs.getNamedItem("condition").getNodeValue();
      element = new LayoutIf(parent, condition);
  } else if ("ui:foreach".equals(nodeName)) {
      // Handle "foreach" conditions
      Node valueNode = attrs.getNamedItem("value");
      if (valueNode == null) {
    throw new SyntaxException("The 'value' property is required on 'foreach'.");
      }
      Node varNode = attrs.getNamedItem("var");
      if (varNode == null) {
    throw new SyntaxException("The 'var' property is required on 'foreach'.");
      }

      element = new LayoutForEach(parent, valueNode.getNodeValue(), varNode.getNodeValue());
  } else if ("f:facet".equals(nodeName)) {
      // FIXME: Need to take NameSpace into account
View Full Code Here


      ch = parser.nextChar()// Throw away '>'
      single = true;
      reader.popTag();      // Don't look for ending tag
  }
  if (ch != '>') {
      throw new SyntaxException(
    "Expected '>' found '" + (char) ch + "'.");
  }

  if (single) {
      // This is also the end of the component in this case...
View Full Code Here

    name = defName;
    // Add a flag to ensure the next switch goes to the "default" case
    unread(next);
    unread('f');
      } else {
    throw new SyntaxException(
        "'=' or ':' missing for Name Value Pair: '" + name + "'!");
      }
  }

  // Skip whitespace...
  skipCommentsAndWhiteSpace(SIMPLE_WHITE_SPACE);

  // Check for '>' character (means we're mapping an output value)
  String target = null;
  int endingChar = -1;
  next = nextChar();
  switch (next) {
      case '>':
    if (!requireQuotes) {
        // This means output mappings are not allowed, this must
        // be the end of the input (meaning there was no input
        // since we're at the beginning also)
        unread(next);
        value = "";
        break;
    }

    // We are mapping an output value, this should look like:
    //      keyName => $attribute{attKey}
    //      keyName => $application{appKey}
    //      keyName => $session{sessionKey}
    //      keyName => $pageSession{pageSessionKey}

    // First skip any whitespace after the '>'
    skipCommentsAndWhiteSpace(SIMPLE_WHITE_SPACE);

    // Next Make sure we have a '$' character
    next = nextChar();
    if (next != '$') {
        throw new SyntaxException(
      "'$' missing for Name Value Pair named: '" + name
      + "=>'!  This NVP appears to be a mapping expression, "
      + "therefor requires a format similar to:\n\t" + name
      + " => $attribute{attKey}\nor:\n\t" + name
      + " => $application{applicationKey}\nor:\n\t" + name
      + " => $session{sessionKey}\nor:\n\t" + name
      + " => $pageSession{pageSessionKey}");
    }

    // Next look for valid type...
    target = readToken();
    OutputTypeManager otm = OutputTypeManager.getInstance();
    if (otm.getOutputType(null, target) == null) {
        throw new SyntaxException(
      "Invalid OutputType ('" + target + "') for Name Value "
      + "Pair named: '" + name + "=>$" + target + "{...}'!  "
      + "This NVP appears to be a mapping expression, "
      + "therefor requires a format similar to:\n\t" + name
      + " => $attribute{attKey}\nor:\n\t" + name
      + " => $application{applicationKey}\nor:\n\t" + name
      + " => $session{sessionKey}\nor:\n\t" + name
      + " => $pageSession{pageSessionKey}");
    }

    // Skip whitespace again...
    skipCommentsAndWhiteSpace(SIMPLE_WHITE_SPACE);

    // Now look for '{'
    next = nextChar();
    if (next != '{') {
        throw new SyntaxException(
      "'{' missing for Name Value Pair: '" + name
      + "=>$" + target
      + "'!  The format must resemble the following:\n\t"
      + name + " => $" + target + "{key}");
    }
    endingChar = '}';
    break;
      case '{':
    // NVP w/ a List as its value
    value = parseList('}');
    break;
      case '[':
    // NVP w/ an array as its value
    value = parseList(']').toArray();
    break;
      case '"':
      case '\'':
    // Regular NVP...
    // Set the ending character to the same type of quote
    endingChar = next;
    break;
      case 'f':
    if ((value != null) && (value.toString().length() > 0)) {
        // We have the case where the whole string is the value
        // Get the next character so we can fall through w/ it
        // to the default case
        next = nextChar();
    }
    // Don't break here, fall through...
      default:
    // See if we require quotes around the value...
    if (!requireQuotes) {
        unread(next);   // Include "next" when getting the value
        // Read the value until '>'
        String strVal = readUntil('>', true);

        // Unread the '>'
        unread('>');

        // See if we also need put back a '/'...
        if (strVal.endsWith("/")) {
      // Remove the '/' and place back in the read buffer
      strVal = strVal.substring(0, strVal.length() - 1).trim();
      unread('/');
        }
        value = (value == null) ? strVal : (value.toString() + strVal);
        break;
    }

    // This isn't legal, throw an exception
    throw new SyntaxException("Name Value Pair named '"
        + name + "' is missing single or double quotes enclosing "
        + "its value.  It must follow one of these formats:\n\t"
        + name + "=\"value\"\nor:\n\t" + name + "='value'");
  }
View Full Code Here

      buf.append(arr[cnt]);
  }

  if (arrlen != idx) {
      // Didn't find it!
      throw new SyntaxException("Unable to find: '" + endingStr
    + "'.  Read to EOF and gave up.  Read: \n" + buf.toString());
  }

  // Return the result
  return buf.toString();
View Full Code Here

      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);
View Full Code Here

  def = parent.getLayoutDefinition().getHandlerDefinition(handlerId);
  if (def == null) {
      // Check globally defined Handler
      def = LayoutDefinitionManager.getGlobalHandlerDefinition(handlerId);
      if (def == null) {
    throw new SyntaxException("Handler '" + handlerId
        + "' in event '" + eventName + "' is not declared!  "
        + "Ensure the '@Handler' annotation has been defined "
        + "on the handler Java method, that it has been "
        + "compiled with the annotation processing tool, and "
        + "that the resulting"
        + " 'META-INF/jsftemplating/Handler.map' is located "
        + "in your classpath (you may need to do a clean "
        + "build).");
      }
  }

  // Create a Handler
  Handler handler = new Handler(def);

  // Get the default name
  Map inputs = def.getInputDefs();
// FIXME: Allow for HandlerDefs to declare their default input
  if (inputs.size() == 1) {
      defVal = inputs.keySet().toArray()[0].toString();
  }

  // Get the outputs so we can see what outputs have been declared
  Map outputs = def.getOutputDefs();

  // Ensure we have an opening parenthesis
  parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
  int ch = parser.nextChar();
  if (ch != '(') {
      throw new SyntaxException("While processing '&lt;!" + eventName
    + "...' the handler '" + handlerId
    + "' was missing the '(' character!");
  }

  // Move to the first char inside the parenthesis
  parser.skipWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
  ch = parser.nextChar();

  // We should not ignore '#' characters for 'if' (Issue #5)
  if ((ch != '#') || !handlerId.equals(IF_HANDLER)) {
      parser.unread(ch);
      parser.skipCommentsAndWhiteSpace(""); // Already skipped white
      ch = parser.nextChar();
  }

  // Allow if() handlers to be more flexible...
  if (handlerId.equals(IF_HANDLER)
    && (ch != '\'') && (ch != '"') && (ch != 'c')) {
// FIXME: check for "condition", otherwise expressions starting with 'c' will
// FIXME: not parse correctly
      // We have an if() w/o a condition="" && w/o quotes...
      // Take the entire value inside the ()'s to be the expression
      parser.unread(ch);
      handler.setCondition(parser.readUntil(')', false).trim());
      ch = ')';
  }

  // Read NVP(s)...
  while ((ch != -1) && (ch != ')')) {
      // Read NVP
      parser.unread(ch);
      try {
    nvp = parser.getNVP(defVal);
      } catch (SyntaxException ex) {
    throw new SyntaxException("Unable to process handler '"
      + handlerId + "'!", ex);
      }
      parser.skipCommentsAndWhiteSpace(
    TemplateParser.SIMPLE_WHITE_SPACE + ",;");
      ch = parser.nextChar();
View Full Code Here

      // Parse the XML file
      try {
    doc = db.parse(inputStream, getBaseURI());
      } catch (IOException ex) {
    throw new SyntaxException("Unable to parse XML file!", ex);
      } catch (SAXException ex) {
    throw new SyntaxException(ex);
      }
  } finally {
      try {
    inputStream.close();
      } catch (Exception ex) {
View Full Code Here

          TemplateParser.SIMPLE_WHITE_SPACE);
      // Get the expected String
      if (isTagStackEmpty()) {
          parser.skipCommentsAndWhiteSpace(
        TemplateParser.SIMPLE_WHITE_SPACE + '!');
          throw new SyntaxException("Found end tag '&lt;/"
        + parser.readToken()
        + "...' but did not find matching begin tag!");
      }
      startTag = popTag();
      if ((startTag.length() > 0)
        && (startTag.charAt(0) == '!')) {
          // Check for special flag, might have a '!'
          ch = parser.nextChar();
          // Ignore the '!' if there, if not push it back
          if (ch == '!') {
        // Ignore '!', but skip white space after it
        parser.skipCommentsAndWhiteSpace(
            TemplateParser.SIMPLE_WHITE_SPACE);
          } else {
        // No optional '!', push back extra read char
        parser.unread(ch);
          }
          tmpstr = parser.readToken();
          if (!startTag.contains(tmpstr)) {
        throw new SyntaxException(
            "Expected to find closing tag '&lt;/"
            + startTag
            + "...&gt;' but instead found '&lt;/'"
            + ((ch == '!') ? '!' : "")
            + tmpstr + "...&gt;'.");
          }
          ctx.endSpecial(env, tmpstr);
      } else {
          tmpstr = parser.readToken();
          if (!startTag.equals(tmpstr)) {
        throw new SyntaxException(
            "Expected to find closing tag '&lt;/"
            + startTag
            + "...&gt;' but instead found '&lt;/'"
            + tmpstr + "...&gt;'.");
          }
          ctx.endComponent(env, tmpstr);
      }
      finished = true; // Indicate done with this context
      parser.skipCommentsAndWhiteSpace(   // Skip white space
          TemplateParser.SIMPLE_WHITE_SPACE);
      ch = parser.nextChar(); // Throw away '>' character
      if (ch != '>') {
          throw new SyntaxException(
        "While processing closing tag '&lt;/" + tmpstr
        + "...' expected to encounter closing '&gt;' but"
        + " found '" + (char) ch + "' instead!");
      }
        } else if (ch == '!') {
View Full Code Here

      }
      if (ch == '/') {
    parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
    ch = parser.nextChar();
    if (ch != '>') {
        throw new SyntaxException("'" + tagName + "' tag contained "
      + "'/' that was not followed by a '&gt;' character!");
    }

    // We're at the end of the parameters and the component,
    // put this information back into the parser
View Full Code Here

      // Check to see if the 'id' is wrapped in quotes.
      char first = id.charAt(0);
      if ((first == '"') || (first == '\'')) {
    if (id.indexOf('>') != -1) {
        // Means we didn't have an ending quote before '>'
        throw new SyntaxException("Unable to find ending (" + first
          + ") on !facet declaration with id ("
          + id.substring(0, id.indexOf('>'))
          + ") on component ("
          + env.getParent().getUnevaluatedId() + ").");
    }
View Full Code Here

TOP

Related Classes of com.sun.jsftemplating.layout.SyntaxException

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.