Skip to content

Commit

Permalink
XML Catalogs for XML files should now work; #40
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed May 5, 2017
1 parent 0456669 commit af05601
Show file tree
Hide file tree
Showing 6 changed files with 454 additions and 23 deletions.
6 changes: 6 additions & 0 deletions ph-schematron-ant-task/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
<version>${ant.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-apache-resolver</artifactId>
<version>${ant.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ public class Schematron extends Task
*/
private boolean m_bExpectSuccess = true;

/** for resolving entities such as dtds */
/**
* For resolving entities such as DTDs. This is used both for the Schematron
* file as well as for the XML files to be validated.
*/
private final XMLCatalog m_aXmlCatalog = new XMLCatalog ();

public Schematron ()
{}

public void setSchematronFile (@Nonnull final File aFile)
{
m_aSchematronFile = aFile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,74 @@
package com.helger.schematron.ant;

import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.Project;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.helger.commons.system.SystemProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class Issue40Test
{
private static final Logger s_aLogger = LoggerFactory.getLogger (Issue40Test.class);

@Rule
public final BuildFileRule buildRule = new BuildFileRule ();
public final BuildFileRule m_aBuildRule = new BuildFileRule ();

@Before
public void init ()
{
SystemProperties.setPropertyValue ("javax.xml.accessExternalDTD", "all");
buildRule.configureProject ("src/test/resources/issues/40/build.xml");
m_aBuildRule.configureProject ("src/test/resources/issues/40/build.xml");
m_aBuildRule.getProject ().addBuildListener (new BuildListener ()
{
public void taskStarted (final BuildEvent aEvent)
{}

public void taskFinished (final BuildEvent aEvent)
{}

public void targetStarted (final BuildEvent aEvent)
{}

public void targetFinished (final BuildEvent aEvent)
{}

public void messageLogged (final BuildEvent aEvent)
{
if (aEvent.getPriority () <= Project.MSG_ERR)
s_aLogger.error (aEvent.getMessage (), aEvent.getException ());
else
if (aEvent.getPriority () <= Project.MSG_WARN)
s_aLogger.warn (aEvent.getMessage (), aEvent.getException ());
else
if (aEvent.getPriority () <= Project.MSG_INFO)
s_aLogger.info (aEvent.getMessage (), aEvent.getException ());
else
s_aLogger.debug (aEvent.getMessage (), aEvent.getException ());
}

public void buildStarted (final BuildEvent aEvent)
{}

public void buildFinished (final BuildEvent aEvent)
{}
});
}

@Test
public void testWithExternalDTD ()
{
buildRule.executeTarget ("check");
try
{
// Do not redirect stdout etc.
m_aBuildRule.getProject ().executeTarget ("check");
}
catch (final BuildException ex)
{
s_aLogger.error ("Ooops", ex);
}
}
}
Loading

0 comments on commit af05601

Please sign in to comment.