コード例 #1
0
 @PostConstruct
 protected void init() {
   transformerFactory.setURIResolver(
       new URIResolver() {
         @Override
         public Source resolve(String href, String base) throws TransformerException {
           try {
             return new StreamSource(new ClassPathResource("transform/" + href).getInputStream());
           } catch (IOException e) {
             throw new TransformerException("Failed to resolve uri: " + href, e);
           }
         }
       });
 }
コード例 #2
0
  static {
    try {
      // Try to load Saxon implementation before defaulting to default implementation.
      transformerFactory =
          (TransformerFactoryImpl)
              Class.forName("net.sf.saxon.TransformerFactoryImpl").getConstructor().newInstance();
      logger.info("Using Saxon transformer.");
    } catch (Exception e) {
      transformerFactory = TransformerFactory.newInstance();
      logger.info("Using default transformer.");
    }

    transformerFactory.setURIResolver(
        new URIResolver() {
          @Override
          public Source resolve(String href, String base) throws TransformerException {
            return !"".equals(base)
                ? null
                : new StreamSource(
                    getClass()
                        .getResourceAsStream(String.format("/iso-schematron-xslt2/%s", href)));
          }
        });
  }