use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class GetNodeContentCommand method execute.
@Override
public Result<ResourceProxy> execute() {
GetMethod get = new GetMethod(getPath());
try {
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword());
httpClient.getState().setCredentials(new AuthScope(repositoryInfo.getHost(), repositoryInfo.getPort(), AuthScope.ANY_REALM), defaultcreds);
int responseStatus = httpClient.executeMethod(get);
// return EncodingUtil.getString(rawdata, m.getResponseCharSet());
if (!isSuccessStatus(responseStatus))
return failureResultForStatusCode(responseStatus);
ResourceProxy resource = new ResourceProxy(path);
try (JsonReader jsonReader = new JsonReader(new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet()))) {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
JsonToken token = jsonReader.peek();
if (token == JsonToken.STRING) {
resource.addProperty(name, jsonReader.nextString());
} else {
jsonReader.skipValue();
}
}
jsonReader.endObject();
}
return AbstractResult.success(resource);
} catch (Exception e) {
return AbstractResult.failure(new RepositoryException(e));
} finally {
get.releaseConnection();
}
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class AddOrUpdateNodeCommandTest method newResource.
private ResourceProxy newResource(String path, String primaryType) {
ResourceProxy resource = new ResourceProxy(path);
resource.addProperty("jcr:primaryType", primaryType);
return resource;
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ReorderChildNodesCommandTest method doReorderingTest.
private void doReorderingTest(List<String> nodeNames, List<String> resourceNames, List<String> expected) throws Exception {
if (expected == null) {
expected = resourceNames;
}
File out = new File(new File("target"), "jackrabbit");
TransientRepository repo = new TransientRepository(new File(out, "repository.xml"), new File(out, "repository"));
SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
Session session = repo.login(credentials);
List<String> finalOrder;
try {
Node content = session.getRootNode().addNode("content");
for (String nodeName : nodeNames) {
content.addNode(nodeName);
}
session.save();
ResourceProxy resource = newResource("/content", "nt:unstructured");
for (String resourceName : resourceNames) {
resource.addChild(newResource("/content/" + resourceName, "nt:unstructured"));
}
ReorderChildNodesCommand cmd = new ReorderChildNodesCommand(repo, credentials, resource, logger);
cmd.execute().get();
session.refresh(false);
finalOrder = new ArrayList<>();
NodeIterator nodes = session.getNode("/content").getNodes();
while (nodes.hasNext()) {
finalOrder.add(nodes.nextNode().getName());
}
} finally {
session.removeItem("/content");
session.save();
session.logout();
}
assertThat("Incorrect node order", finalOrder, equalTo(expected));
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ReorderChildNodesCommandTest method newResource.
private ResourceProxy newResource(String path, String primaryType) {
ResourceProxy resource = new ResourceProxy(path);
resource.addProperty("jcr:primaryType", primaryType);
return resource;
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ContentXmlHandlerTest method parseContentXmlWithEscapedValues.
@Test
public void parseContentXmlWithEscapedValues() throws ParserConfigurationException, SAXException, IOException {
ResourceProxy root = parseContentXmlFile("escaped-value-in-property.xml", "/");
assertThat(root.getProperties(), hasEntry("property", (Object) "{\"template\":\"<p class=\\\"contexthub-module-line1\\\">\"}"));
}
Aggregations