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);
}
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);
}
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();
}
}
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);
}
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);
}
Aggregations