Examples of TemplateDocument


Examples of cambridge.model.TemplateDocument

public class SetDirectiveTest {
   @Test
   public void testSetDirective() throws Exception {
      TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("set.html"));
      TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
      TemplateDocument doc = parser.parse();
      FragmentList fragmentList = doc.normalize();
      MapExpressionContext context = new MapExpressionContext();
      StringWriter out = new StringWriter();
      for (Fragment f : fragmentList) {
         f.eval(context, out);
      }
View Full Code Here

Examples of cambridge.model.TemplateDocument

      ExpressionContext context = new MapExpressionContext();

      User user = new User("test", "test@test.com");
      context.put("user", user);

      TemplateDocument t = parser.parse();
      assertNotNull(t);
      FragmentList fragments = t.normalize();

      StringWriter builder = new StringWriter();

      for (Fragment f : fragments) {
         f.eval(context, builder);
View Full Code Here

Examples of cambridge.model.TemplateDocument

         TemplateFactory f = loader.newTemplateFactory("a.html", new TemplateModifier() {
            public void modifyTemplate(TemplateDocument doc) {
               try {
                  TemplateTokenizer tokenizer = new TemplateTokenizer(new InputStreamReader(new FileInputStream("b.html"), "UTF-8"));
                  TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
                  TemplateDocument document = parser.parse();

                  Tag tag = document.getElementsByTagName("body").get(0);
                  Tag bodyTag = doc.getElementsByTagName("body").get(0);

                  bodyTag.addChildren(tag.getChildren());

               } catch (IOException e) {
View Full Code Here

Examples of cambridge.model.TemplateDocument

        namespaceMappings.put(name, uri);
    }

    public TemplateDocument parse() throws IOException, TemplateParsingException {
        template = new TemplateDocument(expressionLanguage);
        fillBuffer();
        nextToken();

        while (currentToken.getType() != TokenType.EOF) {
            getNode();
View Full Code Here

Examples of cambridge.model.TemplateDocument

   @Test
   public void testFull() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("full.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         TemplateDocument t = parser.parse();
         assertNotNull(t);
         FragmentList fragments = t.normalize();


         StringWriter builder = new StringWriter();

         for (Fragment f : fragments) {
View Full Code Here

Examples of cambridge.model.TemplateDocument

   @Test
   public void testSelectBefore() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("full.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         TemplateDocument t = parser.parse();
         FragmentList fragments = t.select("before /html/body/div[3]");

         StringWriter builder = new StringWriter();

         for (Fragment f : fragments) {
            f.eval(bindings, builder);
View Full Code Here

Examples of cambridge.model.TemplateDocument

   @Test
   public void testSelectAfter() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("full.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         TemplateDocument t = parser.parse();
         FragmentList fragments = t.select("after /html/body/div[3]");

         StringWriter builder = new StringWriter();

         for (Fragment f : fragments) {
            f.eval(bindings, builder);
View Full Code Here

Examples of cambridge.model.TemplateDocument

   @Test
   public void testSelectInside() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("full.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         TemplateDocument t = parser.parse();
         FragmentList fragments = t.select("inside /html/body");

         StringWriter builder = new StringWriter();

         for (Fragment f : fragments) {
            f.eval(bindings, builder);
View Full Code Here

Examples of cambridge.model.TemplateDocument

    public static int DefaultChangeDetectionInterval = 5000;
    public static final String DefaultEncoding = "UTF-8";

    public TemplateFactory parseAndCreateTemplateFactory(String templateSource, ExpressionLanguage expressionLanguage) throws TemplateLoadingException
    {
        TemplateDocument doc = parseAndCreateTemplateDocument(templateSource, expressionLanguage);
        try
        {
            FragmentList fragments = doc.normalize();
            return new ImmutableTemplateFactory(this, fragments);
        }
        catch (BehaviorInstantiationException e)
        {
            throw new TemplateLoadingException(e);
View Full Code Here

Examples of cambridge.model.TemplateDocument

   public TemplateFactory newTemplateFactory(File file, TemplateModifier modifier, ExpressionLanguage expressionLanguage) throws TemplateLoadingException {
      return newTemplateFactory(file, DefaultEncoding, modifier, expressionLanguage);
   }

   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);
      }
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.