use of org.apache.sling.ide.serialization.SerializationData in project sling by apache.
the class SimpleXmlSerializationManagerTest method emptySerializedData.
@Test
public void emptySerializedData() throws SerializationException, SAXException {
SerializationData serializationData = sm.newBuilder(null, null).buildSerializationData(null, newResourceWithProperties(new HashMap<String, Object>()));
assertThat(serializationData, is(nullValue()));
}
use of org.apache.sling.ide.serialization.SerializationData 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