@Nonnull
  public SchematronResourcePure setFunctionResolver (@Nullable final XPathFunctionResolver aFunctionResolver)
  {
    if (m_aBoundSchema != null)
      throw new IllegalStateException ("Schematron was already bound and can therefore not be altered!");
    m_aFunctionResolver = aFunctionResolver;
    return this;
  }

Set the function resolver to be used in the XPath statements. This can only
be set before the Schematron is bound. If it is already bound an exception
is thrown to indicate the unnecessity of the call.

@param aFunctionResolver
The function resolver to set. May be null.
@return this

Set the function resolver to be used in the XPath statements . This can only be set before the Schematron is bound . If it is already bound an exception is thrown to indicate the unnecessity of the call .


@Nonnull
  public SchematronResourcePure setEntityResolver (@Nullable final EntityResolver aEntityResolver)
  {
    if (m_aBoundSchema != null)
      throw new IllegalStateException ("Schematron was already bound and can therefore not be altered!");
    internalSetEntityResolver (aEntityResolver);
    return this;
  }

Set the XML entity resolver to be used when reading the Schematron or the
XML to be validated. This can only be set before the Schematron is bound.
If it is already bound an exception is thrown to indicate the unnecessity
of the call.

@param aEntityResolver
The entity resolver to set. May be null.
@return this
@since 4.1.1

Set the XML entity resolver to be used when reading the Schematron or the XML to be validated . This can only be set before the Schematron is bound . If it is already bound an exception is thrown to indicate the unnecessity of the call .


@Nonnull
  public IPSBoundSchema getOrCreateBoundSchema ()
  {
    if (m_aBoundSchema == null)
      try
      {
        m_aBoundSchema = createBoundSchema ();
      }
      catch (final RuntimeException ex)
      {
        if (m_aErrorHandler != null)
          m_aErrorHandler.error (getResource (), null, "Error creating bound schema", ex);
        throw ex;
      }

    return m_aBoundSchema;
  }

@
Nonnull
public
IPSBoundSchema
getOrCreateBoundSchema
(
)
{
if
(
m_aBoundSchema
==
)
try
{
m_aBoundSchema
=
createBoundSchema
(
)
;
}
catch
(
final
RuntimeException
ex
)
{
if
(
m_aErrorHandler
!=
)
m_aErrorHandler
.
error
(
getResource
(
)
,
,
"Error creating bound schema"
,
ex
)
;
throw
ex
;
}
return
m_aBoundSchema
;
}

Get the cached bound schema or create a new one.

@return The bound schema. Never null.

Get the cached bound schema or create a new one .


public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
  {
    ValueEnforcer.notNull (aErrorHandler, "ErrorHandler");

    try
    {
      getOrCreateBoundSchema ().getOriginalSchema ().validateCompletely (aErrorHandler);
    }
    catch (final RuntimeException ex)
    {
      // May happen when XPath errors are contained
    }
  }

Use the provided error handler to validate all elements in the schematron.
It tries to catch as many errors as possible.

@param aErrorHandler
The error handler to use. May not be null.

Use the provided error handler to validate all elements in the schematron . It tries to catch as many errors as possible .


@Nonnull
  public SchematronOutputType applySchematronValidationToSVRL (@Nonnull final Node aXMLNode,
                                                               @Nullable final String sBaseURI) throws SchematronException
  {
    ValueEnforcer.notNull (aXMLNode, "XMLNode");

    final SchematronOutputType aSOT = getOrCreateBoundSchema ().validateComplete (aXMLNode, sBaseURI);

    // Debug print the created SVRL document
    if (SchematronDebug.isShowCreatedSVRL ())
      LOGGER.info ("Created SVRL:\n" + new SVRLMarshaller (false).getAsString (aSOT));

    return aSOT;
  }

The main method to convert a node to an SVRL document.

@param aXMLNode
The source node to be validated. May not be null.
@param sBaseURI
Base URI of the XML document to be validated. May be
null.
@return The SVRL document. Never null.
@throws SchematronException
in case of a sever error validating the schema

The main method to convert a node to an SVRL document .


private void _resolveRuleContent (@Nonnull final ICommonsList <IPSElement> aRuleContent,
                                    @Nonnull final PreprocessorLookup aLookup,
                                    @Nonnull final PreprocessorIDPool aIDPool,
                                    @Nullable final ICommonsMap <String, String> aParamValueMap,
                                    @Nonnull final PSRule aTargetRule) throws SchematronPreprocessException
  {
    for (final IPSElement aElement : aRuleContent)
    {
      if (aElement instanceof PSAssertReport)
      {
        final PSAssertReport aAssertReport = (PSAssertReport) aElement;
        aTargetRule.addAssertReport (_getPreprocessedAssert (aAssertReport, aIDPool, aParamValueMap));
      }
      else
      {
        final PSExtends aExtends = (PSExtends) aElement;
        final String sRuleID = aExtends.getRule ();
        final PSRule aBaseRule = aLookup.getAbstractRuleOfID (sRuleID);
        if (aBaseRule == null)
          throw new SchematronPreprocessException ("Failed to resolve rule ID '" +
                                                   sRuleID +
                                                   "' in extends statement. Available rules are: " +
                                                   aLookup.getAllAbstractRuleIDs ());

        // Recursively resolve the extends of the base rule
        _resolveRuleContent (aBaseRule.getAllContentElements (), aLookup, aIDPool, aParamValueMap, aTargetRule);

        // Copy all lets
        for (final PSLet aBaseLet : aBaseRule.getAllLets ())
          aTargetRule.addLet (aBaseLet.getClone ());
      }
    }
  }

Resolve all <extends> elements. This method calls itself recursively
until all extends elements are resolved.

@param aRuleContent
A list consisting of {@link PSAssertReport} and {@link PSExtends}
objects. Never null.
@param aLookup
The rule lookup object
@throws SchematronPreprocessException
If the base rule of an extends object could not be resolved.

Resolve all &lt ; extends&gt ; elements . This method calls itself recursively until all extends elements are resolved .


@Nullable
  public PSSchema getAsMinimalSchema (@Nonnull final PSSchema aSchema) throws SchematronPreprocessException
  {
    ValueEnforcer.notNull (aSchema, "Schema");

    // Anything to do?
    if (aSchema.isMinimal ())
      return aSchema;

    return getForcedPreprocessedSchema (aSchema);
  }

@
Nullable
public
PSSchema
getAsMinimalSchema
(
@
Nonnull
final
PSSchema
aSchema
)
throws
SchematronPreprocessException
{
ValueEnforcer
.
notNull
(
aSchema
,
"Schema"
)
;
// Anything to do?
if
(
aSchema
.
isMinimal
(
)
)
return
aSchema
;
return
getForcedPreprocessedSchema
(
aSchema
)
;
}

Convert the passed schema to a minimal schema.

