Search in sources :

Example 1 with PSNS

use of com.helger.schematron.pure.model.PSNS in project ph-schematron by phax.

the class PSPreprocessor method getForcedPreprocessedSchema.

/**
 * 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 <code>null</code>
 * @return A minimal copy of the schema. May be <code>null</code> if the
 *         original schema is not yet minimal and {@link #isKeepEmptySchema()}
 *         is set to <code>false</code>.
 * @throws SchematronPreprocessException
 *         In case a preprocessing error occurs
 */
@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;
}
Also used : PSPhase(com.helger.schematron.pure.model.PSPhase) PSLet(com.helger.schematron.pure.model.PSLet) PSPattern(com.helger.schematron.pure.model.PSPattern) PSSchema(com.helger.schematron.pure.model.PSSchema) PSNS(com.helger.schematron.pure.model.PSNS) Nullable(javax.annotation.Nullable)

Aggregations

PSLet (com.helger.schematron.pure.model.PSLet)1 PSNS (com.helger.schematron.pure.model.PSNS)1 PSPattern (com.helger.schematron.pure.model.PSPattern)1 PSPhase (com.helger.schematron.pure.model.PSPhase)1 PSSchema (com.helger.schematron.pure.model.PSSchema)1 Nullable (javax.annotation.Nullable)1