org.mixer2.Mixer2Engine - java examples

Here are the examples of the java api org.mixer2.Mixer2Engine taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

63 Examples 7

19 View Complete Implementation : SchemaOrgTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced SchemaOrgTest {

    private Log log = LogFactory.getLog(SchemaOrgTest.clreplaced);

    private String templateFileName = "SchemaOrgTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test() throws Exception {
        log.trace("");
        File file = new File(templateFilePath);
        Html html = m2e.loadHtmlTemplate(file);
        Article article = html.getById("ITEM0001", Article.clreplaced);
        replacedert.replacedertTrue(article.gereplacedemtype().equals("http://data-vocabulary.org/Product"));
    }
}

19 View Complete Implementation : DataAttrTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced DataAttrTest {

    private String templateFileName = "DataAttrTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void getData() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        String DataRole = html.getById("span1", Span.clreplaced).getData("role");
        replacedertEquals("foo", DataRole);
    }

    @Test
    public void setData() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.getById("span2", Span.clreplaced).setData("hoge", "あいうえお");
        // System.out.println(m2e.saveToString(html.getById("span2",
        // Span.clreplaced)));
        // System.out.println(m2e.saveToString(html.getById("span2",
        // Span.clreplaced)));
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        String dataHoge = html.getById("span2", Span.clreplaced).getData("hoge");
        replacedertEquals("あいうえお", dataHoge);
    }

    @Test
    public void removeData() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Span span = html.getById("span3", Span.clreplaced);
        // System.out.println(m2e.saveToString(span));
        span.removeData("foo");
        // System.out.println(m2e.saveToString(span));
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertNull(html.getById("span3", Span.clreplaced).getData("foo"));
    }

    @Test
    public void getAria() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Span span = html.getById("span3", Span.clreplaced);
        replacedertThat(span.getAria("foo"), is("ariafoo"));
    }

    @Test
    public void setAria() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.getById("span2", Span.clreplaced).setAria("hoge", "あいうえお");
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        String ariaHoge = html.getById("span2", Span.clreplaced).getAria("hoge");
        replacedertThat(ariaHoge, is("あいうえお"));
    }

    @Test
    public void removeAria() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Span span = html.getById("span3", Span.clreplaced);
        // System.out.println(m2e.saveToString(span));
        span.removeAria("foo");
        // System.out.println(m2e.saveToString(span));
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertNull(html.getById("span3", Span.clreplaced).getAria("foo"));
    }
}

19 View Complete Implementation : SampleHtml5.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced SampleHtml5 {

    private String templateFileName = "sample-html5.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void copyTest() throws Exception {
        InputStream in = new FileInputStream(templateFilePath);
        Html html = m2e.loadHtmlTemplate(in);
        Html html2 = html.copy(Html.clreplaced);
        replacedertEquals(m2e.saveToString(html), m2e.saveToString(html2));
    }

    @Test
    public void test() throws Exception {
        InputStream in = new FileInputStream(templateFilePath);
        Html html = m2e.loadHtmlTemplate(in);
        replacedertNotNull(html.getById("summary1"));
        replacedertNotNull(html.getById("output1"));
        replacedertNotNull(html.getById("canvas1"));
        replacedertNotNull(html.getById("audio1"));
        replacedertNotNull(html.getById("abbr1"));
        replacedertNotNull(html.getById("time1"));
        replacedertNotNull(html.getById("mark1"));
        replacedertNotNull(html.getById("meter1"));
        replacedertNotNull(html.getById("progress1"));
        replacedertNotNull(html.getById("ruby1"));
        replacedertNotNull(html.getById("rt2"));
        // open graph meta tag
        Meta meta = html.getHead().getById("metaWithProperty", Meta.clreplaced);
        replacedert.replacedertThat(meta.getProperty(), is("og:replacedle"));
        replacedert.replacedertThat(meta.getContent(), is("sample page"));
    }

    @Test
    public void emptyTagTest() throws Exception {
        InputStream in = new FileInputStream(templateFilePath);
        Html html = m2e.loadHtmlTemplate(in);
        String str = m2e.saveToString(html);
        // System.out.println(str);
        replacedertTrue(str.contains("<meta charset=\"utf-8\"/>"));
        replacedertTrue(str.contains("<br id=\"dummy_br\"/>"));
    }
}

19 View Complete Implementation : AbstractMixer2XhtmlView.java
Copyright Apache License 2.0
Author : nabedge
public void setMixer2Engine(Mixer2Engine mixer2Engine) {
    this.mixer2Engine = mixer2Engine;
}

19 View Complete Implementation : MarshalAndUnmarshalTest.java
Copyright Apache License 2.0
Author : nabedge
@Ignore("ignore for issue0004 ")
public clreplaced MarshalAndUnmarshalTest {

    private String templateFileName = "sample-xhtml1-transitional.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void getSame() throws Exception {
        String original = FileUtils.readFileToString(new File(templateFilePath));
        Html html1 = m2e.loadHtmlTemplate(original);
        String str1 = m2e.saveToString(html1);
        Html html2 = m2e.loadHtmlTemplate(str1);
        String str2 = m2e.saveToString(html2);
        replacedertEquals(str1, str2);
    }
}

19 View Complete Implementation : HelloWorldTest.java
Copyright Apache License 2.0
Author : nabedge
// @Ignore("for sample")
public clreplaced HelloWorldTest {

    private String templateFileName = "HelloWorld_html5.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test() throws Exception {
        File file = new File(templateFilePath);
        // System.out.println(FileUtils.readFileToString(file));
        Html html = m2e.loadHtmlTemplate(file);
        P p = html.getById("hellomsg", P.clreplaced);
        p.unsetContent();
        p.getContent().add("Hello World!");
        String result = m2e.saveToString(html);
        // System.out.println(result);
        Span span = TagCreator.span();
        span.getContent().add(p);
        html.getHead().getContent().add(span);
        System.out.println(m2e.saveToString(html));
        // String cloneResult = m2e.saveToString((AbstractJaxb)html.clone());
        // System.out.println(cloneResult);
        replacedert.replacedertTrue(result.contains("<p id=\"hellomsg\">Hello World!</p>"));
    }
}

19 View Complete Implementation : ReplaceByIdTest.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced ReplaceByIdTest {

    private String templateFileName = "ReplaceByIdTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void style() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertNotNull(html.getById("style1", Style.clreplaced));
        Style style = TagCreator.styleWithId("style2");
        style.setType("text/css");
        style.setContent("foobar { color:red; }");
        html.replaceById("style1", style);
        replacedertNull(html.getById("style1", Style.clreplaced));
        replacedertNotNull(html.getById("style2", Style.clreplaced));
    }

    @Test
    public void script() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertNotNull(html.getById("fooScript", Script.clreplaced));
        Script barScript = TagCreator.scriptWithId("barScript");
        barScript.setSrc("bar.js");
        barScript.setType("text/javascript");
        html.replaceById("fooScript", barScript);
        replacedertNull(html.getById("fooScript", Script.clreplaced));
        replacedertNotNull(html.getById("barScript", Script.clreplaced));
    }

    @Test
    public void testReplaceById_tbody() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Tbody tbody = TagCreator.tbody();
        Tr tr = TagCreator.tr();
        Td td = TagCreator.td();
        td.setId("td_hoge");
        td.getContent().add("foobar");
        tr.getThOrTd().add(td);
        tbody.getTr().add(tr);
        replacedertNotNull(html.getById("tbody_dummy", Tbody.clreplaced));
        html.replaceById("tbody_dummy", tbody);
        replacedertNull(html.getById("tbody_dummy", Tbody.clreplaced));
        replacedertNotNull(html.getById("td_hoge", Td.clreplaced));
    }

    @Test
    public void testReplaceById() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Span span = span();
        span.setId("hellospan");
        span.getContent().add("hello");
        replacedertNotNull(html.getById("hellomsg", Div.clreplaced));
        html.replaceById("hellomsg", span);
        replacedertNull(html.getById("hellomsg", Div.clreplaced));
        replacedertTrue(((Span) html.getBody().getContent().get(0)).getId().equals("hellospan"));
        Li li = li();
        li.setId("newli");
        li.getContent().add("new li!");
        replacedertNotNull(html.getById("ol_a_li02", Li.clreplaced));
        try {
            html.replaceById("ol_a_li02", span);
            fail("liが入るべきところにspanを入れているためExceptionが発生するはず");
        } catch (TagTypeUnmatchException e) {
        // 
        }
        html.replaceById("ol_a_li02", li);
        replacedertNull(html.getById("ol_a_li02", Li.clreplaced));
        replacedertTrue(html.getById("ol_a", Ol.clreplaced).getLi().get(1).getId().equals("newli"));
        Td td1 = td();
        td1.setId("newtd1");
        td1.getContent().add("new td 1");
        Tr tr = tr();
        tr.getThOrTd().add(td1);
        replacedertNotNull(html.getById("tr_dummy", Tr.clreplaced));
        html.getById("tbl", Table.clreplaced).getTbody().get(1).unsetTr();
        html.getById("tbl", Table.clreplaced).getTbody().get(1).getTr().add(tr);
        replacedertNull(html.getById("tr_dummy", Tr.clreplaced));
        replacedertNotNull(html.getById("tbl", Table.clreplaced).getTbody().get(1).getTr().get(0).getById("newtd1", Td.clreplaced));
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.replaceById("hellomsg", "replacedByString");
        replacedertTrue(((String) html.getBody().getContent().get(0)).startsWith("replacedByString"));
    }
}

19 View Complete Implementation : Issue0008.java
Copyright Apache License 2.0
Author : nabedge
/**
 * see https://github.com/nabedge/mixer2/issues/8
 *
 * @author nabedge
 */
public clreplaced Issue0008 {

    private String templateFileName = "issue0008.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test() throws Exception {
        InputStream in = new FileInputStream(templateFilePath);
        Html html = m2e.loadHtmlTemplate(in);
        A a = html.getBody().getById("link1", A.clreplaced);
        replacedert.replacedertNotNull(a.getById("barP", P.clreplaced));
        replacedert.replacedertNotNull(a.getById("barDiv", Div.clreplaced));
    }
}

19 View Complete Implementation : ToStringTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced ToStringTest {

    private String templateFileName = "HelloWorld.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(-1, html.toString().indexOf("=<null>"));
    // System.out.println(html.toString());
    }

    @Test
    public void test_list() throws Exception {
        Div div = TagCreator.div();
        div.getContent().add("a");
        A a = TagCreator.a();
        a.getContent().add("link");
        a.setHref("http://example.com");
        div.getContent().add(a);
        div.getContent().add("b");
        String result = m2e.saveToString(div.getContent());
        replacedertEquals(result, "a<a href=\"http://example.com\">link</a>b");
    }
}

19 View Complete Implementation : Issue0011.java
Copyright Apache License 2.0
Author : nabedge
/**
 * see https://github.com/nabedge/mixer2/issues/11
 *
 * @author nabedge
 */
public clreplaced Issue0011 {

    private static Log log = LogFactory.getLog(Issue0011.clreplaced);

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Test
    public void test() throws Exception {
        StringBuilder sb = new StringBuilder();
        sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        sb.append("<head>");
        sb.append("<replacedle>test</replacedle>");
        sb.append("</head>");
        sb.append("<body>");
        sb.append("<iframe>");
        sb.append("</iframe>");
        sb.append("</body>");
        sb.append("</html>");
        String str = sb.toString();
        Html html = m2e.loadHtmlTemplate(str);
        String result = m2e.saveToString(html);
        // log.info(result);
        replacedertThat(result.contains("<iframe>"), is(true));
        replacedertThat(result.contains("</iframe>"), is(true));
    }

    @Test
    public void test2() throws Exception {
        StringBuilder sb = new StringBuilder();
        sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        sb.append("<head>");
        sb.append("<replacedle>test</replacedle>");
        sb.append("</head>");
        sb.append("<body>");
        sb.append("<iframe id=\"fooId\" src=\"barSrc\"><p>foo</p></iframe>");
        sb.append("</body>");
        sb.append("</html>");
        String str = sb.toString();
        Html html = m2e.loadHtmlTemplate(str);
        String result = m2e.saveToString(html);
        // log.info(result);
        replacedertThat(result.contains("<iframe "), is(true));
        replacedertThat(result.contains("id=\"fooId\""), is(true));
        replacedertThat(result.contains("src=\"barSrc\""), is(true));
        replacedertThat(result.contains("<p>foo</p>"), is(true));
        replacedertThat(result.contains("</iframe>"), is(true));
    }

    @Test
    public void test3() throws Exception {
        Iframe iframe = TagCreator.iframe();
        String iframeStr = m2e.saveToString(iframe);
        // log.info(iframeStr);
        replacedertThat(iframeStr.matches("<iframe>.*</iframe>"), is(true));
    // replacedertThat(m2e.saveToString(iframe).matches("<iframe/>"), is(true));
    }

    @Test
    public void test4() throws Exception {
        Iframe iframe = TagCreator.iframe();
        iframe.setId("foo");
        String iframeStr = m2e.saveToString(iframe);
        replacedertThat(iframeStr.matches("<iframe id=\"foo\">.*</iframe>"), is(true));
    // replacedertThat(m2e.saveToString(iframe).matches("<iframe/>"), is(true));
    }
}

19 View Complete Implementation : Mixer2XhtmlViewTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced Mixer2XhtmlViewTest {

    private String templateFileName = "HelloWorld_html5.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void testMixer2XhtmlView() throws Exception {
        Html html = m2e.loadHtmlTemplate(new FileInputStream(templateFilePath));
        MockHttpServletRequest req = new MockHttpServletRequest();
        MockHttpServletResponse res = new MockHttpServletResponse();
        Mixer2XhtmlView view = new Mixer2XhtmlView(m2e, html);
        Map<String, Object> model = new HashMap<String, Object>();
        view.render(model, req, res);
        Html result = m2e.loadHtmlTemplate(res.getContentreplacedtring());
        replacedert.replacedertThat(m2e.saveToString(result), is(m2e.saveToString(html)));
    }
}

19 View Complete Implementation : PseudoCachingTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced PseudoCachingTest {

    private static Log log = LogFactory.getLog(PseudoCachingTest.clreplaced);

    private String templateFileName = "sample-xhtml1-transitional.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private int loop = 1000;

    private ConcurrentHashMap<String, Html> cacheMap = new ConcurrentHashMap<String, Html>();

    @Before
    public void before() {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    private Html loadHtmlTemplateThroughCache(String templateFilePath) throws Exception {
        Html html = cacheMap.get(templateFilePath);
        if (html == null) {
            html = m2e.loadHtmlTemplate(new File(templateFilePath));
            cacheMap.putIfAbsent(templateFilePath, html.copy(Html.clreplaced));
        }
        return html.copy(Html.clreplaced);
    }

    @Test
    public void replacedertSame() throws Exception {
        Html html1 = loadHtmlTemplateThroughCache(templateFilePath);
        Html html2 = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedert.replacedertEquals(m2e.saveToString(html1), m2e.saveToString(html2));
    }

    @Test
    public void loopWithCache() throws Exception {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i = 0; i < loop; i++) {
            loadHtmlTemplateThroughCache(templateFilePath);
        }
        stopWatch.stop();
        log.info("using cache: loop= " + loop + ", time(msec)= " + stopWatch.getTime());
    }

    @Test
    public void loopWithoutCache() throws Exception {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        File file;
        for (int i = 0; i < loop; i++) {
            file = new File(templateFilePath);
            m2e.loadHtmlTemplate(file);
        }
        stopWatch.stop();
        log.info("   no cache: loop= " + loop + ", time(msec)= " + stopWatch.getTime());
    }
}

19 View Complete Implementation : TableBuilderSampleTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced TableBuilderSampleTest {

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private String templateFilePath;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource("TableBuilderSample.html").toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void sample() throws IOException {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.removeDescendants("comment");
        TableBuilder tBuilder = new TableBuilder();
        String[][] data = new String[][] { // id, name, price
        { "1", "cookie", "2.50" }, { "2", "candy", "3.75" } };
        for (String[] row : data) {
            tBuilder.addTr().addTd(row[0]).addTd(row[1]).addTd(row[2]);
        }
        Table newtable = tBuilder.build();
        Table table = html.getById("search_result", Table.clreplaced);
        Tr headTr = table.getTr().get(0);
        table.getTr().clear();
        table.getTr().add(headTr);
        table.getTr().addAll(newtable.getTr());
    // System.out.println(mixer2Engine.saveToString(html));
    }

    @Test
    public void sample2() {
        TableBuilder tableBuilder = new TableBuilder();
        tableBuilder.thead.tr(0).addTd("id").addTd("name").addTd("price");
        tableBuilder.tbody(0).tr(0).addTd("1").addTd("cookie").addTd("2.75");
        tableBuilder.tbody(0).tr(1).addTd("2").addTd("candy").addTd("3.25");
    // System.out.println(mixer2Engine.saveToString(tableBuilder.build()));
    }

    @Test
    public void sample3() {
        HashMap<String, Object> attrMap = new HashMap<String, Object>();
        attrMap.put("id", "foo_id");
        // clreplacedの属性名はcssClreplacedでもかまいません
        attrMap.put("clreplaced", "clreplaced_1 clreplaced_2");
        TableBuilder tableBuilder = new TableBuilder();
        tableBuilder.tr(0).td(0).add("foo");
        tableBuilder.tr(0).td(0).setAttr(attrMap);
        tableBuilder.tr(0).td(0).setAttr("replacedle", "foo_replacedle");
    // System.out.println(mixer2Engine.saveToString(tableBuilder.tr(0).buildTr()));
    // System.out.println(mixer2Engine.saveToString(tableBuilder.build()));
    }
}

19 View Complete Implementation : CheckAndLoadTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced CheckAndLoadTest {

    private String templateFileName = "invalid-xhtml.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test(expected = Mixer2JAXBException.clreplaced)
    public void exceptionThrowTest() throws Exception {
        m2e.checkAndLoadHtmlTemplate(new File(templateFilePath));
    }

    @Test
    public void getSAXParseExceptionTest() {
        try {
            m2e.checkAndLoadHtmlTemplate(new File(templateFilePath));
        } catch (Mixer2JAXBException e) {
            // System.out.println("###");
            // e.getCause().getCause().printStackTrace();
            // System.out.println("###");
            replacedertNotNull(e.getSAXParseException());
            replacedertNotNull(e.getSAXParseExceptionMessage());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

19 View Complete Implementation : CopyWithNullTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced CopyWithNullTest {

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Test
    public void test_null_and_blank() throws Exception {
        Div div = TagCreator.div();
        div.getContent().add(Arrays.asList(null, " "));
        Div copy = div.copy(Div.clreplaced);
        replacedertEquals(m2e.saveToString(div), m2e.saveToString(copy));
    }

    @Test
    public void test_td_null() throws Exception {
        Td td = TagCreator.td();
        td.getContent().add(null);
        Td copy = td.copy(Td.clreplaced);
        replacedertEquals(m2e.saveToString(td), m2e.saveToString(copy));
    }

    @Test
    public void test_span_null() throws Exception {
        Span span = TagCreator.span();
        span.getContent().add(null);
        Span copy = span.copy(Span.clreplaced);
        replacedertEquals(m2e.saveToString(span), m2e.saveToString(copy));
    }

    @Test
    public void test_td_empty() throws Exception {
        Td td = TagCreator.td();
        td.getContent().add("");
        Td copy = td.copy(Td.clreplaced);
        replacedertEquals(m2e.saveToString(td), m2e.saveToString(copy));
    }

    @Test
    public void test_body_null() throws Exception {
        Body body = TagCreator.body();
        body.getContent().add(null);
        Body copy = body.copy(Body.clreplaced);
        replacedertEquals(m2e.saveToString(body), m2e.saveToString(copy));
    }

    @Test
    public void test_body_empty() throws Exception {
        Body body = TagCreator.body();
        body.getContent().add("");
        body.copy(Body.clreplaced);
    }
}

19 View Complete Implementation : CopyPerformanceTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced CopyPerformanceTest {

    private static Log log = LogFactory.getLog(CopyPerformanceTest.clreplaced);

    private String templateFileName = "sample-xhtml1-transitional.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private int loop = 1000;

    @BeforeClreplaced
    public static void beforeClreplaced() {
    }

    @Before
    public void before() {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test()
    public void wholeHtmlCopy() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        @SuppressWarnings("unused")
        Html tmp = null;
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i = 0; i < loop; i++) {
            tmp = html.copy(Html.clreplaced);
        }
        stopWatch.stop();
        log.info("whale html: loop= " + loop + ", time(msec)= " + stopWatch.getTime());
    }

    @Test()
    public void smallTagCopy() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Meta tmp = html.getById("meta-content-type", Meta.clreplaced);
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i = 0; i < loop; i++) {
            tmp = tmp.copy(Meta.clreplaced);
        }
        stopWatch.stop();
        log.info(" small tag: loop= " + loop + ", time(msec)= " + stopWatch.getTime());
    }
}

19 View Complete Implementation : RemoveById_html5Test.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced RemoveById_html5Test {

    private String templateFileName = "RemoveByIdTest_html5.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void testRemoveById() throws IOException {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        // 
        replacedertNotNull(html.getById("dummy_br", Br.clreplaced));
        html.removeById("dummy_br");
        replacedertNull(html.getById("dummy_br"));
        // 
        replacedertNotNull(html.getById("article2", Article.clreplaced));
        html.removeById("article2");
        replacedertNull(html.getById("article2", Article.clreplaced));
    }
}

19 View Complete Implementation : CopyTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced CopyTest {

    private String templateFileName = "copytest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void testHtml() throws Exception {
        Html original = m2e.loadHtmlTemplate(new File(templateFilePath));
        Html copy = original.copy(Html.clreplaced);
        replacedertEquals("bar", copy.getById("li_sample01", Li.clreplaced).getData("foo"));
        replacedertEquals("111", copy.getById("test_h1", H1.clreplaced).getData("xxx"));
        replacedertEquals("222", copy.getById("test_h1", H1.clreplaced).getData("yyy"));
        replacedertEquals(m2e.saveToString(original), m2e.saveToString(copy));
    }

    @Test
    public void testDiv() throws Exception {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Div helloWorldDiv = html.getById("hellomsg", Div.clreplaced);
        Div newDiv = helloWorldDiv.copyNoException(Div.clreplaced);
        newDiv.setId("bar");
        newDiv.unsetContent();
        newDiv.getContent().add("Life is beautiful.");
        replacedertEquals("Div", newDiv.getClreplaced().getSimpleName());
        replacedertEquals("Hello World !", helloWorldDiv.getContent().get(0));
        replacedertEquals("Life is beautiful.", newDiv.getContent().get(0));
        replacedertEquals("hellomsg", helloWorldDiv.getId());
        replacedertEquals("bar", newDiv.getId());
        replacedertEquals("bar", newDiv.getData("foo"));
        replacedertEquals("foo", newDiv.getData("bar"));
    }
}

19 View Complete Implementation : StyleAttrTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced StyleAttrTest {

    private String templateFileName = "StyleAttrTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void getStyle() throws IOException {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        TreeMap<String, String> styleMap = html.getById("span1", Span.clreplaced).getStyleAsTreeMap();
        replacedertEquals("large", styleMap.get("font-weight"));
        replacedertEquals("0", styleMap.get("margin"));
        replacedertEquals("0", styleMap.get("padding"));
    }

    @Test
    public void setStyle() throws IOException {
        Html html = m2e.loadHtmlTemplate(new File(templateFilePath));
        TreeMap<String, String> styleMap;
        styleMap = html.getById("div1", Div.clreplaced).getStyleAsTreeMap();
        replacedertEquals("solid", styleMap.get("border-style"));
        styleMap.put("font-weight", "bold");
        html.getById("div1", Div.clreplaced).setStyleByTreeMap(styleMap);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        styleMap = html.getById("div1", Div.clreplaced).getStyleAsTreeMap();
        replacedertEquals("solid", styleMap.get("border-style"));
        replacedertEquals("bold", styleMap.get("font-weight"));
    }

    @Test
    public void setStyleNew() throws IOException {
        Html html;
        TreeMap<String, String> styleMap;
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        styleMap = html.getById("div1", Div.clreplaced).getStyleAsTreeMap();
        replacedertEquals("solid", styleMap.get("border-style"));
        TreeMap<String, String> newStyleMap = new TreeMap<String, String>();
        newStyleMap.put("border-color", "red");
        html.getById("div1", Div.clreplaced).setStyleByTreeMap(newStyleMap);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        styleMap = html.getById("div1", Div.clreplaced).getStyleAsTreeMap();
        replacedertNull(styleMap.get("border-style"));
        replacedertEquals("red", styleMap.get("border-color"));
    }
}

19 View Complete Implementation : Mixer2XhtmlViewResolver.java
Copyright Apache License 2.0
Author : nabedge
/**
 * View Resolver for SpringMVC . <br>
 * your should add dependency for your application .
 *
 * <pre>
 * {@code
 * <dependency>
 *     <groupId>org.springframework</groupId>
 *     <artifactId>spring-webmvc</artifactId>
 *     <version>3.1.2.RELEASE (or higher)</version>
 * </dependency>
 * }
 * </pre>
 *
 * <b>Spring MVC configuration Sample</b><br>
 *
 * <pre>
 * {@code
 * <bean id="mixer2Engine" clreplaced="org.mixer2.Mixer2Engine" scope="singleton" />
 * <bean clreplaced="org.mixer2.spring.webmvc.Mixer2XhtmlViewResolver">
 *     <property name="order" value="1" />
 *     <property name="prefix" value="clreplacedpath:m2mockup/m2template/" />
 *     <!-- Also, you can use file system path like "file:/var/foo/"  -->
 *     <property name="suffix" value=".html" />
 *     <property name="basePackage" value="com.example.yourproject.web.view" />
 *     <property name="mixer2Engine" ref="mixer2Engine" />
 *
 *     <!-- Default value is true that means this resolver returns null -->
 *     <!-- if template file not found and continue to resolve view name -->
 *     <!-- by another subsequent view resolver. -->
 *     <!-- Set "false" if you expect FileNotFoundException for unknown view name -->
 *     <property name="returnNullIfTemplateFileNotFound" value="true" />
 *
 *     <!-- If this resolver can not find the view clreplaced, -->
 *     <!-- returns html template "as is" with defaultView. -->
 *     <!-- But if use this property, raise ClreplacedNotFoundException .  -->
 *     <!-- Default value is false. -->
 *     <property name="raiseErrorIfViewClreplacedNotFound" value="true" />
 * </bean>
 * }
 * </pre>
 *
 * <p>
 * Using this ViewResolver, Your controller method can returns <strong>template
 * html file path and name without file extension</strong>.<br>
 * See sample below.
 * </p>
 *
 * <pre>
 * <code>
 * {@literal @}Controller
 * public clreplaced HelloWorldController {
 *
 *    {@literal @}Autowired
 *    protected helloMessageService helloMessageService;
 *
 *    {@literal @}RequestMapping(value = "/hello", method = RequestMethod.GET)
 *    public String showHello(Model model) {
 *        String helloMessage = helloMessageService.getMessage();
 *        model.addAttribute("helloMessage", helloMessage);
 *        return "foo/bar/helloWorld";
 *    }
 * }
 * </code>
 * </pre>
 *
 * <p>
 * In this case, "foo/bar/helloWorld" will be attached to
 * "com.example.yourproject.web.view.foo.bar.HelloWorldView" clreplaced .
 * </p>
 *
 * <p>
 * AbstractMixer2XhtmlView which is the base clreplaced of HelloWorldView loads the
 * file "m2mockup/m2template/foo/bar/helloWorld.html" as a html template and
 * convert it to the instance of org.mixer2.jaxb.xhtml.Html . You can change the
 * html object in HelloWorldView clreplaced.
 * </p>
 *
 * <p>
 * The template file is "prefix" + viewName + "suffix" . See "prefix" and
 * "suffix" property of Mixer2XhtmlViewResolver bean configuration sample above.
 * </p>
 *
 * <p>
 * If there were no "com.example.yourproject.web.view.foo.bar.HelloWorldView"
 * clreplaced in clreplacedpath,default view will be created automatically that load the
 * template file. You can not change the the html object. That means the view
 * resolver returns html on template file as is.
 * </p>
 *
 * @see <a href="http://mixer2.org/site/springmvcsample.html">spring mvc sample</a>
 * @see <a href="http://github.com/nabedge/mixer2-sample/tree/master/mixer2-fruitshop-springboot">spring mvc sample code</a>
 * @author kazuki43zoo
 * @author nabedge
 */
public clreplaced Mixer2XhtmlViewResolver extends UrlBasedViewResolver {

    private static final String PATH_SEPARATOR = "/";

    private static final String PACKAGE_SEPARATOR = ".";

    private static final Pattern PATH_SEPARATOR_PATTERN = Pattern.compile(PATH_SEPARATOR);

    private static Log log = LogFactory.getLog(Mixer2XhtmlViewResolver.clreplaced);

    private Mixer2Engine mixer2Engine;

    private String basePackage = "";

    private String clreplacedNameSuffix = "View";

    private String docType;

    private boolean returnNullIfTemplateFileNotFound = true;

    private boolean raiseErrorIfViewClreplacedNotFound = false;

    public Mixer2XhtmlViewResolver() {
        setViewClreplaced(AbstractMixer2XhtmlView.clreplaced);
    }

    public void setMixer2Engine(Mixer2Engine mixer2Engine) {
        this.mixer2Engine = mixer2Engine;
    }

    public void setBasePackage(String basePackage) {
        this.basePackage = basePackage;
    }

    public void setClreplacedNameSuffix(String clreplacedNameSuffix) {
        this.clreplacedNameSuffix = clreplacedNameSuffix;
    }

    public void setDocType(String docType) {
        this.docType = docType;
    }

    public boolean isReturnNullIfTemplateFileNotFound() {
        return returnNullIfTemplateFileNotFound;
    }

    public void setReturnNullIfTemplateFileNotFound(boolean returnNullIfTemplateFileNotFound) {
        this.returnNullIfTemplateFileNotFound = returnNullIfTemplateFileNotFound;
    }

    public boolean isRaiseErrorIfViewClreplacedNotFound() {
        return raiseErrorIfViewClreplacedNotFound;
    }

    public void setRaiseErrorIfViewClreplacedNotFound(boolean raiseErrorIfViewClreplacedNotFound) {
        this.raiseErrorIfViewClreplacedNotFound = raiseErrorIfViewClreplacedNotFound;
    }

    @Override
    protected boolean canHandle(String viewName, Locale locale) {
        if (isReturnNullIfTemplateFileNotFound()) {
            String url = createUrl(viewName);
            if (log.isDebugEnabled()) {
                log.debug("template url: " + url);
            }
            Resource resource = getApplicationContext().getResource(url);
            return resource.exists();
        } else {
            return true;
        }
    }

    protected AbstractUrlBasedView buildView(String viewName) throws Exception {
        // create view object.
        AbstractMixer2XhtmlView view = null;
        String fqcnOfView = (StringUtils.hasLength(basePackage) ? basePackage + PACKAGE_SEPARATOR : "") + toViewClreplacedNamePrefix(viewName) + (StringUtils.hasLength(clreplacedNameSuffix) ? clreplacedNameSuffix : "");
        try {
            Clreplaced<?> viewClreplaced = ClreplacedUtils.forName(fqcnOfView, ClreplacedUtils.getDefaultClreplacedLoader());
            view = BeanUtils.instantiateClreplaced(viewClreplaced, AbstractMixer2XhtmlView.clreplaced);
            getApplicationContext().getAutowireCapableBeanFactory().autowireBean(view);
        } catch (ClreplacedNotFoundException e) {
            if (isRaiseErrorIfViewClreplacedNotFound()) {
                throw e;
            } else {
                view = createDefaultView();
                log.debug("Applied default view. viewName is '" + viewName + "'. fqcnOfView is '" + fqcnOfView + "'.");
            }
        }
        // inject properties of AbstractMixer2XhtmlView.
        view.setMixer2Engine(mixer2Engine);
        view.setResourceLoader(getApplicationContext());
        if (docType != null) {
            view.setDocType(docType);
        }
        // inject properties of parent clreplaced.
        view.setUrl(createUrl(viewName));
        String contentType = getContentType();
        if (contentType != null) {
            view.setContentType(contentType);
        }
        view.setRequestContextAttribute(getRequestContextAttribute());
        view.setAttributesMap(getAttributesMap());
        return view;
    }

    protected String createUrl(String viewName) {
        return getPrefix() + viewName + getSuffix();
    }

    protected String toViewClreplacedNamePrefix(String viewName) {
        if (viewName.contains(PATH_SEPARATOR)) {
            int lastIndexOfPathSeparator = viewName.lastIndexOf(PATH_SEPARATOR);
            Matcher pathSeparatorMatcher = PATH_SEPARATOR_PATTERN.matcher(viewName.substring(0, lastIndexOfPathSeparator));
            String packageName = pathSeparatorMatcher.replaceAll(PACKAGE_SEPARATOR);
            String lastElement = viewName.substring(lastIndexOfPathSeparator + 1);
            return packageName + PACKAGE_SEPARATOR + StringUtils.capitalize(lastElement);
        } else {
            return StringUtils.capitalize(viewName);
        }
    }

    protected AbstractMixer2XhtmlView createDefaultView() {
        return AbstractMixer2XhtmlView.createDefaultView();
    }
}

19 View Complete Implementation : Issue0004.java
Copyright Apache License 2.0
Author : nabedge
/**
 * see https://github.com/nabedge/mixer2/issues/4
 *
 * @author nabedge
 */
public clreplaced Issue0004 {

    private String templateFileName = "issue0004.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void templateTest() throws Exception {
        InputStream in = new FileInputStream(templateFilePath);
        Html html = m2e.loadHtmlTemplate(in);
        String str = "<p><a href=\"link1\">link1</a><a href=\"link2\">link2</a></p>";
        // System.out.println(m2e.saveToString(html));
        replacedertTrue(m2e.saveToString(html).contains(str));
    }

    @Test
    public void zeroTemplateTest() throws Exception {
        List<Object> aList = new ArrayList<Object>();
        for (int i = 1; i <= 2; i++) {
            A linkA = TagCreator.a();
            linkA.getContent().add("link" + i);
            linkA.setHref("link" + i);
            aList.add(linkA);
        }
        P p = TagCreator.p();
        p.getContent().addAll(aList);
        String str = "<p><a href=\"link1\">link1</a><a href=\"link2\">link2</a></p>";
        // System.out.println(m2e.saveToString(p));
        replacedertTrue(m2e.saveToString(p).contains(str));
    }
}

19 View Complete Implementation : RemoveByIdTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced RemoveByIdTest {

    private String templateFileName = "RemoveByIdTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void removeStyleTest() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertTrue(html.getHead().getById("style1", Style.clreplaced) != null);
        html.getHead().removeById("style1");
        replacedertTrue(html.getHead().getById("style1", Style.clreplaced) == null);
    }

    @Test
    public void removeScriptTest() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertTrue(html.getHead().getById("script1", Script.clreplaced) != null);
        html.getHead().removeById("script1");
        replacedertTrue(html.getHead().getById("script1", Script.clreplaced) == null);
    }

    @Test
    public void testRemoveById() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertTrue(html.getById("span2", Span.clreplaced) != null);
        html.removeById("span2");
        replacedertTrue(html.getById("span2", Span.clreplaced) == null);
        replacedertTrue(html.getById("hellomsg", Div.clreplaced) != null);
        html.removeById("hellomsg");
        replacedertTrue(html.getById("hellomsg", Div.clreplaced) == null);
        replacedertTrue(html.getById("dt01", Dt.clreplaced) != null);
        html.removeById("dt01");
        replacedertTrue(html.getById("dt01", Dt.clreplaced) == null);
        replacedertTrue(html.getById("strong_a", Strong.clreplaced) != null);
        html.removeById("strong_a");
        replacedertTrue(html.getById("strong_a", Strong.clreplaced) == null);
        replacedertTrue(html.getById("small_a", Small.clreplaced) != null);
        html.removeById("small_a");
        replacedertTrue(html.getById("small_a", Small.clreplaced) == null);
        replacedertTrue(html.getById("li_a", Li.clreplaced) != null);
        html.removeById("li_a");
        replacedertTrue(html.getById("li_a", Li.clreplaced) == null);
        replacedertTrue(html.getById("ul_a", Ul.clreplaced) != null);
        html.removeById("ul_a");
        replacedertTrue(html.getById("ul_a", Ul.clreplaced) == null);
        replacedertTrue(html.getById("lastfoo", Div.clreplaced) != null);
        html.removeById("lastfoo");
        replacedertTrue(html.getById("lastfoo", Div.clreplaced) == null);
        replacedertNotNull(html.getById("tbody_dummy", Tbody.clreplaced));
        html.removeById("tbody_dummy");
        replacedertNull(html.getById("tbody_dummy", Tbody.clreplaced));
    }

    @Test
    public void removeMenuAndLi() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertNotNull(html.getById("menu01", Menu.clreplaced));
        replacedertNotNull(html.getById("menu01_li", Li.clreplaced));
        replacedertNotNull(html.getById("menu02", Menu.clreplaced));
        replacedertNotNull(html.getById("menu02_li", Li.clreplaced));
        html.removeById("menu01");
        replacedertNull(html.getById("menu01", Menu.clreplaced));
        replacedertNull(html.getById("menu01_li", Li.clreplaced));
        replacedertNotNull(html.getById("menu02", Menu.clreplaced));
        replacedertNotNull(html.getById("menu02_li", Li.clreplaced));
        html.removeById("menu02_li");
        replacedertNull(html.getById("menu02_li", Li.clreplaced));
        replacedertNotNull(html.getById("menu02_button", Button.clreplaced));
    }

    @Test
    public void tableTest() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Table table = html.getById("tbl", Table.clreplaced);
        replacedertNotNull(table.getById("th00", Th.clreplaced));
        table.removeById("th00");
        replacedertNull(table.getById("th00", Th.clreplaced));
    }

    public void span2test() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertNotNull(html.getById("span2", Span.clreplaced));
        html.removeById("span2");
        replacedertNull(html.getById("span2", Span.clreplaced));
    }
}

18 View Complete Implementation : GetByIdTest.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced GetByIdTest {

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private String templateFileName = "GetByIdTest.html";

    private String templateFilePath;

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void testGetById() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertTrue(html.getById("div_a", Div.clreplaced).getContent().get(0).equals("div_a"));
        replacedertTrue(html.getById("span2", Span.clreplaced).getContent().get(0).equals("span2"));
        replacedertTrue(html.getById("bbb", B.clreplaced).getContent().get(1).equals(html.getById("span2", Span.clreplaced)));
        replacedertTrue(html.getById("href_google", A.clreplaced).getHref().equals("http://www.google.com/"));
        replacedertTrue(html.getById("pre_a", Pre.clreplaced).getContent().get(0).equals("pre_a"));
        Td td = html.getById("thead_a", Thead.clreplaced).getTr().get(0).getThOrTd().get(0).cast(Td.clreplaced);
        replacedertTrue(td.getContent().get(0).equals("thead00"));
        replacedertTrue(html.getById("thead01", Td.clreplaced).getContent().get(0).equals("thead01"));
        replacedertTrue(html.getById("ol_a_li01", Li.clreplaced).getContent().get(0).equals("ol_a_li01"));
        replacedertTrue(html.getById("strong_a", Strong.clreplaced).getContent().get(0).equals("XML!"));
    }

    /**
     * AbstractJaxbクラスで設定したダミーのgetId()メソッドでも
     * id属性をきちんと取得できるかどうかのテスト。
     * @throws IOException
     */
    @Test
    public void getByIdOnAbstractJaxb() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<AbstractJaxb> ajList = html.getDescendants("h_foo");
        replacedertEquals("h1", ajList.get(0).getId());
        replacedertEquals("h2", ajList.get(1).getId());
        replacedertEquals("h3", ajList.get(2).getId());
        replacedertEquals("h4", ajList.get(3).getId());
        replacedertEquals("h5", ajList.get(4).getId());
        replacedertEquals("h6", ajList.get(5).getId());
    }
}

18 View Complete Implementation : GetById_html5Test.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced GetById_html5Test {

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private String templateFileName = "GetByIdTest_html5.html";

    private String templateFilePath;

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void testGetById() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        // System.out.println(html.toString());
        replacedertNotNull(html.getById("dummy_br", Br.clreplaced));
        replacedertEquals("paragraph 5", html.getById("p5", P.clreplaced).getContent().get(0));
        replacedertEquals("paragraph 5", html.getById("article2", Article.clreplaced).getById("p5", P.clreplaced).getContent().get(0));
        replacedertEquals("autoplay", html.getById("video1", Video.clreplaced).getAutoplay());
        replacedertEquals("brave.ja.vtt", html.getById("track1", Track.clreplaced).getSrc());
        replacedertEquals("audio1.src", html.getById("audio1", Audio.clreplaced).getSrc());
        Progress progress1 = html.getById("progress1", Progress.clreplaced);
        replacedertEquals("0", ((Span) progress1.getContent().get(0)).getContent().get(0));
        replacedertEquals("%", progress1.getContent().get(1));
        // System.out.println(m2e.saveToString(html));
        replacedertEquals("8", html.getById("meter1", Meter.clreplaced).getMax());
    }
}

18 View Complete Implementation : GetDescendants02Test.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced GetDescendants02Test {

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private String templateFileName = "GetDescendantsTest02.html";

    private String templateFilePath;

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void getDescendants02() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<AbstractJaxb> ajList;
        ajList = html.getById("div1", Div.clreplaced).getDescendants("foo");
        replacedertEquals(6, ajList.size());
        replacedertEquals(H6.clreplaced, ajList.get(5).getClreplaced());
        H6 h6 = (H6) ajList.get(5);
        replacedertEquals(2, h6.getDescendants("bar").size());
        replacedertEquals(1, h6.getDescendants("bar", Span.clreplaced).size());
        replacedertEquals(1, h6.getDescendants("bar", Strong.clreplaced).size());
        List<Form> formList;
        formList = html.getDescendants(Form.clreplaced);
        replacedertEquals(2, formList.size());
        formList = html.getDescendants("bar", Form.clreplaced);
        replacedertEquals(1, formList.size());
        replacedertEquals("form2", ((Form) formList.get(0)).getId());
        ajList = html.getById("div2", Div.clreplaced).getDescendants("bar");
        replacedertEquals(3, ajList.size());
        replacedertEquals(Div.clreplaced, ajList.get(0).getClreplaced());
        replacedertEquals("div2", ((Div) ajList.get(0)).getId());
        replacedertEquals(Option.clreplaced, ajList.get(1).getClreplaced());
        replacedertEquals("option2", ((Option) ajList.get(1)).getId());
        replacedertEquals(Form.clreplaced, ajList.get(2).getClreplaced());
        replacedertEquals("form2", ((Form) ajList.get(2)).getId());
    }
}

