Skip to content

Instantly share code, notes, and snippets.

@jfut
Created September 11, 2014 05:00
Show Gist options
  • Save jfut/44693bdd38b0a7b011f8 to your computer and use it in GitHub Desktop.
Save jfut/44693bdd38b0a7b011f8 to your computer and use it in GitHub Desktop.
AllMixer2HtmlTest1.java
import java.util.List;
import org.junit.Test;
import org.mixer2.Mixer2Engine;
import org.mixer2.jaxb.xhtml.Article;
import org.mixer2.jaxb.xhtml.Body;
import org.mixer2.jaxb.xhtml.H1;
import org.mixer2.jaxb.xhtml.Html;
import org.mixer2.jaxb.xhtml.P;
import org.mixer2.jaxb.xhtml.Section;
import org.mixer2.jaxb.xhtml.Span;
import org.mixer2.xhtml.AbstractJaxb;
import org.mixer2.xhtml.TagCreator;
import org.mixer2.xhtml.exception.TagTypeUnmatchException;
public class AllMixer2HtmlTest1 {
@Test
public void test1() throws TagTypeUnmatchException {
Html html = TagCreator.html();
Body body = TagCreator.body();
Article article = TagCreator.article();
Section section = TagCreator.section();
H1 h1 = TagCreator.h1();
h1.getContent().add("headline");
P p1 = TagCreator.pWithId("HERE.msg");
p1.getContent().add("here comes hello message");
Span span1 = TagCreator.span();
span1.addCssClass("DEBUG");
span1.getContent().add("dummy span");
P p2 = TagCreator.p();
p2.addCssClass("DEBUG");
p2.getContent().add("dummy p");
section.getContent().add(h1);
section.getContent().add(p1);
section.getContent().add(span1);
section.getContent().add(p2);
article.getContent().add(section);
body.getContent().add(article);
html.setBody(body);
Mixer2Engine m2e = new Mixer2Engine();
System.out.println(m2e.saveToString(html));
replace(html);
System.out.println("# After");
System.out.println(m2e.saveToString(html));
}
public void replace(Html html) throws TagTypeUnmatchException {
P p = html.getById("HERE.msg");
p.setId("msg");
p.unsetContent();
p.getContent().add("Hello World!");
H1 h1 = html.getDescendants(H1.class).get(0);
h1.unsetContent();
h1.getContent().add("New Headline");
// or html.removeDescendants("DEBUG");
List<AbstractJaxb> debugTagList = html.getDescendants("DEBUG");
for (AbstractJaxb abstractJaxb : debugTagList) {
html.remove(abstractJaxb);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment