phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
116 stars 36 forks source link

[question] InputStream instead of file #122

Closed cshjsc closed 3 years ago

cshjsc commented 3 years ago

Is there a way to make a ISchematronResource out of an Inputstream instead of just a file I couldn't find anywhere a way to do that, the only solution for me wold be to write a temp file and then use that to create the ISchematronResource and then validate the xml

Instead of this SchematronResource aResSCH = SchematronResourceSCH.fromFile( file ); i would need something like this ISchematronResource aResSCH = SchematronResourceSCH.fromInputStream( inputStream ); If that is just not possible then I guess I'll write a temp file...

phax commented 3 years ago

Thanks. Good point - I will add this to the next version. In the meantime you can build this factory method yourself like this:

  /**
   * Create a new {@link SchematronResourceSCH} from Schematron rules provided
   * by an arbitrary {@link InputStream}.<br>
   * <b>Important:</b> in this case, no include resolution will be performed!!
   *
   * @param sResourceID
   *        Resource ID to be used as the cache key. Should neither be
   *        <code>null</code> nor empty.
   * @param aSchematronIS
   *        The {@link InputStream} to read the Schematron rules from. May not
   *        be <code>null</code>.
   * @return Never <code>null</code>.
   * @since 6.2.6
   */
  @Nonnull
  public static SchematronResourceSCH fromInputStream (@Nonnull @Nonempty final String sResourceID,
                                                       @Nonnull final InputStream aSchematronIS)
  {
    return new SchematronResourceSCH (new ReadableResourceInputStream (sResourceID, aSchematronIS));
  }
phax commented 3 years ago

Will be part of the 6.2.6 release. Thanks for pointing that out!