@param aSchema
The schema to be made minimal. May not be null
@return The original schema object, if it is already minimal - a minimal
copy otherwise! May be null if the original schema is
not yet minimal and {@link #isKeepEmptySchema()} is set to
false.
@throws SchematronPreprocessException
In case a preprocessing error occurs

Convert the passed schema to a minimal schema .


@Nullable
  public PSSchema getAsPreprocessedSchema (@Nonnull final PSSchema aSchema) throws SchematronPreprocessException
  {
    ValueEnforcer.notNull (aSchema, "Schema");

    // Anything to do?
    if (aSchema.isPreprocessed ())
      return aSchema;

    return getForcedPreprocessedSchema (aSchema);
  }

@
Nullable
public
PSSchema
getAsPreprocessedSchema
(
@
Nonnull
final
PSSchema
aSchema
)
throws
SchematronPreprocessException
{
ValueEnforcer
.
notNull
(
aSchema
,
"Schema"
)
;
// Anything to do?
if
(
aSchema
.
isPreprocessed
(
)
)
return
aSchema
;
return
getForcedPreprocessedSchema
(
aSchema
)
;
}

Convert the passed schema to a pre-processed schema.

@param aSchema
The schema to pre-process. May not be null
@return The original schema object, if it is already pre-processed - a
pre-processed copy otherwise! May be null if the
original schema is not yet pre-processed and
{@link #isKeepEmptySchema()} is set to false.
@throws SchematronPreprocessException
In case a preprocessing error occurs

Convert the passed schema to a pre - processed schema .


@Nullable
  public PSSchema getForcedPreprocessedSchema (@Nonnull final PSSchema aSchema) throws SchematronPreprocessException
  {
    ValueEnforcer.notNull (aSchema, "Schema");

    final PreprocessorLookup aLookup = new PreprocessorLookup (aSchema);
    final PreprocessorIDPool aIDPool = new PreprocessorIDPool ();

    final PSSchema ret = new PSSchema (aSchema.getResource ());
    ret.setID (aIDPool.getUniqueID (aSchema.getID ()));
    ret.setRich (aSchema.getRichClone ());
    ret.setSchemaVersion (aSchema.getSchemaVersion ());
    ret.setDefaultPhase (aSchema.getDefaultPhase ());
    ret.setQueryBinding (aSchema.getQueryBinding ());
    if (m_bKeepTitles && aSchema.hasTitle ())
      ret.setTitle (aSchema.getTitle ().getClone ());
    if (aSchema.hasAnyInclude ())
      throw new SchematronPreprocessException ("Cannot preprocess <schema> with an <include>");
    for (final PSNS aNS : aSchema.getAllNSs ())
      ret.addNS (aNS.getClone ());
    // start ps are skipped
    for (final PSLet aLet : aSchema.getAllLets ())
      ret.addLet (aLet.getClone ());
    for (final PSPhase aPhase : aSchema.getAllPhases ())
      ret.addPhase (_getPreprocessedPhase (aPhase, aIDPool));
    for (final PSPattern aPattern : aSchema.getAllPatterns ())
    {
      final PSPattern aMinifiedPattern = _getPreprocessedPattern (aPattern, aLookup, aIDPool);
      if (aMinifiedPattern != null)
      {
        // Pattern without rules?
        if (aMinifiedPattern.getRuleCount () > 0 || m_bKeepEmptyPatterns)
          ret.addPattern (aMinifiedPattern);
      }
    }

    // Schema without patterns?
    if (aSchema.getPatternCount () == 0 && !m_bKeepEmptySchema)
      return null;

    // end ps are skipped
    if (m_bKeepDiagnostics && aSchema.hasDiagnostics ())
      ret.setDiagnostics (_getPreprocessedDiagnostics (aSchema.getDiagnostics ()));
    ret.addForeignElements (aSchema.getAllForeignElements ());
    ret.addForeignAttributes (aSchema.getAllForeignAttributes ());
    return ret;
  }

Convert the passed schema to a pre-processed schema independent if it is
already minimal or not.

@param aSchema
The schema to be made minimal. May not be null
@return A minimal copy of the schema. May be null if the
original schema is not yet minimal and {@link #isKeepEmptySchema()}
is set to false.
@throws SchematronPreprocessException
In case a preprocessing error occurs

Convert the passed schema to a pre - processed schema independent if it is already minimal or not .


@Nonnull
  @OverrideOnDemand
  public PSSchema readSchema (@Nonnull final IReadableResource aResource,
                              @Nullable final IPSErrorHandler aErrorHandler,
                              @Nullable final EntityResolver aEntityResolver) throws SchematronException
  {
    return new PSReader (aResource, aErrorHandler, aEntityResolver).readSchema ();
  }

@ Nonnull @ OverrideOnDemand public PSSchema readSchema ( @ Nonnull final IReadableResource aResource , @ Nullable final IPSErrorHandler aErrorHandler , @ Nullable final EntityResolver aEntityResolver ) throws SchematronException { return new PSReader ( aResource , aErrorHandler , aEntityResolver ) . readSchema ( ) ; }

Read the specified schema from the passed resource.

@param aResource
The resource to read from. Never null.
@param aErrorHandler
The error handler to use. May be null.
@param aEntityResolver
The XML entity resolver to be used. May be null.
@return The read schema. May not be null.
@throws SchematronException
In case there is an error reading.

Read the specified schema from the passed resource .


@Nonnull
  @OverrideOnDemand
  public IPSQueryBinding getQueryBinding (@Nonnull final PSSchema aSchema) throws SchematronException
  {
    return PSQueryBindingRegistry.getQueryBindingOfNameOrThrow (aSchema.getQueryBinding ());
  }

@ Nonnull @ OverrideOnDemand public IPSQueryBinding getQueryBinding ( @ Nonnull final PSSchema aSchema ) throws SchematronException { return PSQueryBindingRegistry . getQueryBindingOfNameOrThrow ( aSchema . getQueryBinding ( ) ) ; }

Determine the query binding for the read schema.

@param aSchema
The read schema. Never null.
@return The query binding to use. Never null.
@throws SchematronException
In case the determination fails.

Determine the query binding for the read schema .


@Nonnull
  @OverrideOnDemand
  public PSSchema createPreprocessedSchema (@Nonnull final PSSchema aSchema,
                                            @Nonnull final IPSQueryBinding aQueryBinding) throws SchematronException
  {
    final PSPreprocessor aPreprocessor = createPreprocessor (aQueryBinding);
    final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema (aSchema);
    if (aPreprocessedSchema == null)
      throw new SchematronPreprocessException ("Failed to preprocess schema " +
                                               aSchema +
                                               " with query binding " +
                                               aQueryBinding);
    if (SchematronDebug.isShowPreprocessedSchematron ())
      LOGGER.info ("Preprocessed Schematron:\n" +
                      MicroWriter.getNodeAsString (aPreprocessedSchema.getAsMicroElement ()));
    return aPreprocessedSchema;
  }

@
Nonnull
@
OverrideOnDemand
public
PSSchema
createPreprocessedSchema
(
@
Nonnull
final
PSSchema
aSchema
,
@
Nonnull
final
IPSQueryBinding
aQueryBinding
)
throws
SchematronException
{
final
PSPreprocessor
aPreprocessor
=
createPreprocessor
(
aQueryBinding
)
;
final
PSSchema
aPreprocessedSchema
=
aPreprocessor
.
getAsPreprocessedSchema
(
aSchema
)
;
if
(
aPreprocessedSchema
==
)
throw
new
SchematronPreprocessException
(
"Failed to preprocess schema "
+
aSchema
+
" with query binding "
+
aQueryBinding
)
;
if
(
SchematronDebug
.
isShowPreprocessedSchematron
(
)
)
LOGGER
.
info
(
"Preprocessed Schematron:\n"
+
MicroWriter
.
getNodeAsString
(
aPreprocessedSchema
.
getAsMicroElement
(
)
)
)
;
return
aPreprocessedSchema
;
}

Pre-process the read schema, using the determined query binding.

@param aSchema
The read schema. Never null.
@param aQueryBinding
The determined query binding. Never null.
@return The pre-processed schema and never null.
@throws SchematronException
In case pre-processing fails

Pre - process the read schema using the determined query binding .


@Nonnull
  public ESuccess writeToFile (@Nonnull final IPSElement aPSElement, @Nonnull final File aFile)
  {
    ValueEnforcer.notNull (aPSElement, "PSElement");
    final IMicroElement eXML = aPSElement.getAsMicroElement ();
    return MicroWriter.writeToFile (getAsDocument (eXML), aFile, m_aWriterSettings.getXMLWriterSettings ());
  }

@ Nonnull public ESuccess writeToFile ( @ Nonnull final IPSElement aPSElement , @ Nonnull final File aFile ) { ValueEnforcer . notNull ( aPSElement , "PSElement" ) ; final IMicroElement eXML = aPSElement . getAsMicroElement ( ) ; return MicroWriter . writeToFile ( getAsDocument ( eXML ) , aFile , m_aWriterSettings . getXMLWriterSettings ( ) ) ; }

Write the passed Schematron element to the passed file.

@param aPSElement
The schematron element to write. May not be null.
@param aFile
The file to write things to. May not be null.
@return {@link ESuccess}.

Write the passed Schematron element to the passed file .


@Nonnull
  public ESuccess writeToStream (@Nonnull final IPSElement aPSElement, @Nonnull @WillClose final OutputStream aOS)
  {
    ValueEnforcer.notNull (aPSElement, "PSElement");
    final IMicroElement eXML = aPSElement.getAsMicroElement ();
    return MicroWriter.writeToStream (getAsDocument (eXML), aOS, m_aWriterSettings.getXMLWriterSettings ());
  }

@ Nonnull public ESuccess writeToStream ( @ Nonnull final IPSElement aPSElement , @ Nonnull @ WillClose final OutputStream aOS ) { ValueEnforcer . notNull ( aPSElement , "PSElement" ) ; final IMicroElement eXML = aPSElement . getAsMicroElement ( ) ; return MicroWriter . writeToStream ( getAsDocument ( eXML ) , aOS , m_aWriterSettings . getXMLWriterSettings ( ) ) ; }

Write the passed Schematron element to the passed output stream.

@param aPSElement
The schematron element to write. May not be null.
@param aOS
The output stream to write things to. May not be null.
The stream is automatically closed.
@return {@link ESuccess}.

Write the passed Schematron element to the passed output stream .


@Nonnull
  public ESuccess writeToWriter (@Nonnull final IPSElement aPSElement, @Nonnull @WillClose final Writer aWriter)
  {
    ValueEnforcer.notNull (aPSElement, "PSElement");
    final IMicroElement eXML = aPSElement.getAsMicroElement ();
    return MicroWriter.writeToWriter (getAsDocument (eXML), aWriter, m_aWriterSettings.getXMLWriterSettings ());
  }

@ Nonnull public ESuccess writeToWriter ( @ Nonnull final IPSElement aPSElement , @ Nonnull @ WillClose final Writer aWriter ) { ValueEnforcer . notNull ( aPSElement , "PSElement" ) ; final IMicroElement eXML = aPSElement . getAsMicroElement ( ) ; return MicroWriter . writeToWriter ( getAsDocument ( eXML ) , aWriter , m_aWriterSettings . getXMLWriterSettings ( ) ) ; }

Write the passed Schematron element to the passed writer.

@param aPSElement
The schematron element to write. May not be null.
@param aWriter
The writer to write things to. May not be null. The
writer is automatically closed.
@return {@link ESuccess}.

Write the passed Schematron element to the passed writer .


@Nullable
  public static SchematronOutputType applySchematron (@Nonnull final ISchematronResource aSchematron,
                                                      @Nonnull final IReadableResource aXML)
  {
    ValueEnforcer.notNull (aSchematron, "SchematronResource");
    ValueEnforcer.notNull (aXML, "XMLSource");

    try
    {
      // Apply Schematron on XML
      return aSchematron.applySchematronValidationToSVRL (aXML);
    }
    catch (final Exception ex)
    {
      throw new IllegalArgumentException ("Failed to apply Schematron " +
                                          aSchematron.getID () +
                                          " onto XML resource " +
                                          aXML.getResourceID (),
                                          ex);
    }
  }

@
Nullable
public
static
SchematronOutputType
applySchematron
(
@
Nonnull
final
ISchematronResource
aSchematron
,
@
Nonnull
final
IReadableResource
aXML
)
{
ValueEnforcer
.
notNull
(
aSchematron
,
"SchematronResource"
)
;
ValueEnforcer
.
notNull
(
aXML
,
"XMLSource"
)
;
try
{
// Apply Schematron on XML
return
aSchematron
.
applySchematronValidationToSVRL
(
aXML
)
;
}
catch
(
final
Exception
ex
)
{
throw
new
IllegalArgumentException
(
"Failed to apply Schematron "
+
aSchematron
.
getID
(
)
+
" onto XML resource "
+
aXML
.
getResourceID
(
)
,
ex
)
;
}
}

Apply the passed schematron on the passed XML resource using a custom error
handler.

@param aSchematron
The Schematron resource. May not be null.
@param aXML
The XML resource. May not be null.
@return null if either the Schematron or the XML could not be
read.
@throws IllegalStateException
if the processing throws an unexpected exception.

Apply the passed schematron on the passed XML resource using a custom error handler .


@Nullable
  public static SchematronOutputType applySchematron (@Nonnull final ISchematronResource aSchematron,
                                                      @Nonnull final Node aNode)
  {
    ValueEnforcer.notNull (aSchematron, "SchematronResource");
    ValueEnforcer.notNull (aNode, "Node");

    return applySchematron (aSchematron, new DOMSource (aNode));
  }

@ Nullable public static SchematronOutputType applySchematron ( @ Nonnull final ISchematronResource aSchematron , @ Nonnull final Node aNode ) { ValueEnforcer . notNull ( aSchematron , "SchematronResource" ) ; ValueEnforcer . notNull ( aNode , "Node" ) ; return applySchematron ( aSchematron , new DOMSource ( aNode ) ) ; }

Apply the passed schematron on the passed XML node.

@param aSchematron
The Schematron resource. May not be null.
@param aNode
The XML node. May not be null.
@return null if either the Schematron or the XML could not be
read.
@throws IllegalStateException
if the processing throws an unexpected exception.

Apply the passed schematron on the passed XML node .


@Nonnull
  public EChange remove (@Nullable final String sVarName)
  {
    if (StringHelper.hasText (sVarName))
      if (m_aMap.remove (PSXPathQueryBinding.PARAM_VARIABLE_PREFIX + sVarName) == null)
        return EChange.CHANGED;
    return EChange.UNCHANGED;
  }

@ Nonnull public EChange remove ( @ Nullable final String sVarName ) { if ( StringHelper . hasText ( sVarName ) ) if ( m_aMap . remove ( PSXPathQueryBinding . PARAM_VARIABLE_PREFIX + sVarName ) == null ) return EChange . CHANGED ; return EChange . UNCHANGED ; }

Remove the variable with the specified name

@param sVarName
The name of the variable to be removed. May be null.
@return {@link EChange#CHANGED} if the variable was removed successfully.
Never null.


@Nonnull
  public EChange removeAll (@Nullable final Iterable <String> aVars)
  {
    EChange eChange = EChange.UNCHANGED;
    if (aVars != null)
      for (final String sName : aVars)
        eChange = eChange.or (remove (sName));
    return eChange;
  }

  @Nonnull
  @ReturnsMutableCopy
  public ICommonsNavigableMap <String, String> getAll ()
  {
    return m_aMap.getClone ();
  }

  public boolean contains (@Nullable final String sName)
  {
    if (StringHelper.hasNoText (sName))
      return false;
    return m_aMap.containsKey (sName);
  }

@ Nonnull public EChange removeAll ( @ Nullable final Iterable < String > aVars ) { EChange eChange = EChange . UNCHANGED ; if ( aVars != null ) for ( final String sName : aVars ) eChange = eChange . or ( remove ( sName ) ) ; return eChange ; } @ Nonnull @ ReturnsMutableCopy public ICommonsNavigableMap < String , String > getAll ( ) { return m_aMap . getClone ( ) ; } public boolean contains ( @ Nullable final String sName ) { if ( StringHelper . hasNoText ( sName ) ) return false ; return m_aMap . containsKey ( sName ) ; }

Remove all variables with the specified names

@param aVars
A list of variable names to be removed. May be null.
@return {@link EChange#CHANGED} if at least one variable was removed
successfully. Never null.


@Nonnull
  @ReturnsMutableCopy
  public static ICommonsList <SVRLFailedAssert> getAllFailedAssertions (@Nullable final SchematronOutputType aSchematronOutput)
  {
    final ICommonsList <SVRLFailedAssert> ret = new CommonsArrayList <> ();
    if (aSchematronOutput != null)
      for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
        if (aObj instanceof FailedAssert)
          ret.add (new SVRLFailedAssert ((FailedAssert) aObj));
    return ret;
  }

Get a list of all failed assertions in a given schematron output.

@param aSchematronOutput
The schematron output to be used. May be null.
@return A non-null list with all failed assertions.

Get a list of all failed assertions in a given schematron output .


@Nonnull
  @ReturnsMutableCopy
  public static ICommonsList <SVRLFailedAssert> getAllFailedAssertionsMoreOrEqualSevereThan (@Nullable final SchematronOutputType aSchematronOutput,
                                                                                @Nonnull final IErrorLevel aErrorLevel)
  {
    final ICommonsList <SVRLFailedAssert> ret = new CommonsArrayList <> ();
    if (aSchematronOutput != null)
      for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
        if (aObj instanceof FailedAssert)
        {
          final SVRLFailedAssert aFA = new SVRLFailedAssert ((FailedAssert) aObj);
          if (aFA.getFlag ().isGE (aErrorLevel))
            ret.add (aFA);
        }
    return ret;
  }

Get a list of all failed assertions in a given schematron output, with an
error level equally or more severe than the passed error level.

@param aSchematronOutput
The schematron output to be used. May be null.
@param aErrorLevel
Minimum error level to be queried
@return A non-null list with all failed assertions.

Get a list of all failed assertions in a given schematron output with an error level equally or more severe than the passed error level .


@Nonnull
  @ReturnsMutableCopy
  public static ICommonsList <SVRLSuccessfulReport> getAllSuccessfulReports (@Nullable final SchematronOutputType aSchematronOutput)
  {
    final ICommonsList <SVRLSuccessfulReport> ret = new CommonsArrayList <> ();
    if (aSchematronOutput != null)
      for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
        if (aObj instanceof SuccessfulReport)
          ret.add (new SVRLSuccessfulReport ((SuccessfulReport) aObj));
    return ret;
  }

Get a list of all successful reports in a given schematron output.

@param aSchematronOutput
The schematron output to be used. May be null.
@return A non-null list with all successful reports.

Get a list of all successful reports in a given schematron output .


@Nonnull
  @ReturnsMutableCopy
  public static ICommonsList <SVRLSuccessfulReport> getAllSuccessfulReportsMoreOrEqualSevereThan (@Nullable final SchematronOutputType aSchematronOutput,
                                                                                @Nonnull final IErrorLevel aErrorLevel)
  {
    final ICommonsList <SVRLSuccessfulReport> ret = new CommonsArrayList <> ();
    if (aSchematronOutput != null)
      for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
        if (aObj instanceof SuccessfulReport)
        {
          final SVRLSuccessfulReport aSR = new SVRLSuccessfulReport ((SuccessfulReport) aObj);
          if (aSR.getFlag ().isGE (aErrorLevel))
            ret.add (aSR);
        }
    return ret;
  }

Get a list of all successful reports in a given schematron output, with an
error level equally or more severe than the passed error level.

@param aSchematronOutput
The schematron output to be used. May be null.
@param aErrorLevel
Minimum error level to be queried
@return A non-null list with all successful reports.

Get a list of all successful reports in a given schematron output with an error level equally or more severe than the passed error level .


@Nonnull
  @ReturnsMutableCopy
  public static ICommonsList <AbstractSVRLMessage> getAllFailedAssertionsAndSuccessfulReports (@Nullable final SchematronOutputType aSchematronOutput)
  {
    final ICommonsList <AbstractSVRLMessage> ret = new CommonsArrayList <> ();
    if (aSchematronOutput != null)
      for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
        if (aObj instanceof FailedAssert)
          ret.add (new SVRLFailedAssert ((FailedAssert) aObj));
        else
          if (aObj instanceof SuccessfulReport)
            ret.add (new SVRLSuccessfulReport ((SuccessfulReport) aObj));
    return ret;
  }

Get a list of all failed assertions and successful reports in a given
schematron output.

@param aSchematronOutput
The schematron output to be used. May be null.
@return A non-null list with all failed assertions and
successful reports. Maybe an empty list if the input is
null.

Get a list of all failed assertions and successful reports in a given schematron output .


public static void setErrorLevelDeterminator (@Nonnull final ISVRLErrorLevelDeterminator aELD)
  {
    ValueEnforcer.notNull (aELD, "ErrorLevelDeterminator");

    s_aRWLock.readLocked ( () -> s_aELD = aELD);
  }

public static void setErrorLevelDeterminator ( @ Nonnull final ISVRLErrorLevelDeterminator aELD ) { ValueEnforcer . notNull ( aELD , "ErrorLevelDeterminator" ) ; s_aRWLock . readLocked ( ( ) -> s_aELD = aELD ) ; }

Set the global error level determinator.

@param aELD
The determinator to use. May not be null.

Set the global error level determinator .


@Nullable
  public static IPSQueryBinding getQueryBindingOfName (@Nullable final String sName)
  {
    if (sName == null)
      return DEFAULT_QUERY_BINDING;

    return s_aRWLock.readLocked ( () -> s_aMap.get (sName));
  }

@ Nullable public static IPSQueryBinding getQueryBindingOfName ( @ Nullable final String sName ) { if ( sName == null ) return DEFAULT_QUERY_BINDING ; return s_aRWLock . readLocked ( ( ) -> s_aMap . get ( sName ) ) ; }

Get the query binding with the specified name.

@param sName
The name to the query binding to retrieve. May be null.
If it is null than the {@link #DEFAULT_QUERY_BINDING}
object is returned.
@return null if no such query binding was found.

Get the query binding with the specified name .


@Nonnull
  public static IPSQueryBinding getQueryBindingOfNameOrThrow (@Nullable final String sName) throws SchematronBindException
  {
    final IPSQueryBinding aQB = getQueryBindingOfName (sName);
    if (aQB == null)
      throw new SchematronBindException ("No query binding implementation present for query binding '" + sName + "'");
    return aQB;
  }

Get the query binding with the specified name

@param sName
The name of the query binding to look up. May be null.
@return Never null.
@throws SchematronBindException
In case the query binding could not be resolved!


@Nonnull
  public MapBasedXPathFunctionResolver loadXQuery (@Nonnull @WillClose final InputStream aXQueryIS) throws XPathException,
                                                                                IOException
  {
    ValueEnforcer.notNull (aXQueryIS, "XQueryIS");

    try
    {
      final MapBasedXPathFunctionResolver aFunctionResolver = new MapBasedXPathFunctionResolver ();

      // create a Configuration object
      final Configuration aConfiguration = new Configuration ();
      final DynamicQueryContext aDynamicQueryContext = new DynamicQueryContext (aConfiguration);
      final StaticQueryContext aStaticQueryCtx = aConfiguration.newStaticQueryContext ();
      // The base URI required for resolving within the XQuery
      aStaticQueryCtx.setBaseURI (m_sBaseURL);
      // null == auto detect
      final String sEncoding = null;
      final XQueryExpression exp = aStaticQueryCtx.compileQuery (aXQueryIS, sEncoding);
      final Controller aXQController = exp.newController (aDynamicQueryContext);

      // find all loaded methods and convert them to XPath functions
      final FunctionLibraryList aFuncLibList = exp.getExecutable ().getFunctionLibrary ();
      for (final FunctionLibrary aFuncLib : aFuncLibList.getLibraryList ())
      {
        // Ignore all Vendor, System etc. internal libraries
        if (aFuncLib instanceof FunctionLibraryList)
        {
          // This block works with Saxon HE 9.5.1-x :)
          // This is the custom function library list
          final FunctionLibraryList aRealFuncLib = (FunctionLibraryList) aFuncLib;
          for (final FunctionLibrary aNestedFuncLib : aRealFuncLib.getLibraryList ())
          {
            // Currently the user functions are in ExecutableFunctionLibrary
            if (aNestedFuncLib instanceof ExecutableFunctionLibrary)
              for (final UserFunction aUserFunc : new IterableIterator <> (((ExecutableFunctionLibrary) aNestedFuncLib).iterateFunctions ()))
              {
                // Saxon 9.7 changes "getNumberOfArguments" to "getArity"
                aFunctionResolver.addUniqueFunction (aUserFunc.getFunctionName ().getNamespaceBinding ().getURI (),
                                                     aUserFunc.getFunctionName ().getLocalPart (),
                                                     aUserFunc.getArity (),
                                                     new XPathFunctionFromUserFunction (aConfiguration,
                                                                                aXQController,
                                                                                aUserFunc));
              }
          }
        }
        else
          if (aFuncLib instanceof XQueryFunctionLibrary)
          {
            // This block works with Saxon HE 9.6.0-x :)
            final XQueryFunctionLibrary aRealFuncLib = (XQueryFunctionLibrary) aFuncLib;
            for (final XQueryFunction aXQueryFunction : new IterableIterator <> (aRealFuncLib.getFunctionDefinitions ()))
            {
              // Ensure the function is compiled
              aXQueryFunction.compile ();
              aFunctionResolver.addUniqueFunction (aXQueryFunction.getFunctionName ().getNamespaceBinding ().getURI (),
                                                   aXQueryFunction.getFunctionName ().getLocalPart (),
                                                   aXQueryFunction.getNumberOfArguments (),
                                                   new XPathFunctionFromUserFunction (aConfiguration,
                                                                                aXQController,
                                                                                aXQueryFunction.getUserFunction ()));
            }
          }
      }

      return aFunctionResolver;
    }
    finally
    {
      StreamHelper.close (aXQueryIS);
    }
  }

Load XQuery functions from an input stream. As this function is supposed to
work with Saxon HE, this method allows only for loading full XQuery modules
and not for XQuery libraries.

@param aXQueryIS
The Input Stream to read from. May not be null. Will be
closed automatically in this method.
@return A non-null {@link MapBasedXPathFunctionResolver}
containing all loaded functions.
@throws XPathException
if the syntax of the expression is wrong, or if it references
namespaces, variables, or functions that have not been declared, or
any other static error is reported.
@throws IOException
if a failure occurs reading the supplied input.

Load XQuery functions from an input stream . As this function is supposed to work with Saxon HE this method allows only for loading full XQuery modules and not for XQuery libraries .


private String _format (final String format, final Object arg)
  {
    final FormattingTuple tuple = MessageFormatter.format (format, arg);
    return tuple.getMessage ();
  }

private String _format ( final String format , final Object arg ) { final FormattingTuple tuple = MessageFormatter . format ( format , arg ) ; return tuple . getMessage ( ) ; }

Format with one object.

@param format
Format to use
@param arg
One argument
@return The message


private String _format (final String format, final Object first, final Object second)
  {
    final FormattingTuple tuple = MessageFormatter.format (format, first, second);
    return tuple.getMessage ();
  }

private String _format ( final String format , final Object first , final Object second ) { final FormattingTuple tuple = MessageFormatter . format ( format , first , second ) ; return tuple . getMessage ( ) ; }

Format with two objects.

@param format
Format to use
@param first
First argument
@param second
Second argument
@return The message


public static boolean isValidSchematron (@Nullable final IMicroNode aNode)
  {
    if (aNode == null)
      return false;

    return isValidSchematron (TransformSourceFactory.create (MicroWriter.getNodeAsString (aNode)));
  }

public static boolean isValidSchematron ( @ Nullable final IMicroNode aNode ) { if ( aNode == null ) return false ; return isValidSchematron ( TransformSourceFactory . create ( MicroWriter . getNodeAsString ( aNode ) ) ) ; }

Check if the passed micro node is a valid schematron instance.

@param aNode
The micro node to check. May be null.
@return true if the schematron is valid, false
otherwise.

Check if the passed micro node is a valid schematron instance .


public static boolean isValidSchematron (@Nullable final Node aNode)
  {
    if (aNode == null)
      return false;

    return isValidSchematron (TransformSourceFactory.create (aNode));
  }

public static boolean isValidSchematron ( @ Nullable final Node aNode ) { if ( aNode == null ) return false ; return isValidSchematron ( TransformSourceFactory . create ( aNode ) ) ; }

Check if the passed DOM node is a valid schematron instance.

@param aNode
The DOM node to check. May be null.
@return true if the schematron is valid, false
otherwise.

Check if the passed DOM node is a valid schematron instance .


public static boolean isValidSchematron (@Nullable final IReadableResource aRes)
  {
    if (aRes == null)
      return false;

    return isValidSchematron (TransformSourceFactory.create (aRes));
  }

public static boolean isValidSchematron ( @ Nullable final IReadableResource aRes ) { if ( aRes == null ) return false ; return isValidSchematron ( TransformSourceFactory . create ( aRes ) ) ; }

Check if the passed resource is a valid schematron instance.

@param aRes
The resource to check. May be null.
@return true if the schematron is valid, false
otherwise.

Check if the passed resource is a valid schematron instance .


public static boolean isValidSchematron (@Nullable final Source aSource)
  {
    if (aSource == null)
      return false;

    try
    {
      // Get a validator from the RNC schema.
      final Validator aValidator = RelaxNGCompactSchemaCache.getInstance ().getValidator (SCHEMATRON_RNC);

      // Ensure a collecting error handler is set
      final ErrorHandler aOldEH = aValidator.getErrorHandler ();
      CollectingSAXErrorHandler aCEH;
      if (aOldEH instanceof CollectingSAXErrorHandler)
        aCEH = (CollectingSAXErrorHandler) aOldEH;
      else
      {
        aCEH = new CollectingSAXErrorHandler ();
        aValidator.setErrorHandler (aCEH.andThen (aOldEH));
      }

      // Perform validation
      aValidator.validate (aSource, null);

      // Check results
      return aCEH.getErrorList ().getMostSevereErrorLevel ().isLT (EErrorLevel.ERROR);
    }
    catch (final SAXException ex)
    {
      // Document is not valid in respect to XML
    }
    catch (final IOException ex)
    {
      LOGGER.warn ("Failed to read source " + aSource, ex);
    }
    return false;
  }

Check if the passed source is a valid schematron instance.

@param aSource
The source to check. May be null.
@return true if the schematron is valid, false
otherwise.

Check if the passed source is a valid schematron instance .


@Nullable
  public static SchematronProviderXSLTFromSCH createSchematronXSLTProvider (@Nonnull final IReadableResource aSchematronResource,
                                                                            @Nonnull final SCHTransformerCustomizer aTransformerCustomizer)
  {
    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Compiling Schematron instance " + aSchematronResource.toString ());

    final SchematronProviderXSLTFromSCH aXSLTPreprocessor = new SchematronProviderXSLTFromSCH (aSchematronResource,
                                                                                aTransformerCustomizer);
    if (!aXSLTPreprocessor.isValidSchematron ())
    {
      // Schematron is invalid -> parsing failed
      LOGGER.warn ("The Schematron resource '" + aSchematronResource.getResourceID () + "' is invalid!");
      if (LOGGER.isDebugEnabled () && aXSLTPreprocessor.getXSLTDocument () != null)
      {
        // Log the created XSLT document for better error tracking
        LOGGER.debug ("  Created XSLT document:\n" +
                         XMLWriter.getNodeAsString (aXSLTPreprocessor.getXSLTDocument ()));
      }
      return null;
    }

    // If it is a valid schematron, there must be a result XSLT present!
    if (aXSLTPreprocessor.getXSLTDocument () == null)
      throw new IllegalStateException ("No XSLT document retrieved from Schematron resource '" +
                                       aSchematronResource.getResourceID () +
                                       "'!");

    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Finished compiling Schematron instance " + aSchematronResource.toString ());

    // Create the main validator for the schematron
    return aXSLTPreprocessor;
  }

Create a new Schematron validator for the passed resource.

@param aSchematronResource
The resource of the Schematron rules. May not be null.
@param aTransformerCustomizer
The XSLT transformer customizer to be used. May not be
null.
@return null if the passed Schematron resource does not exist
or is invalid.

Create a new Schematron validator for the passed resource .


@Nullable
  public static SchematronProviderXSLTFromSCH getSchematronXSLTProvider (@Nonnull final IReadableResource aSchematronResource,
                                                                         @Nonnull final SCHTransformerCustomizer aTransformerCustomizer)
  {
    ValueEnforcer.notNull (aSchematronResource, "SchematronResource");
    ValueEnforcer.notNull (aTransformerCustomizer, "TransformerCustomizer");

    if (!aSchematronResource.exists ())
    {
      LOGGER.warn ("Schematron resource " + aSchematronResource + " does not exist!");
      return null;
    }

    if (!aTransformerCustomizer.canCacheResult ())
    {
      // Create new object and return without cache handling because the custom
      // parameters may have side effects on the created XSLT!
      return createSchematronXSLTProvider (aSchematronResource, aTransformerCustomizer);
    }

    // Determine the unique resource ID for caching
    final String sCacheKey = StringHelper.<String> getImploded (':',
                                                                aSchematronResource.getResourceID (),
                                                                StringHelper.getNotNull (aTransformerCustomizer.getPhase ()),
                                                                StringHelper.getNotNull (aTransformerCustomizer.getLanguageCode ()));

    s_aLock.lock ();
    try
    {
      // Validator already in the cache?
      SchematronProviderXSLTFromSCH aProvider = s_aCache.get (sCacheKey);
      if (aProvider == null)
      {
        // Create new object and put in cache
        aProvider = createSchematronXSLTProvider (aSchematronResource, aTransformerCustomizer);
        if (aProvider != null)
          s_aCache.put (sCacheKey, aProvider);
      }
      return aProvider;
    }
    finally
    {
      s_aLock.unlock ();
    }
  }

Get the Schematron validator for the passed resource. If no custom
parameter are present, the result is cached. The respective cache key is a
combination of the Schematron resource path, the phase and the language
code.

@param aSchematronResource
The resource of the Schematron rules. May not be null.
@param aTransformerCustomizer
The XSLT transformer customizer to be used. May not be
null.
@return null if the passed Schematron resource does not exist
or is invalid.

Get the Schematron validator for the passed resource . If no custom parameter are present the result is cached . The respective cache key is a combination of the Schematron resource path the phase and the language code .


@Nonnull
  private String _getErrorText (@Nonnull final List <PSXPathBoundElement> aBoundContentElements,
                                @Nonnull final Node aSourceNode) throws SchematronValidationException
  {
    final StringBuilder aSB = new StringBuilder ();

    for (final PSXPathBoundElement aBoundElement : aBoundContentElements)
    {
      final Object aContent = aBoundElement.getElement ();
      if (aContent instanceof String)
        aSB.append ((String) aContent);
      else
        if (aContent instanceof PSName)
        {
          final PSName aName = (PSName) aContent;
          if (aName.hasPath ())
          {
            // XPath present
            try
            {
              aSB.append ((String) XPathEvaluationHelper.evaluate (aBoundElement.getBoundExpression (),
                                                                   aSourceNode,
                                                                   XPathConstants.STRING,
                                                                   m_sBaseURI));
            }
            catch (final XPathExpressionException ex)
            {
              _error (aName,
                      "Failed to evaluate XPath expression to a string: '" + aBoundElement.getExpression () + "'",
                      ex.getCause () != null ? ex.getCause () : ex);
              // Append the path so that something is present in the output
              aSB.append (aName.getPath ());
            }
          }
          else
          {
            // No XPath present
            aSB.append (aSourceNode.getNodeName ());
          }
        }
        else
          if (aContent instanceof PSValueOf)
          {
            final PSValueOf aValueOf = (PSValueOf) aContent;
            try
            {
              aSB.append ((String) XPathEvaluationHelper.evaluate (aBoundElement.getBoundExpression (),
                                                                   aSourceNode,
                                                                   XPathConstants.STRING,
                                                                   m_sBaseURI));
            }
            catch (final XPathExpressionException ex)
            {
              _error (aValueOf,
                      "Failed to evaluate XPath expression to a string: '" + aBoundElement.getExpression () + "'",
                      ex);
              // Append the path so that something is present in the output
              aSB.append (aValueOf.getSelect ());
            }
          }
          else
            if (aContent instanceof PSEmph)
              aSB.append (((PSEmph) aContent).getAsText ());
            else
              if (aContent instanceof PSDir)
                aSB.append (((PSDir) aContent).getAsText ());
              else
                if (aContent instanceof PSSpan)
                  aSB.append (((PSSpan) aContent).getAsText ());
                else
                  throw new SchematronValidationException ("Unsupported assert/report content element: " + aContent);
    }
    return aSB.toString ();
  }

Get the error text from an assert or report element.

@param aBoundContentElements
The list of bound elements to be evaluated.
@param aSourceNode
The XML node of the document currently validated.
@return A non-null String
@throws SchematronValidationException
In case evaluating an XPath expression fails.

Get the error text from an assert or report element .


@Nullable
  public static String getBeautifiedLocation (@Nonnull final String sNamespaceURI, @Nonnull final String sLocalName)
  {
    for (final ISVRLLocationBeautifierSPI aBeautifier : s_aList)
    {
      final String sBeautified = aBeautifier.getReplacementText (sNamespaceURI, sLocalName);
      if (sBeautified != null)
        return sBeautified;
    }
    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Unsupported elements for beautification: " + sNamespaceURI + " -- " + sLocalName);
    return null;
  }

Get the beautified location for the given namespace and local name.

@param sNamespaceURI
The namespace URI
@param sLocalName
The element local name
@return null if no beautification is available

Get the beautified location for the given namespace and local name .


private void _warn (@Nonnull final IPSElement aSourceElement, @Nonnull final String sMessage)
  {
    ValueEnforcer.notNull (aSourceElement, "SourceElement");
    ValueEnforcer.notNull (sMessage, "Message");

    m_aErrorHandler.warn (m_aResource, aSourceElement, sMessage);
  }

private void _warn ( @ Nonnull final IPSElement aSourceElement , @ Nonnull final String sMessage ) { ValueEnforcer . notNull ( aSourceElement , "SourceElement" ) ; ValueEnforcer . notNull ( sMessage , "Message" ) ; m_aErrorHandler . warn ( m_aResource , aSourceElement , sMessage ) ; }

Emit a warning with the registered error handler.

@param aSourceElement
The source element where the error occurred.
@param sMessage
The main warning message.

Emit a warning with the registered error handler .


@Nonnull
  public PSActive readActiveFromXML (@Nonnull final IMicroElement eActive)
  {
    final PSActive ret = new PSActive ();
    eActive.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_PATTERN))
        ret.setPattern (sAttrValue);
      else
        ret.addForeignAttribute (sAttrName, sAttrValue);
    });

    eActive.forAllChildren (aActiveChild -> {
      switch (aActiveChild.getType ())
      {
        case TEXT:
          ret.addText (((IMicroText) aActiveChild).getNodeValue ());
          break;
        case ELEMENT:
          final IMicroElement eElement = (IMicroElement) aActiveChild;
          if (CSchematron.NAMESPACE_SCHEMATRON.equals (eElement.getNamespaceURI ()))
          {
            final String sLocalName = eElement.getLocalName ();
            if (sLocalName.equals (CSchematronXML.ELEMENT_DIR))
              ret.addDir (readDirFromXML (eElement));
            else
              if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH))
                ret.addEmph (readEmphFromXML (eElement));
              else
                if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN))
                  ret.addSpan (readSpanFromXML (eElement));
                else
                  _warn (ret, "Unsupported Schematron element '" + sLocalName + "'");
          }
          else
            ret.addForeignElement (eElement.getClone ());

          break;
        case COMMENT:
          // Ignore comments
          break;
        default:
          _warn (ret, "Unsupported child node: " + aActiveChild);
      }
    });
    return ret;
  }

