use of org.xembly.Xembler in project wring by yegor256.
the class XePrint method text.
/**
* Render text via XPath.
* @param pattern Pattern to use
* @return Plain text
*/
public String text(final CharSequence pattern) {
final XML xml = new XMLDocument(new Xembler(this.dirs).domQuietly());
final Pattern ptn = Pattern.compile("\\{([^}]+)}");
final Matcher mtr = ptn.matcher(pattern);
final StringBuffer out = new StringBuffer(pattern.length());
while (mtr.find()) {
mtr.appendReplacement(out, xml.xpath(mtr.group(1)).get(0).replace("\\", "\\\\").replace("$", "\\$"));
}
mtr.appendTail(out);
return out.toString();
}
use of org.xembly.Xembler in project wring by yegor256.
the class DyEventITCase method upvotes.
/**
* DyEvent can up-vote.
* @throws Exception If some problem inside
*/
@Test
public void upvotes() throws Exception {
final User user = new DyUser(new Dynamo(), "nick");
final Events events = user.events();
events.post("hey you", "some text [test](http://a.com/$t)!");
final Event event = events.iterate().iterator().next();
event.vote(Tv.FIFTEEN);
MatcherAssert.assertThat(new Xembler(events.iterate().iterator().next().asXembly()).xml(), XhtmlMatchers.hasXPaths("/event[title='hey you']", "/event[rank=16]"));
}
use of org.xembly.Xembler in project wring by yegor256.
the class DyEventsITCase method postsAndVotes.
/**
* DyEvents can post and vote.
* @throws Exception If some problem inside
*/
@Test
public void postsAndVotes() throws Exception {
final User user = new DyUser(new Dynamo(), "erikk");
final Events events = user.events();
final String title = "the title of the Event --+";
events.post(title, "some body text of the event");
events.event(title).vote(1);
MatcherAssert.assertThat(new Xembler(events.event(title).asXembly()).xml(), XhtmlMatchers.hasXPaths("/event[rank=2]"));
}
use of org.xembly.Xembler in project wring by yegor256.
the class DyEventsITCase method appendsToExistingEvents.
/**
* DyEvents can append text to.
* @throws Exception If some problem inside
*/
@Test
public void appendsToExistingEvents() throws Exception {
final User user = new DyUser(new Dynamo(), "peter");
final Events events = user.events();
final String title = "a simple title";
events.post(title, "\n\tfirst body");
events.post(title, "\n\u0000\u00fdin between");
events.post(title, "second body\n\n");
MatcherAssert.assertThat(new Xembler(events.iterate().iterator().next().asXembly()).xml(), XhtmlMatchers.hasXPaths("/event/text[contains(.,'first')]", "/event/text[contains(.,'second body')]", "/event/text[not(contains(.,'first body\n'))]"));
}
use of org.xembly.Xembler in project wring by yegor256.
the class DyPipesITCase method addsAndRemovePipes.
/**
* DyPipes can add and remove pipes.
* @throws Exception If some problem inside
*/
@Test
public void addsAndRemovePipes() throws Exception {
final User user = new DyUser(new Dynamo(), "jeffrey");
final Pipes pipes = user.pipes();
pipes.add("{\"name\": \"hello\"}");
final Pipe pipe = pipes.iterate().iterator().next();
MatcherAssert.assertThat(new Xembler(pipe.asXembly()).xml(), XhtmlMatchers.hasXPaths("/pipe/json", "/pipe/id"));
pipe.delete();
}
Aggregations