-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from com-pas/develop
New release
- Loading branch information
Showing
27 changed files
with
1,165 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
validator/src/main/java/org/lfenergy/compas/scl/validator/xsd/SclInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-FileCopyrightText: 2022 Alliander N.V. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.lfenergy.compas.scl.validator.xsd; | ||
|
||
import org.lfenergy.compas.scl.validator.exception.SclValidatorException; | ||
|
||
import javax.xml.stream.XMLInputFactory; | ||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.events.StartElement; | ||
import javax.xml.stream.events.XMLEvent; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.LOADING_SCL_FILE_ERROR_CODE; | ||
import static org.lfenergy.compas.scl.validator.util.StaxUtil.getAttributeValue; | ||
import static org.lfenergy.compas.scl.validator.util.StaxUtil.isElement; | ||
|
||
public class SclInfo { | ||
private static final String SCL_ELEMENT_NAME = "SCL"; | ||
|
||
private String version = null; | ||
private String revision = null; | ||
private String release = null; | ||
|
||
public SclInfo(String sclData) { | ||
try (var fis = new ByteArrayInputStream(sclData.getBytes(StandardCharsets.UTF_8))) { | ||
var xmlInputFactory = getXMLInputFactory(); | ||
var reader = xmlInputFactory.createXMLEventReader(fis); | ||
|
||
while (reader.hasNext()) { | ||
processEvent(reader.nextEvent()); | ||
} | ||
} catch (IOException | XMLStreamException exp) { | ||
throw new SclValidatorException(LOADING_SCL_FILE_ERROR_CODE, "Error loading SCL File", exp); | ||
} | ||
} | ||
|
||
private void processEvent(XMLEvent nextEvent) { | ||
if (nextEvent.isStartElement()) { | ||
processStartElement(nextEvent.asStartElement()); | ||
} | ||
} | ||
|
||
private void processStartElement(StartElement element) { | ||
if (isElement(element, SCL_ELEMENT_NAME)) { | ||
version = getAttributeValue(element, "version"); | ||
revision = getAttributeValue(element, "revision"); | ||
release = getAttributeValue(element, "release"); | ||
} | ||
} | ||
|
||
private XMLInputFactory getXMLInputFactory() { | ||
var xmlInputFactory = XMLInputFactory.newInstance(); | ||
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); | ||
return xmlInputFactory; | ||
} | ||
|
||
public String getSclVersion() { | ||
var sclVersion = ""; | ||
if (version != null) sclVersion += version; | ||
if (revision != null) sclVersion += revision; | ||
if (release != null) sclVersion += release; | ||
|
||
return sclVersion; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
validator/src/main/java/org/lfenergy/compas/scl/validator/xsd/SclXsdValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-FileCopyrightText: 2022 Alliander N.V. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.lfenergy.compas.scl.validator.xsd; | ||
|
||
import org.lfenergy.compas.scl.validator.model.ValidationError; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SclXsdValidator { | ||
|
||
public List<ValidationError> validate(String sclData) { | ||
var validationErrors = new ArrayList<ValidationError>(); | ||
|
||
var xsdValidator = new XSDValidator(validationErrors, sclData); | ||
xsdValidator.validate(); | ||
|
||
return validationErrors; | ||
} | ||
} |
Oops, something went wrong.