@
Nonnull
public
PSActive
readActiveFromXML
(
@
Nonnull
final
IMicroElement
eActive
)
{
final
PSActive
ret
=
new
PSActive
(
)
;
eActive
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_PATTERN
)
)
ret
.
setPattern
(
sAttrValue
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
eActive
.
forAllChildren
(
aActiveChild
->
{
switch
(
aActiveChild
.
getType
(
)
)
{
case
TEXT
:
ret
.
addText
(
(
(
IMicroText
)
aActiveChild
)
.
getNodeValue
(
)
)
;
break
;
case
ELEMENT
:
final
IMicroElement
eElement
=
(
IMicroElement
)
aActiveChild
;
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eElement
.
getNamespaceURI
(
)
)
)
{
final
String
sLocalName
=
eElement
.
getLocalName
(
)
;
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_DIR
)
)
ret
.
addDir
(
readDirFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_EMPH
)
)
ret
.
addEmph
(
readEmphFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_SPAN
)
)
ret
.
addSpan
(
readSpanFromXML
(
eElement
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
sLocalName
+
"'"
)
;
}
else
ret
.
addForeignElement
(
eElement
.
getClone
(
)
)
;
break
;
case
COMMENT
:
// Ignore comments
break
;
default
:
_warn
(
ret
,
"Unsupported child node: "
+
aActiveChild
)
;
}
}
)
;
return
ret
;
}

