Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diver110 #22

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phive-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.helger.phive</groupId>
<artifactId>phive-parent-pom</artifactId>
<version>9.0.1-SNAPSHOT</version>
<version>9.1.0-SNAPSHOT</version>
</parent>
<artifactId>phive-api</artifactId>
<packaging>bundle</packaging>
Expand Down
2 changes: 1 addition & 1 deletion phive-result/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.helger.phive</groupId>
<artifactId>phive-parent-pom</artifactId>
<version>9.0.1-SNAPSHOT</version>
<version>9.1.0-SNAPSHOT</version>
</parent>
<artifactId>phive-result</artifactId>
<packaging>bundle</packaging>
Expand Down
2 changes: 1 addition & 1 deletion phive-ves-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.helger.phive</groupId>
<artifactId>phive-parent-pom</artifactId>
<version>9.0.1-SNAPSHOT</version>
<version>9.1.0-SNAPSHOT</version>
</parent>
<artifactId>phive-ves-engine</artifactId>
<packaging>bundle</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@
*/
public class DefaultVESLoaderSchematron implements IVESLoaderSchematron
{
public static final String RESOURCE_TYPE_SCH = "sch";
public static final String RESOURCE_TYPE_XSLT = "xslt";

private static final Logger LOGGER = LoggerFactory.getLogger (DefaultVESLoaderSchematron.class);

@Nonnull
public IValidationExecutor <IValidationSourceXML> loadSchematron (@Nonnull final IRepoStorageBase aRepo,
@Nonnull final VesSchematronType aSCH,
@Nonnull final ErrorList aErrorList)
{
final RepoStorageKey aSCHKey = VESLoader.wrapKey (aSCH.getResource ());
final RepoStorageKey aSCHKey = VESLoader.createRepoStorageKey (aSCH.getResource ());

// Read referenced Item
final RepoStorageItem aSCHItem = aRepo.read (aSCHKey);
Expand All @@ -74,7 +77,7 @@ public IValidationExecutor <IValidationSourceXML> loadSchematron (@Nonnull final
final String sResourceType = aSCH.getResource ().getType ();
switch (sResourceType)
{
case "sch":
case RESOURCE_TYPE_SCH:
{
// Resolve Schematron Engine
final String sEngine = aSCH.getEngine ();
Expand Down Expand Up @@ -110,7 +113,7 @@ public IValidationExecutor <IValidationSourceXML> loadSchematron (@Nonnull final
}
break;
}
case "xslt":
case RESOURCE_TYPE_XSLT:
{
// Indicate a potential error
if (StringHelper.hasText (aSCH.getEngine ()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.xml.validation.Schema;

import org.slf4j.Logger;
Expand All @@ -42,6 +43,7 @@
import com.helger.commons.io.resource.IReadableResource;
import com.helger.commons.io.resource.inmemory.ReadableResourceInputStream;
import com.helger.commons.io.stream.NonBlockingByteArrayOutputStream;
import com.helger.commons.lang.EnumHelper;
import com.helger.commons.string.StringHelper;
import com.helger.commons.string.ToStringGenerator;
import com.helger.diver.repo.IRepoStorageBase;
Expand All @@ -68,25 +70,49 @@
*/
public class DefaultVESLoaderXSD implements IVESLoaderXSD
{
public static final String RESOURCE_TYPE_ZIP = "zip";
public static final String RESOURCE_TYPE_XSD = "xsd";

private static final Logger LOGGER = LoggerFactory.getLogger (DefaultVESLoaderXSD.class);

/**
* Catalog entry type
*
* @author Philip Helger
*/
private enum ECatalogType
public enum ECatalogType implements IHasID <String>
{
PUBLIC,
SYSTEM
PUBLIC ("public"),
SYSTEM ("system");

private final String m_sID;

ECatalogType (@Nonnull @Nonempty final String sID)
{
m_sID = sID;
}

@Nonnull
@Nonempty
public String getID ()
{
return m_sID;
}

@Nullable
public static ECatalogType getFromIDOrNull (@Nullable final String sID)
{
return EnumHelper.getFromIDOrNull (ECatalogType.class, sID);
}
}

/**
* Represent a single XML catalog entry
*
* @author Philip Helger
*/
private static final class CatalogEntry implements IHasID <String>
@Immutable
public static final class CatalogEntry implements IHasID <String>
{
private final ECatalogType m_eType;
private final String m_sID;
Expand Down Expand Up @@ -136,12 +162,13 @@ public String toString ()
@Nullable
private static final String _unifyPath (@Nullable final String x)
{
// Converty any "\" to "/"
String ret = FilenameHelper.getPathUsingUnixSeparator (x);
if (ret != null)
{
// Make absolute to simply LS resource resolving
if (!ret.startsWith ("/"))
ret = "/" + ret;
ret = '/' + ret;
}
return ret;
}
Expand All @@ -151,7 +178,7 @@ public IValidationExecutor <IValidationSourceXML> loadXSD (@Nonnull final IRepoS
@Nonnull final VesXsdType aXSD,
@Nonnull final ErrorList aErrorList)
{
final RepoStorageKey aXSDKey = VESLoader.wrapKey (aXSD.getResource ());
final RepoStorageKey aXSDKey = VESLoader.createRepoStorageKey (aXSD.getResource ());

// Read referenced Item
final RepoStorageItem aXSDItem = aRepo.read (aXSDKey);
Expand All @@ -176,12 +203,14 @@ public IValidationExecutor <IValidationSourceXML> loadXSD (@Nonnull final IRepoS
final VesXsdCatalogItemPublicType aPublic = (VesXsdCatalogItemPublicType) aItem;
aEntry = new CatalogEntry (ECatalogType.PUBLIC,
aPublic.getUri (),
VESLoader.wrapKey (aPublic.getResource ()));
VESLoader.createRepoStorageKey (aPublic.getResource ()));
}
else
{
final VesXsdCatalogItemSystemType aSystem = (VesXsdCatalogItemSystemType) aItem;
aEntry = new CatalogEntry (ECatalogType.SYSTEM, aSystem.getId (), VESLoader.wrapKey (aSystem.getResource ()));
aEntry = new CatalogEntry (ECatalogType.SYSTEM,
aSystem.getId (),
VESLoader.createRepoStorageKey (aSystem.getResource ()));
}
if (aCatalogEntries.containsKey (aEntry.getID ()))
{
Expand All @@ -204,7 +233,7 @@ public IValidationExecutor <IValidationSourceXML> loadXSD (@Nonnull final IRepoS
final String sResourceType = aXSD.getResource ().getType ();
switch (sResourceType)
{
case "xsd":
case RESOURCE_TYPE_XSD:
{
// Indicate a potential error
if (StringHelper.hasText (aXSD.getMain ()))
Expand Down Expand Up @@ -239,7 +268,7 @@ public IValidationExecutor <IValidationSourceXML> loadXSD (@Nonnull final IRepoS
aExecutorXSD = ValidationExecutorXSD.create (aRepoRes);
break;
}
case "zip":
case RESOURCE_TYPE_ZIP:
{
final String sMainUnified = _unifyPath (aXSD.getMain ());
if (StringHelper.hasNoText (sMainUnified))
Expand All @@ -258,7 +287,7 @@ public IValidationExecutor <IValidationSourceXML> loadXSD (@Nonnull final IRepoS
long nUnzippedLed = 0;
final byte [] aBuffer = new byte [4096];
boolean bFoundMain = false;
try (ZipInputStream aZIS = new ZipInputStream (aRepoRes.getInputStream ()))
try (final ZipInputStream aZIS = new ZipInputStream (aRepoRes.getInputStream ()))
{
ZipEntry aEntry = null;
while ((aEntry = aZIS.getNextEntry ()) != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
Expand All @@ -42,22 +44,18 @@
import com.helger.phive.api.executorset.ValidationExecutorSet;
import com.helger.phive.api.result.ValidationResultList;
import com.helger.phive.api.source.IValidationSource;
import com.helger.phive.ves.model.v1.EVESSyntax;
import com.helger.xml.namespace.MapBasedNamespaceContext;

/**
* This class represents a single Loaded VES.
*
* @author Philip Helger
*/
@NotThreadSafe
public final class LoadedVES
{
public enum EVESSyntax
{
XSD,
SCHEMATRON,
EDIFACT
}

@Immutable
public static final class Header
{
private final VESID m_aVESID;
Expand Down Expand Up @@ -110,6 +108,7 @@ public EVESSyntax getVESSyntax ()
*
* @author Philip Helger
*/
@Immutable
public static final class Status
{
private final XMLOffsetDateTime m_aStatusLastMod;
Expand All @@ -136,12 +135,12 @@ public XMLOffsetDateTime getStatusLastModification ()
return m_aStatusLastMod;
}

public boolean isDTValidNow ()
public boolean isDateTimeValidNow ()
{
return isDTValidAt (PDTFactory.getCurrentXMLOffsetDateTime ());
return isDateTimeValidAt (PDTFactory.getCurrentXMLOffsetDateTime ());
}

public boolean isDTValidAt (@Nonnull final XMLOffsetDateTime aDT)
public boolean isDateTimeValidAt (@Nonnull final XMLOffsetDateTime aDT)
{
if (m_aValidFrom != null)
{
Expand Down Expand Up @@ -171,7 +170,7 @@ public boolean isExplicitlyDeprecated ()

public boolean isOverallValid ()
{
return isDTValidNow () && !isExplicitlyDeprecated ();
return isDateTimeValidNow () && !isExplicitlyDeprecated ();
}

@Nonnull
Expand All @@ -187,6 +186,7 @@ public static Status createUndefined ()
*
* @author Philip Helger
*/
@NotThreadSafe
public static final class OutputType
{
private final ICommonsMap <String, EErrorLevel> m_aCustomErrorLevels = new CommonsHashMap <> ();
Expand All @@ -202,6 +202,7 @@ public void addCustomErrorLevel (@Nonnull final String sID, @Nonnull final EErro
*
* @author Philip Helger
*/
@NotThreadSafe
public static final class Requirement
{
private final VESID m_aRequiredVESID;
Expand Down Expand Up @@ -262,12 +263,18 @@ public boolean isStopOnError ()
m_aStatus = aStatus;
}

/**
* @return The header of the loaded VES. Never <code>null</code>.
*/
@Nonnull
public Header getHeader ()
{
return m_aHeader;
}

/**
* @return The status information of the loaded VES. Never <code>null</code>.
*/
@Nonnull
public Status getStatus ()
{
Expand Down Expand Up @@ -297,11 +304,18 @@ void setEagerRequires (@Nonnull final Requirement aRequirement, @Nonnull final L
m_aRequiresLoader = null;
}

/**
* @return <code>true</code> if a validation executor is present,
* <code>false</code> if not.
*/
public boolean hasExecutor ()
{
return m_aExecutor != null;
}

/**
* @return The contained validation executor. May be <code>null</code>.
*/
@Nullable
public IValidationExecutor <? extends IValidationSource> getExecutor ()
{
Expand All @@ -319,7 +333,7 @@ private LoadedVES _getLoadedVESRequiresNotNull ()
LoadedVES ret = m_aLoadedRequires;
if (ret == null)
{
// TODO do something with the error list
// TODO do something better with the error list
final ErrorList aErrorList = new ErrorList ();
m_aLoadedRequires = ret = m_aRequiresLoader.deferredLoad (aErrorList);
if (ret == null)
Expand Down Expand Up @@ -353,12 +367,16 @@ private ICommonsList <IValidationExecutor <IValidationSource>> _getValidationExe

private boolean _isRecursivelyValid ()
{
// Local status first, because in case of failure, this is a quicker break
if (!m_aStatus.isOverallValid ())
return false;

// No requirement
if (m_aRequires == null)
return m_aStatus.isOverallValid ();
return true;

// Requirement present
return _getLoadedVESRequiresNotNull ()._isRecursivelyValid () && m_aStatus.isOverallValid ();
return _getLoadedVESRequiresNotNull ()._isRecursivelyValid ();
}

public void applyValidation (@Nonnull final IValidationSource aValidationSource,
Expand All @@ -369,7 +387,7 @@ public void applyValidation (@Nonnull final IValidationSource aValidationSource,
ValueEnforcer.notNull (aValidationResultList, "ValidationResultList");
ValueEnforcer.notNull (aLocale, "Locale");

if (m_aExecutor == null)
if (!hasExecutor ())
throw new VESLoadingException ("The loaded VES has no Executor Set and can therefore not be used for validating objects");

final boolean bIsValid = _isRecursivelyValid ();
Expand Down
Loading
Loading