com.helger.commons.io.resource.ClassPathResource Java Examples

The following examples show how to use com.helger.commons.io.resource.ClassPathResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenericJAXBMarshaller.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor with XSD paths.
 *
 * @param aType
 *        The class of the JAXB document implementation type. May not be
 *        <code>null</code>.
 * @param aXSDs
 *        The XSDs used to validate document. May be <code>null</code> or
 *        empty indicating, that no XSD check is needed.
 * @param aJAXBElementWrapper
 *        Wrap the passed domain object into a {@link JAXBElement} for
 *        marshalling (writing). This can usually be done using the
 *        respective's package ObjectFactory implementation. May not be
 *        <code>null</code>.
 */
public GenericJAXBMarshaller (@Nonnull final Class <JAXBTYPE> aType,
                              @Nullable final List <? extends ClassPathResource> aXSDs,
                              @Nonnull final IFunction <? super JAXBTYPE, ? extends JAXBElement <JAXBTYPE>> aJAXBElementWrapper)
{
  m_aType = ValueEnforcer.notNull (aType, "Type");
  if (aXSDs != null)
  {
    ValueEnforcer.notEmptyNoNullValue (aXSDs, "XSDs");
    m_aXSDs.addAll (aXSDs);
  }
  for (final ClassPathResource aRes : m_aXSDs)
    ValueEnforcer.isTrue (aRes.hasClassLoader (),
                          () -> "ClassPathResource " + aRes + " should define its ClassLoader for OSGI handling!");

  m_aJAXBElementWrapper = ValueEnforcer.notNull (aJAXBElementWrapper, "JAXBElementWrapper");
  // By default this class loader of the type to be marshaled should be used
  // This is important for OSGI application containers and ANT tasks
  m_aClassLoader = new WeakReference <> (aType.getClassLoader ());
  m_aReadExceptionCallbacks.add (new LoggingJAXBReadExceptionHandler ());
  m_aWriteExceptionCallbacks.add (new LoggingJAXBWriteExceptionHandler ());
}
 
Example #2
Source File: MicroReaderTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadEntity ()
{
  // Read file with notation
  final IMicroDocument doc = MicroReader.readMicroXML (new ClassPathResource ("xml/xml-entity-public.xml"),
                                                       new SAXReaderSettings ().setEntityResolver (new EmptyEntityResolver ()));
  assertNotNull (doc);

  final MicroSAXHandler aHdl = new MicroSAXHandler (true, new EmptyEntityResolver (), true);
  final ISAXReaderSettings aSettings = new SAXReaderSettings ().setEntityResolver (aHdl)
                                                               .setDTDHandler (aHdl)
                                                               .setContentHandler (aHdl)
                                                               .setErrorHandler (aHdl)
                                                               .setLexicalHandler (aHdl);
  assertTrue (SAXReader.readXMLSAX (InputSourceFactory.create (ClassPathResource.getInputStream ("xml/xml-entity-public.xml")),
                                    aSettings)
                       .isSuccess ());
  assertNotNull (aHdl.getDocument ());

  // Write again
  assertNotNull (MicroWriter.getNodeAsString (doc));
}
 
Example #3
Source File: XMLMapHandlerTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadBuildInfo ()
{
  final ICommonsMap <String, String> aMap = new CommonsHashMap <> ();
  final IReadableResource aRes = new ClassPathResource ("xml/buildinfo.xml");
  assertTrue (XMLMapHandler.readMap (aRes, aMap).isSuccess ());
  assertNull (XMLMapHandler.readMap (new ClassPathResource ("test1.txt")));
  assertTrue (aMap.containsKey ("buildinfo.version"));
  assertEquals ("1", aMap.get ("buildinfo.version"));

  assertTrue (XMLMapHandler.readMap (aRes).containsKey ("buildinfo.version"));
  assertEquals ("1", XMLMapHandler.readMap (aRes).get ("buildinfo.version"));

  assertTrue (XMLMapHandler.writeMap (aMap, new ByteArrayOutputStreamProvider ()).isSuccess ());
  assertTrue (XMLMapHandler.writeMap (aMap, new NonBlockingByteArrayOutputStream ()).isSuccess ());
}
 