Read an <active> element

@param eActive
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSAssertReport readAssertReportFromXML (@Nonnull final IMicroElement eAssertReport)
  {
    final PSAssertReport ret = new PSAssertReport (eAssertReport.getLocalName ()
                                                                .equals (CSchematronXML.ELEMENT_ASSERT));

    final PSRichGroup aRichGroup = new PSRichGroup ();
    final PSLinkableGroup aLinkableGroup = new PSLinkableGroup ();
    eAssertReport.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_TEST))
        ret.setTest (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_FLAG))
          ret.setFlag (sAttrValue);
        else
          if (sAttrName.equals (CSchematronXML.ATTR_ID))
            ret.setID (sAttrValue);
          else
            if (sAttrName.equals (CSchematronXML.ATTR_DIAGNOSTICS))
              ret.setDiagnostics (sAttrValue);
            else
              if (PSRichGroup.isRichAttribute (sAttrName))
                _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
              else
                if (PSLinkableGroup.isLinkableAttribute (sAttrName))
                  _handleLinkableGroup (sAttrName, sAttrValue, aLinkableGroup);
                else
                  ret.addForeignAttribute (sAttrName, sAttrValue);
    });
    ret.setRich (aRichGroup);
    ret.setLinkable (aLinkableGroup);

    eAssertReport.forAllChildren (aAssertReportChild -> {
      switch (aAssertReportChild.getType ())
      {
        case TEXT:
          ret.addText (((IMicroText) aAssertReportChild).getNodeValue ());
          break;
        case ELEMENT:
          final IMicroElement eElement = (IMicroElement) aAssertReportChild;
          if (CSchematron.NAMESPACE_SCHEMATRON.equals (eElement.getNamespaceURI ()))
          {
            final String sLocalName = eElement.getLocalName ();
            if (sLocalName.equals (CSchematronXML.ELEMENT_NAME))
              ret.addName (readNameFromXML (eElement));
            else
              if (sLocalName.equals (CSchematronXML.ELEMENT_VALUE_OF))
                ret.addValueOf (readValueOfFromXML (eElement));
              else
                if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH))
                  ret.addEmph (readEmphFromXML (eElement));
                else
                  if (sLocalName.equals (CSchematronXML.ELEMENT_DIR))
                    ret.addDir (readDirFromXML (eElement));
                  else
                    if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN))
                      ret.addSpan (readSpanFromXML (eElement));
                    else
                      _warn (ret, "Unsupported Schematron element '" + sLocalName + "'");
          }
          else
            ret.addForeignElement (eElement.getClone ());

          break;
        case COMMENT:
          // Ignore comments
          break;
        default:
          _warn (ret, "Unsupported child node: " + aAssertReportChild);
      }
    });
    return ret;
  }

