Search in sources :

Example 6 with SerializationData

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()));
}
Also used : SerializationData(org.apache.sling.ide.serialization.SerializationData) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with SerializationData

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());
    }
}
Also used : SerializationData(org.apache.sling.ide.serialization.SerializationData) IPath(org.eclipse.core.runtime.IPath) Iterator(java.util.Iterator) FilterResult(org.apache.sling.ide.filter.FilterResult) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) LinkedList(java.util.LinkedList) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

SerializationData (org.apache.sling.ide.serialization.SerializationData)7 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 RepositoryException (javax.jcr.RepositoryException)1 Transformer (javax.xml.transform.Transformer)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)1 TransformerHandler (javax.xml.transform.sax.TransformerHandler)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Aggregate (org.apache.jackrabbit.vault.fs.api.Aggregate)1 DocViewSerializer (org.apache.jackrabbit.vault.fs.impl.io.DocViewSerializer)1 FilterResult (org.apache.sling.ide.filter.FilterResult)1