Example #4
Source File: Issue29Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Nullable
static SchematronOutputType validateXmlUsingSchematron (@Nonnull final IReadableResource aRes)
{
  SchematronOutputType ob = null;

  // Must use the XSLT based version, because of "key" usage
  final ISchematronResource aResSCH = new SchematronResourcePure (new ClassPathResource ("issues/github29/pbs.sch"));
  if (!aResSCH.isValidSchematron ())
    throw new IllegalArgumentException ("Invalid Schematron!");
  try
  {
    final Document aDoc = aResSCH.applySchematronValidation (new ResourceStreamSource (aRes));
    if (aDoc != null)
    {
      final SVRLMarshaller marshaller = new SVRLMarshaller ();
      ob = marshaller.read (aDoc);
    }
  }
  catch (final Exception pE)
  {
    pE.printStackTrace ();
  }
  return ob;
}
 
Example #5
Source File: DefaultResourceResolver.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static ClassPathResource _resolveClassPathResource (final String sSystemId,
                                                            final String sBaseURI,
                                                            final ClassLoader aClassLoader)
{
  // Skip leading "cp:" or "classpath:"
  final String sBaseURIWithoutPrefix = ClassPathResource.getWithoutClassPathPrefix (sBaseURI);

  // Get the parent path of the base path
  final File aBaseFile = new File (sBaseURIWithoutPrefix).getParentFile ();

  // Concatenate the path with the URI to search
  final String sNewPath = FilenameHelper.getCleanPath (aBaseFile == null ? sSystemId
                                                                         : aBaseFile.getPath () + '/' + sSystemId);

  final ClassPathResource ret = new ClassPathResource (sNewPath, aClassLoader);
  if (isDebugResolve ())
    if (LOGGER.isInfoEnabled ())
      LOGGER.info ("  [ClassPath] resolved base + system to " + ret);
  return ret;
}
 
Example #6
Source File: Issue19Test.java    From ph-css with Apache License 2.0 6 votes vote down vote up
@Test
public void testIssue ()
{
  // Multiple errors contained
  final IReadableResource aRes = new ClassPathResource ("testfiles/css30/bad_but_browsercompliant/issue19.css");
  assertTrue (aRes.exists ());
  final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
                                                             new CSSReaderSettings ().setFallbackCharset (StandardCharsets.UTF_8)
                                                                                     .setCSSVersion (ECSSVersion.CSS30)
                                                                                     .setCustomErrorHandler (new LoggingCSSParseErrorHandler ())
                                                                                     .setBrowserCompliantMode (true));
  assertNotNull (aCSS);
  if (false)
    System.out.println (new CSSWriter (ECSSVersion.CSS30).getCSSAsString (aCSS));
  assertEquals (1, aCSS.getRuleCount ());
  assertEquals (1, aCSS.getStyleRuleCount ());
}
 
Example #7
Source File: SVRLMarshallerTest.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteValid () throws Exception
{
  final Document aDoc = SchematronResourceSCH.fromClassPath (VALID_SCHEMATRON)
                                             .applySchematronValidation (new ClassPathResource (VALID_XMLINSTANCE));
  assertNotNull (aDoc);
  final SchematronOutputType aSO = new SVRLMarshaller ().read (aDoc);

  // Create XML
  final Document aDoc2 = new SVRLMarshaller ().getAsDocument (aSO);
  assertNotNull (aDoc2);
  assertEquals (CSVRL.SVRL_NAMESPACE_URI, aDoc2.getDocumentElement ().getNamespaceURI ());

  // Create String
  final String sDoc2 = new SVRLMarshaller ().getAsString (aSO);
  assertTrue (StringHelper.hasText (sDoc2));
  assertTrue (sDoc2.contains (CSVRL.SVRL_NAMESPACE_URI));
}
 
Example #8
Source File: LoggingTransformErrorListenerTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  final LoggingTransformErrorListener el = new LoggingTransformErrorListener (L_EN);
  final TransformerFactory fac = XMLTransformerFactory.createTransformerFactory (el,
                                                                                 new LoggingTransformURIResolver ());
  assertNotNull (fac);

  // Read valid XSLT
  Templates t1 = XMLTransformerFactory.newTemplates (fac, new ClassPathResource ("xml/test1.xslt"));
  assertNotNull (t1);

  // Read valid XSLT (with import)
  t1 = XMLTransformerFactory.newTemplates (fac, new ClassPathResource ("xml/test2.xslt"));
  assertNotNull (t1);

  // Read invalid XSLT
  assertNull (XMLTransformerFactory.newTemplates (fac, new ClassPathResource ("test1.txt")));

  CommonsTestHelper.testToStringImplementation (el);
}
 
Example #9
Source File: RelaxNGCompactSchemaCacheTest.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Test
public void testSVRL () throws IOException
{
  // Check the document
  try
  {
    // Get a validator from the schema.
    final Validator aValidator = RelaxNGCompactSchemaCache.getInstance ()
                                                          .getValidator (new ClassPathResource ("schemas/svrl-2006.rnc"));

    aValidator.validate (TransformSourceFactory.create (new ClassPathResource ("test-svrl/test1.svrl")));
    // Success
  }
  catch (final SAXException ex)
  {
    fail (ex.getMessage ());
  }
}
 
Example #10
Source File: CSSWriterFuncTest.java    From ph-css with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompressCSS_Size ()
{
  final CascadingStyleSheet aCSS = CSSReader.readFromStream (new ClassPathResource ("/testfiles/css21/good/phloc/test/content.css"),
                                                             StandardCharsets.UTF_8,
                                                             ECSSVersion.CSS30);
  assertNotNull (aCSS);

  // Only whitespace optimization
  final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS21, true);
  String sContent = new CSSWriter (aSettings).getCSSAsString (aCSS);
  assertEquals (2846, sContent.length ());

  // Also remove empty declarations
  aSettings.setRemoveUnnecessaryCode (true);
  sContent = new CSSWriter (aSettings).getCSSAsString (aCSS);
  assertEquals (2839, sContent.length ());
}
 
Example #11
Source File: ConfigFactoryTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testSysPropConfigUrlProperties ()
{
  SystemProperties.setPropertyValue ("config.url", new ClassPathResource ("sysprops/url.properties").getAsURL ().toExternalForm ());
  try
  {
    final IConfig aConfig = Config.create (ConfigFactory.createDefaultValueProvider ());
    assertEquals ("from-sysprop-url-properties0", aConfig.getAsString ("element0"));
    assertEquals ("from-private-application-properties1", aConfig.getAsString ("element1"));
    assertEquals ("from-application-json2", aConfig.getAsString ("element2"));
    assertEquals ("from-application-properties3", aConfig.getAsString ("element3"));
    assertEquals ("from-reference-properties4", aConfig.getAsString ("element4"));
    assertNull (aConfig.getAsString ("element5"));
  }
  finally
  {
    SystemProperties.removePropertyValue ("config.url");
  }
}
 
Example #12
Source File: ConfigFactoryTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testSysPropConfigUrlJson ()
{
  SystemProperties.setPropertyValue ("config.url", new ClassPathResource ("sysprops/url.json").getAsURL ().toExternalForm ());
  try
  {
    final IConfig aConfig = Config.create (ConfigFactory.createDefaultValueProvider ());
    assertEquals ("from-sysprop-url-json0", aConfig.getAsString ("element0"));
    assertEquals ("from-private-application-properties1", aConfig.getAsString ("element1"));
    assertEquals ("from-application-json2", aConfig.getAsString ("element2"));
    assertEquals ("from-application-properties3", aConfig.getAsString ("element3"));
    assertEquals ("from-reference-properties4", aConfig.getAsString ("element4"));
    assertNull (aConfig.getAsString ("element5"));
  }
  finally
  {
    SystemProperties.removePropertyValue ("config.url");
  }
}
 
Example #13
Source File: Issue21Test.java    From ph-css with Apache License 2.0 6 votes vote down vote up
@Test
public void testIssue ()
{
  // Multiple errors contained
  final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue21.css");
  assertTrue (aRes.exists ());
  final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
                                                             new CSSReaderSettings ().setFallbackCharset (StandardCharsets.UTF_8)
                                                                                     .setCustomErrorHandler (new LoggingCSSParseErrorHandler ())
                                                                                     .setBrowserCompliantMode (true));
  assertNotNull (aCSS);
  if (false)
    System.out.println (new CSSWriter (ECSSVersion.CSS30).getCSSAsString (aCSS));
  assertEquals (2, aCSS.getRuleCount ());
  assertEquals (2, aCSS.getStyleRuleCount ());
}
 
Example #14
Source File: Issue8Test.java    From ph-css with Apache License 2.0 6 votes vote down vote up
@Test
public void testIssue8 ()
{
  final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue8.css");
  assertTrue (aRes.exists ());
  final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
                                                             StandardCharsets.UTF_8,
                                                             ECSSVersion.CSS30,
                                                             new LoggingCSSParseErrorHandler ());
  assertNotNull (aCSS);

  assertEquals (1, aCSS.getStyleRuleCount ());
  final CSSStyleRule aStyleRule = aCSS.getStyleRuleAtIndex (0);
  assertNotNull (aStyleRule);

  assertEquals (4, aStyleRule.getDeclarationCount ());
}
 
Example #15
Source File: DefaultTransformURIResolverTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  for (int i = 0; i < 2; ++i)
  {
    final DefaultTransformURIResolver res = new DefaultTransformURIResolver (i == 0 ? null
                                                                                    : new LoggingTransformURIResolver ());
    final TransformerFactory fac = XMLTransformerFactory.createTransformerFactory (null, res);
    assertNotNull (fac);

    // Read valid XSLT
    Templates t1 = XMLTransformerFactory.newTemplates (fac, new ClassPathResource ("xml/test1.xslt"));
    assertNotNull (t1);

    // Read valid XSLT with valid include
    t1 = XMLTransformerFactory.newTemplates (fac, new ClassPathResource ("xml/test2.xslt"));
    assertNotNull (t1);

    // Read valid XSLT with invalid include
    t1 = XMLTransformerFactory.newTemplates (fac, new ClassPathResource ("xml/test3.xslt"));
    assertNull (t1);

    CommonsTestHelper.testToStringImplementation (res);
  }
}
 
Example #16
Source File: SchematronHelperTest.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadValidSchematronValidXML ()
{
  final ISchematronResource aSchematron = SchematronResourceSCH.fromClassPath (VALID_SCHEMATRON);
  final IReadableResource aXML = new ClassPathResource (VALID_XMLINSTANCE);
  final SchematronOutputType aSO = SchematronHelper.applySchematron (aSchematron, aXML);
  assertNotNull ("Failed to parse Schematron output", aSO);
}
 
Example #17
Source File: Issue9Test.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Test
public void testIssue9 ()
{
  // File starts (and ends) with an invalid comment
  final IReadableResource aRes = new ClassPathResource ("testfiles/css30/bad/issue9.css");
  assertTrue (aRes.exists ());
  final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
                                                             StandardCharsets.UTF_8,
                                                             ECSSVersion.CSS30,
                                                             new LoggingCSSParseErrorHandler ());
  assertNull (aCSS);
}
 
Example #18
Source File: Issue4Test.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Test
public void testIssue4 ()
{
  final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue4.css");
  assertTrue (aRes.exists ());
  final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
                                                             StandardCharsets.UTF_8,
                                                             ECSSVersion.CSS30,
                                                             new LoggingCSSParseErrorHandler ());
  assertNotNull (aCSS);
  if (false)
    System.out.println (new CSSWriter (ECSSVersion.CSS30).getCSSAsString (aCSS));
}
 
Example #19
Source File: UBL22InvoiceHelperTest.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
@Test
public void testComvertBackAndForth ()
{
  for (final String sFilename : MockUBL22TestDocuments.getUBL22TestDocuments (EUBL22DocumentType.INVOICE))
  {
    LOGGER.info (sFilename);

    // Read
    final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource (sFilename),
                                                new DOMReaderSettings ().setSchema (EUBL22DocumentType.INVOICE.getSchema ()));
    assertNotNull (sFilename, aDoc);
    final InvoiceType aUBLObject = UBL22Reader.invoice ().read (aDoc);
    assertNotNull (sFilename, aUBLObject);

    // Convert Invoice to CreditNote
    final CreditNoteType aCreditNote = new CreditNoteType ();
    UBL22InvoiceHelper.cloneInvoiceToCreditNote (aUBLObject, aCreditNote);

    // Validate CreditNote
    IErrorList aErrors = UBL22Validator.creditNote ().validate (aCreditNote);
    assertNotNull (sFilename, aErrors);
    assertFalse (sFilename, aErrors.containsAtLeastOneError ());

    // Convert CreditNote back to Invoice
    final InvoiceType aInvoice2 = new InvoiceType ();
    UBL22CreditNoteHelper.cloneCreditNoteToInvoice (aCreditNote, aInvoice2);

    // Validate Invoice again
    aErrors = UBL22Validator.invoice ().validate (aInvoice2);
    assertNotNull (sFilename, aErrors);
    assertFalse (sFilename, aErrors.containsAtLeastOneError ());
  }
}
 
Example #20
Source File: FileHelperTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testExistsDir ()
{
  assertFalse (FileHelper.existsDir (new File ("oaaajeee")));
  assertTrue (FileHelper.existsDir (new File ("src")));
  assertFalse (FileHelper.existsDir (ClassPathResource.getAsFile ("streamutils-lines")));
}
 
Example #21
Source File: SchematronHelperTest.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadInvalidSchematronInvalidXML ()
{
  final SchematronOutputType aSO = SchematronHelper.applySchematron (SchematronResourceSCH.fromClassPath (VALID_SCHEMATRON +
                                                                                                          ".does.not.exist"),
                                                                     new ClassPathResource (VALID_XMLINSTANCE +
                                                                                            ".does.not.exist"));
  assertNull ("Invalid Schematron and XML", aSO);
}
 
Example #22
Source File: SchematronHelperTest.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadInvalidSchematronValidXML ()
{
  final SchematronOutputType aSO = SchematronHelper.applySchematron (SchematronResourceSCH.fromClassPath (VALID_SCHEMATRON +
                                                                                                          ".does.not.exist"),
                                                                     new ClassPathResource (VALID_XMLINSTANCE));
  assertNull ("Invalid Schematron", aSO);
}
 
Example #23
Source File: SchematronHelperTest.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadValidSchematronInvalidXML ()
{
  final SchematronOutputType aSO = SchematronHelper.applySchematron (SchematronResourceSCH.fromClassPath (VALID_SCHEMATRON),
                                                                     new ClassPathResource (VALID_XMLINSTANCE +
                                                                                            ".does.not.exist"));
  assertNull ("Invalid XML", aSO);
}
 
Example #24
Source File: GenericJAXBMarshaller.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return A list of all XSD resources used for validation. Never
 *         <code>null</code>.
 */
@Nonnull
@Nonempty
@ReturnsMutableCopy
public final ICommonsList <ClassPathResource> getOriginalXSDs ()
{
  return m_aXSDs.getClone ();
}
 
Example #25
Source File: SchematronResourceSCHCacheTest.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidSchematron ()
{
  assertFalse (new SchematronResourceSCH (new ClassPathResource ("test-sch/invalid01.sch")).isValidSchematron ());
  assertFalse (new SchematronResourceSCH (new ClassPathResource ("test-sch/this.file.does.not.exists")).isValidSchematron ());

  assertFalse (new SchematronResourceSCH (new FileSystemResource ("src/test/resources/test-sch/invalid01.sch")).isValidSchematron ());
  assertFalse (new SchematronResourceSCH (new FileSystemResource ("src/test/resources/test-sch/this.file.does.not.exists")).isValidSchematron ());
}
 