@
Nonnull
public
PSAssertReport
readAssertReportFromXML
(
@
Nonnull
final
IMicroElement
eAssertReport
)
{
final
PSAssertReport
ret
=
new
PSAssertReport
(
eAssertReport
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_ASSERT
)
)
;
final
PSRichGroup
aRichGroup
=
new
PSRichGroup
(
)
;
final
PSLinkableGroup
aLinkableGroup
=
new
PSLinkableGroup
(
)
;
eAssertReport
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_TEST
)
)
ret
.
setTest
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_FLAG
)
)
ret
.
setFlag
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ID
)
)
ret
.
setID
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_DIAGNOSTICS
)
)
ret
.
setDiagnostics
(
sAttrValue
)
;
else
if
(
PSRichGroup
.
isRichAttribute
(
sAttrName
)
)
_handleRichGroup
(
sAttrName
,
sAttrValue
,
aRichGroup
)
;
else
if
(
PSLinkableGroup
.
isLinkableAttribute
(
sAttrName
)
)
_handleLinkableGroup
(
sAttrName
,
sAttrValue
,
aLinkableGroup
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
ret
.
setRich
(
aRichGroup
)
;
ret
.
setLinkable
(
aLinkableGroup
)
;
eAssertReport
.
forAllChildren
(
aAssertReportChild
->
{
switch
(
aAssertReportChild
.
getType
(
)
)
{
case
TEXT
:
ret
.
addText
(
(
(
IMicroText
)
aAssertReportChild
)
.
getNodeValue
(
)
)
;
break
;
case
ELEMENT
:
final
IMicroElement
eElement
=
(
IMicroElement
)
aAssertReportChild
;
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eElement
.
getNamespaceURI
(
)
)
)
{
final
String
sLocalName
=
eElement
.
getLocalName
(
)
;
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_NAME
)
)
ret
.
addName
(
readNameFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_VALUE_OF
)
)
ret
.
addValueOf
(
readValueOfFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_EMPH
)
)
ret
.
addEmph
(
readEmphFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_DIR
)
)
ret
.
addDir
(
readDirFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_SPAN
)
)
ret
.
addSpan
(
readSpanFromXML
(
eElement
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
sLocalName
+
"'"
)
;
}
else
ret
.
addForeignElement
(
eElement
.
getClone
(
)
)
;
break
;
case
COMMENT
:
// Ignore comments
break
;
default
:
_warn
(
ret
,
"Unsupported child node: "
+
aAssertReportChild
)
;
}
}
)
;
return
ret
;
}

Read an <assert> or a <report> element

@param eAssertReport
The source micro element. Never null.
@return The created domain object. May not be null.

Read an &lt ; assert&gt ; or a &lt ; report&gt ; element


@Nonnull
  public PSDiagnostic readDiagnosticFromXML (@Nonnull final IMicroElement eDiagnostic)
  {
    final PSDiagnostic ret = new PSDiagnostic ();

    final PSRichGroup aRichGroup = new PSRichGroup ();
    eDiagnostic.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_ID))
        ret.setID (sAttrValue);
      else
        if (PSRichGroup.isRichAttribute (sAttrName))
          _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
        else
          ret.addForeignAttribute (sAttrName, sAttrValue);
    });
    ret.setRich (aRichGroup);

    eDiagnostic.forAllChildren (aDiagnosticChild -> {
      switch (aDiagnosticChild.getType ())
      {
        case TEXT:
          ret.addText (((IMicroText) aDiagnosticChild).getNodeValue ());
          break;
        case ELEMENT:
          final IMicroElement eElement = (IMicroElement) aDiagnosticChild;
          if (CSchematron.NAMESPACE_SCHEMATRON.equals (eElement.getNamespaceURI ()))
          {
            final String sLocalName = eElement.getLocalName ();
            if (sLocalName.equals (CSchematronXML.ELEMENT_VALUE_OF))
              ret.addValueOf (readValueOfFromXML (eElement));
            else
              if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH))
                ret.addEmph (readEmphFromXML (eElement));
              else
                if (sLocalName.equals (CSchematronXML.ELEMENT_DIR))
                  ret.addDir (readDirFromXML (eElement));
                else
                  if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN))
                    ret.addSpan (readSpanFromXML (eElement));
                  else
                    _warn (ret, "Unsupported Schematron element '" + sLocalName + "'");
          }
          else
            ret.addForeignElement (eElement.getClone ());

          break;
        case COMMENT:
          // Ignore comments
          break;
        default:
          _warn (ret, "Unsupported child node: " + aDiagnosticChild);
      }
    });
    return ret;
  }

