Skip to content

Commit

Permalink
XSLDocument.make()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Dec 7, 2013
1 parent a680083 commit 8e9a386
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/com/jcabi/xml/XSLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ public XSLDocument(@NotNull(message = "XSL input stream can't be NULL")
this(IOUtils.toString(stream, CharEncoding.UTF_8));
}

/**
* Make an instance of XSL stylesheet without I/O exceptions.
*
* <p>This factory method is useful when you need to create
* an instance of XSL stylesheet as a static final variable. In this
* case you can't catch an exception but this method can help, for example:
*
* <pre> class Foo {
* private static final XSL STYLESHEET = XSLDocument.make(
* Foo.class.getResourceAsStream("my-stylesheet.xsl")
* );
* }</pre>
*
* @param stream Input stream
* @return XSL stylesheet
*/
public static XSL make(@NotNull(message = "XSL input stream can't be NULL")
final InputStream stream) {
try {
return new XSLDocument(stream);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}

@Override
public String toString() {
return new XMLDocument(this.xsl).toString();
Expand Down

0 comments on commit 8e9a386

Please sign in to comment.