I have generated an UML file from a model.xml with UML2 generator.
Now I want to replace the generated ids created in xmi:id="generated id".
Below is a snippet of the generated UML code.
<packagedElement xmi:type="uml:Package" xmi:id="_lAAK0A34Eeap1Y_jd5mZDA" name="java">
<packagedElement xmi:type="uml:Package" xmi:id="_lAAK0Q34Eeap1Y_jd5mZDA" name="lang">
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK0g34Eeap1Y_jd5mZDA" name="String"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK0w34Eeap1Y_jd5mZDA" name="Boolean"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1A34Eeap1Y_jd5mZDA" name="Byte"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1Q34Eeap1Y_jd5mZDA" name="Character"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1g34Eeap1Y_jd5mZDA" name="Double"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1w34Eeap1Y_jd5mZDA" name="Float"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK2A34Eeap1Y_jd5mZDA" name="Integer"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK2Q34Eeap1Y_jd5mZDA" name="Long"/>
<packagedElement xmi:type="uml:DataType" xmi:id="_lAAK2g34Eeap1Y_jd5mZDA" name="Short"/>
</packagedElement>
</packagedElement>
I have tried to use regex to remove the IDs. First I read the file and convert it to a string then I find an pattern with Matcher and try to replace it. One problem is that the gernerated ID's are similar but not the same and i don't know how to tackle this. I guess this doesn't work because it only takes the first?
Path path = profileFile.toPath();
Charset charset = StandardCharsets.UTF_8;
String replaceString = "";
String content = new String(Files.readAllBytes(path), charset);
Pattern pattern = Pattern.compile("xmi:id=\"([A-Za-z0-9_]*)\"");
Matcher matcher = pattern.matcher(content);
if (matcher.find())
{
replaceString = matcher.group(0);
Pattern p = Pattern.compile("\"([^\"]*)\"");
Matcher m = p.matcher(replaceString);
if (m.find())
{
System.out.println("is this the real life: " + m.group(1));
replaceString = m.group(1);
}
}
// content = content.replaceAll("xmi:id=\"([A-Za-z0-9_]*)\"", "xmi:id=\"\"");
content = content.replaceAll(replaceString, "");
Files.write(path, content.getBytes(charset));
Any idea is appreciated, you can just nudge me in the right direction. My brain is a bit blurry right now.
if (matcher.find())
towhile (matcher.find())
content = content.replaceAll(replaceString, "");
insideif (m.find())