@
Nonnull
public
PSDiagnostic
readDiagnosticFromXML
(
@
Nonnull
final
IMicroElement
eDiagnostic
)
{
final
PSDiagnostic
ret
=
new
PSDiagnostic
(
)
;
final
PSRichGroup
aRichGroup
=
new
PSRichGroup
(
)
;
eDiagnostic
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ID
)
)
ret
.
setID
(
sAttrValue
)
;
else
if
(
PSRichGroup
.
isRichAttribute
(
sAttrName
)
)
_handleRichGroup
(
sAttrName
,
sAttrValue
,
aRichGroup
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
ret
.
setRich
(
aRichGroup
)
;
eDiagnostic
.
forAllChildren
(
aDiagnosticChild
->
{
switch
(
aDiagnosticChild
.
getType
(
)
)
{
case
TEXT
:
ret
.
addText
(
(
(
IMicroText
)
aDiagnosticChild
)
.
getNodeValue
(
)
)
;
break
;
case
ELEMENT
:
final
IMicroElement
eElement
=
(
IMicroElement
)
aDiagnosticChild
;
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eElement
.
getNamespaceURI
(
)
)
)
{
final
String
sLocalName
=
eElement
.
getLocalName
(
)
;
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_VALUE_OF
)
)
ret
.
addValueOf
(
readValueOfFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_EMPH
)
)
ret
.
addEmph
(
readEmphFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_DIR
)
)
ret
.
addDir
(
readDirFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_SPAN
)
)
ret
.
addSpan
(
readSpanFromXML
(
eElement
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
sLocalName
+
"'"
)
;
}
else
ret
.
addForeignElement
(
eElement
.
getClone
(
)
)
;
break
;
case
COMMENT
:
// Ignore comments
break
;
default
:
_warn
(
ret
,
"Unsupported child node: "
+
aDiagnosticChild
)
;
}
}
)
;
return
ret
;
}

Read a <diagnostic> element

@param eDiagnostic
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSDiagnostics readDiagnosticsFromXML (@Nonnull final IMicroElement eDiagnostics)
  {
    final PSDiagnostics ret = new PSDiagnostics ();

    eDiagnostics.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      ret.addForeignAttribute (sAttrName, sAttrValue);
    });

    eDiagnostics.forAllChildElements (eDiagnosticsChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eDiagnosticsChild.getNamespaceURI ()))
      {
        if (eDiagnosticsChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
          ret.addInclude (readIncludeFromXML (eDiagnosticsChild));
        else
          if (eDiagnosticsChild.getLocalName ().equals (CSchematronXML.ELEMENT_DIAGNOSTIC))
            ret.addDiagnostic (readDiagnosticFromXML (eDiagnosticsChild));
          else
            _warn (ret, "Unsupported Schematron element '" + eDiagnosticsChild.getLocalName () + "'");
      }
      else
        ret.addForeignElement (eDiagnosticsChild.getClone ());
    });
    return ret;
  }

@
Nonnull
public
PSDiagnostics
readDiagnosticsFromXML
(
@
Nonnull
final
IMicroElement
eDiagnostics
)
{
final
PSDiagnostics
ret
=
new
PSDiagnostics
(
)
;
eDiagnostics
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
eDiagnostics
.
forAllChildElements
(
eDiagnosticsChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eDiagnosticsChild
.
getNamespaceURI
(
)
)
)
{
if
(
eDiagnosticsChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_INCLUDE
)
)
ret
.
addInclude
(
readIncludeFromXML
(
eDiagnosticsChild
)
)
;
else
if
(
eDiagnosticsChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_DIAGNOSTIC
)
)
ret
.
addDiagnostic
(
readDiagnosticFromXML
(
eDiagnosticsChild
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
eDiagnosticsChild
.
getLocalName
(
)
+
"'"
)
;
}
else
ret
.
addForeignElement
(
eDiagnosticsChild
.
getClone
(
)
)
;
}
)
;
return
ret
;
}

Read a <diagnostics> element

@param eDiagnostics
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSDir readDirFromXML (@Nonnull final IMicroElement eDir)
  {
    final PSDir ret = new PSDir ();

    eDir.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_VALUE))
        ret.setValue (EDirValue.getFromIDOrNull (sAttrValue));
      else
        ret.addForeignAttribute (sAttrName, sAttrValue);
    });

    eDir.forAllChildren (aDirChild -> {
      switch (aDirChild.getType ())
      {
        case TEXT:
          ret.addText (((IMicroText) aDirChild).getNodeValue ());
          break;
        case ELEMENT:
          final IMicroElement eElement = (IMicroElement) aDirChild;
          if (CSchematron.NAMESPACE_SCHEMATRON.equals (eElement.getNamespaceURI ()))
          {
            _warn (ret, "Unsupported Schematron element '" + eElement.getLocalName () + "'");
          }
          else
            ret.addForeignElement (eElement.getClone ());

          break;
        case COMMENT:
          // Ignore comments
          break;
        default:
          _warn (ret, "Unsupported child node: " + aDirChild);
      }
    });
    return ret;
  }

@
Nonnull
public
PSDir
readDirFromXML
(
@
Nonnull
final
IMicroElement
eDir
)
{
final
PSDir
ret
=
new
PSDir
(
)
;
eDir
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_VALUE
)
)
ret
.
setValue
(
EDirValue
.
getFromIDOrNull
(
sAttrValue
)
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
eDir
.
forAllChildren
(
aDirChild
->
{
switch
(
aDirChild
.
getType
(
)
)
{
case
TEXT
:
ret
.
addText
(
(
(
IMicroText
)
aDirChild
)
.
getNodeValue
(
)
)
;
break
;
case
ELEMENT
:
final
IMicroElement
eElement
=
(
IMicroElement
)
aDirChild
;
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eElement
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eElement
.
getLocalName
(
)
+
"'"
)
;
}
else
ret
.
addForeignElement
(
eElement
.
getClone
(
)
)
;
break
;
case
COMMENT
:
// Ignore comments
break
;
default
:
_warn
(
ret
,
"Unsupported child node: "
+
aDirChild
)
;
}
}
)
;
return
ret
;
}

Read a <dir> element

@param eDir
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSEmph readEmphFromXML (@Nonnull final IMicroElement eEmph)
  {
    final PSEmph ret = new PSEmph ();

    eEmph.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
    });

    eEmph.forAllChildren (aEmphChild -> {
      switch (aEmphChild.getType ())
      {
        case TEXT:
          ret.addText (((IMicroText) aEmphChild).getNodeValue ());
          break;
        case ELEMENT:
          final IMicroElement eElement = (IMicroElement) aEmphChild;
          if (CSchematron.NAMESPACE_SCHEMATRON.equals (eElement.getNamespaceURI ()))
          {
            _warn (ret, "Unsupported Schematron element '" + eElement.getLocalName () + "'");
          }
          else
            _warn (ret, "Unsupported namespace URI '" + eElement.getNamespaceURI () + "'");

          break;
        case COMMENT:
          // Ignore comments
          break;
        default:
          _warn (ret, "Unsupported child node: " + aEmphChild);
      }
    });
    return ret;
  }

@
Nonnull
public
PSEmph
readEmphFromXML
(
@
Nonnull
final
IMicroElement
eEmph
)
{
final
PSEmph
ret
=
new
PSEmph
(
)
;
eEmph
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
_warn
(
ret
,
"Unsupported attribute '"
+
sAttrName
+
"'='"
+
sAttrValue
+
"'"
)
;
}
)
;
eEmph
.
forAllChildren
(
aEmphChild
->
{
switch
(
aEmphChild
.
getType
(
)
)
{
case
TEXT
:
ret
.
addText
(
(
(
IMicroText
)
aEmphChild
)
.
getNodeValue
(
)
)
;
break
;
case
ELEMENT
:
final
IMicroElement
eElement
=
(
IMicroElement
)
aEmphChild
;
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eElement
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eElement
.
getLocalName
(
)
+
"'"
)
;
}
else
_warn
(
ret
,
"Unsupported namespace URI '"
+
eElement
.
getNamespaceURI
(
)
+
"'"
)
;
break
;
case
COMMENT
:
// Ignore comments
break
;
default
:
_warn
(
ret
,
"Unsupported child node: "
+
aEmphChild
)
;
}
}
)
;
return
ret
;
}

Read an <emph> element

@param eEmph
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSExtends readExtendsFromXML (@Nonnull final IMicroElement eExtends)
  {
    final PSExtends ret = new PSExtends ();

    eExtends.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_RULE))
        ret.setRule (sAttrValue);
      else
        ret.addForeignAttribute (sAttrName, sAttrValue);
    });

    eExtends.forAllChildElements (eChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eChild.getNamespaceURI ()))
      {
        _warn (ret, "Unsupported Schematron element '" + eChild.getLocalName () + "'");
      }
      else
        _warn (ret, "Unsupported namespace URI '" + eChild.getNamespaceURI () + "'");
    });
    return ret;
  }

@
Nonnull
public
PSExtends
readExtendsFromXML
(
@
Nonnull
final
IMicroElement
eExtends
)
{
final
PSExtends
ret
=
new
PSExtends
(
)
;
eExtends
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_RULE
)
)
ret
.
setRule
(
sAttrValue
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
eExtends
.
forAllChildElements
(
eChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eChild
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eChild
.
getLocalName
(
)
+
"'"
)
;
}
else
_warn
(
ret
,
"Unsupported namespace URI '"
+
eChild
.
getNamespaceURI
(
)
+
"'"
)
;
}
)
;
return
ret
;
}

Read an <extends> element

@param eExtends
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSInclude readIncludeFromXML (@Nonnull final IMicroElement eInclude)
  {
    final PSInclude ret = new PSInclude ();

    eInclude.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_HREF))
        ret.setHref (sAttrValue);
      else
        _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
    });

    eInclude.forAllChildElements (eValueOfChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eValueOfChild.getNamespaceURI ()))
      {
        _warn (ret, "Unsupported Schematron element '" + eValueOfChild.getLocalName () + "'");
      }
      else
        _warn (ret, "Unsupported namespace URI '" + eValueOfChild.getNamespaceURI () + "'");
    });
    return ret;
  }

@
Nonnull
public
PSInclude
readIncludeFromXML
(
@
Nonnull
final
IMicroElement
eInclude
)
{
final
PSInclude
ret
=
new
PSInclude
(
)
;
eInclude
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_HREF
)
)
ret
.
setHref
(
sAttrValue
)
;
else
_warn
(
ret
,
"Unsupported attribute '"
+
sAttrName
+
"'='"
+
sAttrValue
+
"'"
)
;
}
)
;
eInclude
.
forAllChildElements
(
eValueOfChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eValueOfChild
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eValueOfChild
.
getLocalName
(
)
+
"'"
)
;
}
else
_warn
(
ret
,
"Unsupported namespace URI '"
+
eValueOfChild
.
getNamespaceURI
(
)
+
"'"
)
;
}
)
;
return
ret
;
}

Read an <include> element

@param eInclude
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSLet readLetFromXML (@Nonnull final IMicroElement eLet)
  {
    final PSLet ret = new PSLet ();

    eLet.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_NAME))
        ret.setName (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_VALUE))
          ret.setValue (sAttrValue);
        else
          _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
    });

    eLet.forAllChildElements (eLetChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eLetChild.getNamespaceURI ()))
      {
        _warn (ret, "Unsupported Schematron element '" + eLetChild.getLocalName () + "'");
      }
      else
        _warn (ret, "Unsupported namespace URI '" + eLetChild.getNamespaceURI () + "'");
    });
    return ret;
  }

