Skip to content

Commit

Permalink
#1 xslt() doesnt throw any checked exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Oct 23, 2013
1 parent fe5e91c commit 9e509b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/jcabi/xml/XML.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import javax.validation.constraints.NotNull;
import javax.xml.namespace.NamespaceContext;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Node;

/**
Expand Down Expand Up @@ -147,10 +146,13 @@ public interface XML {

/**
* Transform to another XML using provided XSL.
*
* <p>A runtime exception will be thrown if transformation fails for any
* reason.
*
* @param xsl XSL stylesheet
* @return XML document
* @throws TransformerException If fails to transform
*/
XML xslt(Source xsl) throws TransformerException;
XML xslt(Source xsl);

}
15 changes: 12 additions & 3 deletions src/main/java/com/jcabi/xml/XMLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,24 @@ public Node node() {

@Override
@NotNull
public XML xslt(final Source xsl) throws TransformerException {
final Transformer trans = XMLDocument.TFACTORY.newTransformer(xsl);
public XML xslt(final Source xsl) {
final Transformer trans;
try {
trans = XMLDocument.TFACTORY.newTransformer(xsl);
} catch (TransformerConfigurationException ex) {
throw new IllegalStateException(ex);
}
final Document target;
try {
target = XMLDocument.DFACTORY.newDocumentBuilder().newDocument();
} catch (ParserConfigurationException ex) {
throw new IllegalStateException(ex);
}
trans.transform(new DOMSource(this.dom), new DOMResult(target));
try {
trans.transform(new DOMSource(this.dom), new DOMResult(target));
} catch (TransformerException ex) {
throw new IllegalStateException(ex);
}
return new XMLDocument(target, this.context);
}

Expand Down

0 comments on commit 9e509b2

Please sign in to comment.