Search in sources :

Example 1 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class JsonPatch method patch.

/**
 * Patch an XML object/element.
 * @param xpath XPath to locate the node to patch
 * @param obj Object to apply
 * @throws IOException If there is any I/O problem
 */
public void patch(final String xpath, final JsonObject obj) throws IOException {
    final Directives dirs = new Directives().xpath(xpath);
    for (final Map.Entry<String, JsonValue> entry : obj.entrySet()) {
        dirs.addIf(entry.getKey()).set(StringUtils.strip(entry.getValue().toString(), "\"")).up();
    }
    this.storage.apply(dirs);
}
Also used : Directives(org.xembly.Directives) JsonValue(javax.json.JsonValue) Map(java.util.Map)

Example 2 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkContents method create.

@Override
public Content create(final JsonObject json) throws IOException {
    this.storage.lock();
    // @checkstyle MultipleStringLiterals (20 lines)
    final String branch;
    try {
        if (json.containsKey("ref")) {
            branch = json.getString("ref");
        } else {
            branch = "master";
        }
        this.storage.apply(new Directives().xpath(this.xpath()).add("content").attr("ref", branch).add("name").set(json.getString("path")).up().add("path").set(json.getString("path")).up().add("content").set(json.getString("content")).up().add("type").set("file").up().add("encoding").set("base64").up().add("sha").set(fakeSha()).up().add("url").set("http://localhost/1").up().add("git_url").set("http://localhost/2").up().add("html_url").set("http://localhost/3").up());
        this.commit(json);
    } finally {
        this.storage.unlock();
    }
    return new MkContent(this.storage, this.self, this.coords, json.getString("path"), branch);
}
Also used : Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 3 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkContents method remove.

@Override
public RepoCommit remove(final JsonObject content) throws IOException {
    this.storage.lock();
    final String path = content.getString("path");
    // @checkstyle MultipleStringLiterals (20 lines)
    final String branch;
    try {
        if (content.containsKey("ref")) {
            branch = content.getString("ref");
        } else {
            branch = "master";
        }
        this.storage.apply(new Directives().xpath(this.xpath()).xpath(String.format("content[path='%s']", path)).attr("ref", branch).remove());
        return this.commit(content);
    } finally {
        this.storage.unlock();
    }
}
Also used : Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 4 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkDeployKeys method create.

@Override
public DeployKey create(final String title, final String key) throws IOException {
    this.storage.lock();
    final int number;
    try {
        number = 1 + this.storage.xml().xpath(String.format("%s/deploykey/id/text()", this.xpath())).size();
        this.storage.apply(new Directives().xpath(this.xpath()).add("deploykey").add("id").set(String.valueOf(number)).up().add("title").set(title).up().add("key").set(key));
    } finally {
        this.storage.unlock();
    }
    return this.get(number);
}
Also used : Directives(org.xembly.Directives)

Example 5 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkHooks method create.

@Override
public Hook create(final String name, final Map<String, String> config, final boolean active) throws IOException {
    this.storage.lock();
    final int number;
    try {
        number = 1 + this.storage.xml().xpath(String.format("%s/hook/id/text()", this.xpath())).size();
        final Directives dirs = new Directives().xpath(this.xpath()).add("hook").add("id").set(String.valueOf(number)).up().add("name").set(name).up().add("active").set(Boolean.toString(active)).up().add("events").up().add("config");
        for (final Map.Entry<String, String> entr : config.entrySet()) {
            dirs.add(entr.getKey()).set(entr.getValue()).up();
        }
        this.storage.apply(dirs);
    } finally {
        this.storage.unlock();
    }
    return this.get(number);
}
Also used : Directives(org.xembly.Directives) ToString(lombok.ToString) Map(java.util.Map)

Aggregations

Directives (org.xembly.Directives)28 ToString (lombok.ToString)12 Github (com.jcabi.github.Github)4 Map (java.util.Map)3 JsonValue (javax.json.JsonValue)3 JsonObject (javax.json.JsonObject)2 Test (org.junit.Test)2 Coordinates (com.jcabi.github.Coordinates)1 Issue (com.jcabi.github.Issue)1 Repo (com.jcabi.github.Repo)1 XML (com.jcabi.xml.XML)1 FkBase (io.wring.fake.FkBase)1 FkPipe (io.wring.fake.FkPipe)1 Base (io.wring.model.Base)1 Pipe (io.wring.model.Pipe)1 XePrint (io.wring.model.XePrint)1 HashSet (java.util.HashSet)1 JsonArray (javax.json.JsonArray)1 Href (org.takes.misc.Href)1 XeDirectives (org.takes.rs.xe.XeDirectives)1