18 View Complete Implementation : IdrefTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced IdrefTest {

    @SuppressWarnings("unused")
    private static Log log = LogFactory.getLog(IdrefTest.clreplaced);

    private String templateFileName = "IdrefTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void setForPropOfLabelTag() throws Exception {
        InputStream in = new FileInputStream(templateFilePath);
        Html html = m2e.loadHtmlTemplate(in);
        Form fooForm = html.getById("fooForm", Form.clreplaced);
        Label label_familyName = TagCreator.label();
        label_familyName.getContent().add("family name:");
        label_familyName.setFor(fooForm.getById("familyName", Input.clreplaced));
        fooForm.insertBeforeId("familyName", label_familyName);
        Label label_lastName = TagCreator.label();
        label_lastName.getContent().add("last name:");
        label_lastName.setFor(fooForm.getById("lastName", Input.clreplaced));
        fooForm.insertBeforeId("lastName", label_lastName);
        String str = m2e.saveToString(html);
        replacedert.replacedertTrue(str.contains("<label for=\"familyName\">family name:</label>"));
        replacedert.replacedertTrue(str.contains("<label for=\"lastName\">last name:</label>"));
    }

    @Test
    public void getForPropOfLabelTag() throws Exception {
        InputStream in = new FileInputStream(templateFilePath);
        Html html = m2e.loadHtmlTemplate(in);
        Form barForm = html.getById("barForm", Form.clreplaced);
        Label label = barForm.getById("barInputLabel", Label.clreplaced);
        replacedertTrue(label.getFor().getClreplaced().equals(Input.clreplaced));
        replacedertEquals("barInput", ((Input) label.getFor()).getId());
    }
}

18 View Complete Implementation : InsertById01Test.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced InsertById01Test {

    private String templateFileName = "InsertByIdTest01.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    /**
     * olにliタグを挿入してみる
     */
    @Test
    public void liTest() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<Li> liList;
        Li li = li();
        li.setId("newli");
        li.getContent().add("aaa");
        liList = html.getById("ol1", Ol.clreplaced).getLi();
        replacedertEquals(2, liList.size());
        replacedertEquals("li1", liList.get(0).getId());
        replacedertEquals("li2", liList.get(1).getId());
        // 
        html.insertAfterId("li1", li);
        // System.out.println(html.getById("ol1", Ol.clreplaced).toString());
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        // 
        liList = html.getById("ol1", Ol.clreplaced).getLi();
        replacedertEquals(3, liList.size());
        replacedertEquals("li1", liList.get(0).getId());
        replacedertEquals("newli", liList.get(1).getId());
        replacedertEquals("li2", liList.get(2).getId());
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.insertBeforeId("li1", li);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        liList = html.getById("ol1", Ol.clreplaced).getLi();
        replacedertEquals(3, liList.size());
        replacedertEquals("newli", liList.get(0).getId());
        replacedertEquals("li1", liList.get(1).getId());
        replacedertEquals("li2", liList.get(2).getId());
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.insertAfterId("li2", li);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        liList = html.getById("ol1", Ol.clreplaced).getLi();
        replacedertEquals(3, liList.size());
        replacedertEquals("li1", liList.get(0).getId());
        replacedertEquals("li2", liList.get(1).getId());
        replacedertEquals("newli", liList.get(2).getId());
    }

    /**
     * 文字列を挿入してみる
     */
    @Test
    public void stringTest() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getById("test2div", Div.clreplaced).getContent().size());
        html.insertAfterId("test2span", "bar");
        // html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertEquals("test2span", ((Span) html.getById("test2div", Div.clreplaced).getContent().get(0)).getId());
        replacedertEquals("bar", html.getById("test2div", Div.clreplaced).getContent().get(1));
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getById("test2div", Div.clreplaced).getContent().size());
        html.insertBeforeId("test2span", "bar");
        replacedertEquals("bar", html.getById("test2div", Div.clreplaced).getContent().get(0));
        replacedertEquals("test2span", ((Span) html.getById("test2div", Div.clreplaced).getContent().get(1)).getId());
    }

    @Test
    public void trtdTest() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Tr tr = tr();
        Td td = td();
        tr.setId("newtr");
        td.setId("newtd");
        td.getContent().add("bar");
        tr.getThOrTd().add(td);
        replacedertEquals(1, html.getById("trtdtest", Table.clreplaced).getTr().size());
        replacedertEquals("foo", html.getById("td1", Td.clreplaced).getContent().get(0));
        html.insertAfterId("tr1", tr.copy(Tr.clreplaced));
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertEquals(2, html.getById("trtdtest", Table.clreplaced).getTr().size());
        Td tmpTd = (Td) html.getById("trtdtest", Table.clreplaced).getTr().get(1).getThOrTd().get(0);
        replacedertEquals("bar", ((String) tmpTd.getContent().get(0)).trim());
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.insertBeforeId("tr1", tr.copy(Tr.clreplaced));
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertEquals(2, html.getById("trtdtest", Table.clreplaced).getTr().size());
        Td tmpTd2 = (Td) html.getById("trtdtest", Table.clreplaced).getTr().get(0).getThOrTd().get(0);
        replacedertEquals("bar", ((String) tmpTd2.getContent().get(0)).trim());
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.insertAfterId("td1", td);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertEquals(1, html.getById("trtdtest", Table.clreplaced).getTr().size());
        replacedertEquals(2, html.getById("trtdtest", Table.clreplaced).getTr().get(0).getThOrTd().size());
        Td tmpTd3;
        tmpTd3 = (Td) html.getById("trtdtest", Table.clreplaced).getTr().get(0).getThOrTd().get(0);
        replacedertEquals("td1", tmpTd3.getId());
        tmpTd3 = (Td) html.getById("trtdtest", Table.clreplaced).getTr().get(0).getThOrTd().get(1);
        replacedertEquals("newtd", tmpTd3.getId());
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.insertBeforeId("td1", td);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertEquals(1, html.getById("trtdtest", Table.clreplaced).getTr().size());
        replacedertEquals(2, html.getById("trtdtest", Table.clreplaced).getTr().get(0).getThOrTd().size());
        Td tmpTd4;
        tmpTd4 = (Td) html.getById("trtdtest", Table.clreplaced).getTr().get(0).getThOrTd().get(1);
        replacedertEquals("td1", tmpTd4.getId());
        tmpTd4 = (Td) html.getById("trtdtest", Table.clreplaced).getTr().get(0).getThOrTd().get(0);
        replacedertEquals("newtd", tmpTd4.getId());
    }
}

18 View Complete Implementation : InsertById02Test.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced InsertById02Test {

    private String templateFileName = "InsertByIdTest02.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    /**
     * menuタグ内で文字列を挿入してみる
     */
    @Test
    public void menu_String_Test() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.insertAfterId("menu2", "insert_after_menu2");
        List<Object> objList = html.getById("li2", Li.clreplaced).getContent();
        // System.out.println(objList.get(2).toString());
        replacedertEquals(objList.get(2), "insert_after_menu2");
    }

    /**
     * menuタグ内でliを挿入してみる
     */
    @Test
    public void menu_li_Test() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        // 
        Li newli01 = new Li();
        newli01.setId("newli01");
        newli01.getContent().add("newli01!");
        html.insertAfterId("li2", newli01);
        // 
        List<Li> liList = html.getById("menu0", Menu.clreplaced).getDescendants(Li.clreplaced);
        replacedertEquals("newli01", liList.get(2).getId());
    }
}

18 View Complete Implementation : FormUtilTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced FormUtilTest {

    private String templateFileName = "FormUtilTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void populateFormTest() throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        // System.out.println(m2e.saveToString(html));
        Form form = html.getById("the_form", Form.clreplaced);
        Bean bean = new Bean();
        FormUtil.populateForm(form, bean);
        // hidden
        replacedertThat(form.getById("hidden1", Input.clreplaced).getValue(), is("bean_hidden1"));
        // text
        replacedertThat(form.getById("text1", Input.clreplaced).getValue(), is("bean_text1"));
        replacedertThat(form.getById("text2", Input.clreplaced).getValue(), is("bean_text2"));
        // textarea
        replacedertThat(form.getById("textarea1", Textarea.clreplaced).getContent(), is("bean_textarea1"));
        replacedertThat(form.getById("textarea2", Textarea.clreplaced).getContent(), is("bean_textarea2"));
        // select and option
        replacedertThat(form.getById("select1_option_a", Option.clreplaced).getValue(), is("option_a"));
        replacedertThat(form.getById("select1_option_a", Option.clreplaced).getSelected(), is("selected"));
        replacedertThat(form.getById("select1_option_b", Option.clreplaced).getValue(), is("option_b"));
        replacedertThat(form.getById("select1_option_b", Option.clreplaced).getSelected(), is(nullValue()));
        replacedertThat(form.getById("select1_option_c", Option.clreplaced).getValue(), is("option_c"));
        replacedertThat(form.getById("select1_option_c", Option.clreplaced).getSelected(), is(nullValue()));
        // select and option
        replacedertThat(form.getById("select1_option_a", Option.clreplaced).getValue(), is("option_a"));
        replacedertThat(form.getById("select2_option_a", Option.clreplaced).getSelected(), is(nullValue()));
        replacedertThat(form.getById("select1_option_b", Option.clreplaced).getValue(), is("option_b"));
        replacedertThat(form.getById("select2_option_b", Option.clreplaced).getSelected(), is("selected"));
        replacedertThat(form.getById("select1_option_c", Option.clreplaced).getValue(), is("option_c"));
        replacedertThat(form.getById("select2_option_c", Option.clreplaced).getSelected(), is("selected"));
        // radio1_radio_a
        replacedertThat(form.getById("radio1_radio_a", Input.clreplaced).getValue(), is("radio_a"));
        replacedertThat(form.getById("radio1_radio_a", Input.clreplaced).getChecked(), is(nullValue()));
        replacedertThat(form.getById("radio1_radio_b", Input.clreplaced).getValue(), is("radio_b"));
        replacedertThat(form.getById("radio1_radio_b", Input.clreplaced).getChecked(), is("checked"));
        replacedertThat(form.getById("radio1_radio_c", Input.clreplaced).getValue(), is("radio_c"));
        replacedertThat(form.getById("radio1_radio_c", Input.clreplaced).getChecked(), is(nullValue()));
        // checkbox1
        replacedertThat(form.getById("checkbox1_checkbox_a", Input.clreplaced).getValue(), is("checkbox_a"));
        replacedertThat(form.getById("checkbox1_checkbox_a", Input.clreplaced).getChecked(), is("checked"));
        replacedertThat(form.getById("checkbox1_checkbox_b", Input.clreplaced).getValue(), is("checkbox_b"));
        replacedertThat(form.getById("checkbox1_checkbox_b", Input.clreplaced).getChecked(), is(nullValue()));
        replacedertThat(form.getById("checkbox1_checkbox_c", Input.clreplaced).getValue(), is("checkbox_c"));
        replacedertThat(form.getById("checkbox1_checkbox_c", Input.clreplaced).getChecked(), is(nullValue()));
        // checkbox2
        replacedertThat(form.getById("checkbox2_checkbox_a", Input.clreplaced).getValue(), is("checkbox_a"));
        replacedertThat(form.getById("checkbox2_checkbox_a", Input.clreplaced).getChecked(), is(nullValue()));
        replacedertThat(form.getById("checkbox2_checkbox_b", Input.clreplaced).getValue(), is("checkbox_b"));
        replacedertThat(form.getById("checkbox2_checkbox_b", Input.clreplaced).getChecked(), is("checked"));
        replacedertThat(form.getById("checkbox2_checkbox_c", Input.clreplaced).getValue(), is("checkbox_c"));
        replacedertThat(form.getById("checkbox2_checkbox_c", Input.clreplaced).getChecked(), is("checked"));
        // checkbox3
        replacedertThat(form.getById("checkbox3", Input.clreplaced).getChecked(), is("checked"));
    }

    public clreplaced Bean {

        private String hidden1 = "bean_hidden1";

        private String text1 = "bean_text1";

        private String text2 = "bean_text2";

        private String textarea1 = "bean_textarea1";

        private String textarea2 = "bean_textarea2";

        private String select1 = "option_a";

        private String[] select2 = { "option_b", "option_c" };

        private String radio1 = "radio_b";

        private String radio2 = "radio_c";

        private String checkbox1 = "checkbox_a";

        private String[] checkbox2 = { "checkbox_b", "checkbox_c" };

        private boolean checkbox3 = true;

        public String getHidden1() {
            return hidden1;
        }

        public void setHidden1(String hidden1) {
            this.hidden1 = hidden1;
        }

        public String getText1() {
            return text1;
        }

        public void setText1(String text1) {
            this.text1 = text1;
        }

        public String getText2() {
            return text2;
        }

        public void setText2(String text2) {
            this.text2 = text2;
        }

        public String getTextarea1() {
            return textarea1;
        }

        public void setTextarea1(String textarea1) {
            this.textarea1 = textarea1;
        }

        public String getTextarea2() {
            return textarea2;
        }

        public void setTextarea2(String textarea2) {
            this.textarea2 = textarea2;
        }

        public String getSelect1() {
            return select1;
        }

        public void setSelect1(String select1) {
            this.select1 = select1;
        }

        public String[] getSelect2() {
            return select2;
        }

        public void setSelect2(String[] select2) {
            this.select2 = select2;
        }

        public String getRadio1() {
            return radio1;
        }

        public void setRadio1(String radio1) {
            this.radio1 = radio1;
        }

        public String getRadio2() {
            return radio2;
        }

        public void setRadio2(String radio2) {
            this.radio2 = radio2;
        }

        public String getCheckbox1() {
            return checkbox1;
        }

        public void setCheckbox1(String checkbox1) {
            this.checkbox1 = checkbox1;
        }

        public String[] getCheckbox2() {
            return checkbox2;
        }

        public void setCheckbox2(String[] checkbox2) {
            this.checkbox2 = checkbox2;
        }

        public boolean isCheckbox3() {
            return checkbox3;
        }

        public void setCheckbox3(boolean checkbox3) {
            this.checkbox3 = checkbox3;
        }
    }
}

18 View Complete Implementation : NullValueTest.java
Copyright Apache License 2.0
Author : nabedge
// Pタグの中身がnullだとreplaceByIdがおかしくなるっぽい件。
// まだうまくテストを実装できてない。
@Ignore
public clreplaced NullValueTest {

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Test
    public final void replaceById() throws Exception {
        StringBuilder sb = new StringBuilder();
        sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        sb.append("<body>");
        sb.append("<p id=\"foo\">bar</p>");
        sb.append("</body>");
        sb.append("</html>");
        Html html = m2e.loadHtmlTemplate(sb.toString());
        P nullP = TagCreator.pWithId("nullP");
        List<Object> list = new ArrayList<Object>();
        list.add(nullP);
        html.getBody().getContent().addAll(0, list);
        System.out.println(m2e.saveToString(html));
        html.replaceById("foo", TagCreator.spanWithId("xyz"));
        System.out.println(m2e.saveToString(html));
    }
}

18 View Complete Implementation : GetDescendantsTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced GetDescendantsTest {

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private String templateFileName = "GetDescendantsTest.html";

    private String templateFilePath;

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void getDescendants01() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<Span> spanList;
        spanList = html.getById("descTest", Div.clreplaced).getDescendants(Span.clreplaced);
        replacedertTrue(spanList.size() == 4);
        spanList = html.getDescendants("desc_foo", Span.clreplaced);
        replacedertTrue(spanList.size() == 2);
        replacedertTrue(spanList.get(0).getId().equals("desc_span01"));
        replacedertTrue(spanList.get(1).getContent().get(0).equals("bbb"));
    }

    @Test
    public void getDescendants02() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<AbstractJaxb> ajList;
        ajList = html.getById("descTest", Div.clreplaced).getDescendants("desc_bar");
        replacedertTrue(ajList.get(0).getClreplaced().equals(Li.clreplaced));
        replacedertTrue(((Li) ajList.get(0)).getContent().get(0).equals("desc_bar_li"));
        replacedertTrue(ajList.get(1).getClreplaced().equals(A.clreplaced));
        replacedertTrue(((A) ajList.get(1)).getContent().get(0).equals("example.com"));
        ajList = html.getById("descTest", Div.clreplaced).getDescendants("desc_foo_2");
        replacedertEquals(ajList.size(), 3);
        replacedertTrue(ajList.get(0).getClreplaced().equals(Tr.clreplaced));
        replacedertTrue(ajList.get(1).getClreplaced().equals(Td.clreplaced));
        replacedertTrue(ajList.get(2).getClreplaced().equals(Span.clreplaced));
    }

    @Test
    public void getDescendants_tbody() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Table table = html.getById("tbl", Table.clreplaced);
        List<Tbody> tbodyList;
        tbodyList = table.getDescendants(Tbody.clreplaced);
        replacedertEquals(2, tbodyList.size());
        tbodyList = table.getDescendants("tbody_clreplaced_b", Tbody.clreplaced);
        replacedertEquals(1, tbodyList.size());
    }
}

18 View Complete Implementation : PathAjusterTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced PathAjusterTest {

    private String templateFileName = "PathAjusterTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void testReplacePath() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        PathAdjuster.replacePath(html, Pattern.compile("^.*/foo/bar/"), "/ctx/foobar/");
        replacedertThat(html.getById("link01", Link.clreplaced).getHref(), is("/ctx/foobar/foo.css"));
        replacedertThat(html.getById("script01", Script.clreplaced).getSrc(), is("/ctx/foobar/foo.js"));
    }

    @Test
    public void testReplacePathIncludesClreplaced() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<String> clazz = new ArrayList<String>();
        clazz.add("foo");
        PathAdjuster.replacePathIncludeClreplaced(html, Pattern.compile("^.*$"), "zzz", clazz);
        replacedertThat(html.getById("track1", Track.clreplaced).getSrc(), is("zzz"));
        replacedertThat(html.getById("track2", Track.clreplaced).getSrc(), not("zzz"));
    }

    @Test
    public void testReplacePathIncludesTag() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<Clreplaced<?>> tagTypes = new ArrayList<Clreplaced<?>>();
        tagTypes.add(A.clreplaced);
        tagTypes.add(Form.clreplaced);
        PathAdjuster.replacePathIncludeTag(html, Pattern.compile(".*"), "zzz", tagTypes);
        replacedertThat(html.getById("track1", Track.clreplaced).getSrc(), not("zzz"));
        replacedertThat(html.getById("a_001", A.clreplaced).getHref(), is("zzz"));
        replacedertThat(html.getById("form01", Form.clreplaced).getAction(), is("zzz"));
    }

    @Test
    public void testReplacePathInclude() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<String> clazz = new ArrayList<String>();
        clazz.add("bar");
        List<Clreplaced<?>> tagTypes = new ArrayList<Clreplaced<?>>();
        tagTypes.add(Img.clreplaced);
        tagTypes.add(Iframe.clreplaced);
        PathAdjuster.replacePathInclude(html, Pattern.compile(".*"), "zzz", clazz, tagTypes);
        replacedertThat(html.getById("img_01", Img.clreplaced).getSrc(), is("xyz"));
        replacedertThat(html.getById("img_02", Img.clreplaced).getSrc(), is("zzz"));
        replacedertThat(html.getById("iframe_01", Iframe.clreplaced).getSrc(), is("zzz"));
        replacedertThat(html.getById("iframe_02", Iframe.clreplaced).getSrc(), is("example.html"));
    }

    @Test
    public void testReplacePathExcludeClreplaced() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<String> clazz = new ArrayList<String>();
        clazz.add("foo");
        PathAdjuster.replacePathExcludeClreplaced(html, Pattern.compile("^.*$"), "zzz", clazz);
        replacedertThat(html.getById("track1", Track.clreplaced).getSrc(), not("zzz"));
        replacedertThat(html.getById("track2", Track.clreplaced).getSrc(), is("zzz"));
    }

    @Test
    public void testReplacePathExcludesTag() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<Clreplaced<?>> tagTypes = new ArrayList<Clreplaced<?>>();
        tagTypes.add(Iframe.clreplaced);
        tagTypes.add(Form.clreplaced);
        PathAdjuster.replacePathExcludeTag(html, Pattern.compile(".*"), "zzz", tagTypes);
        replacedertThat(html.getById("track1", Track.clreplaced).getSrc(), is("zzz"));
        replacedertThat(html.getById("a_001", A.clreplaced).getHref(), is("zzz"));
        replacedertThat(html.getById("form01", Form.clreplaced).getAction(), not("zzz"));
        replacedertThat(html.getById("iframe_01", Iframe.clreplaced).getSrc(), not("zzz"));
    }

    @Test
    public void testReplacePathExclude() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        List<String> clazz = new ArrayList<String>();
        clazz.add("bar");
        List<Clreplaced<?>> tagTypes = new ArrayList<Clreplaced<?>>();
        tagTypes.add(Img.clreplaced);
        tagTypes.add(Iframe.clreplaced);
        PathAdjuster.replacePathExclude(html, Pattern.compile(".*"), "zzz", clazz, tagTypes);
        replacedertThat(html.getById("form01", Form.clreplaced).getAction(), is("zzz"));
        replacedertThat(html.getById("img_01", Img.clreplaced).getSrc(), is("zzz"));
        replacedertThat(html.getById("img_02", Img.clreplaced).getSrc(), not("zzz"));
        replacedertThat(html.getById("iframe_01", Iframe.clreplaced).getSrc(), not("zzz"));
        replacedertThat(html.getById("iframe_02", Iframe.clreplaced).getSrc(), is("zzz"));
        replacedertThat(html.getById("track1", Track.clreplaced).getSrc(), is("zzz"));
        replacedertThat(html.getById("track2", Track.clreplaced).getSrc(), is("zzz"));
    }
}

18 View Complete Implementation : PreAndScriptTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced PreAndScriptTest {

    private static Log log = LogFactory.getLog(PreAndScriptTest.clreplaced);

    private String templateFileName = "preAndScript.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void createNewScript() throws Exception {
        Script script = TagCreator.script();
        script.setType("text/javascript");
        script.setSrc("foo.js");
        // script.setContent("");
        String str = m2e.saveToString(script);
        // if error, NullPointerException !
        log.info(str);
    }

    @Test
    public void test() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        String xmlStr = m2e.saveToString(html);
        // log.info(xmlStr);
        Doreplacedent doc = Jsoup.parse(xmlStr);
        replacedertThat(doc.getElementById("fooJs").data(), is(" "));
    }

    @Test
    public void test2() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        String xmlStr = m2e.saveToString(html);
        replacedertTrue(xmlStr.contains("//<![CDATA["));
        replacedertTrue(xmlStr.contains("if (foo > 0 || bar < 100) {"));
        replacedertTrue(xmlStr.contains("//]]>"));
    }
}

18 View Complete Implementation : RemoveDescendantsTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced RemoveDescendantsTest {

    private String templateFileName = "RemoveDescendantsTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void removeScripts() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertNotNull(html.getById("fooscript1", Script.clreplaced));
        replacedertNotNull(html.getById("fooscript2", Script.clreplaced));
        replacedertNotNull(html.getById("fooscript3", Script.clreplaced));
        html.removeDescendants("fooscript", Script.clreplaced);
        replacedertNull(html.getById("fooscript1", Script.clreplaced));
        replacedertNotNull(html.getById("fooscript2", Script.clreplaced));
        replacedertNull(html.getById("fooscript3", Script.clreplaced));
    }

    @Test
    public void testRemoveDescendants() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        // 
        replacedertNotNull(html.getById("a1", A.clreplaced));
        replacedertNotNull(html.getById("a2", A.clreplaced));
        replacedertNotNull(html.getById("a3", A.clreplaced));
        html.removeDescendants(A.clreplaced);
        replacedertNull(html.getById("a1", A.clreplaced));
        replacedertNull(html.getById("a2", A.clreplaced));
        replacedertNull(html.getById("a3", A.clreplaced));
        // 
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.removeDescendants("foo", A.clreplaced);
        replacedertNull(html.getById("a1", A.clreplaced));
        replacedertNotNull(html.getById("a2", A.clreplaced));
        replacedertNull(html.getById("a3", A.clreplaced));
    }
}

