Search in sources :

Example 31 with ResourceProxy

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) GetMethod(org.apache.commons.httpclient.methods.GetMethod) AuthScope(org.apache.commons.httpclient.auth.AuthScope) JsonReader(com.google.gson.stream.JsonReader) JsonToken(com.google.gson.stream.JsonToken) RepositoryException(org.apache.sling.ide.transport.RepositoryException) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) RepositoryException(org.apache.sling.ide.transport.RepositoryException) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 32 with ResourceProxy

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;
}
Also used : ResourceProxy(org.apache.sling.ide.transport.ResourceProxy)

Example 33 with ResourceProxy

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));
}
Also used : NodeIterator(javax.jcr.NodeIterator) SimpleCredentials(javax.jcr.SimpleCredentials) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) File(java.io.File) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Session(javax.jcr.Session)

Example 34 with ResourceProxy

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;
}
Also used : ResourceProxy(org.apache.sling.ide.transport.ResourceProxy)

Example 35 with ResourceProxy

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\\\">\"}"));
}
Also used : ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Test(org.junit.Test)

Aggregations

ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)42 Test (org.junit.Test)14 Node (javax.jcr.Node)8 NodeIterator (javax.jcr.NodeIterator)5 IPath (org.eclipse.core.runtime.IPath)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 FilterResult (org.apache.sling.ide.filter.FilterResult)4 IFile (org.eclipse.core.resources.IFile)4 IFolder (org.eclipse.core.resources.IFolder)4 Filter (org.apache.sling.ide.filter.Filter)3 RepositoryException (org.apache.sling.ide.transport.RepositoryException)3 JsonReader (com.google.gson.stream.JsonReader)2 JsonToken (com.google.gson.stream.JsonToken)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2