private void createIntermediaryPaths()

in src/main/java/org/apache/sling/maven/bundlesupport/deploy/method/WebDavPutDeployMethod.java [96:150]


    private void createIntermediaryPaths(URI targetURL, DeployContext context) throws IOException {
        // extract all intermediate URIs (longest one first)
        List<URI> intermediateUris = IntermediateUrisExtractor.extractIntermediateUris(targetURL);

        // 1. go up to the node in the repository which exists already (HEAD request towards the root node)
        URI existingIntermediateUri = null;
        // go through all intermediate URIs (longest first)
        for (URI intermediateUri : intermediateUris) {
            // until one is existing
            try {
                try {
                    performHead(intermediateUri, context);
                    // if the result is 200 (in case the default get servlet allows returning index files)
                    existingIntermediateUri = intermediateUri;
                    break;
                } catch (HttpResponseException e) {
                    // or 403 (in case the default get servlet does no allow returning index files)
                    if (e.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
                        // we assume that the intermediate node exists already
                        existingIntermediateUri = intermediateUri;
                        break;
                    } else if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
                        throw e;
                    }
                }
            } catch (IOException e) {
                throw new IOException(
                        "Failed getting intermediate path at " + intermediateUri + "." + " Reason: " + e.getMessage(),
                        e);
            }
        }

        if (existingIntermediateUri == null) {
            throw new IOException("Could not find any intermediate path up until the root of " + targetURL + ".");
        }

        // 2. now create from that level on each intermediate node individually towards the target path
        int startOfInexistingIntermediateUri = intermediateUris.indexOf(existingIntermediateUri);
        if (startOfInexistingIntermediateUri == -1) {
            throw new IllegalStateException(
                    "Could not find intermediate uri " + existingIntermediateUri + " in the list");
        }

        for (int index = startOfInexistingIntermediateUri - 1; index >= 0; index--) {
            // use MKCOL to create the intermediate paths
            URI intermediateUri = intermediateUris.get(index);
            try {
                performMkCol(intermediateUri, context);
                context.getLog().debug("Intermediate path at " + intermediateUri + " successfully created");
            } catch (IOException e) {
                throw new IOException("Failed creating intermediate path at '" + intermediateUri + "'." + " Reason: "
                        + e.getMessage());
            }
        }
    }