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

The following examples show how to use com.helger.commons.io.resource.FileSystemResource. 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: DocumentationExamples.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
public static boolean validateXMLViaPureSchematron2 (@Nonnull final File aSchematronFile,
                                                     @Nonnull final File aXMLFile) throws Exception
{
  // Read the schematron from file
  final PSSchema aSchema = new PSReader (new FileSystemResource (aSchematronFile)).readSchema ();
  if (!aSchema.isValid (new DoNothingPSErrorHandler ()))
    throw new IllegalArgumentException ("Invalid Schematron!");
  // Resolve the query binding to use
  final IPSQueryBinding aQueryBinding = PSQueryBindingRegistry.getQueryBindingOfNameOrThrow (aSchema.getQueryBinding ());
  // Pre-process schema
  final PSPreprocessor aPreprocessor = new PSPreprocessor (aQueryBinding);
  aPreprocessor.setKeepTitles (true);
  final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema (aSchema);
  // Bind the pre-processed schema
  final IPSBoundSchema aBoundSchema = aQueryBinding.bind (aPreprocessedSchema);
  // Read the XML file
  final Document aXMLNode = DOMReader.readXMLDOM (aXMLFile);
  if (aXMLNode == null)
    return false;
  // Perform the validation
  return aBoundSchema.validatePartially (aXMLNode, FileHelper.getAsURLString (aXMLFile)).isValid ();
}
 
Example #2
Source File: InputSourceFactory.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
public static InputSource create (@Nonnull final IReadableResource aResource)
{
  if (aResource instanceof FileSystemResource)
  {
    final File aFile = aResource.getAsFile ();
    if (aFile != null)
    {
      // Potentially use memory mapped files
      final InputSource ret = create (FileHelper.getInputStream (aFile));
      if (ret != null)
      {
        // Ensure system ID is present - may be helpful for resource
        // resolution
        final URL aURL = aResource.getAsURL ();
        if (aURL != null)
          ret.setSystemId (aURL.toExternalForm ());
      }
      return ret;
    }
  }
  return new ReadableResourceSAXInputSource (aResource);
}
 