@
Nonnull
public
PSLet
readLetFromXML
(
@
Nonnull
final
IMicroElement
eLet
)
{
final
PSLet
ret
=
new
PSLet
(
)
;
eLet
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_NAME
)
)
ret
.
setName
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_VALUE
)
)
ret
.
setValue
(
sAttrValue
)
;
else
_warn
(
ret
,
"Unsupported attribute '"
+
sAttrName
+
"'='"
+
sAttrValue
+
"'"
)
;
}
)
;
eLet
.
forAllChildElements
(
eLetChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eLetChild
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eLetChild
.
getLocalName
(
)
+
"'"
)
;
}
else
_warn
(
ret
,
"Unsupported namespace URI '"
+
eLetChild
.
getNamespaceURI
(
)
+
"'"
)
;
}
)
;
return
ret
;
}

Read a <let> element

@param eLet
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSName readNameFromXML (@Nonnull final IMicroElement eName)
  {
    final PSName ret = new PSName ();

    eName.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_PATH))
        ret.setPath (sAttrValue);
      else
        ret.addForeignAttribute (sAttrName, sAttrValue);
    });

    eName.forAllChildElements (eNameChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eNameChild.getNamespaceURI ()))
      {
        _warn (ret, "Unsupported Schematron element '" + eNameChild.getLocalName () + "'");
      }
      else
        _warn (ret, "Unsupported namespace URI '" + eNameChild.getNamespaceURI () + "'");
    });
    return ret;
  }

@
Nonnull
public
PSName
readNameFromXML
(
@
Nonnull
final
IMicroElement
eName
)
{
final
PSName
ret
=
new
PSName
(
)
;
eName
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_PATH
)
)
ret
.
setPath
(
sAttrValue
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
eName
.
forAllChildElements
(
eNameChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eNameChild
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eNameChild
.
getLocalName
(
)
+
"'"
)
;
}
else
_warn
(
ret
,
"Unsupported namespace URI '"
+
eNameChild
.
getNamespaceURI
(
)
+
"'"
)
;
}
)
;
return
ret
;
}

Read a <name> element

@param eName
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSNS readNSFromXML (@Nonnull final IMicroElement eNS)
  {
    final PSNS ret = new PSNS ();

    eNS.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_URI))
        ret.setUri (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_PREFIX))
          ret.setPrefix (sAttrValue);
        else
          ret.addForeignAttribute (sAttrName, sAttrValue);
    });

    eNS.forAllChildElements (eLetChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eLetChild.getNamespaceURI ()))
      {
        _warn (ret, "Unsupported Schematron element '" + eLetChild.getLocalName () + "'");
      }
      else
        _warn (ret, "Unsupported namespace URI '" + eLetChild.getNamespaceURI () + "'");
    });
    return ret;
  }

@
Nonnull
public
PSNS
readNSFromXML
(
@
Nonnull
final
IMicroElement
eNS
)
{
final
PSNS
ret
=
new
PSNS
(
)
;
eNS
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_URI
)
)
ret
.
setUri
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_PREFIX
)
)
ret
.
setPrefix
(
sAttrValue
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
eNS
.
forAllChildElements
(
eLetChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eLetChild
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eLetChild
.
getLocalName
(
)
+
"'"
)
;
}
else
_warn
(
ret
,
"Unsupported namespace URI '"
+
eLetChild
.
getNamespaceURI
(
)
+
"'"
)
;
}
)
;
return
ret
;
}

Read a <ns> element

@param eNS
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSP readPFromXML (@Nonnull final IMicroElement eP)
  {
    final PSP ret = new PSP ();
    eP.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_ID))
        ret.setID (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_CLASS))
          ret.setClazz (sAttrValue);
        else
          if (sAttrName.equals (CSchematronXML.ATTR_ICON))
            ret.setIcon (sAttrValue);
          else
            ret.addForeignAttribute (sAttrName, sAttrValue);
    });

    eP.forAllChildren (aChild -> {
      switch (aChild.getType ())
      {
        case TEXT:
          ret.addText (((IMicroText) aChild).getNodeValue ());
          break;
        case ELEMENT:
          final IMicroElement eElement = (IMicroElement) aChild;
          if (CSchematron.NAMESPACE_SCHEMATRON.equals (eElement.getNamespaceURI ()))
          {
            final String sLocalName = eElement.getLocalName ();
            if (sLocalName.equals (CSchematronXML.ELEMENT_DIR))
              ret.addDir (readDirFromXML (eElement));
            else
              if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH))
                ret.addEmph (readEmphFromXML (eElement));
              else
                if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN))
                  ret.addSpan (readSpanFromXML (eElement));
                else
                  _warn (ret, "Unsupported Schematron element '" + sLocalName + "'");
          }
          else
            ret.addForeignElement (eElement.getClone ());

          break;
        case COMMENT:
          // Ignore comments
          break;
        default:
          _warn (ret, "Unsupported child node: " + aChild);
      }
    });
    return ret;
  }

@
Nonnull
public
PSP
readPFromXML
(
@
Nonnull
final
IMicroElement
eP
)
{
final
PSP
ret
=
new
PSP
(
)
;
eP
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ID
)
)
ret
.
setID
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_CLASS
)
)
ret
.
setClazz
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ICON
)
)
ret
.
setIcon
(
sAttrValue
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
eP
.
forAllChildren
(
aChild
->
{
switch
(
aChild
.
getType
(
)
)
{
case
TEXT
:
ret
.
addText
(
(
(
IMicroText
)
aChild
)
.
getNodeValue
(
)
)
;
break
;
case
ELEMENT
:
final
IMicroElement
eElement
=
(
IMicroElement
)
aChild
;
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eElement
.
getNamespaceURI
(
)
)
)
{
final
String
sLocalName
=
eElement
.
getLocalName
(
)
;
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_DIR
)
)
ret
.
addDir
(
readDirFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_EMPH
)
)
ret
.
addEmph
(
readEmphFromXML
(
eElement
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_SPAN
)
)
ret
.
addSpan
(
readSpanFromXML
(
eElement
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
sLocalName
+
"'"
)
;
}
else
ret
.
addForeignElement
(
eElement
.
getClone
(
)
)
;
break
;
case
COMMENT
:
// Ignore comments
break
;
default
:
_warn
(
ret
,
"Unsupported child node: "
+
aChild
)
;
}
}
)
;
return
ret
;
}

Read a <p> element

@param eP
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSParam readParamFromXML (@Nonnull final IMicroElement eParam)
  {
    final PSParam ret = new PSParam ();

    eParam.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_NAME))
        ret.setName (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_VALUE))
          ret.setValue (sAttrValue);
        else
          _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
    });

    eParam.forAllChildElements (eParamChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eParamChild.getNamespaceURI ()))
      {
        _warn (ret, "Unsupported Schematron element '" + eParamChild.getLocalName () + "'");
      }
      else
        _warn (ret, "Unsupported namespace URI '" + eParamChild.getNamespaceURI () + "'");
    });
    return ret;
  }

@
Nonnull
public
PSParam
readParamFromXML
(
@
Nonnull
final
IMicroElement
eParam
)
{
final
PSParam
ret
=
new
PSParam
(
)
;
eParam
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_NAME
)
)
ret
.
setName
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_VALUE
)
)
ret
.
setValue
(
sAttrValue
)
;
else
_warn
(
ret
,
"Unsupported attribute '"
+
sAttrName
+
"'='"
+
sAttrValue
+
"'"
)
;
}
)
;
eParam
.
forAllChildElements
(
eParamChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eParamChild
.
getNamespaceURI
(
)
)
)
{
_warn
(
ret
,
"Unsupported Schematron element '"
+
eParamChild
.
getLocalName
(
)
+
"'"
)
;
}
else
_warn
(
ret
,
"Unsupported namespace URI '"
+
eParamChild
.
getNamespaceURI
(
)
+
"'"
)
;
}
)
;
return
ret
;
}

Read a <param> element

@param eParam
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSPattern readPatternFromXML (@Nonnull final IMicroElement ePattern)
  {
    final PSPattern ret = new PSPattern ();

    final PSRichGroup aRichGroup = new PSRichGroup ();
    ePattern.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_ABSTRACT))
        ret.setAbstract (StringParser.parseBool (sAttrValue));
      else
        if (sAttrName.equals (CSchematronXML.ATTR_ID))
          ret.setID (sAttrValue);
        else
          if (sAttrName.equals (CSchematronXML.ATTR_IS_A))
            ret.setIsA (sAttrValue);
          else
            if (PSRichGroup.isRichAttribute (sAttrName))
              _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
            else
              ret.addForeignAttribute (sAttrName, sAttrValue);
    });
    ret.setRich (aRichGroup);

    ePattern.forAllChildElements (ePatternChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (ePatternChild.getNamespaceURI ()))
      {
        if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
          ret.addInclude (readIncludeFromXML (ePatternChild));
        else
          if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_TITLE))
            ret.setTitle (readTitleFromXML (ePatternChild));
          else
            if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_P))
              ret.addP (readPFromXML (ePatternChild));
            else
              if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_LET))
                ret.addLet (readLetFromXML (ePatternChild));
              else
                if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_RULE))
                  ret.addRule (readRuleFromXML (ePatternChild));
                else
                  if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_PARAM))
                    ret.addParam (readParamFromXML (ePatternChild));
                  else
                    _warn (ret,
                           "Unsupported Schematron element '" +
                                ePatternChild.getLocalName () +
                                "' in " +
                                ret.toString ());
      }
      else
        ret.addForeignElement (ePatternChild.getClone ());
    });
    return ret;
  }

@
Nonnull
public
PSPattern
readPatternFromXML
(
@
Nonnull
final
IMicroElement
ePattern
)
{
final
PSPattern
ret
=
new
PSPattern
(
)
;
final
PSRichGroup
aRichGroup
=
new
PSRichGroup
(
)
;
ePattern
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ABSTRACT
)
)
ret
.
setAbstract
(
StringParser
.
parseBool
(
sAttrValue
)
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ID
)
)
ret
.
setID
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_IS_A
)
)
ret
.
setIsA
(
sAttrValue
)
;
else
if
(
PSRichGroup
.
isRichAttribute
(
sAttrName
)
)
_handleRichGroup
(
sAttrName
,
sAttrValue
,
aRichGroup
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
ret
.
setRich
(
aRichGroup
)
;
ePattern
.
forAllChildElements
(
ePatternChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
ePatternChild
.
getNamespaceURI
(
)
)
)
{
if
(
ePatternChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_INCLUDE
)
)
ret
.
addInclude
(
readIncludeFromXML
(
ePatternChild
)
)
;
else
if
(
ePatternChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_TITLE
)
)
ret
.
setTitle
(
readTitleFromXML
(
ePatternChild
)
)
;
else
if
(
ePatternChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_P
)
)
ret
.
addP
(
readPFromXML
(
ePatternChild
)
)
;
else
if
(
ePatternChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_LET
)
)
ret
.
addLet
(
readLetFromXML
(
ePatternChild
)
)
;
else
if
(
ePatternChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_RULE
)
)
ret
.
addRule
(
readRuleFromXML
(
ePatternChild
)
)
;
else
if
(
ePatternChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_PARAM
)
)
ret
.
addParam
(
readParamFromXML
(
ePatternChild
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
ePatternChild
.
getLocalName
(
)
+
"' in "
+
ret
.
toString
(
)
)
;
}
else
ret
.
addForeignElement
(
ePatternChild
.
getClone
(
)
)
;
}
)
;
return
ret
;
}

