use of com.helger.phive.engine.vom.v10.VOMNamespacesType in project phive by phax.
the class VOM1Validator method validateNamespaces.
public static void validateNamespaces(@Nonnull final String sXPath, @Nullable final VOMNamespacesType aNamespaces, @Nonnull final IVOMNamespaceContextResolver aNamespaceContextResolver, @Nonnull final ErrorList aErrorList) {
// Is optional
if (aNamespaces != null) {
final String sBuiltIn = aNamespaces.getBuiltIn();
final MapBasedNamespaceContext aNsCtx;
if (sBuiltIn != null) {
// Built-in
final MapBasedNamespaceContext ret = aNamespaceContextResolver.getNamespaceContextOfID(sBuiltIn);
if (ret == null) {
aErrorList.add(_createError(EVOMErrorCode.BUILTIN_NAMESPACE_CONTEXT_NOT_FOUND.getErrorMessage(sBuiltIn), sXPath + "/builtin"));
// Avoid NPE later on
aNsCtx = new MapBasedNamespaceContext();
} else
aNsCtx = ret.getClone();
} else {
// Start empty
aNsCtx = new MapBasedNamespaceContext();
}
int nIndex = 1;
int nErrors = 0;
for (final VOMNamespaceMappingType aMapping : aNamespaces.getMapping()) {
final String sLocalXPath = sXPath + "/mapping[" + nIndex + ']';
// Default to the default namespace prefix
final String sPrefix = StringHelper.getNotNull(aMapping.getPrefix(), "");
final String sNamespaceURI = aMapping.getNamespace();
if (StringHelper.hasNoText(sNamespaceURI)) {
aErrorList.add(_createError(EVOMErrorCode.REQUIRED_NOT_EMPTY, sLocalXPath + "/namespace"));
nErrors++;
} else {
if (aNsCtx.isPrefixMapped(sPrefix))
aErrorList.add(_createWarn(EVOMErrorCode.NAMESPACE_PREFIX_ALREADY_MAPPED.getErrorMessage(sPrefix, sNamespaceURI), sLocalXPath + "/prefix"));
aNsCtx.setMapping(sPrefix, sNamespaceURI);
}
++nIndex;
}
if (!aNsCtx.hasAnyMapping() && nErrors == 0)
aErrorList.add(_createWarn(EVOMErrorCode.NAMESPACE_CONTEXT_EMPTY, sXPath));
}
}
use of com.helger.phive.engine.vom.v10.VOMNamespacesType in project phive by phax.
the class VOM1Converter method _createExecutorSchematron.
@Nonnull
private ValidationExecutorSchematron _createExecutorSchematron(@Nonnull final VOMSchematronType aSchematron) {
final IReadableResource aRes;
{
final String sBuiltIn = aSchematron.getBuiltIn();
if (StringHelper.hasText(sBuiltIn)) {
LOGGER.info("Trying to resolve built-in Schematron artifact '" + sBuiltIn + "'");
aRes = m_aResourceResolver.getResourceOfID(sBuiltIn);
if (aRes == null)
throw new IllegalStateException("Failed to resolve built-in Schematron artifact '" + sBuiltIn + "'");
} else {
// External resource
final VESID aVESID = _createVESID(aSchematron.getResource());
LOGGER.info("Trying to resolve Schematron artifact with ID '" + aVESID.getAsSingleID() + "'");
aRes = m_aArtifactResolver.getArtifactOfID(aVESID);
if (aRes == null)
throw new IllegalStateException("Failed to resolve Schematron artifact with ID '" + aVESID.getAsSingleID() + "'");
}
}
final EValidationType eValidationType;
if (StringHelper.hasNoText(aSchematron.getType()))
eValidationType = EValidationType.SCHEMATRON_SCH;
else
switch(aSchematron.getType()) {
case "pure":
eValidationType = EValidationType.SCHEMATRON_PURE;
break;
case "sch":
eValidationType = EValidationType.SCHEMATRON_SCH;
break;
case "xslt":
eValidationType = EValidationType.SCHEMATRON_XSLT;
break;
case "schxslt":
eValidationType = EValidationType.SCHEMATRON_SCHXSLT;
break;
case "oioubl":
eValidationType = EValidationType.SCHEMATRON_OIOUBL;
break;
default:
throw new IllegalStateException("The Schematron type '" + aSchematron.getType() + "' is unsupported.");
}
if (aSchematron.getPrerequisiteCount() > 1)
throw new IllegalStateException("Currently only 1 prerequsite path is supported");
final MapBasedNamespaceContext aNamespaceContext = new MapBasedNamespaceContext();
final VOMNamespacesType aNamespaces = aSchematron.getNamespaces();
if (aNamespaces != null) {
final String sBuiltIn = aNamespaces.getBuiltIn();
if (sBuiltIn != null) {
// Built-in
LOGGER.info("Trying to resolve built-in namespace context '" + sBuiltIn + "'");
final MapBasedNamespaceContext ret = m_aNamespaceContextResolver.getNamespaceContextOfID(sBuiltIn);
if (ret == null)
throw new IllegalStateException("Failed to resolve built-in namespace context with ID '" + sBuiltIn + "'");
aNamespaceContext.addMappings(ret);
} else {
// Start empty
}
for (final VOMNamespaceMappingType aMapping : aNamespaces.getMapping()) {
// Default to the default namespace prefix
final String sPrefix = StringHelper.getNotNull(aMapping.getPrefix(), "");
aNamespaceContext.setMapping(sPrefix, aMapping.getNamespace());
}
}
final ValidationExecutorSchematron ret = new ValidationExecutorSchematron(new ValidationArtefact(eValidationType, aRes), aSchematron.hasPrerequisiteEntries() ? aSchematron.getPrerequisiteAtIndex(0) : null, aNamespaceContext.hasAnyMapping() ? aNamespaceContext : null);
// Custom errors afterwards (optional)
for (final VOMCustomError aCE : aSchematron.getCustomError()) ret.addCustomErrorLevel(aCE.getId(), getAsErrorLevel(aCE.getLevel()));
if (aSchematron.hasOptionEntries())
LOGGER.warn("Ignoring all Schematron options");
return ret;
}
Aggregations