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.util.CollectionUtil;
11  import gov.nist.secauto.metaschema.core.util.ObjectUtils;
12  import gov.nist.secauto.oscal.lib.OscalBindingContext;
13  import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand;
14  
15  import org.json.JSONObject;
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  public 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 List<Source> 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 CollectionUtil.unmodifiableList(retval);
38    }
39  
40    @Override
41    protected JSONObject getOscalJsonSchema() throws IOException {
42      try (InputStream is = ObjectUtils.requireNonNull(
43          OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-profile_schema.json"))) {
44        return JsonUtil.toJsonObject(is);
45      }
46    }
47  }