in org.apache.sling.offline/src/main/java/org/apache/sling/offline/impl/Starter.java [92:137]
private void process(final ResourceResolver resolver, final Resource resource, final boolean retry)
throws IOException, ServletException {
if ( this.ignore(resource) ) {
return;
}
if ( this.isImage(resource) ) {
this.handleBinary(resolver, resource);
}
if ( !this.isWebPage(resource) ) {
for(final Resource c : resource.getChildren()) {
process(resolver, c, retry);
}
return;
}
logger.info("Processing {}", resource.getPath());
final long lastModified = resource.getResourceMetadata().getModificationTime();
final File output = new File(config.output_path(), resource.getPath().substring(this.config.input_path().length()).concat(".html"));
if ( lastModified > 0 && output.exists() && output.lastModified() >= lastModified ) {
logger.info("Skipping {} as it is up to date", resource.getPath());
return;
}
final long endAt = System.currentTimeMillis() + this.config.timeout();
while ( System.currentTimeMillis() < endAt ) {
final SlingHttpServletRequest req = Builders.newRequestBuilder(resource)
.withExtension("html")
.build();
final SlingHttpServletResponseResult resp = Builders.newResponseBuilder().build();
processor.processRequest(req, resp, resolver);
if ( resp.getStatus() == 200 ) {
logger.info("Writing output to {}", output.getAbsolutePath());
output.getParentFile().mkdirs();
Files.writeString(output.toPath(), resp.getOutputAsString());
return;
}
if (!retry) {
break;
}
try {
Thread.sleep(this.config.retry_delay());
} catch ( final InterruptedException ie) {
// ignore
}
}
logger.error("Unable to create html for {}", resource.getPath());
}