Package cambridge

Examples of cambridge.TemplateParsingException


            if (c == ')') {
               state--;
            } else if (c == '(') {
               state++;
            } else if (c == Tokenizer.EOL) {
               throw new TemplateParsingException("Unexpected end of file", tokenizer.getLineNo(), tokenizer.getColumn());
            }
         }
      }

      while (c != '}') {
View Full Code Here


         }

         builder.append(c);
         c = tokenizer.nextChar();
         if (c == Tokenizer.EOL) {
            throw new TemplateParsingException("Unexpected end of file", tokenizer.getLineNo(), tokenizer.getColumn());
         }
      }

      return new PlayMessagesToken(line, col, builder.toString(), tokenizer.getLineNo(), tokenizer.getColumn(), builder.toString());
   }
View Full Code Here

                node.setFilters(tok.getFilters());
            }

            return node;
        } catch (ExpressionParsingException e) {
            throw new TemplateParsingException("Error parsing expression", e, currentToken.getLineNo(), currentToken.getColumn());
        }
    }
View Full Code Here

                                                if (expTok.getFilters() != null) {
                                                    expNode.setFilters(expTok.getFilters());
                                                }
                                                fragments.add(expNode);
                                            } catch (ExpressionParsingException e1) {
                                                throw new TemplateParsingException("Error parsing expression", e1, currentToken.getLineNo(), currentToken.getColumn());
                                            }

                                            break;
                                        case EXTENSION:
                                            ExtensionToken extensionToken = (ExtensionToken) attrToken;
                                            ExtensionNode extensionNode = extensionToken.createNode(expressionLanguage);
                                            fragments.add(extensionNode);
                                            break;
                                        case WS:
                                        case STRING:
                                            StaticFragment st = new StaticFragment(attrToken.value);
                                            fragments.add(st);
                                            break;
                                    }
                                }

                                if (fragments.size() == 0 || fragments.size() == 1 && fragments.get(0) instanceof StaticFragment) {
                                    element = new SimpleAttribute(currentToken.getLineNo(), currentToken.getColumn());
                                    ((SimpleAttribute) element).setValue(currentToken.value);
                                } else {
                                    element = new ComplexAttribute(currentToken.getLineNo(), currentToken.getColumn());
                                    ((ComplexAttribute) element).setFragments(fragments);
                                    AttributeValueToken aTok = (AttributeValueToken) currentToken;
                                    if (aTok.getQuotes() == -2) {
                                        ((ComplexAttribute) element).setQuote('"');
                                    } else if (aTok.getQuotes() == -3) {
                                        ((ComplexAttribute) element).setQuote('\'');
                                    }
                                }

                                exitLoop = true;
                                break;
                        }

                        if (exitLoop) break;
                    }

                    if (element == null) {
                        if (tok != null) {
                            element = new SimpleAttribute(tok.getAttributeName(), tok.getNameSpace(), tok.getLineNo(), tok.getLineNo());
                        } else {
                            throw new TemplateParsingException("Error parsing template file. Unterminated tag?", currentToken.getLineNo(), currentToken.getColumn());
                        }
                    }

                    element.setAttributeName(tok.getAttributeName());
                    element.setAttributeNameSpace(tok.getNameSpace());
                    element.setTextContent(textContent.toString());

                    int s = node.getTagParts().size();
                    if (s > 0) {
                        TagPart te = node.getTagParts().get(s - 1);
                        if (te instanceof TextTagPart) {
                            if (te.isWhiteSpace()) {
                                node.getTagParts().remove(s - 1);
                            }
                        }
                    }

                    if (firstTag && "xmlns".equalsIgnoreCase(element.getAttributeNameSpace())) {
                        putNamespaceMapping(element.getAttributeName(), element.getValue());
                    }

                    node.addAttribute(element);
                    break;
                case EXPRESSION:
                    try {

                        ExpressionToken t = (ExpressionToken) currentToken;
                        ExpressionTagPart p = new ExpressionTagPart(currentToken.value,
                            expressionLanguage.parse(currentToken.value, currentToken.getLineNo(), currentToken.getColumn()),
                            t.isRawExpression(), currentToken.getLineNo(), currentToken.getColumn());

                        if (t.getFilters() != null) {
                            p.setFilters(t.getFilters());
                        }

                        node.addExpression(p);

                    } catch (ExpressionParsingException e1) {
                        throw new TemplateParsingException("Error parsing expression", e1, currentToken.getLineNo(), currentToken.getColumn());
                    }
                    break;
                case EXTENSION:
                    ExtensionToken extensionToken = (ExtensionToken) currentToken;
                    ExtensionNode extensionTagPart = extensionToken.createNode(expressionLanguage);