Example #3
Source File: ConfigurationSourcePropertiesTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final ConfigurationSourceProperties c = new ConfigurationSourceProperties (f);
  assertSame (EConfigSourceType.RESOURCE, c.getSourceType ());
  assertEquals (EConfigSourceType.RESOURCE.getDefaultPriority (), c.getPriority ());
  assertTrue (c.isInitializedAndUsable ());
  assertSame (f, c.getResource ());
  assertEquals ("string", c.getConfigurationValue ("element1").getValue ());
  assertEquals ("2", c.getConfigurationValue ("element2").getValue ());
  assertNull (c.getConfigurationValue ("what a mess"));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (c, new ConfigurationSourceProperties (f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (c, new ConfigurationSourceProperties (1234, f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (c,
                                                                         new ConfigurationSourceProperties (new FileSystemResource (new File ("bla"))));
}
 
Example #4
Source File: Issue48Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  final PSSchema aSchema = new PSReader (new FileSystemResource (aSchematron)).readSchema ();
  final PSPreprocessor aPreprocessor = new PSPreprocessor (PSXPathQueryBinding.getInstance ());
  final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema (aSchema);
  final String sSCH = new PSWriter (new PSWriterSettings ().setXMLWriterSettings (new XMLWriterSettings ())).getXMLString (aPreprocessedSchema);

  if (false)
    System.out.println (sSCH);

  final SchematronResourceSCH aSCH = new SchematronResourceSCH (new ReadableResourceString (sSCH,
                                                                                            StandardCharsets.UTF_8));

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #5
Source File: Issue16Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
public static boolean validateXMLViaPureSchematron2 (@Nonnull final File aSchematronFile,
                                                     @Nonnull final File aXMLFile) throws Exception
{
  // Read the schematron from file
  final PSSchema aSchema = new PSReader (new FileSystemResource (aSchematronFile)).readSchema ();
  if (!aSchema.isValid (new DoNothingPSErrorHandler ()))
    throw new IllegalArgumentException ("Invalid Schematron!");
  // Resolve the query binding to use
  final IPSQueryBinding aQueryBinding = PSQueryBindingRegistry.getQueryBindingOfNameOrThrow (aSchema.getQueryBinding ());
  // Pre-process schema
  final PSPreprocessor aPreprocessor = new PSPreprocessor (aQueryBinding);
  aPreprocessor.setKeepTitles (true);
  final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema (aSchema);
  // Bind the pre-processed schema
  final IPSBoundSchema aBoundSchema = aQueryBinding.bind (aPreprocessedSchema);
  // Read the XML file
  final Document aXMLNode = DOMReader.readXMLDOM (aXMLFile);
  if (aXMLNode == null)
    return false;
  // Perform the validation
  return aBoundSchema.validatePartially (aXMLNode, FileHelper.getAsURLString (aXMLFile)).isValid ();
}
 
Example #6
Source File: Issue88Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
private static void _validateAndProduceSVRL (@Nonnull final File aSchematron,
                                             @Nonnull final File aXML) throws Exception
{
  SchematronDebug.setSaveIntermediateXSLTFiles (true);
  final ISchematronResource aSCH = SchematronResourcePure.fromFile (aSchematron);
  if (aSCH instanceof SchematronResourcePure)
    ((SchematronResourcePure) aSCH).setCustomValidationHandler (new LoggingPSValidationHandler ());

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);

  LOGGER.info ("SVRL:\n" + new SVRLMarshaller ().getAsString (aSVRL));

  assertTrue (SVRLHelper.getAllFailedAssertionsAndSuccessfulReports (aSVRL).isEmpty ());
}
 
Example #7
Source File: Issue6Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@SuppressFBWarnings ("BC_IMPOSSIBLE_INSTANCEOF")
public static void validateAndProduceSVRL (final File schematron, final File xml) throws Exception
{
  final IReadableResource aSchematron = new FileSystemResource (schematron.getAbsoluteFile ());
  final IReadableResource anXMLSource = new FileSystemResource (xml.getAbsoluteFile ());
  final AbstractSchematronResource aSCH = new SchematronResourceSCH (aSchematron);
  if (aSCH instanceof SchematronResourcePure)
    ((SchematronResourcePure) aSCH).setErrorHandler (new LoggingPSErrorHandler ());
  else
    System.out.println (XMLWriter.getNodeAsString (((SchematronResourceSCH) aSCH).getXSLTProvider ()
                                                                                 .getXSLTDocument ()));
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (anXMLSource);
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #8
Source File: Issue8Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  final SchematronResourceSCH aSCH = SchematronResourceSCH.fromFile (aSchematron);

  // Assign custom parameters
  aSCH.parameters ().put ("xyz", "mobile");
  aSCH.parameters ().put ("expected", "");

  if (false)
    System.out.println (XMLWriter.getNodeAsString (aSCH.getXSLTProvider ().getXSLTDocument ()));

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #9
Source File: Issue77Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
private static void _validateAndProduceSVRL (@Nonnull final File aSchematron,
                                             @Nonnull final File aXML,
                                             final boolean bValid) throws Exception
{
  final SchematronResourceSCH aSCH = SchematronResourceSCH.fromFile (aSchematron);
  aSCH.setAllowForeignElements (true);

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);

  if (bValid)
    assertTrue (SVRLHelper.getAllFailedAssertionsAndSuccessfulReports (aSVRL).isEmpty ());
  else
    assertTrue (SVRLHelper.getAllFailedAssertionsAndSuccessfulReports (aSVRL).isNotEmpty ());
}
 
Example #10
Source File: Issue99Test.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
private static void _validateAndProduceSVRL (@Nonnull final File aSchematron,
                                             @Nonnull final File aXML) throws Exception
{
  SchematronDebug.setSaveIntermediateXSLTFiles (true);

  final StopWatch aSW = StopWatch.createdStarted ();
  LOGGER.info ("Start");
  final ISchematronResource aSCH = SchematronResourcePure.fromFile (aSchematron);
  if (aSCH instanceof SchematronResourcePure)
    ((SchematronResourcePure) aSCH).setCustomValidationHandler (new LoggingPSValidationHandler ());

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);

  aSW.stop ();
  LOGGER.info ("Took " + aSW.getSeconds () + " seconds");

  LOGGER.info ("SVRL:\n" + new SVRLMarshaller ().getAsString (aSVRL));

  assertTrue (SVRLHelper.getAllFailedAssertionsAndSuccessfulReports (aSVRL).isEmpty ());
}
 
Example #11
Source File: PSPreprocessorTest.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Test
public void testIssue51 () throws SchematronException
{
  final PSPreprocessor aPreprocessor = new PSPreprocessor (PSXPathQueryBinding.getInstance ()).setKeepTitles (true)
                                                                                              .setKeepDiagnostics (true);
  final IReadableResource aRes = new FileSystemResource ("src/test/resources/issues/github51/test51.sch");
  final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes (aRes, true);
  final PSReader aReader = new PSReader (aRes).setLenient (true);
  final PSSchema aSchema = aReader.readSchemaFromXML (aDoc.getDocumentElement ());
  final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema (aSchema);
  assertNotNull (aPreprocessedSchema);
  assertTrue (aPreprocessedSchema.isValid (new DoNothingPSErrorHandler ()));

  final PSWriterSettings aPWS = new PSWriterSettings ();
  aPWS.setXMLWriterSettings (new XMLWriterSettings ().setIndent (EXMLSerializeIndent.INDENT_AND_ALIGN)
                                                     .setPutNamespaceContextPrefixesInRoot (true)
                                                     .setNamespaceContext (PSWriterSettings.createNamespaceMapping (aPreprocessedSchema)));
  LOGGER.info ("Preprocessed:\n" + new PSWriter (aPWS).getXMLString (aPreprocessedSchema));
}
 
Example #12
Source File: Issue20140523Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (final File schematron, final File xml) throws Exception
{
  final IReadableResource aSchematron = new FileSystemResource (schematron.getAbsoluteFile ());
  final IReadableResource anXMLSource = new FileSystemResource (xml.getAbsoluteFile ());
  final AbstractSchematronResource pure = new SchematronResourcePure (aSchematron);
  final SchematronOutputType aSVRL = pure.applySchematronValidationToSVRL (anXMLSource);
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #13
Source File: CSSReaderDeclarationList.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nullable
public static CSSDeclarationList readFromFile (@Nonnull final File aFile,
                                               @Nonnull final Charset aCharset,
                                               @Nonnull final ECSSVersion eVersion)
{
  return readFromReader (new FileSystemResource (aFile).getReader (aCharset),
                         new CSSReaderSettings ().setCSSVersion (eVersion));
}
 
Example #14
Source File: IssueDita1.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (final File aSchematronFile, final File aXmlFile) throws Exception
{
  final AbstractSchematronResource aSCH = SchematronResourcePure.fromFile (aSchematronFile);
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXmlFile));
  assertNotNull (aSVRL);
  if (true)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #15
Source File: IssueGC5Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (final File schematron, final File xml) throws Exception
{
  final IReadableResource aSchematron = new FileSystemResource (schematron.getAbsoluteFile ());
  final IReadableResource anXMLSource = new FileSystemResource (xml.getAbsoluteFile ());
  final SchematronResourcePure pure = new SchematronResourcePure (aSchematron);
  // final FileOutputStream fos = new FileOutputStream (result);
  // final Result res = new StreamResult (fos);

  // res.setSystemId(result.getAbsolutePath());
  // final SchematronOutputType svrl = pure.applySchematronValidationToSVRL
  // (anXMLSource);
  final SchematronOutputType aSO = SchematronHelper.applySchematron (pure, anXMLSource);
  final ICommonsList <SVRLFailedAssert> aFailedAsserts = SVRLHelper.getAllFailedAssertions (aSO);
  LOGGER.info (aFailedAsserts.toString ());
}
 
Example #16
Source File: IssueGC7Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (final File schematron, final File xml) throws Exception
{
  final IReadableResource aSchematron = new FileSystemResource (schematron.getAbsoluteFile ());
  final IReadableResource anXMLSource = new FileSystemResource (xml.getAbsoluteFile ());
  final AbstractSchematronResource pure = new SchematronResourcePure (aSchematron);
  final SchematronOutputType aSVRL = pure.applySchematronValidationToSVRL (anXMLSource);
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #17
Source File: Issue16Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static boolean readModifyAndWrite (@Nonnull final File aSchematronFile) throws Exception
{
  final PSSchema aSchema = new PSReader (new FileSystemResource (aSchematronFile)).readSchema ();
  final PSTitle aTitle = new PSTitle ();
  aTitle.addText ("Created by ph-schematron");
  aSchema.setTitle (aTitle);
  return MicroWriter.writeToFile (aSchema.getAsMicroElement (), aSchematronFile).isSuccess ();
}
 
Example #18
Source File: Issue54Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  final ISchematronResource aSCH = SchematronResourcePure.fromFile (aSchematron);

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #19
Source File: CSSReaderDeclarationList.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nullable
public static CSSDeclarationList readFromFile (@Nonnull final File aFile,
                                               @Nonnull final Charset aCharset,
                                               @Nonnull final ECSSVersion eVersion,
                                               @Nullable final ICSSParseExceptionCallback aCustomExceptionHandler)
{
  return readFromReader (new FileSystemResource (aFile).getReader (aCharset),
                         new CSSReaderSettings ().setCSSVersion (eVersion)
                                                 .setCustomExceptionHandler (aCustomExceptionHandler));
}
 
Example #20
Source File: Issue36Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Test
public void test () throws Exception
{
  final SchematronResourcePure aResPure = SchematronResourcePure.fromFile ("src/test/resources/issues/github36/test.sch");
  aResPure.setErrorHandler (new LoggingPSErrorHandler ());

  final SchematronOutputType aSOT = aResPure.applySchematronValidationToSVRL (new FileSystemResource ("src/test/resources/issues/github36/test.xml"));
  assertNotNull (aSOT);
  assertFalse (SVRLHelper.getAllFailedAssertions (aSOT).isEmpty ());
}
 
Example #21
Source File: Issue11Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  final SchematronResourcePure aSCH = SchematronResourcePure.fromFile (aSchematron);
  aSCH.setErrorHandler (new LoggingPSErrorHandler ());
  assertTrue (aSCH.isValidSchematron ());

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #22
Source File: Issue64Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  final SchematronResourcePure aSCH = SchematronResourcePure.fromFile (aSchematron);
  aSCH.setErrorHandler (new LoggingPSErrorHandler ());

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
}
 
Example #23
Source File: Issue47Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  IXPathConfig aXPathConfig = new XPathConfigBuilder ().setXPathFunctionResolver ( (aFunctionName, aArity) -> {
    System.out.println (aFunctionName + " - " + aArity);
    return null;
  }).build ();
  final SchematronResourcePure aSCH = new SchematronResourcePure (new FileSystemResource (aSchematron)).setXPathConfig (aXPathConfig);

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #24
Source File: IssueXsltKeyTest.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (final File schematron, final File xml) throws Exception
{
  final IReadableResource aSchematron = new FileSystemResource (schematron.getAbsoluteFile ());
  final IReadableResource anXMLSource = new FileSystemResource (xml.getAbsoluteFile ());
  final AbstractSchematronResource pure = new SchematronResourceSCH (aSchematron);
  final SchematronOutputType aSVRL = pure.applySchematronValidationToSVRL (anXMLSource);
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #25
Source File: CSSReaderDeclarationList.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nullable
public static CSSDeclarationList readFromFile (@Nonnull final File aFile,
                                               @Nonnull final Charset aCharset,
                                               @Nonnull final ECSSVersion eVersion,
                                               @Nullable final ICSSParseErrorHandler aCustomErrorHandler,
                                               @Nullable final ICSSParseExceptionCallback aCustomExceptionHandler)
{
  return readFromReader (new FileSystemResource (aFile).getReader (aCharset),
                         new CSSReaderSettings ().setCSSVersion (eVersion)
                                                 .setCustomErrorHandler (aCustomErrorHandler)
                                                 .setCustomExceptionHandler (aCustomExceptionHandler));
}
 
Example #26
Source File: Issue44Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  // SchematronResourcePure fails!
  ISchematronResource aSCH = SchematronResourcePure.fromFile (aSchematron);
  // Parsing Schematron works!
  aSCH = SchematronResourceSCH.fromFile (aSchematron);

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));

  assertEquals (3, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports (aSVRL).size ());
}
 
