Package org.stringtree

Examples of org.stringtree.Tract


        assertEquals("Hello, ${value}!", tpls.getObject("hello"));
    }

    private void check(LocalServer server, String expected, String page) {
        ByteTract request = new LocalRequest(page);
        Tract response = server.request(request);
        assertTrue(response.hasContent());
        assertEquals(expected, response.getContent());
    }
View Full Code Here


  public void request(StringFinder context) {
    OutputStream outstream = (OutputStream)context.getObject(MojasefConstants.RESPONSE_STREAM);
    StreamStringCollector collector = new StreamStringCollector(outstream);

      Tract page = null;
      String filename = context.get(MojasefConstants.REQUEST_LOCALPATH);
      page = (Tract)tracts.getObject(filename);

    if (page == null && ("".equals(filename) || filename.endsWith("/"))) {
        page = (Tract)tracts.getObject(filename+context.get(MojasefConstants.DEFAULT_LEAFNAME));
    }

    if (page == null) {
        page = (Tract)templates.getObject("404");
    }

    if (page == null) {
        page = new MapTract("Oops, 404: ${mojasef.request.path.URI}");
        StorerHelper.put(context, HTTPConstants.RESPONSE_CODE, "404");
    }

    StringFinder result = new FetcherStringFinder(
        new FallbackFetcher(page.getUnderlyingFetcher(), context.getUnderlyingFetcher()));
    Tract template = findTemplate(result);
    engine.expandTemplate(context, template, collector);
    collector.flush();
  }
View Full Code Here

      // look up each tract in the list, return the first match
      String prefix = Templater.TEMPLATE + ".";
      Iterator<String> it = possible.iterator();
      while (it.hasNext()) {
          String fullname = prefix + it.next();
          Tract tract = (Tract)FetcherHelper.getPeelback(context.getUnderlyingFetcher(), fullname);
          if (tract != null) {
                return tract;
            }
      }
 
View Full Code Here

        Mojasef.delegateAndExpand(collector, keeper, null, dfl);
        assertCollected("START[]END");
  }

  public void testNoAppAttributedTemplate() throws IOException {
    Tract tpl = new MapTract("START[${this}+${ugh}]END");
    tpl.put("ugh", "hello");
    templates.put("default", tpl);
        Mojasef.delegateAndExpand(collector, keeper, null, dfl);
        assertCollected("START[+hello]END");
  }
View Full Code Here

        assertCollected("START[+hello]END");
  }

  // FIXME add processing to tract templating to explicitly override "this"
  public void x_testNoAppThisOverrideTemplate1() throws IOException {
    Tract tpl = new MapTract("START[${this}]END");
    tpl.put("this", "hello");
    templates.put("default", tpl);
    context.put("this", "huh");
        Mojasef.delegateAndExpand(collector, keeper, null, dfl);
        assertCollected("START[huh]END");
  }
View Full Code Here

        Mojasef.delegateAndExpand(collector, keeper, null, dfl);
        assertCollected("START[huh]END");
  }

  public void testNoAppThisOverrideTemplate2() throws IOException {
    Tract tpl = new MapTract("START[${this}]END");
    tpl.put("this", "hello");
    templates.put("default", tpl);
        Mojasef.delegateAndExpand(collector, keeper, null, dfl);
        assertCollected("START[hello]END");
  }
View Full Code Here

        assertCollected("START[hello]END");
  }

  public void testThisPassThrough() throws IOException {
    context.put("this", "fkc");
    Tract tpl = new MapTract("START[${this*xx}]END");
    templates.put("default", tpl);
    templates.put("xx", ">${this}<");
        Mojasef.delegateAndExpand(collector, keeper, null, dfl);
        assertCollected("START[>fkc<]END");
  }
View Full Code Here

    server = new LocalServer("src/test/plugins/http.spec");
  }
   
    public void testNonMatchingRequest() {
        ByteTract request = new LocalRequest("simple");
        Tract response = server.request(request);
        assertTrue(response.hasContent());
        assertEquals("Plugin: []", response.getContent());
    }
View Full Code Here

        assertEquals("Plugin: []", response.getContent());
    }
   
    public void testMatchingRequest() {
        ByteTract request = new LocalRequest("complex");
        Tract response = server.request(request);
        assertTrue(response.hasContent());
        assertEquals("Plugin: [hello]", response.getContent());
    }
View Full Code Here

    }
   
    public void testGetRequest() {
        ByteTract request = new LocalRequest("ugh");
        request.setContent("<request>xx</request>");
        Tract response = server.request(request);
        assertTrue(response.hasContent());
        assertEquals("hello xx", response.getContent());
    }
View Full Code Here

TOP

Related Classes of org.stringtree.Tract

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.