Example #26
Source File: FileHelperTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressFBWarnings (value = "DMI_HARDCODED_ABSOLUTE_FILENAME")
public void testEnsureParentDirectoryIsPresent ()
{
  // Root directory (no parent)
  assertTrue (FileHelper.ensureParentDirectoryIsPresent (new File ("/")).isUnchanged ());
  // Existing folder
  assertTrue (FileHelper.ensureParentDirectoryIsPresent (new File ("src")).isUnchanged ());
  // Existing file
  assertTrue (FileHelper.ensureParentDirectoryIsPresent (ClassPathResource.getAsFile ("streamutils-lines"))
                        .isUnchanged ());

  // Non existing object
  try
  {
    assertTrue (FileHelper.ensureParentDirectoryIsPresent (new File ("parent", "file")).isChanged ());
    assertTrue (FileHelper.existsDir (new File ("parent")));
    assertTrue (FileHelper.ensureParentDirectoryIsPresent (new File ("parent", "file2")).isUnchanged ());
  }
  finally
  {
    FileOperations.deleteDirRecursive (new File ("parent"));
  }

  try
  {
    FileHelper.ensureParentDirectoryIsPresent (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #27
Source File: SimpleFileIOTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testReaFileLines ()
{
  assertNull (SimpleFileIO.getAllFileLines (null, StandardCharsets.ISO_8859_1));
  assertNull (SimpleFileIO.getAllFileLines (new File ("ha ha said the clown"), StandardCharsets.ISO_8859_1));
  final File aFile = ClassPathResource.getAsFile ("streamutils-lines");
  assertTrue (aFile.exists ());
  final ICommonsList <String> lines = SimpleFileIO.getAllFileLines (aFile, StandardCharsets.ISO_8859_1);
  assertEquals (10, lines.size ());
}
 
Example #28
Source File: SchematronResourceSCHCacheTest.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidAsynchronous () throws Exception
{
  // Ensure that the Schematron is cached
  SchematronResourceSCH.fromClassPath (VALID_SCHEMATRON);

  // Create Thread pool with fixed number of threads
  final ExecutorService aSenderThreadPool = Executors.newFixedThreadPool (Runtime.getRuntime ()
                                                                                 .availableProcessors () *
                                                                          2);

  final long nStart = System.nanoTime ();
  for (int i = 0; i < RUNS; ++i)
  {
    aSenderThreadPool.submit ( () -> {
      try
      {
        final ISchematronResource aSV = SchematronResourceSCH.fromClassPath (VALID_SCHEMATRON);
        final Document aDoc = aSV.applySchematronValidation (new ClassPathResource (VALID_XMLINSTANCE));
        assertNotNull (aDoc);
      }
      catch (final Exception ex)
      {
        throw new IllegalStateException (ex);
      }
    });
  }
  ExecutorServiceHelper.shutdownAndWaitUntilAllTasksAreFinished (aSenderThreadPool);
  final long nEnd = System.nanoTime ();
  LOGGER.info ("Async Total: " +
               ((nEnd - nStart) / 1000) +
               " microsecs btw. " +
               ((nEnd - nStart) / 1000 / RUNS) +
               " microsecs/run");
}
 
Example #29
Source File: Issue24Test.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Test
public void testIssue ()
{
  final IReadableResource aRes = new ClassPathResource ("testfiles/css30/bad_but_browsercompliant/issue24.css");
  assertTrue (aRes.exists ());
  final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
                                                             new CSSReaderSettings ().setFallbackCharset (StandardCharsets.UTF_8)
                                                                                     .setBrowserCompliantMode (true)
                                                                                     .setCustomErrorHandler (new LoggingCSSParseErrorHandler ()));
  assertNotNull (aCSS);
  if (false)
    System.out.println (new CSSWriter ().getCSSAsString (aCSS));
}
 
Example #30
Source File: SchematronProviderXSLTFromSCH.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void cacheXSLTTemplates ()
{
  // prepare all steps
  if (s_aStep1 == null)
  {
    final TransformerFactory aTF = SchematronTransformerFactory.getDefaultSaxonFirst ();

    // Step 1
    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Creating XSLT step 1 template");
    s_aStep1 = XMLTransformerFactory.newTemplates (aTF,
                                                   new ClassPathResource (XSLT2_STEP1,
                                                                          SchematronProviderXSLTFromSCH.class.getClassLoader ()));
    if (s_aStep1 == null)
      throw new IllegalStateException ("Failed to compile '" + XSLT2_STEP1 + "'");

    // Step 2
    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Creating XSLT step 2 template");
    s_aStep2 = XMLTransformerFactory.newTemplates (aTF,
                                                   new ClassPathResource (XSLT2_STEP2,
                                                                          SchematronProviderXSLTFromSCH.class.getClassLoader ()));
    if (s_aStep2 == null)
      throw new IllegalStateException ("Failed to compile '" + XSLT2_STEP2 + "'");

    // Step 3
    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Creating XSLT step 3 template");
    s_aStep3 = XMLTransformerFactory.newTemplates (aTF,
                                                   new ClassPathResource (XSLT2_STEP3,
                                                                          SchematronProviderXSLTFromSCH.class.getClassLoader ()));
    if (s_aStep3 == null)
      throw new IllegalStateException ("Failed to compile '" + XSLT2_STEP3 + "'");
  }
}