Search in sources :

Example 1 with Xembler

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();
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) XML(com.jcabi.xml.XML) Xembler(org.xembly.Xembler) XMLDocument(com.jcabi.xml.XMLDocument)

Example 2 with Xembler

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]"));
}
Also used : User(io.wring.model.User) Events(io.wring.model.Events) Event(io.wring.model.Event) Xembler(org.xembly.Xembler) Test(org.junit.Test)

Example 3 with Xembler

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]"));
}
Also used : User(io.wring.model.User) Events(io.wring.model.Events) Xembler(org.xembly.Xembler) Test(org.junit.Test)

Example 4 with Xembler

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'))]"));
}
Also used : User(io.wring.model.User) Events(io.wring.model.Events) Xembler(org.xembly.Xembler) Test(org.junit.Test)

Example 5 with Xembler

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();
}
Also used : User(io.wring.model.User) Pipe(io.wring.model.Pipe) Xembler(org.xembly.Xembler) Pipes(io.wring.model.Pipes) Test(org.junit.Test)

Aggregations

Xembler (org.xembly.Xembler)5 User (io.wring.model.User)4 Test (org.junit.Test)4 Events (io.wring.model.Events)3 XML (com.jcabi.xml.XML)1 XMLDocument (com.jcabi.xml.XMLDocument)1 Event (io.wring.model.Event)1 Pipe (io.wring.model.Pipe)1 Pipes (io.wring.model.Pipes)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1