18 View Complete Implementation : RemoveDescendants_html5Test.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced RemoveDescendants_html5Test {

    private String templateFileName = "RemoveDescendantsTest_html5.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    /**
     * タグとclreplacedを指定して削除
     * @throws IOException
     */
    @Test
    public void removeByTagAndClreplaced() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertNotNull(html.getById("header", Header.clreplaced));
        replacedertNotNull(html.getById("footer", Footer.clreplaced));
        replacedertNotNull(html.getById("figcaption1", Figcaption.clreplaced));
        replacedertNotNull(html.getById("figcaption2", Figcaption.clreplaced));
        html.removeDescendants("bbb", Figcaption.clreplaced);
        replacedertNotNull(html.getById("header", Header.clreplaced));
        replacedertNotNull(html.getById("footer", Footer.clreplaced));
        replacedertNotNull(html.getById("figcaption1", Figcaption.clreplaced));
        replacedertNull(html.getById("figcaption2", Figcaption.clreplaced));
    }

    /**
     * clreplacedを指定して削除
     * @throws IOException
     */
    @Test
    public void removeByCssClreplaced() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        // clreplaced="aaa bbb ccc"
        replacedertNotNull(html.getById("header", Header.clreplaced));
        // clreplaced=bbb ccc
        replacedertNotNull(html.getById("nav", Nav.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("area1", Area.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("area2", Area.clreplaced));
        // clreplaced=aaa ccc
        replacedertNotNull(html.getById("article1", Article.clreplaced));
        // clreplaced=aaa bbb
        replacedertNotNull(html.getById("section1", Section.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("bdi1", Bdi.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("bdi2", Bdi.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("bdo1", Bdo.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("bdo2", Bdo.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("pre1", Pre.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("figcaption1", Figcaption.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("figcaption2", Figcaption.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td1", Td.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("td2", Td.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td3", Td.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("td4", Td.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td5", Td.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("td6", Td.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td7", Td.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("td8", Td.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("footer", Footer.clreplaced));
        html.removeDescendants("bbb");
        // clreplaced="aaa bbb ccc"
        replacedertNull(html.getById("header", Header.clreplaced));
        // clreplaced=bbb ccc
        replacedertNull(html.getById("nav", Nav.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("area1", Area.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("area2", Area.clreplaced));
        // clreplaced=aaa ccc
        replacedertNotNull(html.getById("article1", Article.clreplaced));
        // clreplaced=aaa bbb
        replacedertNull(html.getById("section1", Section.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("bdi1", Bdi.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("bdi2", Bdi.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("bdo1", Bdo.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("bdo2", Bdo.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("pre1", Pre.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("figcaption1", Figcaption.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("figcaption2", Figcaption.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td1", Td.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("td2", Td.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td3", Td.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("td4", Td.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td5", Td.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("td6", Td.clreplaced));
        // clreplaced=aaa
        replacedertNotNull(html.getById("td7", Td.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("td8", Td.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("footer", Footer.clreplaced));
    }

    /**
     * タグを指定して削除
     * @throws IOException
     */
    @Test
    public void removeByTag() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        // clreplaced=aaa
        replacedertNotNull(html.getById("bdi1", Bdi.clreplaced));
        // clreplaced=bbb
        replacedertNotNull(html.getById("bdi2", Bdi.clreplaced));
        html.removeDescendants(Bdi.clreplaced);
        // clreplaced=aaa
        replacedertNull(html.getById("bdi1", Bdi.clreplaced));
        // clreplaced=bbb
        replacedertNull(html.getById("bdi2", Bdi.clreplaced));
    }
}

18 View Complete Implementation : AbstractMixer2XhtmlView.java
Copyright Apache License 2.0
Author : nabedge
/**
 * Abstract clreplaced to create view clreplaced for Spring MVC.
 * <p>
 * use this clreplaced with {@link Mixer2XhtmlViewResolver}
 * </p>
 *
 * <b>implementation sample</b>
 *
 * <pre><code>
 * public clreplaced HelloWorldView extends AbstractMixer2XhtmlView {
 *
 *    {@literal @}Autowired
 *    private FooBar fooBar;
 *
 *    {@literal @}Override
 *    protected Html renderHtml(Html html, Map<String, Object> model, HttpServletRequest request,
 *          HttpServletResponse response) throws TagTypeUnmatchException {
 *
 *        {@literal @}SuppressWarnings("unchecked")
 *        String message = (String) model.get("helloMessage");
 *        Div div = html.getById("message", Div.clreplaced);
 *        div.unsetContent();
 *        div.getContent().add(message);
 *
 *        return html;
 * }
 * </code></pre>
 *
 * <p>
 * You NEED NOT to add "@Component" annotation because
 * {@link Mixer2XhtmlViewResolver} instantiate the view clreplaced
 * through AutowireCapableBeanFactory.
 * </p>
 *
 * @see <a href="http://mixer2.org/site/helloworld.html">helloworld</a>
 * @see <a href="http://mixer2.org/site/springmvcsample.html">spring mvc sample</a>
 * @see <a href="https://github.com/nabedge/mixer2-sample/tree/master/mixer2-fruitshop-springboot">spring mvc sample code</a>
 * @author kazuki43zoo
 * @author nabedge
 */
public abstract clreplaced AbstractMixer2XhtmlView extends AbstractUrlBasedView {

    private static String lineBreakChar = System.getProperty("line.separator");

    protected ResourceLoader resourceLoader;

    protected String docType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

    protected Mixer2Engine mixer2Engine;

    public static final AbstractMixer2XhtmlView createDefaultView() {
        return new AbstractMixer2XhtmlView() {

            @Override
            protected Html renderHtml(Html templateHtml, Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
                return templateHtml;
            }
        };
    }

    public AbstractMixer2XhtmlView() {
        setContentType("text/html; charset=UTF-8");
    }

    public void setDocType(String docType) {
        this.docType = docType;
    }

    public String getDocType() {
        return docType;
    }

    public void setMixer2Engine(Mixer2Engine mixer2Engine) {
        this.mixer2Engine = mixer2Engine;
    }

    public Mixer2Engine getMixer2Engine() {
        return mixer2Engine;
    }

    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    public ResourceLoader setResourceLoader() {
        return resourceLoader;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        super.afterPropertiesSet();
        replacedert.notNull(mixer2Engine, "Property 'mixer2Engine' is required.");
        replacedert.notNull(resourceLoader, "Property 'resourceLoader' is required.");
    }

    @Override
    protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        Html templateHtml = mixer2Engine.checkAndLoadHtmlTemplate(resourceLoader.getResource(getUrl()).getInputStream());
        Html renderedHtml = renderHtml(templateHtml, model, request, response);
        response.setContentType(getContentType());
        responseHtml(renderedHtml, response);
    }

    protected void responseHtml(Html renderedHtml, HttpServletResponse response) throws IOException {
        PrintWriter writer = response.getWriter();
        StringBuilder sb = new StringBuilder();
        if (docType != null && !docType.trim().isEmpty()) {
            sb.append(docType.trim());
            sb.append(lineBreakChar);
        }
        sb.append(getMixer2Engine().saveToString(renderedHtml).trim());
        writer.write(modifyHtmlStringHook(sb.toString()));
    }

    /**
     * Override this method if you modify html as string right before http response.
     *
     * @param htmlString String object that is saveToString()ed by mixer2Engine.
     * @return
     */
    protected String modifyHtmlStringHook(String htmlString) {
        return htmlString;
    }

    /**
     * Need implementation.
     *
     * @param html
     *            {@link org.mixer2.jaxb.xhtml.Html Html} instance of xhtml
     *            template that is loaded by {@link Mixer2XhtmlViewResolver}.
     * @param model
     * @param request
     * @param response
     * @return
     * @throws Exception
     * {@link Mixer2XhtmlViewResolver}
     */
    protected abstract Html renderHtml(Html html, Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception;
}

18 View Complete Implementation : RemoveInnerTest.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author nabedge/watanabe
 */
public clreplaced RemoveInnerTest {

    private String templateFileName = "RemoveInnerTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    /**
     * divタグの中身を削除してみる
     *
     * @throws Exception
     */
    @Test
    public void removeInnerDiv() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Div mainDiv = html.getById("main", Div.clreplaced);
        replacedertTrue(mainDiv.getContent().size() > 0);
        mainDiv.removeInner();
        replacedertTrue(mainDiv.getContent().size() == 0);
        replacedertNotNull(html.getById("main", Div.clreplaced));
    }

    @Test
    public void removeInnerTable() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Table tbl = html.getById("tbl", Table.clreplaced);
        replacedertTrue(tbl.getTbody().size() > 0);
        replacedertTrue(tbl.isSetThead());
        replacedertTrue(tbl.isSetTfoot());
        tbl.removeInner();
        replacedertFalse(tbl.getTbody().size() > 0);
        replacedertFalse(tbl.isSetThead());
        replacedertFalse(tbl.isSetTfoot());
    }
}

18 View Complete Implementation : InsertById_html5Test.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced InsertById_html5Test {

    private String templateFileName = "InsertById_html5.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    /**
     * hgroupタグの後にpタグを挿入
     */
    @Test
    public void insertAfterHgroup() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        P p = pWithId("p1");
        p.getContent().add("paragraph");
        html.insertAfterId("hgroup1", p);
        // html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        List<Object> objList = html.getById("header1", Header.clreplaced).getContent();
        for (Lisreplacederator<Object> i = objList.lisreplacederator(); i.hasNext(); ) {
            Object obj = i.next();
            if (obj instanceof Hgroup) {
                replacedertEquals("p1", ((P) i.next()).getId());
                break;
            }
        }
    }

    /**
     * hgroupタグの後にpタグを挿入
     */
    @Test
    public void insertBeforeHgroup() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        P p = pWithId("p1");
        p.getContent().add("paragraph");
        html.insertBeforeId("hgroup1", p);
        List<Object> objList = html.getById("header1", Header.clreplaced).getContent();
        for (int i = 0; i < objList.size(); i++) {
            if (objList.get(i) instanceof Hgroup) {
                replacedertEquals("p1", ((P) objList.get(i - 1)).getId());
                break;
            }
        }
    }

    @Test
    public void insertAfterDummyBr() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.insertAfterId("dummy_br", "test");
        List<Object> list = html.getById("footer", Footer.clreplaced).getContent();
        for (int i = 0; i < list.size(); i++) {
            java.lang.Object obj = list.get(i);
            if (obj instanceof Br) {
                replacedertEquals(list.get(i + 1), "test");
                break;
            }
        }
    }
}

18 View Complete Implementation : RemoveDescendants02Test.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced RemoveDescendants02Test {

    private String templateFileName = "RemoveDescendantsTest02.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void testRemoveDescendants() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Html html01 = html.copy(Html.clreplaced);
        replacedertNotNull(html01.getById("dd1", Dd.clreplaced));
        replacedertNotNull(html01.getById("dd2", Dd.clreplaced));
        html01.removeDescendants(Dd.clreplaced);
        replacedertNull(html01.getById("dd1", Dd.clreplaced));
        replacedertNull(html01.getById("dd2", Dd.clreplaced));
        Html html02 = html.copy(Html.clreplaced);
        replacedertNotNull(html02.getById("dd1", Dd.clreplaced));
        replacedertNotNull(html02.getById("dd2", Dd.clreplaced));
        html02.removeDescendants("foo", Dd.clreplaced);
        replacedertNull(html02.getById("dd1", Dd.clreplaced));
        replacedertNotNull(html02.getById("dd2", Dd.clreplaced));
        Html html03 = html.copy(Html.clreplaced);
        replacedertNotNull(html03.getById("li1", Li.clreplaced));
        replacedertNotNull(html03.getById("li2", Li.clreplaced));
        replacedertNotNull(html03.getById("li3", Li.clreplaced));
        replacedertNotNull(html03.getById("li4", Li.clreplaced));
        replacedertNotNull(html03.getById("img1", Img.clreplaced));
        replacedertNotNull(html03.getById("img2", Img.clreplaced));
        replacedertNotNull(html03.getById("h1", H1.clreplaced));
        replacedertNotNull(html03.getById("h2", H2.clreplaced));
        replacedertNotNull(html03.getById("h3", H3.clreplaced));
        replacedertNotNull(html03.getById("h4", H4.clreplaced));
        replacedertNotNull(html03.getById("h5", H5.clreplaced));
        replacedertNotNull(html03.getById("h6", H6.clreplaced));
        replacedertNotNull(html03.getById("dt1", Dt.clreplaced));
        replacedertNotNull(html03.getById("dd1", Dd.clreplaced));
        replacedertNotNull(html03.getById("dd2", Dd.clreplaced));
        html03.removeDescendants("bar");
        replacedertNotNull(html03.getById("li1", Li.clreplaced));
        replacedertNull(html03.getById("li2", Li.clreplaced));
        replacedertNotNull(html03.getById("li3", Li.clreplaced));
        replacedertNull(html03.getById("li4", Li.clreplaced));
        replacedertNotNull(html03.getById("img1", Img.clreplaced));
        replacedertNull(html03.getById("img2", Img.clreplaced));
        replacedertNotNull(html03.getById("h1", H1.clreplaced));
        replacedertNotNull(html03.getById("h2", H2.clreplaced));
        replacedertNotNull(html03.getById("h3", H3.clreplaced));
        replacedertNotNull(html03.getById("h4", H4.clreplaced));
        replacedertNotNull(html03.getById("h5", H5.clreplaced));
        replacedertNull(html03.getById("h6", H6.clreplaced));
        replacedertNotNull(html03.getById("dt1", Dt.clreplaced));
        replacedertNotNull(html03.getById("dd1", Dd.clreplaced));
        replacedertNull(html03.getById("dd2", Dd.clreplaced));
    }
}

18 View Complete Implementation : Remove_html5Test.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author jfut
 * @author watanabe
 */
public clreplaced Remove_html5Test {

    private String templateFileName = "RemoveTest_html5.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    /**
     * idのないheaderタグを削除してみる
     * @throws Exception
     */
    @Test
    public void removeHeaderToOtherHeader() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getDescendants(Header.clreplaced).size());
        Header header = html.getDescendants(Header.clreplaced).get(0);
        boolean result = html.remove(header);
        replacedertEquals(true, result);
        replacedertEquals(0, html.getDescendants(Header.clreplaced).size());
    }

    /**
     * idのないhgroupタグを親要素のheaderを起点に削除してみる
     * @throws Exception
     */
    @Test
    public void removeHgroupFromHeader() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getDescendants(Header.clreplaced).size());
        Header header = html.getDescendants(Header.clreplaced).get(0);
        replacedertEquals(1, html.getDescendants(Hgroup.clreplaced).size());
        Hgroup hgroup = html.getDescendants(Hgroup.clreplaced).get(0);
        boolean result = header.remove(hgroup);
        replacedertEquals(true, result);
        replacedertEquals(1, html.getDescendants(Header.clreplaced).size());
        replacedertEquals(0, html.getDescendants(Hgroup.clreplaced).size());
    }

    /**
     * idのないheaderタグを違う親要素のhtmlを起点に削除してみる
     * @throws IOException
     */
    @Test
    public void removeFail() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getDescendants(Header.clreplaced).size());
        Header header = html.getDescendants(Header.clreplaced).get(0);
        replacedertEquals(3, header.getContent().size());
        Html otherHtml = new Html();
        boolean result = otherHtml.remove(header);
        replacedertEquals(false, result);
        replacedertEquals(1, html.getDescendants(Header.clreplaced).size());
        Header notReplacedHeader = html.getDescendants(Header.clreplaced).get(0);
        replacedertEquals(3, notReplacedHeader.getContent().size());
    }
}

18 View Complete Implementation : Mixer2XhtmlViewResolverTest.java
Copyright Apache License 2.0
Author : nabedge
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration(loader = AnnotationConfigContextLoader.clreplaced)
public clreplaced Mixer2XhtmlViewResolverTest {

    private static Log log = LogFactory.getLog(Mixer2XhtmlViewResolverTest.clreplaced);

    @Configuration
    static clreplaced ContextConfiguration {

        @Bean
        public Mixer2Engine mixer2Engine() {
            return new Mixer2Engine();
        }

        @Bean
        public Mixer2XhtmlViewResolver mixer2XhtmlViewResolver() {
            Mixer2XhtmlViewResolver resolver = new Mixer2XhtmlViewResolver();
            resolver.setOrder(1);
            resolver.setPrefix("clreplacedpath:org/mixer2/spring/webmvc/");
            resolver.setSuffix(".html");
            resolver.setBasePackage("org.mixer2.spring.webmvc");
            resolver.setMixer2Engine(mixer2Engine());
            return resolver;
        }
    }

    @Autowired
    private Mixer2Engine mixer2Engine;

    @Autowired
    private Mixer2XhtmlViewResolver resolver;

    @Test
    public final void useAbstractMixer2XhtmlViewAsDefault() throws Exception {
        AbstractUrlBasedView view = resolver.buildView("HelloWorld");
        replacedertTrue(view instanceof AbstractMixer2XhtmlView);
        AbstractMixer2XhtmlView m2View = (AbstractMixer2XhtmlView) view;
        Map<String, Object> model = new HashMap<String, Object>();
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        m2View.renderMergedOutputModel(model, request, response);
        Html html = mixer2Engine.loadHtmlTemplate(response.getContentreplacedtring());
        Div div = html.getBody().getById("hellomsg", Div.clreplaced);
        String msg = div.getContent().get(0).toString().trim();
        replacedertThat(msg, is("Hello World !"));
    }

    @Test
    public final void useImplementedView() throws Exception {
        AbstractUrlBasedView view = resolver.buildView("Mixer2XhtmlViewResolverTest");
        replacedertTrue(view instanceof Mixer2XhtmlViewResolverTestView);
        Mixer2XhtmlViewResolverTestView m2View = (Mixer2XhtmlViewResolverTestView) view;
        Map<String, Object> model = new HashMap<String, Object>();
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        m2View.renderMergedOutputModel(model, request, response);
        Html html = mixer2Engine.loadHtmlTemplate(response.getContentreplacedtring());
        Span span = html.getBody().getById("newSpan", Span.clreplaced);
        replacedertThat(span.getContent().get(0).toString(), is("new span"));
    }

    @Test
    public final void pathSeparatedTest() throws Exception {
        AbstractUrlBasedView view = resolver.buildView("foo/bar");
        replacedertTrue(view instanceof BarView);
        BarView barView = (BarView) view;
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("barMessage", "Hello Bar !");
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        barView.renderMergedOutputModel(model, request, response);
        Html html = mixer2Engine.loadHtmlTemplate(response.getContentreplacedtring());
        Span span = html.getBody().getById("barSpan", Span.clreplaced);
        replacedertThat(span.getContent().get(0).toString(), is("Hello Bar !"));
    }

    @Test(expected = ClreplacedNotFoundException.clreplaced)
    public final void viewClreplacedNotFoundTest() throws Exception {
        resolver.setRaiseErrorIfViewClreplacedNotFound(true);
        AbstractUrlBasedView existsView = resolver.buildView("foo/bar");
        replacedert.replacedertNotNull(existsView);
        // raise exception.
        resolver.buildView("nonExistsViewClazzzzzzz");
    }

    @Test
    public final void viewClreplacedNotFoundTest2() throws Exception {
        resolver.setRaiseErrorIfViewClreplacedNotFound(false);
        AbstractUrlBasedView existsView = resolver.buildView("foo/bar");
        replacedert.replacedertNotNull(existsView);
        AbstractUrlBasedView defaultView = resolver.buildView("nonExistsViewClazzzzzzz");
        replacedert.replacedertNotNull(defaultView);
        log.trace("");
    }
}

18 View Complete Implementation : ReplaceById02Test.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author watanabe
 */
public clreplaced ReplaceById02Test {

    private String templateFileName = "ReplaceByIdTest02.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test1() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Img img = img();
        img.setId("newimg");
        img.setSrc("new.png");
        replacedertNotNull(html.getById("img1", Img.clreplaced));
        // 
        html.replaceById("img1", img);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        // 
        replacedertNull(html.getById("img1", Img.clreplaced));
        replacedertNotNull(html.getById("newimg", Img.clreplaced));
    }

    @Test(expected = TagTypeUnmatchException.clreplaced)
    public void test2() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertNotNull(html.getById("li1", Li.clreplaced));
        replacedertEquals("li1", html.getById("li1", Li.clreplaced).getContent().get(0));
        Li li = li();
        li.setId("li1");
        li.getContent().add("new li1");
        // 
        html.replaceById("li1", li);
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        // 
        replacedertNotNull(html.getById("li1", Li.clreplaced));
        String str = (String) html.getById("li1", Li.clreplaced).getContent().get(0);
        replacedertEquals("new li1", str.trim());
        Div div = div();
        div.getContent().add("aaa");
        html.replaceById("li1", div);
        fail("ulの下のliをdivで置換しようとしているため例外が発生するはず");
    }
}

18 View Complete Implementation : TableBuilderTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced TableBuilderTest {

    @SuppressWarnings("unused")
    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Test
    public void colSpanTest() throws Exception {
        Map<String, Object> attrMap = new HashMap<String, Object>();
        attrMap.put("id", "fooId");
        attrMap.put("colspan", new Integer(2));
        TableBuilder tb = new TableBuilder();
        tb.addTr().addTd("a").addTd("b");
        tb.addTr().addTd("c", attrMap);
        Table table = tb.build();
        replacedertEquals(2, table.getById("fooId", Td.clreplaced).getColspan());
    }

    @Test
    public void methodChainTest1() throws Exception {
        TableBuilder tBuilder = new TableBuilder();
        tBuilder.tr(0).addTd("foo").addTd("bar");
        Table table = tBuilder.build();
        Td td00 = table.getTr().get(0).getThOrTd().get(0).cast(Td.clreplaced);
        Td td01 = table.getTr().get(0).getThOrTd().get(1).cast(Td.clreplaced);
        replacedertEquals("foo", td00.getContent().get(0));
        replacedertEquals("bar", td01.getContent().get(0));
    // m2e.saveToString(table);
    }

    @Test
    public void methodChainTest2() throws Exception {
        ArrayList<Object> tdList0 = new ArrayList<Object>();
        tdList0.add("td00");
        tdList0.add("td01");
        ArrayList<Object> tdList1 = new ArrayList<Object>();
        tdList1.add("td10");
        tdList1.add("td11");
        TableBuilder tBuilder = new TableBuilder();
        tBuilder.addTr(tdList0).addTr(tdList1);
        Table table = tBuilder.build();
        // 
        Td td00 = table.getTr().get(0).getThOrTd().get(0).cast(Td.clreplaced);
        Td td01 = table.getTr().get(0).getThOrTd().get(1).cast(Td.clreplaced);
        Td td10 = table.getTr().get(1).getThOrTd().get(0).cast(Td.clreplaced);
        Td td11 = table.getTr().get(1).getThOrTd().get(1).cast(Td.clreplaced);
        replacedertEquals("td00", td00.getContent().get(0));
        replacedertEquals("td01", td01.getContent().get(0));
        replacedertEquals("td10", td10.getContent().get(0));
        replacedertEquals("td11", td11.getContent().get(0));
    }

    @Test
    public void methodChainTest3() throws Exception {
        TableBuilder tBuilder = new TableBuilder();
        tBuilder.tr(0).addTd("tr0_td0").addTd("tr0_td1");
        tBuilder.addTr().addTd("tr1_td0").addTd("tr1_td1");
        tBuilder.tbody(0).addTr().addTd("tbody0_tr0_td0").addTd("tbody0_tr0_td1");
        tBuilder.addTbody().addTr().addTd("tbody1_tr0_td0").addTd("tbody1_tr0_td1");
        tBuilder.thead.addTr().addTd("thead_tr0_td0").addTd("thead_tr0_td1");
        tBuilder.thead.tr(1).addTd("thead_tr1_td0").addTd("thead_tr1_td1");
        tBuilder.tfoot.addTr().addTd("tfoot_tr0_td0").addTd("tfoot_tr0_td1");
        tBuilder.tfoot.tr(1).addTd("tfoot_tr1_td0").addTd("tfoot_tr1_td1");
        Table table = tBuilder.build();
        table.setBorder(1);
        // System.out.println(m2e.saveToString(table));
        replacedertEquals("tr1_td0", table.getTr().get(1).getThOrTd().get(0).getContent().get(0));
        replacedertEquals("tbody0_tr0_td1", table.getTbody().get(0).getTr().get(0).getThOrTd().get(1).getContent().get(0));
        replacedertEquals("thead_tr1_td1", table.getThead().getTr().get(1).getThOrTd().get(1).getContent().get(0));
        replacedertEquals("tfoot_tr0_td0", table.getTfoot().getTr().get(0).getThOrTd().get(0).getContent().get(0));
    }

    @Test
    public void makeCellTest() throws Exception {
        Span span1 = new Span();
        span1.getContent().add("span1");
        Span span2 = new Span();
        span2.getContent().add("span2");
        TableBuilder tbuilder = new TableBuilder();
        // col1, row1
        tbuilder.tr(0).td(0).add("aaa");
        HashMap<String, Object> attrMap = new HashMap<String, Object>();
        attrMap.put("id", "id1");
        ArrayList<String> cssClreplaced = new ArrayList<String>();
        cssClreplaced.add("clreplaced_1");
        cssClreplaced.add("clreplaced_2");
        attrMap.put("clreplaced", cssClreplaced);
        attrMap.put("style", "font-size:larger;");
        attrMap.put("replacedle", "replacedle1");
        tbuilder.tr(0).td(0).setAttr(attrMap);
        tbuilder.tr(0).td(0).add(span1);
        // col2, row1
        tbuilder.tr(0).td(1).add("bbb");
        // col1 row2
        tbuilder.tr(1).td(0).add("ccc");
        // col2 row2
        tbuilder.tr(1).td(1).add("ddd");
        tbuilder.tr(1).td(1).add(span2);
        Table table = tbuilder.build();
        // 
        // System.out.println(m2e.saveToString(table));
        // col1, row1
        Td td1 = table.getTr().get(0).getThOrTd().get(0).cast(Td.clreplaced);
        // // attr
        replacedertEquals("id1", td1.getId());
        replacedertEquals("clreplaced_1", td1.getCssClreplaced().get(0));
        replacedertEquals("clreplaced_2", td1.getCssClreplaced().get(1));
        replacedertEquals("font-size:larger;", td1.getStyle());
        replacedertEquals("replacedle1", td1.getreplacedle());
        // // content
        replacedertEquals("aaa", td1.getContent().get(0));
        replacedertEquals("span1", ((Span) td1.cast(Td.clreplaced).getContent().get(1)).getContent().get(0));
        // col2, row1
        replacedertEquals("bbb", table.getTr().get(0).getThOrTd().get(1).cast(Td.clreplaced).getContent().get(0));
        // col1, row2
        replacedertEquals("ccc", table.getTr().get(1).getThOrTd().get(0).cast(Td.clreplaced).getContent().get(0));
        // col2, row2
        replacedertEquals("ddd", table.getTr().get(1).getThOrTd().get(1).cast(Td.clreplaced).getContent().get(0));
        replacedertEquals("span2", ((Span) table.getTr().get(1).getThOrTd().get(1).cast(Td.clreplaced).getContent().get(1)).getContent().get(0));
    }

    @Test
    public void addCellTest() throws Exception {
        TableBuilder tBuilder = new TableBuilder();
        // col0 row0
        tBuilder.tr(0).addTd("aaa");
        // col1 row0
        Span span1 = new Span();
        span1.getContent().add("span1");
        HashMap<String, Object> attrMap = new HashMap<String, Object>();
        attrMap.put("id", "id1");
        tBuilder.tr(0).addTd(span1, attrMap);
        // col0 row1
        HashMap<String, Object> attrMap2 = new HashMap<String, Object>();
        attrMap2.put("id", "id2");
        tBuilder.tr(1).addTd("bbb", attrMap2);
        // col1 row1
        Span span2 = new Span();
        span2.getContent().add("span2");
        tBuilder.tr(1).addTd(span2);
        // 
        Table table = tBuilder.build();
        // 
        // System.out.println(m2e.saveToString(table));
        // 
        Td td00 = table.getTr().get(0).getThOrTd().get(0).cast(Td.clreplaced);
        replacedertEquals("aaa", td00.getContent().get(0));
        // 
        Td td01 = table.getTr().get(0).getThOrTd().get(1).cast(Td.clreplaced);
        replacedertEquals("id1", td01.getId());
        replacedertEquals("span1", ((Span) td01.getContent().get(0)).getContent().get(0));
        // Td td10
        Td td10 = table.getTr().get(1).getThOrTd().get(0).cast(Td.clreplaced);
        replacedertEquals("id2", td10.getId());
        replacedertEquals("bbb", td10.getContent().get(0));
        // 
        Td td11 = table.getTr().get(1).getThOrTd().get(1).cast(Td.clreplaced);
        replacedertEquals("span2", ((Span) td11.getContent().get(0)).getContent().get(0));
    }

    @Test
    public void addRowTest() throws Exception {
        TableBuilder tBuilder = new TableBuilder();
        ArrayList<Object> tdList0 = new ArrayList<Object>();
        // 
        tdList0.add("aaa");
        // 
        Div div0 = new Div();
        div0.getContent().add("div0");
        tdList0.add(div0);
        // 
        tBuilder.addTr(tdList0);
        // 
        ArrayList<Object> tdList1 = new ArrayList<Object>();
        tdList1.add("ccc");
        tdList1.add("ddd");
        HashMap<String, Object> attrMap = new HashMap<String, Object>();
        attrMap.put("id", "id_foo");
        tBuilder.addTr(tdList1, attrMap);
        // 
        Table table = tBuilder.build();
        // System.out.println(m2e.saveToString(table));
        // 
        Td td00 = table.getTr().get(0).getThOrTd().get(0).cast(Td.clreplaced);
        replacedertEquals("aaa", td00.getContent().get(0));
        // 
        Td td01 = table.getTr().get(0).getThOrTd().get(1).cast(Td.clreplaced);
        replacedertEquals("div0", ((Div) td01.getContent().get(0)).getContent().get(0));
        // 
        Tr tr = table.getTr().get(1);
        replacedertEquals("id_foo", tr.getId());
    }

    @Test
    public void tbodyTest() throws Exception {
        ArrayList<Object> tdList0 = new ArrayList<Object>();
        tdList0.add("aaa");
        tdList0.add("bbb");
        ArrayList<Object> tdList1 = new ArrayList<Object>();
        tdList1.add("ccc");
        tdList1.add("ddd");
        List<List<Object>> data = new ArrayList<List<Object>>();
        data.add(tdList0);
        data.add(tdList1);
        HashMap<String, Object> attrMap = new HashMap<String, Object>();
        attrMap.put("id", "tbody1");
        // 
        TableBuilder tBuilder = new TableBuilder();
        tBuilder.tbody(0).tr(0).td(0).add("foo");
        tBuilder.tbody(0).tr(0).td(1).add("bar");
        tBuilder.addTbody(data, attrMap);
        Table table = tBuilder.build();
        // 
        // System.out.println(m2e.saveToString(table));
        replacedertEquals("tbody1", table.getTbody().get(1).getId());
        replacedertEquals("ddd", table.getTbody().get(1).getTr().get(1).getThOrTd().get(1).cast(Td.clreplaced).getContent().get(0));
    }

    @Test
    public void nullDataTest() {
        TableBuilder tBuilder = new TableBuilder();
        Table table = tBuilder.build();
        // NullPointerExceptionなどが発生しなければOK
        replacedertNotNull(table);
    // System.out.println(m2e.saveToString(table));
    }

    @Test
    public void theadTest() throws Exception {
        TableBuilder tBuilder = new TableBuilder();
        ArrayList<Object> tdList0 = new ArrayList<Object>();
        tdList0.add("aaa");
        tdList0.add("bbb");
        // 
        tBuilder.thead.tr(0).addTd("foo").addTd("bar");
        tBuilder.thead.addTr(tdList0);
        tBuilder.thead.setAttr("id", "thead_00");
        Table table = tBuilder.build();
        // 
        replacedertEquals("bar", table.getThead().getTr().get(0).getThOrTd().get(1).cast(Td.clreplaced).getContent().get(0));
        replacedertEquals("thead_00", table.getThead().getId());
    }

    @Test
    public void tfootTest() throws Exception {
        TableBuilder tBuilder = new TableBuilder();
        ArrayList<Object> tdList0 = new ArrayList<Object>();
        tdList0.add("aaa");
        tdList0.add("bbb");
        // 
        tBuilder.tfoot.tr(0).addTd("foo").addTd("bar");
        tBuilder.tfoot.addTr(tdList0);
        tBuilder.tfoot.setAttr("id", "tfoot_00");
        Table table = tBuilder.build();
        // 
        replacedertEquals("bar", table.getTfoot().getTr().get(0).getThOrTd().get(1).cast(Td.clreplaced).getContent().get(0));
        replacedertEquals("tfoot_00", table.getTfoot().getId());
    // System.out.println(m2e.saveToString(table));
    }

    @Test
    public void cssClreplacedTest() throws Exception {
        TableBuilder tBuilder = new TableBuilder();
        tBuilder.tr(0).setAttr("clreplaced", "clreplaced_a1 clreplaced_a2    ");
        tBuilder.tr(0).td(0).add("a");
        String[] clreplacedArray = new String[] { "clreplaced_b1", "clreplaced_b2" };
        tBuilder.tr(1).td(0).add("b");
        tBuilder.tr(1).td(0).setAttr("clreplaced", Arrays.asList(clreplacedArray));
        tBuilder.tr(1).td(0).setAttr("replacedle", "replacedle_b");
        Table table = tBuilder.build();
        // System.out.println(m2e.saveToString(table));
        replacedertEquals("clreplaced_a1", table.getTr().get(0).getCssClreplaced().get(0));
        replacedertEquals("clreplaced_a2", table.getTr().get(0).getCssClreplaced().get(1));
        replacedertEquals("a", table.getTr().get(0).getThOrTd().get(0).cast(Td.clreplaced).getContent().get(0));
        replacedertEquals("clreplaced_b1", table.getTr().get(1).getThOrTd().get(0).cast(Td.clreplaced).getCssClreplaced().get(0));
        replacedertEquals("clreplaced_b2", table.getTr().get(1).getThOrTd().get(0).cast(Td.clreplaced).getCssClreplaced().get(1));
        replacedertEquals("replacedle_b", table.getTr().get(1).getThOrTd().get(0).cast(Td.clreplaced).getreplacedle());
        replacedertEquals("b", table.getTr().get(1).getThOrTd().get(0).cast(Td.clreplaced).getContent().get(0));
    }
}

18 View Complete Implementation : CssClassTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced CssClreplacedTest {

    private String templateFileName = "CssClreplacedTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test() throws IOException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Span span = html.getById("test1", Span.clreplaced);
        replacedertEquals(span.hasCssClreplaced("aaa"), true);
        replacedertEquals(span.hasCssClreplaced("bbb"), true);
        replacedertEquals(span.hasCssClreplaced("ccc"), true);
        replacedertEquals(span.hasCssClreplaced("ddd"), false);
        span.removeCssClreplaced("bbb");
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertEquals(span.hasCssClreplaced("aaa"), true);
        replacedertEquals(span.hasCssClreplaced("bbb"), false);
        replacedertEquals(span.hasCssClreplaced("ccc"), true);
        span.addCssClreplaced("ddd");
        html = m2e.loadHtmlTemplate(m2e.saveToString(html));
        replacedertEquals(span.hasCssClreplaced("aaa"), true);
        replacedertEquals(span.hasCssClreplaced("bbb"), false);
        replacedertEquals(span.hasCssClreplaced("ccc"), true);
        replacedertEquals(span.hasCssClreplaced("ddd"), true);
    }
}

18 View Complete Implementation : RemoveTest.java
Copyright Apache License 2.0
Author : nabedge
/**
 * @author jfut
 * @author watanabe
 */
public clreplaced RemoveTest {

    private String templateFileName = "RemoveTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws Exception {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    /**
     * idのないdivタグを削除してみる
     *
     * @throws Exception
     */
    @Test
    public void removeDiv() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getDescendants("dummy", Div.clreplaced).size());
        Div dummyDiv = html.getDescendants("dummy", Div.clreplaced).get(0);
        boolean result = html.remove(dummyDiv);
        replacedertEquals(true, result);
        replacedertEquals(0, html.getDescendants("dummy", Div.clreplaced).size());
    }

    /**
     * idのないdivタグを親要素のbodyを起点に削除してみる
     * @throws Exception
     */
    @Test
    public void removeDivFromBody() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getDescendants(Body.clreplaced).size());
        replacedertEquals(1, html.getDescendants("dummy", Div.clreplaced).size());
        Body body = html.getBody();
        Div dummyDiv = html.getDescendants("dummy", Div.clreplaced).get(0);
        boolean result = body.remove(dummyDiv);
        replacedertEquals(true, result);
        replacedertEquals(0, html.getDescendants("dummy", Div.clreplaced).size());
    }

    /**
     * idのないdivタグを違う親要素のhtmlを起点に削除してみる
     * @throws Exception
     */
    @Test
    public void removeFail() throws Exception {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        replacedertEquals(1, html.getDescendants("dummy", Div.clreplaced).size());
        Html otherHtml = new Html();
        Div dummyDiv = html.getDescendants("dummy", Div.clreplaced).get(0);
        boolean result = otherHtml.remove(dummyDiv);
        replacedertEquals(false, result);
        replacedertEquals(1, html.getDescendants("dummy", Div.clreplaced).size());
    }
}

18 View Complete Implementation : Mixer2XhtmlViewResolver.java
Copyright Apache License 2.0
Author : nabedge
/**
 * View Resolver for SpringMVC .<br>
 * your should add dependency for your application:
 *
 * <pre>{@code
 * <dependency>
 *     <groupId>org.springframework</groupId>
 *     <artifactId>spring-webmvc</artifactId>
 *     <version>3.1.2.RELEASE (or higher)</version>
 * </dependency>
 * }</pre>
 *
 * <b>Spring MVC configuration Sample</b>
 *
 * <pre>{@code
 * <bean id="mixer2Engine" clreplaced="org.mixer2.Mixer2Engine" />
 * <bean clreplaced="org.mixer2.springmvc.Mixer2XhtmlViewResolver">
 *     <property name="mixer2Engine" ref="mixer2Engine" />
 *     <property name="order" value="1" />
 * </bean>
 * <bean clreplaced="org.springframework.web.servlet.view.InternalResourceViewResolver">
 *      <property name="order" value="2" />
 * </bean>
 * }</pre>
 *
 * <p>
 * Using this ViewResolver,
 * Your controller method can returns
 * <strong>view clreplaced name as String</strong>.<br>
 * See also {@link AbstractMixer2XhtmlView}.
 * </p>
 *
 * <pre><code>
 * {@literal @}Controller
 * public clreplaced HelloWorldController {
 *
 *  {@literal @}Autowired
 *  protected helloMessageService helloMessageService;
 *
 *  {@literal @}RequestMapping(value = "/hello", method = RequestMethod.GET)
 *  public String showHello({@literal @}PathVariable long itemId, Model model) {
 *      String helloMessage = helloMessageService.getMessage();
 *      model.addAttribute("helloMessage", helloMessage);
 *      return "helloWorldView"; // attach "HelloWorldView" clreplaced.
 *  }
 * }
 * </code></pre>
 *
 * @deprecated use {@link org.mixer2.spring.webmvc.Mixer2XhtmlViewResolver}
 * @see AbstractMixer2XhtmlView
 * @author nabedge
 */
@Deprecated
public clreplaced Mixer2XhtmlViewResolver extends WebApplicationObjectSupport implements ViewResolver, Ordered {

    protected Mixer2Engine mixer2Engine;

    private static Log log = LogFactory.getLog(Mixer2XhtmlViewResolver.clreplaced);

    private int order = Integer.MAX_VALUE;

    @Override
    public View resolveViewName(String viewName, Locale locale) {
        WebApplicationContext wac = getWebApplicationContext();
        AbstractMixer2XhtmlView view = null;
        try {
            view = wac.getBean(viewName, AbstractMixer2XhtmlView.clreplaced);
            view.setMixer2Engine(mixer2Engine);
            view.setLocale(locale);
        } catch (BeansException e) {
            log.debug(e.getMessage());
            return null;
        }
        return view;
    }

    @Override
    public int getOrder() {
        return this.order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public void setMixer2Engine(Mixer2Engine mixer2Engine) {
        this.mixer2Engine = mixer2Engine;
    }

    public Mixer2Engine getMixer2Engine() {
        return this.mixer2Engine;
    }
}

18 View Complete Implementation : EmptyTextAreaTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced EmptyTextAreaTest {

    @SuppressWarnings("unused")
    private static Log log = LogFactory.getLog(EmptyTextAreaTest.clreplaced);

    private String templateFileName = "emptyTextArea.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        if (SystemUtils.IS_OS_WINDOWS) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test() throws Exception {
        File file = new File(templateFilePath);
        Html html = m2e.loadHtmlTemplate(file);
        html.getById("fooTextarea", Textarea.clreplaced).setContent("");
        String str = m2e.saveToString(html);
        log.info(str);
        replacedert.replacedertTrue(str.contains(">" + SystemUtils.LINE_SEPARATOR + "</textarea>"));
    }
}

18 View Complete Implementation : FormUtilCheckboxTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced FormUtilCheckboxTest {

    private String templateFileName = "FormUtilCheckboxTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test01() throws IOException, IllegalAccessException, InvocationTargetException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Form form = html.getById("test01", Form.clreplaced);
        Bean bean = new Bean();
        // この段階ではvalueがaのboxだけがcheckされている。
        replacedertThat(form.getById("c01", Input.clreplaced).getChecked(), is("checked"));
        replacedertThat(form.getById("c02", Input.clreplaced).getChecked(), is(nullValue()));
        replacedertThat(form.getById("c03", Input.clreplaced).getChecked(), is(nullValue()));
        // beanでform内の値を変える
        bean.setCheckbox01(new String[] { "b" });
        FormUtil.populateForm(form, bean);
        // name属性を与えていないcheckboxは変化なし
        replacedertThat(form.getById("c00", Input.clreplaced).getChecked(), is(nullValue()));
        replacedertThat(form.getById("c00", Input.clreplaced).getValue(), is("xxx"));
        // valueがaのボックスはcheckedが外れている
        replacedertThat(form.getById("c01", Input.clreplaced).getValue(), is("a"));
        replacedertThat(form.getById("c01", Input.clreplaced).getChecked(), is(nullValue()));
        // valueがbのboxはcheckされていること。
        replacedertThat(form.getById("c02", Input.clreplaced).getValue(), is("b"));
        replacedertThat(form.getById("c02", Input.clreplaced).getChecked(), is("checked"));
        // valueがcのboxはcheckされていない(変化がない)こと。
        replacedertThat(form.getById("c03", Input.clreplaced).getValue(), is("c"));
        replacedertThat(form.getById("c03", Input.clreplaced).getChecked(), is(nullValue()));
    }

    public clreplaced Bean {

        private String[] checkbox01;

        public String[] getCheckbox01() {
            return checkbox01;
        }

        public void setCheckbox01(String[] checkbox01) {
            this.checkbox01 = checkbox01;
        }
    }
}

18 View Complete Implementation : FormUtilSampleTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced FormUtilSampleTest {

    private String templateFileName = "FormUtilSampleTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void populateFormTest() throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Form form = html.getById("the_form", Form.clreplaced);
        Bean bean = new Bean();
        bean.setFullName("Harry Potter");
        bean.setSex("male");
        bean.setSubscribeNewsLetter(true);
        bean.setCountry("U.K");
        bean.setInterests(new String[] { "Quidditch", "Defence Against the Dark Arts" });
        FormUtil.populateForm(form, bean);
        // System.out.println(m2e.saveToString(html));
        for (Input input : form.getDescendants(Input.clreplaced)) {
            if ("interests".equals(input.getName())) {
                if ("Quidditch".equals(input.getValue())) {
                    replacedertThat(input.getChecked(), is("checked"));
                }
                if ("Herbology".equals(input.getValue())) {
                    replacedertThat(input.getChecked(), is(nullValue()));
                }
                if ("Defence Against the Dark Arts".equals(input.getValue())) {
                    replacedertThat(input.getChecked(), is("checked"));
                }
            }
        }
    }

    public clreplaced Bean {

        private String fullName;

        private String sex;

        private boolean subscribeNewsLetter;

        private String country;

        private String[] interests;

        public String getFullName() {
            return fullName;
        }

        public void setFullName(String fullName) {
            this.fullName = fullName;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public boolean isSubscribeNewsLetter() {
            return subscribeNewsLetter;
        }

        public void setSubscribeNewsLetter(boolean subscribeNewsLetter) {
            this.subscribeNewsLetter = subscribeNewsLetter;
        }

        public String getCountry() {
            return country;
        }

        public void setCountry(String country) {
            this.country = country;
        }

        public String[] getInterests() {
            return interests;
        }

        public void setInterests(String[] interests) {
            this.interests = interests;
        }
    }
}

18 View Complete Implementation : FormUtilSelectTest.java
Copyright Apache License 2.0
Author : nabedge
public clreplaced FormUtilSelectTest {

    private String templateFileName = "FormUtilSelectTest.html";

    private String templateFilePath;

    private static Mixer2Engine m2e = Mixer2EngineSingleton.getInstance();

    private Html html;

    @AfterClreplaced
    public static void afterClreplaced() {
        m2e = null;
    }

    @Before
    public void init() throws IOException {
        templateFilePath = getClreplaced().getResource(templateFileName).toString();
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") >= 0) {
            templateFilePath = templateFilePath.replaceFirst("file:/", "");
        } else {
            templateFilePath = templateFilePath.replaceFirst("file:", "");
        }
    }

    @Test
    public void test1() throws IOException, IllegalAccessException, InvocationTargetException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Form form = html.getById("test1", Form.clreplaced);
        Bean bean = new Bean();
        bean.setSelect1("a");
        FormUtil.populateForm(form, bean);
        replacedertThat(form.getById("option1a", Option.clreplaced).getSelected(), is("selected"));
        replacedertThat(form.getById("option1b", Option.clreplaced).getSelected(), is(nullValue()));
        replacedertThat(form.getById("option1c", Option.clreplaced).getSelected(), is(nullValue()));
    }

    @Test
    public void test2() throws IOException, IllegalAccessException, InvocationTargetException {
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        Form form = html.getById("test2", Form.clreplaced);
        Bean bean = new Bean();
        bean.setSelect2(new String[] { "a", "b", "c" });
        FormUtil.populateForm(form, bean);
        replacedertThat(form.getById("option2a", Option.clreplaced).getSelected(), is("selected"));
        replacedertThat(form.getById("option2b", Option.clreplaced).getSelected(), is("selected"));
        replacedertThat(form.getById("option2c", Option.clreplaced).getSelected(), is("selected"));
        replacedertThat(form.getById("option2d", Option.clreplaced).getSelected(), is(nullValue()));
        replacedertThat(form.getById("option2e", Option.clreplaced).getSelected(), is(nullValue()));
    }

    /**
     * selectボックスにoptionタグを入れ込むテスト
     *
     * @throws IOException
     */
    @Test
    public void test3() throws IOException {
        List<LabelValueBean> lvList = new ArrayList<LabelValueBean>();
        lvList.add(new LabelValueBean("English", "en"));
        lvList.add(new LabelValueBean("replacedanese", "ja"));
        List<Option> optionList = new ArrayList<Option>();
        optionList = FormUtil.makeOptionList(lvList, optionList);
        html = m2e.loadHtmlTemplate(new File(templateFilePath));
        html.getById("select3", Select.clreplaced).getOptgroupOrOption().addAll(optionList);
        // System.out.println(m2e.saveToString(html));
        replacedertEquals("English", html.getById("select3", Select.clreplaced).getOptgroupOrOption().get(0).cast(Option.clreplaced).getContent());
        replacedertEquals("ja", html.getById("select3", Select.clreplaced).getOptgroupOrOption().get(1).cast(Option.clreplaced).getValue());
    }

    public clreplaced Bean {

        private String select1;

        private String[] select2;

        public String getSelect1() {
            return select1;
        }

        public void setSelect1(String select1) {
            this.select1 = select1;
        }

        public String[] getSelect2() {
            return select2;
        }

        public void setSelect2(String[] select2) {
            this.select2 = select2;
        }
    }
}