Skip to content

Commit

Permalink
Merge pull request #510 from Imvertor/Development
Browse files Browse the repository at this point in the history
Please pull latest Development
  • Loading branch information
ArjanLoeffen authored Jul 10, 2024
2 parents bdd4384 + 2a1fdec commit ffacb9e
Show file tree
Hide file tree
Showing 177 changed files with 11,832 additions and 1,024 deletions.
15 changes: 12 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,27 @@
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-runtime</artifactId>
<version>2.4.1</version>
<version>5.0.0-M2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-rdfxml</artifactId>
<version>2.4.1</version>
<version>5.0.0-M2</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-turtle</artifactId>
<version>2.4.1</version>
<version>5.0.0-M2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.eclipse.rdf4j/rdf4j-model -->
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-model</artifactId>
<version>5.0.0-M2</version>
</dependency>


<dependency>
<groupId>org.slf4j</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/nl/imvertor/ChainTranslateAndReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static void main(String[] args) {
configurator.getCli(ConceptCollector.STEP_NAME);
configurator.getCli(ImvertCompiler.STEP_NAME);
configurator.getCli(MIMCompiler.STEP_NAME);
configurator.getCli(SkosCompiler.STEP_NAME);
configurator.getCli(StcCompiler.STEP_NAME);
configurator.getCli(XsdCompiler.STEP_NAME);
configurator.getCli(ShaclCompiler.STEP_NAME);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/nl/imvertor/EpCompiler/EpCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public boolean generate() throws Exception {

// Create EP
if (requiresMIM()) {
String mimVersion = configurator.getXParm("system/mim-compiler-mim-version");
// check of MIM resultaat beschikbaar is
succeeds = succeeds && AnyFile.exists(configurator.getXParm("properties/WORK_MIMFORMAT_XMLPATH",false));
// verwerk MIM naar EP
succeeds = succeeds && transformer.transformStep("properties/WORK_MIMFORMAT_XMLPATH","properties/WORK_EP_XMLPATH_PRE", "properties/IMVERTOR_EP2_XSLPATH_PRE");
succeeds = succeeds && transformer.transformStep("properties/WORK_EP_XMLPATH_PRE","properties/WORK_EP_XMLPATH_CORE", "properties/IMVERTOR_EP2_XSLPATH_CORE");
succeeds = succeeds && transformer.transformStep("properties/WORK_EP_XMLPATH_CORE","properties/WORK_EP_XMLPATH_FINAL", "properties/IMVERTOR_EP2_XSLPATH_POST");
succeeds = succeeds && transformer.transformStep("properties/WORK_MIMFORMAT_XMLPATH","properties/WORK_EP_XMLPATH_PRE", "properties/IMVERTOR_EP2_" + mimVersion + "_XSLPATH_PRE");
succeeds = succeeds && transformer.transformStep("properties/WORK_EP_XMLPATH_PRE","properties/WORK_EP_XMLPATH_CORE", "properties/IMVERTOR_EP2_" + mimVersion + "_XSLPATH_CORE");
succeeds = succeeds && transformer.transformStep("properties/WORK_EP_XMLPATH_CORE","properties/WORK_EP_XMLPATH_FINAL", "properties/IMVERTOR_EP2_" + mimVersion + "_XSLPATH_POST");
} else
succeeds = succeeds && transformer.transformStep("properties/WORK_EMBELLISH_FILE","properties/WORK_EP_XMLPATH_FINAL", "properties/IMVERTOR_EP_XSLPATH");

Expand Down
21 changes: 11 additions & 10 deletions src/main/java/nl/imvertor/MIMCompiler/MIMCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public boolean generateDefault() throws Exception {

runner.debug(logger,"CHAIN","Generating MIM format");

String mcv = configurator.getXParm("system/mim-compliancy-version", false); // major.minor: wordt bepaald op basis van de actieve configuratie.
String mv = configurator.getXParm("appinfo/mim-model-version", false); // major.minor: wordt bepaald op basis van de actieve configuratie.
String mimVersion = (mv != null && mv.startsWith("1.1")) ? "1.1" : mv; // de versie opgegeven in het model is bepalend voor het mim serialisatie formaat

transformer.setXslParm("mim-version", mimVersion);

String mfv = configurator.getXParm("cli/mimformatversion", false);
String mimFormatterVersion = (mfv != null && mfv.equals("v1")) ? "v1" : "v2";

Expand All @@ -105,10 +111,10 @@ public boolean generateDefault() throws Exception {
String xslFileParam;
switch (mimFormatType) {
case "legacy":
xslFileParam = "properties/IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_LEGACY_XSLPATH";
xslFileParam = "properties/IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_" + mimVersion + "_LEGACY_XSLPATH";
break;
default:
xslFileParam = "properties/IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_XSLPATH";
xslFileParam = "properties/IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_" + mimVersion + "_XSLPATH";
break;
}

Expand All @@ -117,11 +123,6 @@ public boolean generateDefault() throws Exception {
transformer.setXslParm("generate-all-ids", "true");
}

String mv = configurator.getXParm("cli/mimversion", false);
String mimVersion = (mv != null && mv.equals("1.1")) ? "1.1" : "1.1"; // TODO implementeer 1.1.1

transformer.setXslParm("mim-version", mimVersion);

succeeds = succeeds && transformer.transformStep("properties/WORK_EMBELLISH_FILE", "properties/WORK_MIMFORMAT_XMLPATH", xslFileParam); //TODO must relocate generation of WORK_LISTS_FILE to a EMBELLISH step.

/*
Expand All @@ -130,7 +131,7 @@ public boolean generateDefault() throws Exception {
*/

if (isRDFType) {
succeeds = succeeds && transformer.transformStep("properties/WORK_MIMFORMAT_XMLPATH", "properties/WORK_MIMFORMAT_RDFPATH", "properties/IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_RDF_XSLPATH");
succeeds = succeeds && transformer.transformStep("properties/WORK_MIMFORMAT_XMLPATH", "properties/WORK_MIMFORMAT_RDFPATH", "properties/IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_" + mimVersion + "_RDF_XSLPATH");
}

// store to mim folder
Expand All @@ -147,8 +148,8 @@ public boolean generateDefault() throws Exception {

if (!mimFormatType.equals("legacy")) {
/* Copy the MIM XML Schema directory: */
File xslDir = new File(configurator.getXslPath(configurator.getParm("properties", "IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_XSLPATH"))).getParentFile();
File xsdSourceFolder = new File(xslDir, "../../../etc/xsd/MIMformat/" + mimFormatterVersion);
File xslDir = new File(configurator.getXslPath(configurator.getParm("properties", "IMVERTOR_MIMFORMAT_" + mimFormatterVersion + "_" + mimVersion + "_XSLPATH"))).getParentFile();
File xsdSourceFolder = new File(xslDir, "../../../../etc/xsd/MIMformat/" + mimFormatterVersion);
File xsdTargetFolder = new File(xmlFolder, "xsd");
FileUtils.copyDirectory(xsdSourceFolder, xsdTargetFolder);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/imvertor/OfficeCompiler/OfficeCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.util.Iterator;
import java.util.Vector;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.eclipse.jgit.transport.PushResult;
import org.springframework.util.StringUtils;

import nl.imvertor.common.Configurator;
import nl.imvertor.common.Step;
Expand Down Expand Up @@ -146,7 +146,7 @@ public void generateOfficeReport() throws Exception {
}
}
private String trim(String urlfrag) {
return StringUtils.trimTrailingCharacter(StringUtils.trimLeadingCharacter(urlfrag,'/'),'/');
return StringUtils.removeEnd(StringUtils.removeStart(urlfrag,"/"),"/");
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nl/imvertor/SkosCompiler/SkosCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean generateSKOS() throws Exception {
String skosSchemaUrl = configurator.getXParm("system/skos-schema-url"); // wordt gezet bij het genereren van een SKOS file.
if (skosSchemaUrl != null) {
ShaclFile skosSchema = shaclFileByCatalog(skosSchemaUrl);
skosFile.validate(configurator, skosSchema); // TODO
skosFile.validate(configurator, skosSchema);

} else
skosFile.validate(configurator);
Expand Down
134 changes: 134 additions & 0 deletions src/main/java/nl/imvertor/XmiCompiler/XMIImageExporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package nl.imvertor.XmiCompiler;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Base64.Decoder;
import java.util.List;

import javax.sound.sampled.AudioFormat.Encoding;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;

import org.apache.commons.lang.CharEncoding;

public class XMIImageExporter {

public List<Image> export(InputStream xmiStreamIn, OutputStream xmiStreamOut) throws Exception {
String name = null;
String imageID = null;
boolean isImage = false;
List<Image> imageList = new ArrayList<>();
StringBuffer imageDataBuffer = new StringBuffer();
Decoder base64Decoder = Base64.getDecoder();
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(xmiStreamIn);
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(xmiStreamOut);
boolean hasNext;
do {
switch (reader.getEventType()) {
case XMLStreamConstants.START_DOCUMENT:
writer.writeStartDocument(CharEncoding.UTF_8, reader.getVersion());
break;
case XMLStreamConstants.END_DOCUMENT:
writer.writeEndDocument();
break;
case XMLStreamConstants.START_ELEMENT:
writer.writeStartElement(reader.getPrefix(), reader.getLocalName(), def(reader.getNamespaceURI(), ""));
for (int i = 0; i < reader.getNamespaceCount(); i++)
writer.writeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
for (int i = 0; i < reader.getAttributeCount(); i++)
writer.writeAttribute(reader.getAttributePrefix(i), def(reader.getAttributeNamespace(i), ""),
reader.getAttributeLocalName(i), reader.getAttributeValue(i));
if (reader.getLocalName().equals("EAImage")) {
isImage = true;
name = reader.getAttributeValue(null, "name");
imageID = reader.getAttributeValue(null, "imageID");
}
break;
case XMLStreamConstants.END_ELEMENT:
if (isImage) {
byte[] imageData = base64Decoder.decode(imageDataBuffer.toString());
imageDataBuffer.setLength(0);
imageList.add(new Image(name, imageID, imageData));
writer.writeComment("Image data removed");
isImage = false;
}
writer.writeEndElement();
break;
case XMLStreamConstants.CHARACTERS:
if (isImage) {
imageDataBuffer.append(reader.getText().replaceAll("\\s+", ""));
} else {
writer.writeCharacters(reader.getText());
}
break;
case XMLStreamConstants.CDATA:
writer.writeCData(reader.getText());
break;
case XMLStreamConstants.COMMENT:
writer.writeComment(reader.getText());
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
writer.writeProcessingInstruction(reader.getPITarget(), reader.getPIData());
break;
}
hasNext = reader.hasNext();
if (hasNext)
reader.next();
} while (hasNext);
return imageList;
}

public static final class Image {

private String name;
private String imageID;
private byte[] data;

public Image(String name, String imageID, byte[] data) {
this.name = name;
this.imageID = imageID;
this.data = data;
}

public String getName() {
return name;
}

public String getImageID() {
return imageID;
}

public byte[] getData() {
return data;
}

}

private String def(String text, String def) {
return text == null ? def : text;
}

/*
public static void main(String[] args) throws Exception {
XMIImageExporter exporter = new XMIImageExporter();
try (FileInputStream xmiFis = new FileInputStream(new File("D:\\Projects\\validprojects\\Kadaster-Imvertor\\Imvertor-OS-work\\Tasks-GIThub\\xmi\\GIThub-issues.qea.xmi"));
FileOutputStream xmiFos = new FileOutputStream(new File("D:\\Projects\\validprojects\\Kadaster-Imvertor\\Imvertor-OS-work\\Tasks-GIThub\\xmi\\GIThub-issues.qea.out.xmi"))) {
List<Image> images = exporter.export(xmiFis, xmiFos);
for (Image image: images) {
System.out.println(image.name);
System.out.println(image.imageID);
try (FileOutputStream imgFos = new FileOutputStream(new File("D:\\Projects\\validprojects\\Kadaster-Imvertor\\Imvertor-OS-work\\Tasks-GIThub\\xmi\\Images\\" + image.imageID + "_" + image.name))) {
imgFos.write(image.data);
}
}
}
}
*/
}
29 changes: 29 additions & 0 deletions src/main/java/nl/imvertor/XmiCompiler/XmiCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
package nl.imvertor.XmiCompiler;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;

import javax.xml.xpath.XPathConstants;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.w3c.dom.NodeList;

import nl.imvertor.XmiCompiler.XMIImageExporter.Image;
import nl.imvertor.common.Step;
import nl.imvertor.common.Transformer;
import nl.imvertor.common.file.AnyFile;
Expand Down Expand Up @@ -273,11 +278,35 @@ private XmlFile exportEapToXmi(EapFile eapFile, XmlFile xmifile, String projectN
*/
private void cleanXMI(XmlFile xmiFile) throws Exception {

// decode alle images uit content naar de Images folder
extractImages(xmiFile);

// Probeer character fix
String c = xmiFile.getContent();
if (c.contains("&#5"))
xmiFile.setContent(StringUtils.replacePattern(c, "&#5[0-9]{4};", "?"));
}

private void extractImages(XmlFile xmiFile) throws Exception {
XMIImageExporter exporter = new XMIImageExporter();
AnyFile tempFile = new AnyFile(File.createTempFile("extractImages.", ".xmi"));
tempFile.deleteOnExit();
File imageFolder = new File(xmiFile.getParentFile(),"Images");
try (FileInputStream xmiFis = new FileInputStream(xmiFile);
FileOutputStream xmiFos = new FileOutputStream(tempFile)) {
List<Image> images = exporter.export(xmiFis, xmiFos);
for (Image image: images) {
try (FileOutputStream imgFos = new FileOutputStream(new File(imageFolder, image.getImageID() + "_" + image.getName()))) {
imgFos.write(image.getData());
imgFos.close();
}
}
xmiFis.close();
xmiFos.close();
tempFile.copyFile(xmiFile);
}
}

private void migrateXMI(XmlFile xmiFile, String mode) throws Exception {
runner.warn(logger,"This model is subject to migration rules, please consider aligning the model with the metamodel",null,"TMISTMR");
AnyFile outFile = new AnyFile(File.createTempFile("migrateXMI.", ".xmi"));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/imvertor/common/file/AnyFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.FileWriterWithEncoding;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.RegExUtils;

import nl.imvertor.common.Configurator;
import nl.imvertor.common.Transformer;
Expand Down Expand Up @@ -349,7 +349,7 @@ private String getSpecs(AnyFile file) throws IOException {
}

private String cleanXmlPI(String xmlString) {
return StringUtils.removePattern(xmlString, XmlFile.xmlPiRegex);
return RegExUtils.removePattern(xmlString, XmlFile.xmlPiRegex);
}

/*
Expand Down
Loading

0 comments on commit ffacb9e

Please sign in to comment.