View Full Code Here

        if ("debug".equalsIgnoreCase(tok.getDirective())) {
            return new DebugDirective();
        }
        if ("extend".equalsIgnoreCase(tok.getDirective()) || "extends".equalsIgnoreCase(tok.getDirective())) {
            if (template.hasChildren()) {
                throw new TemplateParsingException("extend directive should be the first element of the template", tok.getLineNo(), tok.getColumn());
            }

            return parseExtendsDirective(tok);
        }
View Full Code Here

    private static final Pattern setDirectivePattern = Pattern.compile("(\\w+)\\s?=(.*)");

    private TemplateNode parseSetDirective(ParserDirectiveToken tok) {
        String args = tok.getArgs();
        if (args == null) {
            throw new TemplateParsingException("Invalid set directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        Matcher matcher = setDirectivePattern.matcher(args);
        if (!matcher.find()) {
            throw new TemplateParsingException("Invalid set directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        String varName = matcher.group(1);
        String expression = matcher.group(2);

View Full Code Here

    private static final Pattern namespaceDirectivePattern = Pattern.compile("(\\w+)\\s?=\"([^\"]+)\"");

    private TemplateNode parseNamespaceDirective(ParserDirectiveToken tok) {
        String args = tok.getArgs();
        if (args == null) {
            throw new TemplateParsingException("Invalid namespace directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        Matcher matcher = namespaceDirectivePattern.matcher(args);
        if (!matcher.find()) {
            throw new TemplateParsingException("Invalid namespace directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        String name = matcher.group(1);
        String uri = matcher.group(2);
View Full Code Here

    }

    private TemplateNode parseExpressionLanguageDirective(ParserDirectiveToken tok) {
        String args = tok.getArgs();
        if (args == null || args.trim().equals("")) {
            throw new TemplateParsingException("Invalid expression language directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        expressionLanguage = Expressions.getExpressionLanguageByName(args.trim());
        return new ExpressionLanguageDirective(args.trim());
    }
View Full Code Here

    }

    private TemplateNode parseIncludeNode(ParserDirectiveToken tok) {
        String args = tok.getArgs();
        if (args == null) {
            throw new TemplateParsingException("Invalid include directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        args = args.trim();

        int separatorIndex = args.indexOf('@');
        String fileName;
        String selector = null;

        if (separatorIndex == -1) {
            fileName = args;
        } else if (separatorIndex > 0) {
            fileName = args.substring(0, separatorIndex - 1);
            if (args.length() > separatorIndex) {
                selector = args.substring(separatorIndex + 1).trim();

                Matcher matcher = TemplateDocument.selectorPattern.matcher(selector);

                if (matcher.find()) {
                    selector = matcher.group(0);
                }
            }
        } else {
            throw new TemplateParsingException("Invalid extend directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        try {
            template.addInclude(fileName);
            return new IncludeNode(templateLoader, fileName, expressionLanguage, selector);
        } catch (TemplateLoadingException e) {
            throw new TemplateParsingException("Could not load the include", e, currentToken.getLineNo(), currentToken.getColumn());
        } catch (BehaviorInstantiationException e) {
            throw new TemplateParsingException("Could not load the include", e, currentToken.getLineNo(), currentToken.getColumn());
        }
    }
View Full Code Here

    }

    private TemplateNode parseExtendsDirective(ParserDirectiveToken tok) {
        String args = tok.getArgs();
        if (args == null) {
            throw new TemplateParsingException("Invalid extend directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        args = args.trim();

        int separatorIndex = args.indexOf('@');
        String fileName;
        String selector = null;

        if (separatorIndex == -1) {
            fileName = args;
        } else if (separatorIndex > 0) {
            fileName = args.substring(0, separatorIndex - 1);
            if (args.length() > separatorIndex) {
                selector = args.substring(separatorIndex + 1).trim();

                Matcher matcher = TemplateDocument.selectorPattern.matcher(selector);

                if (matcher.find()) {
                    selector = matcher.group(0);
                }
            }
        } else {
            throw new TemplateParsingException("Invalid extend directive", currentToken.getLineNo(), currentToken.getColumn());
        }

        try {
            template.addInclude(fileName);
            return new ExtendsDirective(templateLoader, fileName, selector, expressionLanguage);
        } catch (TemplateLoadingException e) {
            throw new TemplateParsingException("Could not load the extended template", e, currentToken.getLineNo(), currentToken.getColumn());
        } catch (BehaviorInstantiationException e) {
            throw new TemplateParsingException("Could not load the extended template", e, currentToken.getLineNo(), currentToken.getColumn());
        }
    }
View Full Code Here

TOP

Related Classes of cambridge.TemplateParsingException

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.