1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.oscal.tools.cli.core.commands.profile;
7   
8   import gov.nist.secauto.metaschema.core.model.util.JsonUtil;
9   import gov.nist.secauto.metaschema.core.model.util.XmlUtil;
10  import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator;
11  import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator;
12  import gov.nist.secauto.metaschema.core.util.CollectionUtil;
13  import gov.nist.secauto.metaschema.core.util.ObjectUtils;
14  import gov.nist.secauto.oscal.lib.OscalBindingContext;
15  import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand;
16  
17  import java.io.IOException;
18  import java.io.InputStream;
19  import java.util.LinkedList;
20  import java.util.List;
21  
22  import javax.xml.transform.Source;
23  
24  class ValidateSubcommand
25      extends AbstractDeprecatedOscalValidationSubcommand {
26    @Override
27    public String getDescription() {
28      return "Check that the specified OSCAL Profile is well-formed and valid to the Profile model.";
29    }
30  
31    @Override
32    protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException {
33      List<Source> retval = new LinkedList<>();
34      retval.add(
35          XmlUtil.getStreamSource(ObjectUtils.requireNonNull(
36              OscalBindingContext.class.getResource("/schema/xml/oscal-profile_schema.xsd"))));
37      return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval));
38    }
39  
40    @Override
41    protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException {
42      try (InputStream is = ObjectUtils.requireNonNull(
43          OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-profile_schema.json"))) {
44        return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is));
45      }
46    }
47  }