Created
November 10, 2012 21:32
-
-
Save itoshkov/4052588 to your computer and use it in GitHub Desktop.
Moulder test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static moulder.moulds.Moulds.append; | |
import static moulder.moulds.Moulds.attr; | |
import static moulder.moulds.Moulds.forEach; | |
import static moulder.moulds.Moulds.text; | |
import static moulder.values.Values.seq; | |
import java.util.Arrays; | |
import java.util.List; | |
import moulder.MoulderShop; | |
import moulder.moulds.SubMoulder; | |
import moulder.values.SimpleValue; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
public class MoulderTest { | |
private static final String HTML = "<html>\n" + | |
" <body>\n" + | |
" <h1>dummy text to be replaced<span>blah</span></h1>\n" + | |
" </body>\n" + | |
"</html>"; | |
public static void main(String[] args) { | |
System.out.println(usingMulti().toString()); | |
System.out.println(usingSub().toString()); | |
} | |
private static Document usingMulti() { | |
Document doc = Jsoup.parse(HTML); | |
MoulderShop m = new MoulderShop(); | |
List<String> items = Arrays.asList("summer", "autumn", "winter", "spring"); | |
SimpleValue<String> val = new SimpleValue<String>(null); | |
m.register("h1", | |
forEach(val, seq(items), | |
text(val), | |
attr("class", seq("even", "odd").cycle()), | |
append("<p>content</p>"))); | |
m.process(doc); | |
return doc; | |
} | |
private static Document usingSub() { | |
Document doc = Jsoup.parse(HTML); | |
MoulderShop m = new MoulderShop(); | |
List<String> items = Arrays.asList("summer", "autumn", "winter", "spring"); | |
SimpleValue<String> val = new SimpleValue<String>(null); | |
final SubMoulder subMoulder = new SubMoulder(); | |
subMoulder.register("*", | |
text(val), | |
attr("class", seq("even", "odd").cycle()), | |
append("<p>content</p>")); | |
m.register("h1", | |
forEach(val, seq(items), | |
subMoulder)); | |
m.process(doc); | |
return doc; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head></head> | |
<body> | |
<h1 class="even">summer</h1> | |
<p>content</p> | |
<h1 class="odd">autumn</h1> | |
<p>content</p> | |
<h1 class="even">winter</h1> | |
<p>content</p> | |
<h1 class="odd">spring</h1> | |
<p>content</p> | |
</body> | |
</html> | |
Exception in thread "main" java.lang.IllegalArgumentException: Object must not be null | |
at org.jsoup.helper.Validate.notNull(Validate.java:16) | |
at org.jsoup.nodes.Node.addSiblingHtml(Node.java:301) | |
at org.jsoup.nodes.Node.before(Node.java:256) | |
at org.jsoup.nodes.Element.before(Element.java:371) | |
at moulder.moulds.SubMoulder.process(SubMoulder.java:73) | |
at moulder.moulds.helpers.MouldersApplier.applyMoulder(MouldersApplier.java:16) | |
at moulder.moulds.helpers.MouldersApplier.applyMoulders(MouldersApplier.java:29) | |
at moulder.moulds.ForEach.process(ForEach.java:37) | |
at moulder.moulds.helpers.MouldersApplier.applyMoulder(MouldersApplier.java:16) | |
at moulder.moulds.helpers.MouldersApplier.applyMoulders(MouldersApplier.java:29) | |
at moulder.moulds.SubMoulder.process(SubMoulder.java:70) | |
at moulder.MoulderShop.process(MoulderShop.java:34) | |
at com.edamam.test.oauth.bl.MoulderTest.usingSub(MoulderTest.java:67) | |
at com.edamam.test.oauth.bl.MoulderTest.main(MoulderTest.java:28) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment