Skip to content

Commit

Permalink
(yegor256#1277) Improve javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Jul 3, 2020
1 parent 09548f6 commit 14cd91e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/cactoos/RepeatedProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.cactoos.func.Repeated;

/**
* Proc that repeats its calculation a few times before
* returning the last result.
* Proc that runs repeatedly for a number of times.
*
* @param <X> Type of input
* @since 0.49.2
Expand Down
61 changes: 61 additions & 0 deletions src/test/java/org/cactoos/io/XsltTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.cactoos.io;

import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


public class XsltTransformer {
private final Path input;
private final Path output;
private final Transformer transformer;

XsltTransformer(Path input, Path output, Transformer transformer) {
this.input = input;
this.output = output;
this.transformer = transformer;
}

public static void main(String[] args) throws Exception {
final Transformer transformer = TransformerFactory
.newInstance()
.newTransformer(new StreamSource(Paths.get("/my/directory/file.xsl").toFile()));
new XsltTransformer(
Paths.get("/my/directory"),
Paths.get("/my/output"),
transformer
).run();
}

private Path transform(Path file) {
final StreamSource resource = new StreamSource(file.toFile());
final Path output = this.resolveOutput(file);
final Result result = new StreamResult(
output.toFile()
);
try {
this.transformer.transform(resource, result);
return output;
} catch (TransformerException ex) {
throw new IllegalStateException(ex);
}
}

private Path resolveOutput(Path file) {
return this.output.resolve(this.input.relativize(file));
}

public void run() throws IOException {
Files.walk(this.input)
.filter(file -> file.getFileName().endsWith(".xml"))
.map(this::transform)
.forEach(System.out::println);
}
}
Empty file added stale_outputs_checked
Empty file.

0 comments on commit 14cd91e

Please sign in to comment.