Package cambridge.model

Examples of cambridge.model.TemplateDocument


    * @return Returns the newly created TemplateFactory
    * @throws TemplateLoadingException
    */
   public TemplateFactory newTemplateFactory(String template, TemplateModifier modifier) throws TemplateLoadingException {
      InputStream in = classLoader.getResourceAsStream(template);
      TemplateDocument doc = parseTemplate(in);
      modifier.modifyTemplate(doc);
      try {
         FragmentList fragments = doc.normalize();
         return new ImmutableTemplateFactory(this, fragments);
      } catch (BehaviorInstantiationException e) {
         throw new TemplateLoadingException(e);
      }
   }
View Full Code Here


    * @return Returns the newly created TemplateFactory
    * @throws TemplateLoadingException
    */
   public TemplateFactory newTemplateFactory(String template, String encoding, TemplateModifier modifier) throws TemplateLoadingException {
      InputStream in = classLoader.getResourceAsStream(template);
      TemplateDocument doc = parseTemplate(in, encoding);
      modifier.modifyTemplate(doc);
      try {
         FragmentList fragments = doc.normalize();
         return new ImmutableTemplateFactory(this, fragments);
      } catch (BehaviorInstantiationException e) {
         throw new TemplateLoadingException(e);
      }
   }
View Full Code Here

         TemplateTokenizer tokenizer = new TemplateTokenizer(IfElseTest.class.getResourceAsStream("ifelse.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("var1", true);

         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

         TemplateTokenizer tokenizer = new TemplateTokenizer(IfElseTest.class.getResourceAsStream("ifelse.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("var2", true);

         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

         TemplateTokenizer tokenizer = new TemplateTokenizer(IfElseTest.class.getResourceAsStream("ifelse.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("var3", true);

         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

      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(IfElseTest.class.getResourceAsStream("ifelse.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();

         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

         TemplateTokenizer tokenizer = new TemplateTokenizer(ConditionalAttributeBehaviorTest.class.getResourceAsStream("conditionalattribute.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("condition", true);

         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

         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("basic.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);

         ExpressionContext context = new MapExpressionContext();
         context.put("class", "test");
         TemplateDocument t = parser.parse();

         assertNotNull(t);

         Attribute a = t.locateTag("/div").getAttribute("class");
         assertTrue(a instanceof ComplexAttribute);

         ComplexAttribute c = (ComplexAttribute) a;

         assertEquals(1, c.getFragments().size());

         assertTrue(c.getFragments().get(0) instanceof ExpressionNode);

         ExpressionNode node = (ExpressionNode) c.getFragments().get(0);

         assertEquals("${class}", node.getSource());

         StringWriter builder = new StringWriter();

         FragmentList fragmentList = t.normalize();

         assertEquals(3, fragmentList.size());

         assertTrue(fragmentList.get(0) instanceof StaticFragment);
         assertTrue(fragmentList.get(1) instanceof ExpressionNode);
View Full Code Here

         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("complex.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("a", "AAA");
         context.put("b", "BBB");
         TemplateDocument t = parser.parse();

         assertNotNull(t);

         Attribute a = t.locateTag("/div").getAttribute("id");
         assertTrue(a instanceof ComplexAttribute);

         ComplexAttribute c = (ComplexAttribute) a;

         assertEquals(4, c.getFragments().size());

         assertTrue(c.getFragments().get(0) instanceof ExpressionNode);
         assertTrue(c.getFragments().get(1) instanceof StaticFragment);
         assertTrue(c.getFragments().get(2) instanceof StaticFragment);
         assertTrue(c.getFragments().get(3) instanceof ExpressionNode);

         ExpressionNode node1 = (ExpressionNode) c.getFragments().get(0);
         StaticFragment st = (StaticFragment) c.getFragments().get(1);
         StaticFragment st2 = (StaticFragment) c.getFragments().get(2);
         ExpressionNode node2 = (ExpressionNode) c.getFragments().get(3);

         assertEquals("${a}", node1.getSource());
         assertEquals(" ", st.toString());
         assertEquals("and ", st2.toString());
         assertEquals("${b}", node2.getSource());

         StringWriter builder = new StringWriter();

         FragmentList fragmentList = t.normalize();

         assertEquals(5, fragmentList.size());

         assertTrue(fragmentList.get(0) instanceof StaticFragment);
         assertTrue(fragmentList.get(1) instanceof ExpressionNode);
View Full Code Here

         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();

         context.put("style", "style");

         TemplateDocument t = parser.parse();

         assertNotNull(t);

         Attribute a = t.locateTag("/div").getAttribute("style");
         assertTrue(a instanceof ComplexAttribute);

         ComplexAttribute c = (ComplexAttribute) a;

         assertEquals(1, c.getFragments().size());

         assertTrue(c.getFragments().get(0) instanceof ExpressionNode);

         ExpressionNode node1 = (ExpressionNode) c.getFragments().get(0);

         assertEquals("${style}", node1.getSource());

         StringWriter builder = new StringWriter();

         FragmentList fragmentList = t.normalize();

         assertEquals(1, fragmentList.size());

         assertTrue(fragmentList.get(0) instanceof TagNode);
View Full Code Here

TOP

Related Classes of cambridge.model.TemplateDocument

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.