Example #27
Source File: IssueGC6Test.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void validateAndProduceSVRL (final File schematron, final File xml) throws Exception
{
  final IReadableResource aSchematron = new FileSystemResource (schematron.getAbsoluteFile ());
  final IReadableResource anXMLSource = new FileSystemResource (xml.getAbsoluteFile ());
  final AbstractSchematronResource pure = new SchematronResourcePure (aSchematron);
  final SchematronOutputType aSVRL = pure.applySchematronValidationToSVRL (anXMLSource);
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
Example #28
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 #29
Source File: Issue35Test.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Test
public void testIssue ()
{
  final String css = StreamHelper.getAllBytesAsString (new FileSystemResource ("src/test/resources/testfiles/css30/good/issue35.css"),
                                                       StandardCharsets.UTF_8);
  final CSSReaderSettings aSettings = new CSSReaderSettings ().setCSSVersion (ECSSVersion.LATEST)
                                                              .setBrowserCompliantMode (false);
  final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream (css, aSettings);
  assertNotNull (cascadingStyleSheet);
  final CSSWriter writer = new CSSWriter (new CSSWriterSettings (ECSSVersion.LATEST, true));
  assertNotNull (writer.getCSSAsString (cascadingStyleSheet));
}
 
Example #30
Source File: CSSReaderDeclarationList.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nullable
public static CSSDeclarationList readFromFile (@Nonnull final File aFile,
                                               @Nonnull final Charset aCharset,
                                               @Nonnull final ECSSVersion eVersion,
                                               @Nullable final ICSSParseErrorHandler aCustomErrorHandler)
{
  return readFromReader (new FileSystemResource (aFile).getReader (aCharset),
                         new CSSReaderSettings ().setCSSVersion (eVersion)
                                                 .setCustomErrorHandler (aCustomErrorHandler));
}