public TemplateFactory newTemplateFactory(File file, String encoding, TemplateModifier modifier, ExpressionLanguage expressionLanguage) throws TemplateLoadingException { TemplateDocument document = parseTemplate(file, encoding, expressionLanguage); if (modifier != null) { modifier.modifyTemplate(document); } try { if (document.getIncludes() != null) { return new FileTemplateFactory(this, document.normalize(), file, encoding, modifier, getFiles(document.getIncludes()), changeDetectionInterval); } return new FileTemplateFactory(this, document.normalize(), file, encoding, modifier, null, changeDetectionInterval); } catch (BehaviorInstantiationException e) { throw new TemplateLoadingException(e); } }
public Tag getLastTag(String tagName) { return getTag(tagName, -1); }
tag = getElementById(search); if (m.find()) tag = getTag(m.group(1), Integer.parseInt(m.group(2))); tag = getFirstTag(search);
ArrayList<TemplateNode> children = doc.getChildren(); for (TemplateNode node : children) if (overrides != null) overriden = extendedDocument.locateTag(overrides.getValue()); if (extended == extendedDocument && extendedDocument.getChildren().size() > 0 && extendedDocument.getChildren().get(0) instanceof ExtendsDirective) if (extendedDocument.getChildren().size() > 0 && extendedDocument.getChildren().get(0) instanceof ExtendsDirective) ((ExtendsDirective) extendedDocument.getChildren().get(0)).extend(extendedDocument, f, false); f.addAll(extendedDocument.normalize());
public TemplateDocument parse() throws IOException, TemplateParsingException { template = new TemplateDocument(expressionLanguage); fillBuffer(); nextToken(); while (currentToken.getType() != TokenType.EOF) { getNode(); nextToken(); } template.addChildren(matchedNodes); return template; }
/** * Parses the template reading from the provided input stream and generates an instance of the TagNode * class that gets passed in. The html elements defined in the template file becomes inner elements * of the created TagNode. It then returns the TagNode object that gets created. * * @param in InputStream to read the template from. * @param cl The TagNode implementation class. * @return Returns the newly created tag node object which contains the template contents. * @throws TemplateLoadingException Might be thrown if there is a problem in parsing the provided template. */ public <T extends TagNode> T createTag(InputStream in, Class<T> cl, ExpressionLanguage expressionLanguage) throws TemplateLoadingException { TemplateDocument doc = loader.parseTemplate(in, expressionLanguage); ArrayList<TemplateNode> nodes = doc.getChildren(); try { T tag = cl.newInstance(); tag.addChildren(nodes); return tag; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
template.addInclude(fileName); return new ExtendsDirective(templateLoader, fileName, selector, expressionLanguage); } catch (TemplateLoadingException e) {
f.addFragment(this); } else { fragments = new FragmentList(doc.getExpressionLanguage()); for (TemplateNode t : children) { t.normalize(doc, fragments);
private TemplateNode parserDirective() throws TemplateParsingException { ParserDirectiveToken tok = (ParserDirectiveToken) currentToken; if ("include".equalsIgnoreCase(tok.getDirective()) && templateLoader != null) { return parseIncludeNode(tok); } if ("set".equalsIgnoreCase(tok.getDirective())) { return parseSetDirective(tok); } if ("namespace".equalsIgnoreCase(tok.getDirective())) { return parseNamespaceDirective(tok); } if ("expressionLanguage".equalsIgnoreCase(tok.getDirective())) { return parseExpressionLanguageDirective(tok); } 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); } return null; }
/** * Parses the template reading from the provided template file and generates an instance of the TagNode * class that gets passed in. The html elements defined in the template file becomes inner elements * of the created TagNode. It then returns the TagNode object that gets created. * * @param tagTemplate Template file * @param cl The TagNode implementation class. * @return Returns the newly created tag node object which contains the template contents. * @throws TemplateLoadingException Might be thrown if there is a problem in parsing the provided template. */ public <T extends TagNode> T createTag(File tagTemplate, Class<T> cl, ExpressionLanguage expressionLanguage) throws TemplateLoadingException { TemplateDocument doc = loader.parseTemplate(tagTemplate, expressionLanguage); ArrayList<TemplateNode> nodes = doc.getChildren(); try { T tag = cl.newInstance(); tag.addChildren(nodes); return tag; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; } }
template.addInclude(fileName); return new IncludeNode(templateLoader, fileName, expressionLanguage, selector); } catch (TemplateLoadingException e) {
f.addFragment(this); } else { fragments = new FragmentList(doc.getExpressionLanguage()); for (TemplateNode t : children) { if (t.normalizeUntil(doc, reference, fragments, inclusive)) {
if (doc.getIncludes() != null) includes = l.getFiles(doc.getIncludes()); fragments = doc.normalize();
public Tag getFirstTag(String tagName) { return getTag(tagName, 0); }