Read a <pattern> element

@param ePattern
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSPhase readPhaseFromXML (@Nonnull final IMicroElement ePhase)
  {
    final PSPhase ret = new PSPhase ();

    final PSRichGroup aRichGroup = new PSRichGroup ();
    ePhase.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_ID))
        ret.setID (sAttrValue);
      else
        if (PSRichGroup.isRichAttribute (sAttrName))
          _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
        else
          ret.addForeignAttribute (sAttrName, sAttrValue);
    });
    ret.setRich (aRichGroup);

    ePhase.forAllChildElements (ePhaseChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (ePhaseChild.getNamespaceURI ()))
      {
        if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
          ret.addInclude (readIncludeFromXML (ePhaseChild));
        else
          if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_P))
            ret.addP (readPFromXML (ePhaseChild));
          else
            if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_LET))
              ret.addLet (readLetFromXML (ePhaseChild));
            else
              if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_ACTIVE))
                ret.addActive (readActiveFromXML (ePhaseChild));
              else
                _warn (ret, "Unsupported Schematron element '" + ePhaseChild.getLocalName () + "'");
      }
      else
        ret.addForeignElement (ePhaseChild.getClone ());
    });
    return ret;
  }

@
Nonnull
public
PSPhase
readPhaseFromXML
(
@
Nonnull
final
IMicroElement
ePhase
)
{
final
PSPhase
ret
=
new
PSPhase
(
)
;
final
PSRichGroup
aRichGroup
=
new
PSRichGroup
(
)
;
ePhase
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ID
)
)
ret
.
setID
(
sAttrValue
)
;
else
if
(
PSRichGroup
.
isRichAttribute
(
sAttrName
)
)
_handleRichGroup
(
sAttrName
,
sAttrValue
,
aRichGroup
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
ret
.
setRich
(
aRichGroup
)
;
ePhase
.
forAllChildElements
(
ePhaseChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
ePhaseChild
.
getNamespaceURI
(
)
)
)
{
if
(
ePhaseChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_INCLUDE
)
)
ret
.
addInclude
(
readIncludeFromXML
(
ePhaseChild
)
)
;
else
if
(
ePhaseChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_P
)
)
ret
.
addP
(
readPFromXML
(
ePhaseChild
)
)
;
else
if
(
ePhaseChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_LET
)
)
ret
.
addLet
(
readLetFromXML
(
ePhaseChild
)
)
;
else
if
(
ePhaseChild
.
getLocalName
(
)
.
equals
(
CSchematronXML
.
ELEMENT_ACTIVE
)
)
ret
.
addActive
(
readActiveFromXML
(
ePhaseChild
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
ePhaseChild
.
getLocalName
(
)
+
"'"
)
;
}
else
ret
.
addForeignElement
(
ePhaseChild
.
getClone
(
)
)
;
}
)
;
return
ret
;
}

Read a <phase> element

@param ePhase
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSRule readRuleFromXML (@Nonnull final IMicroElement eRule)
  {
    final PSRule ret = new PSRule ();

    final PSRichGroup aRichGroup = new PSRichGroup ();
    final PSLinkableGroup aLinkableGroup = new PSLinkableGroup ();
    eRule.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_FLAG))
        ret.setFlag (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_ABSTRACT))
          ret.setAbstract (StringParser.parseBool (sAttrValue));
        else
          if (sAttrName.equals (CSchematronXML.ATTR_CONTEXT))
            ret.setContext (sAttrValue);
          else
            if (sAttrName.equals (CSchematronXML.ATTR_ID))
              ret.setID (sAttrValue);
            else
              if (PSRichGroup.isRichAttribute (sAttrName))
                _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
              else
                if (PSLinkableGroup.isLinkableAttribute (sAttrName))
                  _handleLinkableGroup (sAttrName, sAttrValue, aLinkableGroup);
                else
                  ret.addForeignAttribute (sAttrName, sAttrValue);
    });
    ret.setRich (aRichGroup);
    ret.setLinkable (aLinkableGroup);

    eRule.forAllChildElements (eRuleChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eRuleChild.getNamespaceURI ()))
      {
        final String sLocalName = eRuleChild.getLocalName ();
        if (sLocalName.equals (CSchematronXML.ELEMENT_INCLUDE))
          ret.addInclude (readIncludeFromXML (eRuleChild));
        else
          if (sLocalName.equals (CSchematronXML.ELEMENT_LET))
            ret.addLet (readLetFromXML (eRuleChild));
          else
            if (sLocalName.equals (CSchematronXML.ELEMENT_ASSERT) || sLocalName.equals (CSchematronXML.ELEMENT_REPORT))
              ret.addAssertReport (readAssertReportFromXML (eRuleChild));
            else
              if (sLocalName.equals (CSchematronXML.ELEMENT_EXTENDS))
                ret.addExtends (readExtendsFromXML (eRuleChild));
              else
                _warn (ret, "Unsupported Schematron element '" + sLocalName + "'");
      }
      else
        ret.addForeignElement (eRuleChild.getClone ());
    });
    return ret;
  }

@
Nonnull
public
PSRule
readRuleFromXML
(
@
Nonnull
final
IMicroElement
eRule
)
{
final
PSRule
ret
=
new
PSRule
(
)
;
final
PSRichGroup
aRichGroup
=
new
PSRichGroup
(
)
;
final
PSLinkableGroup
aLinkableGroup
=
new
PSLinkableGroup
(
)
;
eRule
.
forAllAttributes
(
(
sNS
,
sAttrName
,
sVal
)
->
{
final
String
sAttrValue
=
_getAttributeValue
(
sVal
)
;
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_FLAG
)
)
ret
.
setFlag
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ABSTRACT
)
)
ret
.
setAbstract
(
StringParser
.
parseBool
(
sAttrValue
)
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_CONTEXT
)
)
ret
.
setContext
(
sAttrValue
)
;
else
if
(
sAttrName
.
equals
(
CSchematronXML
.
ATTR_ID
)
)
ret
.
setID
(
sAttrValue
)
;
else
if
(
PSRichGroup
.
isRichAttribute
(
sAttrName
)
)
_handleRichGroup
(
sAttrName
,
sAttrValue
,
aRichGroup
)
;
else
if
(
PSLinkableGroup
.
isLinkableAttribute
(
sAttrName
)
)
_handleLinkableGroup
(
sAttrName
,
sAttrValue
,
aLinkableGroup
)
;
else
ret
.
addForeignAttribute
(
sAttrName
,
sAttrValue
)
;
}
)
;
ret
.
setRich
(
aRichGroup
)
;
ret
.
setLinkable
(
aLinkableGroup
)
;
eRule
.
forAllChildElements
(
eRuleChild
->
{
if
(
CSchematron
.
NAMESPACE_SCHEMATRON
.
equals
(
eRuleChild
.
getNamespaceURI
(
)
)
)
{
final
String
sLocalName
=
eRuleChild
.
getLocalName
(
)
;
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_INCLUDE
)
)
ret
.
addInclude
(
readIncludeFromXML
(
eRuleChild
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_LET
)
)
ret
.
addLet
(
readLetFromXML
(
eRuleChild
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_ASSERT
)
||
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_REPORT
)
)
ret
.
addAssertReport
(
readAssertReportFromXML
(
eRuleChild
)
)
;
else
if
(
sLocalName
.
equals
(
CSchematronXML
.
ELEMENT_EXTENDS
)
)
ret
.
addExtends
(
readExtendsFromXML
(
eRuleChild
)
)
;
else
_warn
(
ret
,
"Unsupported Schematron element '"
+
sLocalName
+
"'"
)
;
}
else
ret
.
addForeignElement
(
eRuleChild
.
getClone
(
)
)
;
}
)
;
return
ret
;
}

Read a <rule> element

@param eRule
The source micro element. Never null.
@return The created domain object. May not be null.


@Nonnull
  public PSSchema readSchemaFromXML (@Nonnull final IMicroElement eSchema) throws SchematronReadException
  {
    ValueEnforcer.notNull (eSchema, "Schema");
    if (!CSchematron.NAMESPACE_SCHEMATRON.equals (eSchema.getNamespaceURI ()))
      throw new SchematronReadException (m_aResource, "The passed element is not an ISO Schematron element!");

    final PSSchema ret = new PSSchema (m_aResource);
    final PSRichGroup aRichGroup = new PSRichGroup ();
    eSchema.forAllAttributes ( (sNS, sAttrName, sVal) -> {
      final String sAttrValue = _getAttributeValue (sVal);
      if (sAttrName.equals (CSchematronXML.ATTR_ID))
        ret.setID (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_SCHEMA_VERSION))
          ret.setSchemaVersion (sAttrValue);
        else
          if (sAttrName.equals (CSchematronXML.ATTR_DEFAULT_PHASE))
            ret.setDefaultPhase (sAttrValue);
          else
            if (sAttrName.equals (CSchematronXML.ATTR_QUERY_BINDING))
              ret.setQueryBinding (sAttrValue);
            else
              if (PSRichGroup.isRichAttribute (sAttrName))
                _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
              else
                ret.addForeignAttribute (sAttrName, sAttrValue);
    });
    ret.setRich (aRichGroup);

    eSchema.forAllChildElements (eSchemaChild -> {
      if (CSchematron.NAMESPACE_SCHEMATRON.equals (eSchemaChild.getNamespaceURI ()))
      {
        if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
          ret.addInclude (readIncludeFromXML (eSchemaChild));
        else
          if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_TITLE))
            ret.setTitle (readTitleFromXML (eSchemaChild));
          else
            if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_NS))
              ret.addNS (readNSFromXML (eSchemaChild));
            else
              if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_P))
              {
                final PSP aP = readPFromXML (eSchemaChild);
                if (ret.hasNoPatterns ())
                  ret.addStartP (aP);
                else
                  ret.addEndP (aP);
              }
              else
                if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_LET))
                  ret.addLet (readLetFromXML (eSchemaChild));
                else
                  if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_PHASE))
                    ret.addPhase (readPhaseFromXML (eSchemaChild));
                  else
                    if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_PATTERN))
                      ret.addPattern (readPatternFromXML (eSchemaChild));
                    else
                      if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_DIAGNOSTICS))
                        ret.setDiagnostics (readDiagnosticsFromXML (eSchemaChild));
                      else
                        _warn (ret, "Unsupported Schematron element '" + eSchemaChild.getLocalName () + "'");
      }
      else
        ret.addForeignElement (eSchemaChild.getClone ());
    });
    return ret;
  }

Parse the Schematron into a pure Java object. This method makes no
assumptions on the validity of the document!

@param eSchema
The XML element to use. May not be null.
@return The created {@link PSSchema} object or null in case of
null document or a fatal error.
@throws SchematronReadException
If reading fails

Parse the Schematron into a pure Java object . This method makes no assumptions on the validity of the document!