Search in sources :

Example 1 with DocViewSerializer

use of org.apache.jackrabbit.vault.fs.impl.io.DocViewSerializer in project sling by apache.

the class VltSerializationDataBuilder method buildSerializationData.

@Override
public SerializationData buildSerializationData(File contentSyncRoot, ResourceProxy resource) throws SerializationException {
    try {
        List<Aggregate> chain = findAggregateChain(resource);
        if (chain == null) {
            return null;
        }
        Aggregate aggregate = chain.get(chain.size() - 1);
        String fileOrFolderPathHint = calculateFileOrFolderPathHint(chain);
        String nameHint = PlatformNameFormat.getPlatformName(aggregate.getName());
        SerializationKind serializationKind = getSerializationKind(aggregate);
        if (resource.getPath().equals("/") || serializationKind == SerializationKind.METADATA_PARTIAL || serializationKind == SerializationKind.FILE || serializationKind == SerializationKind.FOLDER) {
            nameHint = Constants.DOT_CONTENT_XML;
        } else if (serializationKind == SerializationKind.METADATA_FULL) {
            nameHint += ".xml";
        }
        Activator.getDefault().getPluginLogger().trace("Got location {0} for path {1}", fileOrFolderPathHint, resource.getPath());
        if (!needsDir(aggregate)) {
            return SerializationData.empty(fileOrFolderPathHint, serializationKind);
        }
        DocViewSerializer s = new DocViewSerializer(aggregate);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        s.writeContent(out);
        byte[] result = out.toByteArray();
        return new SerializationData(fileOrFolderPathHint, nameHint, result, serializationKind);
    } catch (RepositoryException e) {
        throw new SerializationException(e);
    } catch (IOException e) {
        throw new SerializationException(e);
    }
}
Also used : SerializationException(org.apache.sling.ide.serialization.SerializationException) SerializationData(org.apache.sling.ide.serialization.SerializationData) SerializationKind(org.apache.sling.ide.serialization.SerializationKind) DocViewSerializer(org.apache.jackrabbit.vault.fs.impl.io.DocViewSerializer) RepositoryException(javax.jcr.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Aggregate(org.apache.jackrabbit.vault.fs.api.Aggregate)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 Aggregate (org.apache.jackrabbit.vault.fs.api.Aggregate)1 DocViewSerializer (org.apache.jackrabbit.vault.fs.impl.io.DocViewSerializer)1 SerializationData (org.apache.sling.ide.serialization.SerializationData)1 SerializationException (org.apache.sling.ide.serialization.SerializationException)1 SerializationKind (org.apache.sling.ide.serialization.SerializationKind)1