Package freemarker.template

Examples of freemarker.template.SimpleScalar


    super.tearDown();
  }
 
  public void testExec() throws Exception{
    List<Object> args = new ArrayList<Object>();
    SimpleScalar htmlCode = new SimpleScalar("<H1>hello<h3></H1> <br> <p>java programming");
    args.add(htmlCode);
   
    TidyHtmlMethod method = new TidyHtmlMethod();
    String output = (String)method.exec(args);
    assertNotNull(output);
View Full Code Here


    SimpleSequence cssClass = new SimpleSequence();
    cssClass.add("matched_text");
    cssClass.add("search-term");
   
    //args.add(new SimpleScalar("abc 123 <img src=\"http://foo.abc.com/abcworld\">abc</a> 123 kkkabckk"));
    args.add(new SimpleScalar("<span style=\"font-weight: bold;\"><span class=\"Title\"></span>Mikes writes: " +
        "</span>A lengthy article in Spiegel explores the possibility that global warming might make life on Earth better, " +
        "not just for humans, but all species. The article argues that 'worst-case scenarios' " +
        "are often the result of inaccurate <strong>simulations</strong> " +
        "made in the 1980s. While climate change is a reality, as far as the " +
        "article is concerned, some planning and forethought may mean that more " +
        "benefits than drawbacks will result from higher temperatures. <font color=\"red\">From " +
            "the article</font>:'The medical benefits of higher average temperatures have also " +
            "been ignored. According to Richard Tol, an environmental economist, &quot;warming " +
            "temperatures will mean that in 2050 there will be about 40,000 fewer deaths " +
            "in Germany attributable to cold-related illnesses like the flu.&quot;<ul>" +
    "<li> Another widespread fear about global warming -- that it will cause super-storms that could devastate" +
        "towns and villages with unprecedented fury -- also appears to be unfounded. </li>" +
    "<li>Current long-term simulations, at any rate, do not suggest that such a trend will in fact materialize.'&quot;</li></ul>"));
    args.add(texts);
    args.add(new SimpleScalar("SPAN"));
    args.add(cssClass);

    HighlightTextMethod method = new HighlightTextMethod();
    String output = (String) method.exec(args);
    assertNotNull(output);
View Full Code Here

    texts.add("abc");
 
    SimpleSequence cssClass = new SimpleSequence();
    cssClass.add("matched_text");
    cssClass.add("search-term");
    args.add(new SimpleScalar("<img src=\"http://abc\">abc</img>jfkds abc ABC aBC fjdksj29<span>abc</span></a>"));
    args.add(texts);
    args.add(new SimpleScalar("SPAN"));
    args.add(cssClass);

    HighlightTextMethod method = new HighlightTextMethod();
    String output = (String) method.exec(args);
    assertNotNull(output);
View Full Code Here

    super.tearDown();
  }
 
  public void testExec() throws Exception{
    List<Object> args = new ArrayList<Object>();
    SimpleScalar htmlCode = new SimpleScalar("<H1>hello<h3></H1> <br> <p>java programming");
    args.add(htmlCode);
   
    ScrapeTextMethod method = new ScrapeTextMethod();
    String output = (String)method.exec(args);
    assertNotNull(output);
View Full Code Here

      content = ((SimpleScalar)args.get(0)).getAsString();
    }else if(args.get(0) instanceof StringModel){
      content = ((StringModel)args.get(0)).getAsString();
    }
    SimpleSequence   textList = (SimpleSequence)args.get(1);
    SimpleScalar htmlTag = (SimpleScalar)args.get(2);
    SimpleSequence cssClass = null;
    if(args.size() == 4){
       cssClass = (SimpleSequence)args.get(3);
    }       
    try{
View Full Code Here

    }
   
    public TemplateModel get(String key) throws TemplateModelException {
        if (key.startsWith("@@")) {
            if (key.equals("@@text")) {
                return new SimpleScalar(getText(node));
            }
            if (key.equals("@@namespace")) {
                String nsURI = node.getNamespaceURI();
                return nsURI == null ? null : new SimpleScalar(nsURI);
            }
            if (key.equals("@@local_name")) {
                String localName = node.getLocalName();
                if (localName == null) {
                    localName = getNodeName();
                }
                return new SimpleScalar(localName);
            }
            if (key.equals("@@markup")) {
                StringBuffer buf = new StringBuffer();
                NodeOutputter nu = new NodeOutputter(node);
                nu.outputContent(node, buf);
                return new SimpleScalar(buf.toString());
            }
            if (key.equals("@@nested_markup")) {
                StringBuffer buf = new StringBuffer();
                NodeOutputter nu = new NodeOutputter(node);
                nu.outputContent(node.getChildNodes(), buf);
                return new SimpleScalar(buf.toString());
            }
            if (key.equals("@@qname")) {
                String qname = getQualifiedName();
                return qname == null ? null : new SimpleScalar(qname);
            }
        }
        XPathSupport xps = getXPathSupport();
        if (xps != null) {
            return xps.executeQuery(node, key);
View Full Code Here

    }

    private TemplateModel getType()
    {
        if (nodes.size() == 0)
            return new SimpleScalar("");
        Object firstNode = nodes.get(0);
        char code;
        if (firstNode instanceof Element)
            code = 'e';
        else if (firstNode instanceof Text || firstNode instanceof String)
            code = 'x';
        else if (firstNode instanceof Attribute)
            code = 'a';
        else if (firstNode instanceof EntityRef)
            code = 'n';
        else if (firstNode instanceof Document)
            code = 'd';
        else if (firstNode instanceof DocType)
            code = 't';
        else if (firstNode instanceof Comment)
            code = 'c';
        else if (firstNode instanceof ProcessingInstruction)
            code = 'p';
        else
            code = '?';
        return new SimpleScalar(new String(new char[] { code}));
    }
View Full Code Here

        List list = evaluateElementOperation((TextOp)OPERATIONS.get("_text"), nodes);
        StringBuffer buf = new StringBuffer();
        for (Iterator it = list.iterator(); it.hasNext();) {
            buf.append(it.next());
        }
        return new SimpleScalar(buf.toString());
    }
View Full Code Here

                            throw new TemplateModelException(e);
                        }
                    }
                    public TemplateModel get(int i) throws TemplateModelException {
                        try {
                            return new SimpleScalar(matcher.group(i));
                        }
                        catch (Exception e) {
                            throw new TemplateModelException(e);
                        }
                    }
View Full Code Here

                Matcher matcher = pattern.matcher(s);
                result = (flags & RE_FLAG_FIRST_ONLY) != 0
                        ? matcher.replaceFirst(arg2)
                        : matcher.replaceAll(arg2);
            }
            return new SimpleScalar(result);
        }
View Full Code Here

TOP

Related Classes of freemarker.template.SimpleScalar

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.