Package cambridge.model

Examples of cambridge.model.TemplateDocument


         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("complex.html"));
         TemplateParser parser = new TemplateParser(tokenizer);
         Map<String, Object> p = new DefaultTemplateBindings();
         p.put("a", "AAA");
         p.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


         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("dynamic.html"));
         TemplateParser parser = new TemplateParser(tokenizer);
         Map<String, Object> p = new DefaultTemplateBindings();
         p.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

   private synchronized void reload() {
      reloading = true;
      FileTemplateLoader l = (FileTemplateLoader) loader;
      try {
         TemplateDocument doc = l.parseTemplate(templateFile, encoding);
         if (modifier != null) {
            modifier.modifyTemplate(doc);
         }

         if (doc.getIncludes() != null) {
            includes = l.getFiles(doc.getIncludes());
         }

         fragments = doc.normalize();

      } catch (TemplateLoadingException e) {
         throw new TemplateReloadingException(e);
      } catch (BehaviorInstantiationException e) {
         e.printStackTrace();
View Full Code Here

    * @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) throws TemplateLoadingException {
      TemplateDocument doc = loader.parseTemplate(in);
      ArrayList<TemplateNode> nodes = doc.getChildren();

      try {
         T tag = cl.newInstance();
         tag.addChildren(nodes);
         return tag;
View Full Code Here

    * @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) throws TemplateLoadingException {
      TemplateDocument doc = loader.parseTemplate(tagTemplate);
      ArrayList<TemplateNode> nodes = doc.getChildren();

      try {
         T tag = cl.newInstance();
         tag.addChildren(nodes);
         return tag;
View Full Code Here

      return newTemplateFactory(templatePath, DefaultEncoding, modifier);
   }

   public TemplateFactory newTemplateFactory(String templatePath, String encoding, TemplateModifier modifier) throws TemplateLoadingException {
      VirtualFile file = getTemplateFile(templatePath);
      TemplateDocument document = parseTemplate(file.getRealFile(), encoding);
      if (modifier != null) {
         modifier.modifyTemplate(document);
      }

      try {
         if (document.getIncludes() != null) {
            return new FileTemplateFactory(this, document.normalize(), file.getRealFile(), encoding, modifier, getFiles(document.getIncludes()), changeDetectionInterval);
         }

         return new FileTemplateFactory(this, document.normalize(), file.getRealFile(), encoding, modifier, null, changeDetectionInterval);
      } catch (BehaviorInstantiationException e) {
         throw new TemplateLoadingException(e);
      }
   }
View Full Code Here

abstract class AbstractTemplateLoader implements TemplateLoader {
   public static int DefaultChangeDetectionInterval = 5000;
   public static final String DefaultEncoding = "UTF-8";

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

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

   public TemplateFactory newTemplateFactory(File file, String encoding, TemplateModifier modifier) throws TemplateLoadingException {
      TemplateDocument document = parseTemplate(file, encoding);
      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

    * @return Returns the newly created TemplateFactory
    * @throws TemplateLoadingException
    */
   public TemplateFactory newTemplateFactory(String template) throws TemplateLoadingException {
      InputStream in = classLoader.getResourceAsStream(template);
      TemplateDocument doc = parseTemplate(in);
      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) throws TemplateLoadingException {
      InputStream in = classLoader.getResourceAsStream(template);
      TemplateDocument doc = parseTemplate(in, encoding);
      try {
         FragmentList fragments = doc.normalize();
         return new ImmutableTemplateFactory(this, fragments);
      } catch (BehaviorInstantiationException e) {
         throw new TemplateLoadingException(e);
      }
   }
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.