use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ContentXmlHandlerTest method parseFullCoverageXmlFile.
@Test
public void parseFullCoverageXmlFile() throws ParserConfigurationException, SAXException, IOException {
ResourceProxy root = parseContentXmlFile("full-coverage.xml", "/apps/full-coverage");
assertThat("full-coverage path", root.getPath(), is("/apps/full-coverage"));
assertThat("full-coverage properties.size", root.getProperties().size(), is(3));
assertThat("full-coverage properties[jcr:title]", root.getProperties(), hasEntry("jcr:title", (Object) "Full coverage parent"));
assertThat("full-coverage children.size", root.getChildren().size(), is(2));
ResourceProxy parent1 = root.getChildren().get(0);
assertThat("parent-1 path", parent1.getPath(), is("/apps/full-coverage/parent-1"));
assertThat("parent-1 properties[jcr:title]", parent1.getProperties(), hasEntry("jcr:title", (Object) "Parent 1"));
assertThat("parent-1 children.size", parent1.getChildren().size(), is(2));
ResourceProxy child11 = parent1.getChildren().get(0);
assertThat("child-1-1 path", child11.getPath(), is("/apps/full-coverage/parent-1/child-1-1"));
assertThat("child-1-1 properties[jcr:title]", child11.getProperties(), hasEntry("jcr:title", (Object) "Child 1-1"));
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ContentXmlHandlerTest method parseContentXmlWithEscapedNames.
@Test
public void parseContentXmlWithEscapedNames() throws ParserConfigurationException, SAXException, IOException {
ResourceProxy root = parseContentXmlFile("full-coverage-escaped-names.xml", "/");
assertThat("node contains /50-50", root.getChildren(), hasChildPath("/50-50"));
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class AddOrUpdateNodeCommand method processDeletedNodes.
private void processDeletedNodes(Node node, ResourceProxy resource2) throws RepositoryException {
// TODO - we probably don't support SNS here ( and in other places as well )
List<ResourceProxy> resourceChildren = resource2.getChildren();
if (resourceChildren.size() == 0) {
getLogger().trace("Resource at {0} has no children, skipping deleted nodes processing", resource2.getPath());
return;
}
Map<String, ResourceProxy> resourceChildrenPaths = new HashMap<>(resourceChildren.size());
for (ResourceProxy child : resourceChildren) {
resourceChildrenPaths.put(child.getPath(), child);
}
for (NodeIterator it = node.getNodes(); it.hasNext(); ) {
Node child = it.nextNode();
if (resourceChildrenPaths.containsKey(child.getPath())) {
// don't have enough information
if (resource2.covers(child.getPath())) {
processDeletedNodes(child, resourceChildrenPaths.get(child.getPath()));
}
continue;
}
if (context.filter() != null && context.filter().filter(child.getPath()) == FilterResult.DENY) {
getLogger().trace("Not deleting node at {0} since it is not included in the filter", child.getPath());
continue;
}
getLogger().trace("Deleting node {0} as it is no longer present in the local checkout", child.getPath());
child.remove();
}
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ResourceChangeCommandFactoryTest method commandForSlingOrderedFolder_children.
@Test
public void commandForSlingOrderedFolder_children() throws CoreException {
// create a sling:OrderedFolder at /content/test-root
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass().getResourceAsStream("sling-ordered-folder-with-children.xml"));
// create the child folder listed in the .content.xml file
contentProject.getFolder("jcr_root/content/test-root/folder").create(true, true, new NullProgressMonitor());
SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo, contentProject.findMember("jcr_root/content/test-root"));
List<ResourceProxy> children = command.getResourceProxy().getChildren();
assertThat("command.resource.children.size", children.size(), equalTo(2));
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ImportRepositoryContentAction method crawlChildrenAndImport.
/**
* Crawls the repository and recursively imports founds resources
* @param path the current path to import from
* @param tracer
* @throws JSONException
* @throws RepositoryException
* @throws CoreException
* @throws IOException
*/
// TODO: This probably should be pushed into the service layer
private void crawlChildrenAndImport(String path) throws RepositoryException, CoreException, IOException, SerializationException {
logger.trace("crawlChildrenAndImport({0}, {1}, {2}, {3}", repository, path, project, projectRelativePath);
ResourceProxy resource = executeCommand(repository.newListChildrenNodeCommand(path));
SerializationData serializationData = builder.buildSerializationData(contentSyncRoot, resource);
logger.trace("For resource at path {0} got serialization data {1}", resource.getPath(), serializationData);
final List<ResourceProxy> resourceChildren = new LinkedList<>(resource.getChildren());
if (serializationData != null) {
IPath serializationFolderPath = contentSyncRootDir.getProjectRelativePath().append(serializationData.getFolderPath());
switch(serializationData.getSerializationKind()) {
case FILE:
{
byte[] contents = executeCommand(repository.newGetNodeCommand(path));
createFile(project, getPathForPlainFileNode(resource, serializationFolderPath), contents);
if (serializationData.hasContents()) {
createFolder(project, serializationFolderPath);
createFile(project, serializationFolderPath.append(serializationData.getFileName()), serializationData.getContents());
// special processing for nt:resource nodes
for (Iterator<ResourceProxy> it = resourceChildren.iterator(); it.hasNext(); ) {
ResourceProxy child = it.next();
if (Repository.NT_RESOURCE.equals(child.getProperties().get(Repository.JCR_PRIMARY_TYPE))) {
ResourceProxy reloadedChildResource = executeCommand(repository.newListChildrenNodeCommand(child.getPath()));
logger.trace("Skipping direct handling of {0} node at {1} ; will additionally handle {2} direct children", Repository.NT_RESOURCE, child.getPath(), reloadedChildResource.getChildren().size());
if (reloadedChildResource.getChildren().size() != 0) {
String pathName = Text.getName(reloadedChildResource.getPath());
pathName = serializationManager.getOsPath(pathName);
createFolder(project, serializationFolderPath.append(pathName));
// 2. recursively handle all resources
for (ResourceProxy grandChild : reloadedChildResource.getChildren()) {
crawlChildrenAndImport(grandChild.getPath());
}
}
it.remove();
break;
}
}
}
break;
}
case FOLDER:
case METADATA_PARTIAL:
{
IFolder folder = createFolder(project, serializationFolderPath);
parseIgnoreFiles(folder, path);
if (serializationData.hasContents()) {
createFile(project, serializationFolderPath.append(serializationData.getFileName()), serializationData.getContents());
}
break;
}
case METADATA_FULL:
{
if (serializationData.hasContents()) {
createFile(project, serializationFolderPath.append(serializationData.getFileName()), serializationData.getContents());
}
break;
}
}
logger.trace("Resource at {0} has children: {1}", resource.getPath(), resourceChildren);
if (serializationData.getSerializationKind() == SerializationKind.METADATA_FULL) {
return;
}
} else {
logger.trace("No serialization data found for {0}", resource.getPath());
}
ProgressUtils.advance(monitor, 1);
for (ResourceProxy child : resourceChildren) {
if (ignoredResources.isIgnored(child.getPath())) {
continue;
}
if (filter != null) {
FilterResult filterResult = filter.filter(child.getPath());
if (filterResult == FilterResult.DENY) {
continue;
}
}
crawlChildrenAndImport(child.getPath());
}
}
Aggregations